ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

emi_registry.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/grim/emi/emi_registry.h"
00024 #include "engines/grim/debug.h"
00025 
00026 #include "audio/mixer.h"
00027 
00028 #include "common/config-manager.h"
00029 
00030 namespace Grim {
00031 
00032 EmiRegistry *g_emiregistry = nullptr;
00033 
00034 const char *EmiRegistry::_translTable[][2] = {
00035     {"speech_mode",     ""},    //Translated key not needed, see below
00036     {"vocvolume",       "speech_volume"},
00037     {"sfxvolume",       "sfx_volume"},
00038     {"musvolume",       "music_volume"},
00039     {"textspeed",       "talkspeed"},
00040     {"gamma",           "gamma"},
00041     {"joystick_enabled","joystick_enabled"},
00042     {"analog_mode",     "analog_joystick_mode"},
00043     {"subtitles",       "movie_subtitles"},
00044     {"camera_mode",     "camera_relative_mode"},
00045     {"shadowfx",        "shadow_effects"},
00046     {"vocfx",           "audio_effects"},
00047     {"miscfx",          "misc_video_effects"},
00048     {"moviequality",    "movie_quality"},
00049     {"musicquality",    "music_quality"},
00050     {nullptr,nullptr}
00051 };
00052 
00053 const char *EmiRegistry::_boolValues[] = {
00054     "joystick_enabled",
00055     "analog_mode",
00056     "subtitles",
00057     "camera_mode",
00058     "vocfx",
00059     "moviequality",
00060     "musicquality",
00061     nullptr
00062 };
00063 
00064 
00065 EmiRegistry::EmiRegistry() {
00066     int i = 0;
00067     while (_translTable[i][0] != nullptr) {
00068         _transMap[_translTable[i][0]] = _translTable[i][1];
00069         ++i;
00070     }
00071 
00072     i = 0;
00073     while (_boolValues[i] != nullptr) {
00074         _boolSet[_boolValues[i]] = true;
00075         ++i;
00076     }
00077 }
00078 
00079 uint EmiRegistry::convertTalkSpeedToGUI(uint talkspeed) const {
00080     return CLIP<uint>(talkspeed * 255 / 10, 0, 255);
00081 }
00082 
00083 uint EmiRegistry::convertTalkSpeedFromGUI(uint talkspeed) const {
00084     return CLIP<uint>(talkspeed * 10 / 255, 1, 10);
00085 }
00086 
00087 const Common::String EmiRegistry::convertGammaToRegistry(float gamma) const {
00088     return Common::String().format("%.2f", gamma);
00089 }
00090 
00091 float EmiRegistry::convertGammaFromRegistry(const Common::String &gamma) const {
00092     float gamma_f;
00093     sscanf(gamma.c_str(), "%f", &gamma_f);
00094     return CLIP<float>(gamma_f, 0.5, 1.5);
00095 }
00096 
00097 uint EmiRegistry::convertVolumeToMixer(uint emiVolume) const {
00098     float vol = float(emiVolume - 25)/(100 - 25)*Audio::Mixer::kMaxMixerVolume;
00099     return CLIP<uint>(uint(vol), 0, Audio::Mixer::kMaxMixerVolume);
00100 }
00101 
00102 uint EmiRegistry::convertVolumeFromMixer(uint volume) const {
00103     float vol = float(volume)*(100 - 25)/Audio::Mixer::kMaxMixerVolume + 25;
00104     return CLIP<uint>(uint(vol), 0, Audio::Mixer::kMaxMixerVolume);
00105 }
00106 
00107 uint EmiRegistry::convertSpeechModeFromGUI(bool subtitles, bool speechMute) const {
00108     if (!subtitles && !speechMute) // Speech only
00109         return 2;
00110     else if (subtitles && !speechMute) // Speech and subtitles
00111         return 3;
00112     else if (subtitles && speechMute) // Subtitles only
00113         return 1;
00114     else
00115         warning("Wrong configuration: Both subtitles and speech are off. Assuming subtitles only");
00116     return 1;
00117 }
00118 
00119 bool EmiRegistry::Get(const Common::String key, float &res) const {
00120     Debug::debug(Debug::Engine, "GetResidualVMPreference(%s)", key.c_str());
00121 
00122     if (!_transMap.contains(key))
00123         return false;
00124 
00125     res = 0.;
00126 
00127     if (key == "speech_mode") {
00128         if (!(ConfMan.hasKey("subtitles") && ConfMan.hasKey("speech_mute")))
00129             return false;
00130 
00131         res = convertSpeechModeFromGUI(ConfMan.getBool("subtitles"), ConfMan.getBool("speech_mute"));
00132     } else {
00133         if (!(ConfMan.hasKey(_transMap[key])))
00134             return false;
00135 
00136         if (key == "vocvolume" || key == "sfxvolume" || key == "musvolume")
00137             res = convertVolumeFromMixer(ConfMan.getInt(_transMap[key]));
00138         else if (key == "textspeed")
00139             res = convertTalkSpeedFromGUI(ConfMan.getInt(_transMap[key]));
00140         else if (key == "gamma")
00141             res = convertGammaFromRegistry(ConfMan.get(_transMap[key]));
00142         else if (key == "shadowfx")
00143             res = ConfMan.getBool(_transMap[key]) + 1;
00144         else if (_boolSet.contains(key))
00145             res = ConfMan.getBool(_transMap[key]);
00146         else
00147             res = ConfMan.getInt(_transMap[key]);
00148     }
00149 
00150     Debug::debug(Debug::Engine, "Pushing %f", res);
00151     return true;
00152 }
00153 
00154 void EmiRegistry::Set(const Common::String key, float &value)  {
00155     Debug::debug(Debug::Engine, "SetResidualVMPreference(%s, %f)", key.c_str(), value);
00156 
00157     if (!_transMap.contains(key))
00158         return;
00159 
00160     uint value_i = uint(value);
00161 
00162     if (key == "speech_mode") {
00163         ConfMan.setBool("subtitles", (value_i == 1 || value_i == 3));
00164         ConfMan.setBool("speech_mute", (value_i == 1));
00165     } else if (key == "vocvolume" || key == "sfxvolume" || key == "musvolume")
00166         ConfMan.setInt(_transMap[key], convertVolumeToMixer(value_i));
00167     else if (key == "textspeed")
00168         ConfMan.setInt(_transMap[key], convertTalkSpeedToGUI(value_i));
00169     else if (key == "gamma")
00170         ConfMan.set(_transMap[key], convertGammaToRegistry(value));
00171     else if (key == "shadowfx")
00172         ConfMan.setBool(_transMap[key], (value_i == 2));
00173     else if (_boolSet.contains(key))
00174         ConfMan.setBool(_transMap[key], (value_i == 1));
00175     else
00176         ConfMan.setInt(_transMap[key], value_i);
00177 }
00178 
00179 } // end of namespace Grim


Generated on Sat Mar 23 2019 05:01:34 for ResidualVM by doxygen 1.7.1
curved edge   curved edge