diff options
author | rubidium <rubidium@openttd.org> | 2011-11-14 21:42:54 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2011-11-14 21:42:54 +0000 |
commit | 834eac49fde187a3af889ba04334d76630e795e3 (patch) | |
tree | 195fc51c0f310369fb7bc1610e4668ef48b1316a /src | |
parent | 5446b40c07dbfaad1911f9230e88a88c1e39972f (diff) | |
download | openttd-834eac49fde187a3af889ba04334d76630e795e3.tar.xz |
(svn r23224) -Codechange: first load the config file partially so we can push scanning AIs to later in the process (when the GUI is showing the progress bar)
Diffstat (limited to 'src')
-rw-r--r-- | src/openttd.cpp | 41 | ||||
-rw-r--r-- | src/settings.cpp | 35 | ||||
-rw-r--r-- | src/settings_func.h | 2 |
3 files changed, 54 insertions, 24 deletions
diff --git a/src/openttd.cpp b/src/openttd.cpp index 5033eff35..cda4aa3c1 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -370,11 +370,19 @@ struct AfterNewGRFScan : NewGRFScanCallback { char *network_conn; ///< Information about the server to connect to, or NULL. const char *join_server_password; ///< The password to join the server with. const char *join_company_password; ///< The password to join the company with. + bool *save_config_ptr; ///< The pointer to the save config setting. + bool save_config; ///< The save config setting. - AfterNewGRFScan() : + /** + * Create a new callback. + * @param save_config_ptr Pointer to the save_config local variable which + * decides whether to save of exit or not. + */ + AfterNewGRFScan(bool *save_config_ptr) : startyear(INVALID_YEAR), generation_seed(GENERATE_NEW_SEED), dedicated_host(NULL), dedicated_port(0), network_conn(NULL), - join_server_password(NULL), join_company_password(NULL) + join_server_password(NULL), join_company_password(NULL), + save_config_ptr(save_config_ptr), save_config(true) { } @@ -382,10 +390,24 @@ struct AfterNewGRFScan : NewGRFScanCallback { { ResetGRFConfig(false); + TarScanner::DoScan(TarScanner::SCENARIO); + + AI::Initialize(); + + /* We want the new (correct) NewGRF count to survive the loading. */ + uint last_newgrf_count = _settings_client.gui.last_newgrf_count; + LoadFromConfig(); + _settings_client.gui.last_newgrf_count = last_newgrf_count; + + AI::Uninitialize(true); CheckConfig(); LoadFromHighScore(); LoadHotkeysFromConfig(); + /* We have loaded the config, so we may possibly save it. */ + *save_config_ptr = save_config; + + if (startyear != INVALID_YEAR) _settings_newgame.game_creation.starting_year = startyear; if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed; @@ -485,8 +507,9 @@ int ttd_main(int argc, char *argv[]) char *sounds_set = NULL; char *music_set = NULL; Dimension resolution = {0, 0}; - bool save_config = true; - AfterNewGRFScan *scanner = new AfterNewGRFScan(); + /* AfterNewGRFScan sets save_config to true after scanning completed. */ + bool save_config = false; + AfterNewGRFScan *scanner = new AfterNewGRFScan(&save_config); #if defined(ENABLE_NETWORK) bool dedicated = false; char *debuglog_conn = NULL; @@ -606,7 +629,7 @@ int ttd_main(int argc, char *argv[]) } case 'G': scanner->generation_seed = atoi(mgo.opt); break; case 'c': _config_file = strdup(mgo.opt); break; - case 'x': save_config = false; break; + case 'x': scanner->save_config = false; break; case 'h': i = -2; // Force printing of help. break; @@ -636,7 +659,7 @@ int ttd_main(int argc, char *argv[]) #endif DeterminePaths(argv[0]); - TarScanner::DoScan(TarScanner::BASESET | TarScanner::SCENARIO); + TarScanner::DoScan(TarScanner::BASESET); BaseGraphics::FindSets(); BaseSounds::FindSets(); BaseMusic::FindSets(); @@ -651,11 +674,9 @@ int ttd_main(int argc, char *argv[]) #endif #endif - AI::Initialize(); - LoadFromConfig(); - AI::Uninitialize(true); + LoadFromConfig(true); - if (resolution.width != 0) { _cur_resolution = resolution; } + if (resolution.width != 0) _cur_resolution = resolution; /* * The width and height must be at least 1 pixel and width times diff --git a/src/settings.cpp b/src/settings.cpp index 3415108aa..0cffb6360 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1489,13 +1489,15 @@ 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) +static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescProcList *proc_list, bool minimal = false) { proc(ini, (const SettingDesc*)_misc_settings, "misc", NULL); #if defined(WIN32) && !defined(DEDICATED) proc(ini, (const SettingDesc*)_win32_settings, "win32", NULL); #endif /* WIN32 */ + if (minimal) return; + proc(ini, _settings, "patches", &_settings_newgame); proc(ini, _currency_settings,"currency", &_custom_currency); proc(ini, _company_settings, "company", &_settings_client.company); @@ -1514,23 +1516,30 @@ static IniFile *IniLoadConfig() return ini; } -/** Load the values from the configuration files */ -void LoadFromConfig() +/** + * Load the values from the configuration files + * @param minimal Load the minimal amount of the configuration to "bootstrap" the blitter and such. + */ +void LoadFromConfig(bool minimal) { IniFile *ini = IniLoadConfig(); - ResetCurrencies(false); // Initialize the array of curencies, without preserving the custom one + if (!minimal) ResetCurrencies(false); // Initialize the array of curencies, without preserving the custom one - HandleSettingDescs(ini, IniLoadSettings, IniLoadSettingList); - _grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false); - _grfconfig_static = GRFLoadConfig(ini, "newgrf-static", true); - NewsDisplayLoadConfig(ini, "news_display"); - AILoadConfig(ini, "ai_players"); + HandleSettingDescs(ini, IniLoadSettings, IniLoadSettingList, minimal); - PrepareOldDiffCustom(); - IniLoadSettings(ini, _gameopt_settings, "gameopt", &_settings_newgame); - HandleOldDiffCustom(false); + if (!minimal) { + _grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false); + _grfconfig_static = GRFLoadConfig(ini, "newgrf-static", true); + NewsDisplayLoadConfig(ini, "news_display"); + AILoadConfig(ini, "ai_players"); + + PrepareOldDiffCustom(); + IniLoadSettings(ini, _gameopt_settings, "gameopt", &_settings_newgame); + HandleOldDiffCustom(false); + + ValidateSettings(); + } - ValidateSettings(); delete ini; } diff --git a/src/settings_func.h b/src/settings_func.h index 65fca20f8..c6f0892c7 100644 --- a/src/settings_func.h +++ b/src/settings_func.h @@ -20,7 +20,7 @@ void IConsoleSetSetting(const char *name, int32 value); void IConsoleGetSetting(const char *name, bool force_newgame = false); void IConsoleListSettings(const char *prefilter); -void LoadFromConfig(); +void LoadFromConfig(bool minimal = false); void SaveToConfig(); void CheckConfig(); |