(svn r22830) -Codechange: move more logic to after the scanning of NewGRFs

This commit is contained in:
rubidium 2011-08-24 17:04:18 +00:00
parent f5dd74499b
commit 432b1a4aff
1 changed files with 41 additions and 47 deletions

View File

@ -325,18 +325,18 @@ void MakeNewgameSettingsLive()
/** 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 @@ struct AfterNewGRFScan : NewGRFScanCallback {
{
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 @@ int ttd_main(int argc, char *argv[])
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 @@ int ttd_main(int argc, char *argv[])
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 @@ int ttd_main(int argc, char *argv[])
_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 @@ int ttd_main(int argc, char *argv[])
BaseSounds::FindSets();
BaseMusic::FindSets();
ShowHelp();
delete scanner;
return 0;
}
@ -569,22 +577,22 @@ int ttd_main(int argc, char *argv[])
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 @@ int ttd_main(int argc, char *argv[])
_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 @@ int ttd_main(int argc, char *argv[])
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();