Mercurial > hg > openttd
changeset 18021:c3d55b648534 draft
(svn r22830) -Codechange: move more logic to after the scanning of NewGRFs
author | rubidium <rubidium@openttd.org> |
---|---|
date | Wed, 24 Aug 2011 17:04:18 +0000 |
parents | fd8f44f55f2a |
children | 0736aec46456 |
files | src/openttd.cpp |
diffstat | 1 files changed, 41 insertions(+), 47 deletions(-) [+] |
line wrap: on
line diff
--- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -325,18 +325,18 @@ /** Callback structure of statements to be executed after the NewGRF scan. */ struct AfterNewGRFScan : NewGRFScanCallback { + Year startyear; ///< The start year. + uint generation_seed; ///< Seed for the new game. + char *dedicated_host; ///< Hostname for the dedicated server. + uint16 dedicated_port; ///< Port for the dedicated server. 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. - /** - * Create the structure. - * @param network_conn Information about the server to connect to, or NULL. - * @param join_server_password The password to join the server with. - * @param join_company_password The password to join the company with. - */ - AfterNewGRFScan(char *network_conn, const char *join_server_password, const char *join_company_password) : - network_conn(network_conn), join_server_password(join_server_password), join_company_password(join_company_password) + AfterNewGRFScan() : + 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) { } @@ -344,6 +344,21 @@ { ResetGRFConfig(false); + CheckConfig(); + LoadFromHighScore(); + LoadHotkeysFromConfig(); + + 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 defined(ENABLE_NETWORK) + if (dedicated_host != NULL) { + _network_bind_list.Clear(); + *_network_bind_list.Append() = strdup(dedicated_host); + } + if (dedicated_port != 0) _settings_client.network.server_port = dedicated_port; +#endif /* ENABLE_NETWORK */ + /* initialize the ingame console */ IConsoleInit(); _cursor.in_window = true; @@ -432,18 +447,11 @@ char *sounds_set = NULL; char *music_set = NULL; Dimension resolution = {0, 0}; - Year startyear = INVALID_YEAR; - uint generation_seed = GENERATE_NEW_SEED; bool save_config = true; + AfterNewGRFScan *scanner = new AfterNewGRFScan(); #if defined(ENABLE_NETWORK) bool dedicated = false; - bool network = false; - char *network_conn = NULL; char *debuglog_conn = NULL; - char *dedicated_host = NULL; - uint16 dedicated_port = 0; - char *join_server_password = NULL; - char *join_company_password = NULL; extern bool _dedicated_forks; _dedicated_forks = false; @@ -484,27 +492,26 @@ const char *temp = NULL; const char *port = NULL; ParseConnectionString(&temp, &port, mgo.opt); - if (!StrEmpty(mgo.opt)) dedicated_host = mgo.opt; - if (port != NULL) dedicated_port = atoi(port); + if (!StrEmpty(mgo.opt)) scanner->dedicated_host = mgo.opt; + if (port != NULL) scanner->dedicated_port = atoi(port); } break; case 'f': _dedicated_forks = true; break; case 'n': - network = true; - network_conn = mgo.opt; // optional IP parameter, NULL if unset + scanner->network_conn = mgo.opt; // optional IP parameter, NULL if unset break; case 'l': debuglog_conn = mgo.opt; break; case 'p': - join_server_password = mgo.opt; + scanner->join_server_password = mgo.opt; break; case 'P': - join_company_password = mgo.opt; + scanner->join_company_password = mgo.opt; break; #endif /* ENABLE_NETWORK */ case 'r': ParseResolution(&resolution, mgo.opt); break; - case 't': startyear = atoi(mgo.opt); break; + case 't': scanner->startyear = atoi(mgo.opt); break; case 'd': { #if defined(WIN32) CreateConsole(); @@ -531,11 +538,11 @@ _switch_mode = SM_NEWGAME; /* Give a random map if no seed has been given */ - if (generation_seed == GENERATE_NEW_SEED) { - generation_seed = InteractiveRandom(); + if (scanner->generation_seed == GENERATE_NEW_SEED) { + scanner->generation_seed = InteractiveRandom(); } break; - case 'G': generation_seed = atoi(mgo.opt); break; + case 'G': scanner->generation_seed = atoi(mgo.opt); break; case 'c': _config_file = strdup(mgo.opt); break; case 'x': save_config = false; break; case 'h': @@ -556,6 +563,7 @@ BaseSounds::FindSets(); BaseMusic::FindSets(); ShowHelp(); + delete scanner; return 0; } @@ -569,22 +577,22 @@ BaseSounds::FindSets(); BaseMusic::FindSets(); -#if defined(ENABLE_NETWORK) && defined(UNIX) && !defined(__MORPHOS__) +#if defined(ENABLE_NETWORK) + if (dedicated) DEBUG(net, 0, "Starting dedicated version %s", _openttd_revision); + if (_dedicated_forks && !dedicated) _dedicated_forks = false; + +#if defined(UNIX) && !defined(__MORPHOS__) /* We must fork here, or we'll end up without some resources we need (like sockets) */ if (_dedicated_forks) DedicatedFork(); #endif +#endif TarScanner::DoScan(); AI::Initialize(); LoadFromConfig(); AI::Uninitialize(true); - CheckConfig(); - LoadFromHighScore(); - LoadHotkeysFromConfig(); if (resolution.width != 0) { _cur_resolution = resolution; } - 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; /* * The width and height must be at least 1 pixel and width times @@ -594,16 +602,6 @@ _cur_resolution.width = ClampU(_cur_resolution.width, 1, UINT16_MAX); _cur_resolution.height = ClampU(_cur_resolution.height, 1, UINT16_MAX); -#if defined(ENABLE_NETWORK) - if (dedicated) DEBUG(net, 0, "Starting dedicated version %s", _openttd_revision); - if (dedicated_host != NULL) { - _network_bind_list.Clear(); - *_network_bind_list.Append() = strdup(dedicated_host); - } - if (dedicated_port != 0) _settings_client.network.server_port = dedicated_port; - if (_dedicated_forks && !dedicated) _dedicated_forks = false; -#endif /* ENABLE_NETWORK */ - /* enumerate language files */ InitializeLanguagePacks(); @@ -718,11 +716,7 @@ CheckForMissingGlyphsInLoadedLanguagePack(); -#if defined(ENABLE_NETWORK) - ScanNewGRFFiles(new AfterNewGRFScan(network ? network_conn : NULL, join_server_password, join_company_password)); -#else - ScanNewGRFFiles(new AfterNewGRFScan(NULL, NULL, NULL)); -#endif + ScanNewGRFFiles(scanner); _video_driver->MainLoop();