summaryrefslogtreecommitdiff
path: root/settings.c
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2006-03-02 00:32:48 +0000
committerDarkvater <Darkvater@openttd.org>2006-03-02 00:32:48 +0000
commita9d33943d734671990920fc093d0025845479370 (patch)
tree6ad37c31a548b6c9554beca6f072de8478242d16 /settings.c
parent85e0d9c967a920db518be78de77a68d1714850a8 (diff)
downloadopenttd-a9d33943d734671990920fc093d0025845479370.tar.xz
(svn r3721) - [3/4] Present the game with a unified structure for the configuration-ini, saveload, console and gui representations of the settings. From part 3 on, OpenTTD is once again compilable.
- Code has been added to the saveload code to honour the SLF_SAVE_NO and SLF_NETWORK_NO flags. SLF_NETWORK_NO just reads in the the bytestream and then discards it because that setting is not synchronised. For this the function SlSkipBytes() has been reinstated - SAVEGAME_VERSION has been changed from a constant ENUM to a constant integer. This was done for the configuration-code to be able to tell which version of a CONDVAR type to handle. As said before, because settings can be saved to the savegame, they will become conditional at some point. The configuration code always has to read the 'most recent' version. - GameOptions are saved through the new structure. It is fully compatible with any old savegame...however it is better. Because of the move to this new format we can instruct the loader to skip certain variables. Autosave for example isn't synchronised anymore (in the network). The same goes for currency and kilometers :D. That is the only functionality change this patch is supposed to have if I have written it correctly. - NOTE! Patches are still not saved so for Multiplayer to work network_client.c and network_server.c needed slight modifications.
Diffstat (limited to 'settings.c')
-rw-r--r--settings.c70
1 files changed, 69 insertions, 1 deletions
diff --git a/settings.c b/settings.c
index 351d50e7b..862155dc6 100644
--- a/settings.c
+++ b/settings.c
@@ -609,6 +609,8 @@ static void ini_load_settings(IniFile *ini, const SettingDesc *sd, const char *g
const SettingDescBase *sdb = &sd->desc;
const SaveLoad *sld = &sd->save;
+ if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
+
// XXX - wtf is this?? (group override?)
s = strchr(sdb->name, '.');
if (s != NULL) {
@@ -673,6 +675,7 @@ static void ini_save_settings(IniFile *ini, const SettingDesc *sd, const char *g
/* If the setting is not saved to the configuration
* file, just continue with the next setting */
+ if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
if (sld->conv & SLF_CONFIG_NO) continue;
// XXX - wtf is this?? (group override?)
@@ -1252,6 +1255,71 @@ void SaveToConfig(void)
ini_free(ini);
}
+/** Save and load handler for patches/settings
+ * @param osd SettingDesc struct containing all information
+ * @param object can be either NULL in which case we load global variables or
+ * a pointer to a struct which is getting saved */
+static void LoadSettings(const SettingDesc *osd, void *object)
+{
+ for (; osd->save.cmd != SL_END; osd++) {
+ const SaveLoad *sld = &osd->save;
+ void *ptr = ini_get_variable(sld, object);
+
+ if (!SlObjectMember(ptr, sld)) continue;
+ }
+}
+
+/** Loadhandler for a list of global variables
+ * @note this is actually a stub for LoadSettings with the
+ * object pointer set to NULL */
+static inline void LoadSettingsGlobList(const SettingDescGlobVarList *sdg)
+{
+ LoadSettings((const SettingDesc*)sdg, NULL);
+}
+
+/** Save and load handler for patches/settings
+ * @param osd SettingDesc struct containing all information
+ * @param object can be either NULL in which case we load global variables or
+ * a pointer to a struct which is getting saved */
+static void SaveSettings(const SettingDesc *sd, void *object)
+{
+ /* We need to write the CH_RIFF header, but unfortunately can't call
+ * SlCalcLength() because we have a different format. So do this manually */
+ const SettingDesc *i;
+ size_t length = 0;
+ for (i = sd; i->save.cmd != SL_END; i++) {
+ length += SlCalcObjMemberLength(&i->save);
+ }
+ SlSetLength(length);
+
+ for (i = sd; i->save.cmd != SL_END; i++) {
+ void *ptr = ini_get_variable(&i->save, object);
+ SlObjectMember(ptr, &i->save);
+ }
+}
+
+/** Savehandler for a list of global variables
+ * @note this is actually a stub for SaveSettings with the
+ * object pointer set to NULL */
+static inline void SaveSettingsGlobList(const SettingDescGlobVarList *sdg)
+{
+ SaveSettings((const SettingDesc*)sdg, NULL);
+}
+
+static void Load_OPTS(void)
+{
+ /* Copy over default setting since some might not get loaded in
+ * a networking environment. This ensures for example that the local
+ * autosave-frequency stays when joining a network-server */
+ _opt = _opt_newgame;
+ LoadSettings(_gameopt_settings, &_opt);
+}
+
+static void Save_OPTS(void)
+{
+ SaveSettings(_gameopt_settings, &_opt);
+}
+
void CheckConfig(void)
{
// fix up news_display_opt from old to new
@@ -1273,5 +1341,5 @@ void CheckConfig(void)
}
const ChunkHandler _setting_chunk_handlers[] = {
- { 'OPTS', SaveLoad_OPTS, SaveLoad_OPTS, CH_RIFF | CH_LAST}
+ { 'OPTS', Save_OPTS, Load_OPTS, CH_RIFF | CH_LAST}
};