summaryrefslogtreecommitdiff
path: root/src/saveload
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-07-09 21:16:03 +0200
committerGitHub <noreply@github.com>2021-07-09 21:16:03 +0200
commit8f5d0ecde39cbaf2ac1a6d27e82239bfc3bf1515 (patch)
tree232daba5b6f77f8ae33191c0b88dd21ef662a1c1 /src/saveload
parentd9ca9ca55571829af88429147e20bf0734e07e2d (diff)
downloadopenttd-8f5d0ecde39cbaf2ac1a6d27e82239bfc3bf1515.tar.xz
Codechange: split settings.ini over several files (#9421)
This reduced the load on compilers, as currently for example MacOS doesn't like the huge settings-tables. Additionally, nobody can find settings, as the list is massive and unordered. By splitting it, it becomes a little bit more sensible.
Diffstat (limited to 'src/saveload')
-rw-r--r--src/saveload/linkgraph_sl.cpp4
-rw-r--r--src/saveload/settings_sl.cpp37
2 files changed, 35 insertions, 6 deletions
diff --git a/src/saveload/linkgraph_sl.cpp b/src/saveload/linkgraph_sl.cpp
index e1094326b..ae21de4c7 100644
--- a/src/saveload/linkgraph_sl.cpp
+++ b/src/saveload/linkgraph_sl.cpp
@@ -17,6 +17,7 @@
#include "../linkgraph/linkgraphschedule.h"
#include "../network/network.h"
#include "../settings_internal.h"
+#include "../settings_table.h"
#include "../safeguards.h"
@@ -165,7 +166,6 @@ public:
SaveLoadTable GetLinkGraphJobDesc()
{
static std::vector<SaveLoad> saveloads;
- static const char *prefix = "linkgraph.";
static const SaveLoad job_desc[] = {
SLE_VAR(LinkGraphJob, join_date, SLE_INT32),
@@ -184,7 +184,7 @@ SaveLoadTable GetLinkGraphJobDesc()
/* Build the SaveLoad array on first call and don't touch it later on */
if (saveloads.size() == 0) {
- GetSettingSaveLoadByPrefix(prefix, saveloads);
+ GetSaveLoadFromSettingTable(_linkgraph_settings, saveloads);
for (auto &sl : saveloads) {
sl.address_proc = proc;
diff --git a/src/saveload/settings_sl.cpp b/src/saveload/settings_sl.cpp
index 59b00e0f0..f19ff910c 100644
--- a/src/saveload/settings_sl.cpp
+++ b/src/saveload/settings_sl.cpp
@@ -151,7 +151,7 @@ struct OPTSChunkHandler : ChunkHandler {
* a networking environment. This ensures for example that the local
* autosave-frequency stays when joining a network-server */
PrepareOldDiffCustom();
- LoadSettings(_gameopt_settings, &_settings_game, _gameopt_sl_compat);
+ LoadSettings(_old_gameopt_settings, &_settings_game, _gameopt_sl_compat);
HandleOldDiffCustom(true);
}
};
@@ -159,22 +159,51 @@ struct OPTSChunkHandler : ChunkHandler {
struct PATSChunkHandler : ChunkHandler {
PATSChunkHandler() : ChunkHandler('PATS', CH_TABLE) {}
+ /**
+ * Create a single table with all settings that should be stored/loaded
+ * in the savegame.
+ */
+ SettingTable GetSettingTable() const
+ {
+ static const SettingTable saveload_settings_tables[] = {
+ _difficulty_settings,
+ _economy_settings,
+ _game_settings,
+ _linkgraph_settings,
+ _locale_settings,
+ _pathfinding_settings,
+ _script_settings,
+ _world_settings,
+ };
+ static std::vector<SettingVariant> settings_table;
+
+ if (settings_table.empty()) {
+ for (auto &saveload_settings_table : saveload_settings_tables) {
+ for (auto &saveload_setting : saveload_settings_table) {
+ settings_table.push_back(saveload_setting);
+ }
+ }
+ }
+
+ return settings_table;
+ }
+
void Load() const override
{
/* Copy over default setting since some might not get loaded in
* a networking environment. This ensures for example that the local
* currency setting stays when joining a network-server */
- LoadSettings(_settings, &_settings_game, _settings_sl_compat);
+ LoadSettings(this->GetSettingTable(), &_settings_game, _settings_sl_compat);
}
void LoadCheck(size_t) const override
{
- LoadSettings(_settings, &_load_check_data.settings, _settings_sl_compat);
+ LoadSettings(this->GetSettingTable(), &_load_check_data.settings, _settings_sl_compat);
}
void Save() const override
{
- SaveSettings(_settings, &_settings_game);
+ SaveSettings(this->GetSettingTable(), &_settings_game);
}
};