(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)

This commit is contained in:
rubidium 2011-11-14 21:42:54 +00:00
parent 5446b40c07
commit 834eac49fd
3 changed files with 54 additions and 24 deletions

View File

@ -370,11 +370,19 @@ struct AfterNewGRFScan : NewGRFScanCallback {
char *network_conn; ///< Information about the server to connect to, or NULL. 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_server_password; ///< The password to join the server with.
const char *join_company_password; ///< The password to join the company 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), startyear(INVALID_YEAR), generation_seed(GENERATE_NEW_SEED),
dedicated_host(NULL), dedicated_port(0), network_conn(NULL), 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); 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(); CheckConfig();
LoadFromHighScore(); LoadFromHighScore();
LoadHotkeysFromConfig(); 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 (startyear != INVALID_YEAR) _settings_newgame.game_creation.starting_year = startyear;
if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed; 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 *sounds_set = NULL;
char *music_set = NULL; char *music_set = NULL;
Dimension resolution = {0, 0}; Dimension resolution = {0, 0};
bool save_config = true; /* AfterNewGRFScan sets save_config to true after scanning completed. */
AfterNewGRFScan *scanner = new AfterNewGRFScan(); bool save_config = false;
AfterNewGRFScan *scanner = new AfterNewGRFScan(&save_config);
#if defined(ENABLE_NETWORK) #if defined(ENABLE_NETWORK)
bool dedicated = false; bool dedicated = false;
char *debuglog_conn = NULL; 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 'G': scanner->generation_seed = atoi(mgo.opt); break;
case 'c': _config_file = strdup(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': case 'h':
i = -2; // Force printing of help. i = -2; // Force printing of help.
break; break;
@ -636,7 +659,7 @@ int ttd_main(int argc, char *argv[])
#endif #endif
DeterminePaths(argv[0]); DeterminePaths(argv[0]);
TarScanner::DoScan(TarScanner::BASESET | TarScanner::SCENARIO); TarScanner::DoScan(TarScanner::BASESET);
BaseGraphics::FindSets(); BaseGraphics::FindSets();
BaseSounds::FindSets(); BaseSounds::FindSets();
BaseMusic::FindSets(); BaseMusic::FindSets();
@ -651,11 +674,9 @@ int ttd_main(int argc, char *argv[])
#endif #endif
#endif #endif
AI::Initialize(); LoadFromConfig(true);
LoadFromConfig();
AI::Uninitialize(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 * The width and height must be at least 1 pixel and width times

View File

@ -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 */ /* 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); proc(ini, (const SettingDesc*)_misc_settings, "misc", NULL);
#if defined(WIN32) && !defined(DEDICATED) #if defined(WIN32) && !defined(DEDICATED)
proc(ini, (const SettingDesc*)_win32_settings, "win32", NULL); proc(ini, (const SettingDesc*)_win32_settings, "win32", NULL);
#endif /* WIN32 */ #endif /* WIN32 */
if (minimal) return;
proc(ini, _settings, "patches", &_settings_newgame); proc(ini, _settings, "patches", &_settings_newgame);
proc(ini, _currency_settings,"currency", &_custom_currency); proc(ini, _currency_settings,"currency", &_custom_currency);
proc(ini, _company_settings, "company", &_settings_client.company); proc(ini, _company_settings, "company", &_settings_client.company);
@ -1514,13 +1516,18 @@ static IniFile *IniLoadConfig()
return ini; 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(); 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); HandleSettingDescs(ini, IniLoadSettings, IniLoadSettingList, minimal);
if (!minimal) {
_grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false); _grfconfig_newgame = GRFLoadConfig(ini, "newgrf", false);
_grfconfig_static = GRFLoadConfig(ini, "newgrf-static", true); _grfconfig_static = GRFLoadConfig(ini, "newgrf-static", true);
NewsDisplayLoadConfig(ini, "news_display"); NewsDisplayLoadConfig(ini, "news_display");
@ -1531,6 +1538,8 @@ void LoadFromConfig()
HandleOldDiffCustom(false); HandleOldDiffCustom(false);
ValidateSettings(); ValidateSettings();
}
delete ini; delete ini;
} }

View File

@ -20,7 +20,7 @@ void IConsoleSetSetting(const char *name, int32 value);
void IConsoleGetSetting(const char *name, bool force_newgame = false); void IConsoleGetSetting(const char *name, bool force_newgame = false);
void IConsoleListSettings(const char *prefilter); void IConsoleListSettings(const char *prefilter);
void LoadFromConfig(); void LoadFromConfig(bool minimal = false);
void SaveToConfig(); void SaveToConfig();
void CheckConfig(); void CheckConfig();