Codechange: Allow early-load settings that are not misc settings.
This commit is contained in:
@@ -86,7 +86,7 @@ typedef std::list<ErrorMessageData> ErrorList;
|
||||
static ErrorList _settings_error_list; ///< Errors while loading minimal settings.
|
||||
|
||||
|
||||
typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const char *grpname, void *object);
|
||||
typedef void SettingDescProc(IniFile *ini, const SettingDesc *desc, const char *grpname, void *object, bool only_startup);
|
||||
typedef void SettingDescProcList(IniFile *ini, const char *grpname, StringList &list);
|
||||
|
||||
static bool IsSignedVarMemType(VarType vt);
|
||||
@@ -501,8 +501,9 @@ static void Write_ValidateSetting(void *ptr, const SettingDesc *sd, int32 val)
|
||||
* be given values
|
||||
* @param grpname the group of the IniFile to search in for the new values
|
||||
* @param object pointer to the object been loaded
|
||||
* @param only_startup load only the startup settings set
|
||||
*/
|
||||
static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
|
||||
static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object, bool only_startup)
|
||||
{
|
||||
IniGroup *group;
|
||||
IniGroup *group_def = ini->GetGroup(grpname);
|
||||
@@ -512,6 +513,7 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
|
||||
const SaveLoad *sld = &sd->save;
|
||||
|
||||
if (!SlIsObjectCurrentlyValid(sld->version_from, sld->version_to)) continue;
|
||||
if (sd->desc.startup != only_startup) continue;
|
||||
|
||||
/* For settings.xx.yy load the settings from [xx] yy = ? */
|
||||
std::string s{ sdb->name };
|
||||
@@ -612,7 +614,7 @@ static void IniLoadSettings(IniFile *ini, const SettingDesc *sd, const char *grp
|
||||
* values are reloaded when saving). If settings indeed have changed, we get
|
||||
* these and save them.
|
||||
*/
|
||||
static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object)
|
||||
static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grpname, void *object, bool)
|
||||
{
|
||||
IniGroup *group_def = nullptr, *group;
|
||||
IniItem *item;
|
||||
@@ -797,7 +799,7 @@ static void IniSaveSettingList(IniFile *ini, const char *grpname, StringList &li
|
||||
*/
|
||||
void IniLoadWindowSettings(IniFile *ini, const char *grpname, void *desc)
|
||||
{
|
||||
IniLoadSettings(ini, _window_settings, grpname, desc);
|
||||
IniLoadSettings(ini, _window_settings, grpname, desc, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -808,7 +810,7 @@ void IniLoadWindowSettings(IniFile *ini, const char *grpname, void *desc)
|
||||
*/
|
||||
void IniSaveWindowSettings(IniFile *ini, const char *grpname, void *desc)
|
||||
{
|
||||
IniSaveSettings(ini, _window_settings, grpname, desc);
|
||||
IniSaveSettings(ini, _window_settings, grpname, desc, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1713,20 +1715,18 @@ static void GRFSaveConfig(IniFile *ini, const char *grpname, const GRFConfig *li
|
||||
}
|
||||
|
||||
/* Common handler for saving/loading variables to the configuration file */
|
||||
static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescProcList *proc_list, bool basic_settings = true, bool other_settings = true)
|
||||
static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescProcList *proc_list, bool only_startup = false)
|
||||
{
|
||||
if (basic_settings) {
|
||||
proc(ini, (const SettingDesc*)_misc_settings, "misc", nullptr);
|
||||
proc(ini, (const SettingDesc*)_misc_settings, "misc", nullptr, only_startup);
|
||||
#if defined(_WIN32) && !defined(DEDICATED)
|
||||
proc(ini, (const SettingDesc*)_win32_settings, "win32", nullptr);
|
||||
proc(ini, (const SettingDesc*)_win32_settings, "win32", nullptr, only_startup);
|
||||
#endif /* _WIN32 */
|
||||
}
|
||||
|
||||
if (other_settings) {
|
||||
proc(ini, _settings, "patches", &_settings_newgame);
|
||||
proc(ini, _currency_settings,"currency", &_custom_currency);
|
||||
proc(ini, _company_settings, "company", &_settings_client.company);
|
||||
proc(ini, _settings, "patches", &_settings_newgame, only_startup);
|
||||
proc(ini, _currency_settings,"currency", &_custom_currency, only_startup);
|
||||
proc(ini, _company_settings, "company", &_settings_client.company, only_startup);
|
||||
|
||||
if (!only_startup) {
|
||||
proc_list(ini, "server_bind_addresses", _network_bind_list);
|
||||
proc_list(ini, "servers", _network_host_list);
|
||||
proc_list(ini, "bans", _network_ban_list);
|
||||
@@ -1742,24 +1742,24 @@ static IniFile *IniLoadConfig()
|
||||
|
||||
/**
|
||||
* Load the values from the configuration files
|
||||
* @param minimal Load the minimal amount of the configuration to "bootstrap" the blitter and such.
|
||||
* @param startup Load the minimal amount of the configuration to "bootstrap" the blitter and such.
|
||||
*/
|
||||
void LoadFromConfig(bool minimal)
|
||||
void LoadFromConfig(bool startup)
|
||||
{
|
||||
IniFile *ini = IniLoadConfig();
|
||||
if (!minimal) ResetCurrencies(false); // Initialize the array of currencies, without preserving the custom one
|
||||
if (!startup) ResetCurrencies(false); // Initialize the array of currencies, without preserving the custom one
|
||||
|
||||
/* Load basic settings only during bootstrap, load other settings not during bootstrap */
|
||||
HandleSettingDescs(ini, IniLoadSettings, IniLoadSettingList, minimal, !minimal);
|
||||
HandleSettingDescs(ini, IniLoadSettings, IniLoadSettingList, startup);
|
||||
|
||||
if (!minimal) {
|
||||
if (!startup) {
|
||||
_grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false);
|
||||
_grfconfig_static = GRFLoadConfig(ini, "newgrf-static", true);
|
||||
AILoadConfig(ini, "ai_players");
|
||||
GameLoadConfig(ini, "game_scripts");
|
||||
|
||||
PrepareOldDiffCustom();
|
||||
IniLoadSettings(ini, _gameopt_settings, "gameopt", &_settings_newgame);
|
||||
IniLoadSettings(ini, _gameopt_settings, "gameopt", &_settings_newgame, false);
|
||||
HandleOldDiffCustom(false);
|
||||
|
||||
ValidateSettings();
|
||||
|
Reference in New Issue
Block a user