diff options
author | Rubidium <rubidium@openttd.org> | 2021-07-08 19:26:21 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-07-09 22:53:30 +0200 |
commit | ede3f79475bc987a154783b874619c16d1aa643c (patch) | |
tree | 23dba03edf74c3f245cdae5c080d1fdfffc69501 | |
parent | 01139d33686945db4ccb77b62acadf2caab3b93e (diff) | |
download | openttd-ede3f79475bc987a154783b874619c16d1aa643c.tar.xz |
Codechange: use the name string in SaveLoad for the name of the Setting as well
-rw-r--r-- | src/saveload/settings_sl.cpp | 6 | ||||
-rw-r--r-- | src/settings_internal.h | 35 | ||||
-rw-r--r-- | src/table/settings.h.preamble | 24 |
3 files changed, 29 insertions, 36 deletions
diff --git a/src/saveload/settings_sl.cpp b/src/saveload/settings_sl.cpp index a93979238..1b1db8fa6 100644 --- a/src/saveload/settings_sl.cpp +++ b/src/saveload/settings_sl.cpp @@ -89,11 +89,7 @@ static std::vector<SaveLoad> GetSettingsDesc(const SettingTable &settings, bool continue; } - SaveLoad sv = sd->save; - /* Replace the name with the actual name of the setting. */ - assert(!sd->GetName().empty()); - sv.name = sd->GetName(); - saveloads.push_back(sv); + saveloads.push_back(sd->save); } return saveloads; diff --git a/src/settings_internal.h b/src/settings_internal.h index f48245af4..75b520222 100644 --- a/src/settings_internal.h +++ b/src/settings_internal.h @@ -70,13 +70,10 @@ struct IniItem; /** Properties of config file settings. */ struct SettingDesc { - SettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup) : - name(name), flags(flags), startup(startup), save(save) {} + SettingDesc(SaveLoad save, SettingFlag flags, bool startup) : + flags(flags), startup(startup), save(save) {} virtual ~SettingDesc() {} -private: - std::string name; ///< Name of the setting. Used in configuration file and for console. -public: SettingFlag flags; ///< Handles how a setting would show up in the GUI (text/currency, etc.). bool startup; ///< Setting has to be loaded directly at startup?. SaveLoad save; ///< Internal structure (going to savegame, parts to config). @@ -90,7 +87,7 @@ public: */ constexpr const std::string &GetName() const { - return this->name; + return this->save.name; } /** @@ -152,10 +149,10 @@ struct IntSettingDesc : SettingDesc { */ typedef void PostChangeCallback(int32 value); - IntSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, int32 def, + IntSettingDesc(SaveLoad save, SettingFlag flags, bool startup, int32 def, int32 min, uint32 max, int32 interval, StringID str, StringID str_help, StringID str_val, SettingCategory cat, PreChangeCheck pre_check, PostChangeCallback post_callback) : - SettingDesc(save, name, flags, startup), def(def), min(min), max(max), interval(interval), + SettingDesc(save, flags, startup), def(def), min(min), max(max), interval(interval), str(str), str_help(str_help), str_val(str_val), cat(cat), pre_check(pre_check), post_callback(post_callback) {} virtual ~IntSettingDesc() {} @@ -194,10 +191,10 @@ private: /** Boolean setting. */ struct BoolSettingDesc : IntSettingDesc { - BoolSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, bool def, + BoolSettingDesc(SaveLoad save, SettingFlag flags, bool startup, bool def, StringID str, StringID str_help, StringID str_val, SettingCategory cat, PreChangeCheck pre_check, PostChangeCallback post_callback) : - IntSettingDesc(save, name, flags, startup, def, 0, 1, 0, str, str_help, str_val, cat, + IntSettingDesc(save, flags, startup, def, 0, 1, 0, str, str_help, str_val, cat, pre_check, post_callback) {} virtual ~BoolSettingDesc() {} @@ -210,11 +207,11 @@ struct BoolSettingDesc : IntSettingDesc { struct OneOfManySettingDesc : IntSettingDesc { typedef size_t OnConvert(const char *value); ///< callback prototype for conversion error - OneOfManySettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, int32 def, + OneOfManySettingDesc(SaveLoad save, SettingFlag flags, bool startup, int32 def, int32 max, StringID str, StringID str_help, StringID str_val, SettingCategory cat, PreChangeCheck pre_check, PostChangeCallback post_callback, std::initializer_list<const char *> many, OnConvert *many_cnvt) : - IntSettingDesc(save, name, flags, startup, def, 0, max, 0, str, str_help, str_val, cat, + IntSettingDesc(save, flags, startup, def, 0, max, 0, str, str_help, str_val, cat, pre_check, post_callback), many_cnvt(many_cnvt) { for (auto one : many) this->many.push_back(one); @@ -234,11 +231,11 @@ struct OneOfManySettingDesc : IntSettingDesc { /** Many of many setting. */ struct ManyOfManySettingDesc : OneOfManySettingDesc { - ManyOfManySettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, + ManyOfManySettingDesc(SaveLoad save, SettingFlag flags, bool startup, int32 def, StringID str, StringID str_help, StringID str_val, SettingCategory cat, PreChangeCheck pre_check, PostChangeCallback post_callback, std::initializer_list<const char *> many, OnConvert *many_cnvt) : - OneOfManySettingDesc(save, name, flags, startup, def, (1 << many.size()) - 1, str, str_help, + OneOfManySettingDesc(save, flags, startup, def, (1 << many.size()) - 1, str, str_help, str_val, cat, pre_check, post_callback, many, many_cnvt) {} virtual ~ManyOfManySettingDesc() {} @@ -263,9 +260,9 @@ struct StringSettingDesc : SettingDesc { */ typedef void PostChangeCallback(const std::string &value); - StringSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, const char *def, + StringSettingDesc(SaveLoad save, SettingFlag flags, bool startup, const char *def, uint32 max_length, PreChangeCheck pre_check, PostChangeCallback post_callback) : - SettingDesc(save, name, flags, startup), def(def == nullptr ? "" : def), max_length(max_length), + SettingDesc(save, flags, startup), def(def == nullptr ? "" : def), max_length(max_length), pre_check(pre_check), post_callback(post_callback) {} virtual ~StringSettingDesc() {} @@ -289,8 +286,8 @@ private: /** List/array settings. */ struct ListSettingDesc : SettingDesc { - ListSettingDesc(SaveLoad save, const char *name, SettingFlag flags, bool startup, const char *def) : - SettingDesc(save, name, flags, startup), def(def) {} + ListSettingDesc(SaveLoad save, SettingFlag flags, bool startup, const char *def) : + SettingDesc(save, flags, startup), def(def) {} virtual ~ListSettingDesc() {} const char *def; ///< default value given when none is present @@ -303,7 +300,7 @@ struct ListSettingDesc : SettingDesc { /** Placeholder for settings that have been removed, but might still linger in the savegame. */ struct NullSettingDesc : SettingDesc { NullSettingDesc(SaveLoad save) : - SettingDesc(save, "", SF_NOT_IN_CONFIG, false) {} + SettingDesc(save, SF_NOT_IN_CONFIG, false) {} virtual ~NullSettingDesc() {} void FormatValue(char *buf, const char *last, const void *object) const override { NOT_REACHED(); } diff --git a/src/table/settings.h.preamble b/src/table/settings.h.preamble index 032714baf..dca29cf88 100644 --- a/src/table/settings.h.preamble +++ b/src/table/settings.h.preamble @@ -57,42 +57,42 @@ static size_t ConvertLandscape(const char *value); /* Macros for various objects to go in the configuration file. * This section is for global variables */ #define SDTG_VAR(name, type, flags, var, def, min, max, interval, str, strhelp, strval, pre_check, post_callback, from, to, cat, extra, startup)\ - NSD(Int, SLEG_GENERAL(#var, SL_VAR, var, type, 1, from, to, extra), name, flags, startup, def, min, max, interval, str, strhelp, strval, cat, pre_check, post_callback) + NSD(Int, SLEG_GENERAL(name, SL_VAR, var, type, 1, from, to, extra), flags, startup, def, min, max, interval, str, strhelp, strval, cat, pre_check, post_callback) #define SDTG_BOOL(name, flags, var, def, str, strhelp, strval, pre_check, post_callback, from, to, cat, extra, startup)\ - NSD(Bool, SLEG_GENERAL(#var, SL_VAR, var, SLE_BOOL, 1, from, to, extra), name, flags, startup, def, str, strhelp, strval, cat, pre_check, post_callback) + NSD(Bool, SLEG_GENERAL(name, SL_VAR, var, SLE_BOOL, 1, from, to, extra), flags, startup, def, str, strhelp, strval, cat, pre_check, post_callback) #define SDTG_LIST(name, type, flags, var, def, length, from, to, cat, extra, startup)\ - NSD(List, SLEG_GENERAL(#var, SL_ARR, var, type, length, from, to, extra), name, flags, startup, def) + NSD(List, SLEG_GENERAL(name, SL_ARR, var, type, length, from, to, extra),flags, startup, def) #define SDTG_SSTR(name, type, flags, var, def, max_length, pre_check, post_callback, from, to, cat, extra, startup)\ - NSD(String, SLEG_GENERAL(#var, SL_STDSTR, var, type, sizeof(var), from, to, extra), name, flags, startup, def, max_length, pre_check, post_callback) + NSD(String, SLEG_GENERAL(name, SL_STDSTR, var, type, sizeof(var), from, to, extra), flags, startup, def, max_length, pre_check, post_callback) #define SDTG_OMANY(name, type, flags, var, def, max, full, str, strhelp, strval, pre_check, post_callback, from, to, cat, extra, startup)\ - NSD(OneOfMany, SLEG_GENERAL(#var, SL_VAR, var, type, 1, from, to, extra), name, flags, startup, def, max, str, strhelp, strval, cat, pre_check, post_callback, full, nullptr) + NSD(OneOfMany, SLEG_GENERAL(name, SL_VAR, var, type, 1, from, to, extra), flags, startup, def, max, str, strhelp, strval, cat, pre_check, post_callback, full, nullptr) #define SDTG_MMANY(name, type, flags, var, def, full, str, strhelp, strval, pre_check, post_callback, from, to, cat, extra, startup)\ - NSD(ManyOfMany, SLEG_GENERAL(#var, SL_VAR, var, type, 1, from, to, extra), name, flags, startup, def, str, strhelp, strval, cat, pre_check, post_callback, full, nullptr) + NSD(ManyOfMany, SLEG_GENERAL(name, SL_VAR, var, type, 1, from, to, extra), flags, startup, def, str, strhelp, strval, cat, pre_check, post_callback, full, nullptr) /* Macros for various objects to go in the configuration file. * This section is for structures where their various members are saved */ #define SDT_VAR(base, var, type, flags, def, min, max, interval, str, strhelp, strval, pre_check, post_callback, from, to, cat, extra, startup)\ - NSD(Int, SLE_GENERAL(SL_VAR, base, var, type, 1, from, to, extra), #var, flags, startup, def, min, max, interval, str, strhelp, strval, cat, pre_check, post_callback) + NSD(Int, SLE_GENERAL(SL_VAR, base, var, type, 1, from, to, extra), flags, startup, def, min, max, interval, str, strhelp, strval, cat, pre_check, post_callback) #define SDT_BOOL(base, var, flags, def, str, strhelp, strval, pre_check, post_callback, from, to, cat, extra, startup)\ - NSD(Bool, SLE_GENERAL(SL_VAR, base, var, SLE_BOOL, 1, from, to, extra), #var, flags, startup, def, str, strhelp, strval, cat, pre_check, post_callback) + NSD(Bool, SLE_GENERAL(SL_VAR, base, var, SLE_BOOL, 1, from, to, extra), flags, startup, def, str, strhelp, strval, cat, pre_check, post_callback) #define SDT_LIST(base, var, type, flags, def, from, to, cat, extra, startup)\ - NSD(List, SLE_GENERAL(SL_ARR, base, var, type, lengthof(((base*)8)->var), from, to, extra), #var, flags, startup, def) + NSD(List, SLE_GENERAL(SL_ARR, base, var, type, lengthof(((base*)8)->var), from, to, extra), flags, startup, def) #define SDT_SSTR(base, var, type, flags, def, pre_check, post_callback, from, to, cat, extra, startup)\ - NSD(String, SLE_GENERAL(SL_STDSTR, base, var, type, sizeof(((base*)8)->var), from, to, extra), #var, flags, startup, def, 0, pre_check, post_callback) + NSD(String, SLE_GENERAL(SL_STDSTR, base, var, type, sizeof(((base*)8)->var), from, to, extra), flags, startup, def, 0, pre_check, post_callback) #define SDT_OMANY(base, var, type, flags, def, max, full, str, strhelp, strval, pre_check, post_callback, from, to, load, cat, extra, startup)\ - NSD(OneOfMany, SLE_GENERAL(SL_VAR, base, var, type, 1, from, to, extra), #var, flags, startup, def, max, str, strhelp, strval, cat, pre_check, post_callback, full, load) + NSD(OneOfMany, SLE_GENERAL(SL_VAR, base, var, type, 1, from, to, extra), flags, startup, def, max, str, strhelp, strval, cat, pre_check, post_callback, full, load) #define SDT_MMANY(base, var, type, flags, def, full, str, pre_check, post_callback, strhelp, strval, from, to, cat, extra, startup)\ - NSD(ManyOfMany, SLE_GENERAL(SL_VAR, base, var, type, 1, from, to, extra), #var, flags, startup, def, str, strhelp, strval, cat, pre_check, post_callback, full, nullptr) + NSD(ManyOfMany, SLE_GENERAL(SL_VAR, base, var, type, 1, from, to, extra), flags, startup, def, str, strhelp, strval, cat, pre_check, post_callback, full, nullptr) #define SDTC_VAR(var, type, flags, def, min, max, interval, str, strhelp, strval, pre_check, post_callback, from, to, cat, extra, startup)\ |