* 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 */
| 103 | * a pointer to a struct which is getting saved |
| 104 | */ |
| 105 | static 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 |
no test coverage detected