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

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/registry.h"
00024 
00025 #include "audio/mixer.h"
00026 
00027 #include "common/config-manager.h"
00028 
00029 namespace Grim {
00030 
00031 Registry *g_registry = nullptr;
00032 
00033 // SpewOnError
00034 // GrimLastSet
00035 // JoystickEnabled
00036 // MovementMode
00037 // SpeechMode
00038 // GammaCorrection, Gamma
00039 // GrimDeveloper
00040 // SfxVolume
00041 // MusicVolume
00042 // VoiceVolume
00043 // TextSpeed
00044 // VoiceEffects
00045 // LastSavedGame
00046 // good_times
00047 
00048 void Registry::Value::setString(const Common::String &str) {
00049     _val._str = str;
00050     _type = Registry::String;
00051 }
00052 
00053 void Registry::Value::setInt(int num) {
00054     _val._num = num;
00055     _type = Registry::Integer;
00056 }
00057 
00058 void Registry::Value::setBool(bool val) {
00059     _val._bool = val;
00060     _type = Registry::Boolean;
00061 }
00062 
00063 const Common::String &Registry::Value::getString() const {
00064     assert(_type == Registry::String);
00065     return _val._str;
00066 }
00067 
00068 int Registry::Value::getInt() const {
00069     if (_type == Registry::Integer)
00070         return _val._num;
00071     if (_type == Registry::Boolean)
00072         return _val._bool;
00073 
00074     return atoi(_val._str.c_str());
00075 }
00076 
00077 bool Registry::Value::getBool() const {
00078     if (_type == Registry::Boolean)
00079         return _val._bool;
00080 
00081     if (_type == Registry::Integer)
00082         return _val._num;
00083 
00084     if (_val._str.equalsIgnoreCase("true"))
00085         return true;
00086 
00087     return false;
00088 }
00089 
00090 Registry::ValueType Registry::Value::getType() const {
00091     return _type;
00092 }
00093 
00094 Registry::Registry() :
00095         _dirty(true) {
00096     // Default settings for GRIM
00097     ConfMan.registerDefault("subtitles", true);
00098     ConfMan.registerDefault("talkspeed", 179);
00099     ConfMan.registerDefault("game_devel_mode", false);
00100 
00101     // Read settings
00102     _spewOnError.setString(ConfMan.get("spew_on_error"));
00103     _dataPath.setString(ConfMan.get("path"));
00104     _savePath.setString(ConfMan.get("savepath"));
00105     _develMode.setBool(ConfMan.getBool("game_devel_mode"));
00106     _lastSet.setString(ConfMan.get("last_set"));
00107     _musicVolume.setInt(convertVolumeFromMixer(ConfMan.getInt("music_volume")));
00108     _sfxVolume.setInt(convertVolumeFromMixer(ConfMan.getInt("sfx_volume")));
00109     _voiceVolume.setInt(convertVolumeFromMixer(ConfMan.getInt("speech_volume")));
00110     _lastSavedGame.setString(ConfMan.get("last_saved_game"));
00111     _gamma.setInt(ConfMan.getInt("gamma"));
00112     _textSpeed.setInt(convertTalkSpeedFromGUI(ConfMan.getInt("talkspeed")));
00113     _speechMode.setInt(convertSpeechModeFromGUI(ConfMan.getBool("subtitles"), ConfMan.getBool("speech_mute")));
00114 
00115     // These can't be set as bool because the scripts do a check against "TRUE" and "FALSE".
00116     // Right, they do string comparisons. doh!
00117     _voiceEffects.setString(ConfMan.get("voice_effects"));
00118     _movement.setString(ConfMan.get("movement"));
00119     _joystick.setString(ConfMan.get("joystick"));
00120     _transcript.setString(ConfMan.get("transcript"));
00121 }
00122 
00123 Registry::Value &Registry::value(const Common::String &key) {
00124     if (scumm_stricmp("good_times", key.c_str()) == 0 || scumm_stricmp("GrimDeveloper", key.c_str()) == 0) {
00125         return _develMode;
00126     } else if (scumm_stricmp("GrimDataDir", key.c_str()) == 0) {
00127         return _dataPath;
00128     } else if (scumm_stricmp("savepath", key.c_str()) == 0) {
00129         return _savePath;
00130     } else if (scumm_stricmp("GrimLastSet", key.c_str()) == 0) {
00131         return _lastSet;
00132     } else if (scumm_stricmp("MusicVolume", key.c_str()) == 0) {
00133         return _musicVolume;
00134     } else if (scumm_stricmp("SfxVolume", key.c_str()) == 0) {
00135         return _sfxVolume;
00136     } else if (scumm_stricmp("VoiceVolume", key.c_str()) == 0) {
00137         return _voiceVolume;
00138     } else if (scumm_stricmp("LastSavedGame", key.c_str()) == 0) {
00139         return _lastSavedGame;
00140     } else if (scumm_stricmp("Gamma", key.c_str()) == 0 || scumm_stricmp("GammaCorrection", key.c_str()) == 0) {
00141         return _gamma;
00142     } else if (scumm_stricmp("VoiceEffects", key.c_str()) == 0) {
00143         return _voiceEffects;
00144     } else if (scumm_stricmp("TextSpeed", key.c_str()) == 0) {
00145         return _textSpeed;
00146     } else if (scumm_stricmp("TextMode", key.c_str()) == 0 || scumm_stricmp("SpeechMode", key.c_str()) == 0) {
00147         return _speechMode;
00148     } else if (scumm_stricmp("MovementMode", key.c_str()) == 0) {
00149         return _movement;
00150     } else if (scumm_stricmp("JoystickEnabled", key.c_str()) == 0) {
00151         return _joystick;
00152     } else if (scumm_stricmp("SpewOnError", key.c_str()) == 0) {
00153         return _spewOnError;
00154     } else if (scumm_stricmp("Transcript", key.c_str()) == 0) {
00155         return _transcript;
00156     }
00157 
00158     assert(0);
00159 }
00160 
00161 const Registry::Value &Registry::value(const Common::String &key) const {
00162     if (scumm_stricmp("good_times", key.c_str()) == 0 || scumm_stricmp("GrimDeveloper", key.c_str()) == 0) {
00163         return _develMode;
00164     } else if (scumm_stricmp("GrimDataDir", key.c_str()) == 0) {
00165         return _dataPath;
00166     } else if (scumm_stricmp("savepath", key.c_str()) == 0) {
00167         return _savePath;
00168     } else if (scumm_stricmp("GrimLastSet", key.c_str()) == 0) {
00169         return _lastSet;
00170     } else if (scumm_stricmp("MusicVolume", key.c_str()) == 0) {
00171         return _musicVolume;
00172     } else if (scumm_stricmp("SfxVolume", key.c_str()) == 0) {
00173         return _sfxVolume;
00174     } else if (scumm_stricmp("VoiceVolume", key.c_str()) == 0) {
00175         return _voiceVolume;
00176     } else if (scumm_stricmp("LastSavedGame", key.c_str()) == 0) {
00177         return _lastSavedGame;
00178     } else if (scumm_stricmp("Gamma", key.c_str()) == 0 || scumm_stricmp("GammaCorrection", key.c_str()) == 0) {
00179         return _gamma;
00180     } else if (scumm_stricmp("VoiceEffects", key.c_str()) == 0) {
00181         return _voiceEffects;
00182     } else if (scumm_stricmp("TextSpeed", key.c_str()) == 0) {
00183         return _textSpeed;
00184     } else if (scumm_stricmp("TextMode", key.c_str()) == 0 || scumm_stricmp("SpeechMode", key.c_str()) == 0) {
00185         return _speechMode;
00186     } else if (scumm_stricmp("MovementMode", key.c_str()) == 0) {
00187         return _movement;
00188     } else if (scumm_stricmp("JoystickEnabled", key.c_str()) == 0) {
00189         return _joystick;
00190     } else if (scumm_stricmp("SpewOnError", key.c_str()) == 0) {
00191         return _spewOnError;
00192     } else if (scumm_stricmp("Transcript", key.c_str()) == 0) {
00193         return _transcript;
00194     }
00195 
00196     assert(0);
00197 }
00198 
00199 const Common::String &Registry::getString(const Common::String &key) const {
00200     return value(key).getString();
00201 }
00202 
00203 int Registry::getInt(const Common::String &key) const {
00204     return value(key).getInt();
00205 }
00206 
00207 bool Registry::getBool(const Common::String &key) const {
00208     return value(key).getBool();
00209 }
00210 
00211 void Registry::setString(const Common::String &key, const Common::String &val) {
00212     _dirty = true;
00213     value(key).setString(val);
00214 }
00215 
00216 void Registry::setInt(const Common::String &key, int val) {
00217     _dirty = true;
00218     value(key).setInt(val);
00219 }
00220 
00221 void Registry::setBool(const Common::String &key, bool val) {
00222     _dirty = true;
00223     value(key).setBool(val);
00224 }
00225 
00226 Registry::ValueType Registry::getValueType(const Common::String &key) const {
00227     return value(key).getType();
00228 }
00229 
00230 void Registry::save() {
00231     if (!_dirty)
00232         return;
00233 
00234     ConfMan.set("spew_on_error", _spewOnError.getString());
00235     ConfMan.set("path", _dataPath.getString());
00236     ConfMan.set("savepath", _savePath.getString());
00237     ConfMan.set("last_set", _lastSet.getString());
00238     ConfMan.setBool("game_devel_mode", _develMode.getBool());
00239     ConfMan.setInt("music_volume", convertVolumeToMixer(_musicVolume.getInt()));
00240     ConfMan.setInt("sfx_volume", convertVolumeToMixer(_sfxVolume.getInt()));
00241     ConfMan.setInt("speech_volume", convertVolumeToMixer(_voiceVolume.getInt()));
00242     ConfMan.set("last_saved_game", _lastSavedGame.getString());
00243     ConfMan.setInt("gamma", _gamma.getInt());
00244     ConfMan.setInt("talkspeed", convertTalkSpeedToGUI(_textSpeed.getInt()));
00245     ConfMan.setBool("subtitles", convertSubtitlesToGUI(_speechMode.getInt()));
00246     ConfMan.setBool("speech_mute", convertSpeechMuteToGUI(_speechMode.getInt()));
00247 
00248     ConfMan.set("movement", _movement.getString());
00249     ConfMan.set("joystick", _joystick.getString());
00250     ConfMan.set("voice_effects", _voiceEffects.getString());
00251     ConfMan.set("transcript", _transcript.getString());
00252 
00253     _dirty = false;
00254 }
00255 
00256 uint Registry::convertVolumeToMixer(uint grimVolume) {
00257     return CLIP<uint>(grimVolume * 2, 0, Audio::Mixer::kMaxMixerVolume);
00258 }
00259 
00260 uint Registry::convertVolumeFromMixer(uint volume) {
00261     return CLIP<uint>(volume / 2, 0, 127);
00262 }
00263 
00264 uint Registry::convertTalkSpeedToGUI(uint talkspeed) {
00265     return CLIP<uint>(talkspeed * 255 / 10, 0, 255);
00266 }
00267 
00268 uint Registry::convertTalkSpeedFromGUI(uint talkspeed) {
00269     return CLIP<uint>(talkspeed * 10 / 255, 1, 10);
00270 }
00271 
00272 bool Registry::convertSubtitlesToGUI(uint speechmode) {
00273     return speechmode == 1 || speechmode == 3;
00274 }
00275 
00276 bool Registry::convertSpeechMuteToGUI(uint speechmode) {
00277     return speechmode == 1;
00278 }
00279 
00280 uint Registry::convertSpeechModeFromGUI(bool subtitles, bool speechMute) {
00281     if (!subtitles && !speechMute) // Speech only
00282         return 2;
00283     else if (subtitles && !speechMute) // Speech and subtitles
00284         return 3;
00285     else if (subtitles && speechMute) // Subtitles only
00286         return 1;
00287     else
00288         warning("Wrong configuration: Both subtitles and speech are off. Assuming subtitles only");
00289     return 1;
00290 }
00291 
00292 } // end of namespace Grim


Generated on Sat May 25 2019 05:00:51 for ResidualVM by doxygen 1.7.1
curved edge   curved edge