Skip to content

Commit

Permalink
(svn r23224) -Codechange: first load the config file partially so we …
Browse files Browse the repository at this point in the history
…can push scanning AIs to later in the process (when the GUI is showing the progress bar)
  • Loading branch information
rubidium42 committed Nov 14, 2011
1 parent 5446b40 commit 834eac4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 24 deletions.
41 changes: 31 additions & 10 deletions src/openttd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,22 +370,44 @@ 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)
{
}

virtual void OnNewGRFsScanned()
{
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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down
35 changes: 22 additions & 13 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/settings_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 834eac4

Please sign in to comment.