MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / LoadSettings

Function LoadSettings

src/saveload/settings_sl.cpp:105–125  ·  view source on GitHub ↗

* Save and load handler for settings * @param settings SettingDesc struct containing all information * @param object can be either nullptr in which case we load global variables or * a pointer to a struct which is getting saved */

Source from the content-addressed store, hash-verified

103 * a pointer to a struct which is getting saved
104 */
105static void LoadSettings(const SettingTable &settings, void *object, const SaveLoadCompatTable &slct)
106{
107 const std::vector<SaveLoad> slt = SlCompatTableHeader(GetSettingsDesc(settings, true), slct);
108
109 if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() == -1) return;
110 SlObject(object, slt);
111 if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() != -1) SlErrorCorrupt("Too many settings entries");
112
113 /* Ensure all IntSettings are valid (min/max could have changed between versions etc). */
114 for (auto &desc : settings) {
115 const SettingDesc *sd = GetSettingDesc(desc);
116 if (sd->flags.Test(SettingFlag::NotInSave)) continue;
117 if (sd->flags.Test(SettingFlag::NoNetworkSync) && _networking && !_network_server) continue;
118 if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
119
120 if (sd->IsIntSetting()) {
121 const IntSettingDesc *int_setting = sd->AsIntSetting();
122 int_setting->MakeValueValidAndWrite(object, int_setting->Read(object));
123 }
124 }
125}
126
127/**
128 * Save and load handler for settings

Callers 3

LoadMethod · 0.85
LoadMethod · 0.85
LoadCheckMethod · 0.85

Calls 13

SlCompatTableHeaderFunction · 0.85
GetSettingsDescFunction · 0.85
IsSavegameVersionBeforeFunction · 0.85
SlIterateArrayFunction · 0.85
SlObjectFunction · 0.85
SlErrorCorruptFunction · 0.85
GetSettingDescFunction · 0.85
SlIsObjectCurrentlyValidFunction · 0.85
TestMethod · 0.80
AsIntSettingMethod · 0.80
IsIntSettingMethod · 0.45

Tested by

no test coverage detected