mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r22830) -Codechange: move more logic to after the scanning of NewGRFs
This commit is contained in:
parent
f5dd74499b
commit
432b1a4aff
|
@ -325,18 +325,18 @@ void MakeNewgameSettingsLive()
|
||||||
|
|
||||||
/** Callback structure of statements to be executed after the NewGRF scan. */
|
/** Callback structure of statements to be executed after the NewGRF scan. */
|
||||||
struct AfterNewGRFScan : NewGRFScanCallback {
|
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.
|
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.
|
||||||
|
|
||||||
/**
|
AfterNewGRFScan() :
|
||||||
* Create the structure.
|
startyear(INVALID_YEAR), generation_seed(GENERATE_NEW_SEED),
|
||||||
* @param network_conn Information about the server to connect to, or NULL.
|
dedicated_host(NULL), dedicated_port(0), network_conn(NULL),
|
||||||
* @param join_server_password The password to join the server with.
|
join_server_password(NULL), join_company_password(NULL)
|
||||||
* @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)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,6 +344,21 @@ struct AfterNewGRFScan : NewGRFScanCallback {
|
||||||
{
|
{
|
||||||
ResetGRFConfig(false);
|
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 */
|
/* initialize the ingame console */
|
||||||
IConsoleInit();
|
IConsoleInit();
|
||||||
_cursor.in_window = true;
|
_cursor.in_window = true;
|
||||||
|
@ -432,18 +447,11 @@ 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};
|
||||||
Year startyear = INVALID_YEAR;
|
|
||||||
uint generation_seed = GENERATE_NEW_SEED;
|
|
||||||
bool save_config = true;
|
bool save_config = true;
|
||||||
|
AfterNewGRFScan *scanner = new AfterNewGRFScan();
|
||||||
#if defined(ENABLE_NETWORK)
|
#if defined(ENABLE_NETWORK)
|
||||||
bool dedicated = false;
|
bool dedicated = false;
|
||||||
bool network = false;
|
|
||||||
char *network_conn = NULL;
|
|
||||||
char *debuglog_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;
|
extern bool _dedicated_forks;
|
||||||
_dedicated_forks = false;
|
_dedicated_forks = false;
|
||||||
|
@ -484,27 +492,26 @@ int ttd_main(int argc, char *argv[])
|
||||||
const char *temp = NULL;
|
const char *temp = NULL;
|
||||||
const char *port = NULL;
|
const char *port = NULL;
|
||||||
ParseConnectionString(&temp, &port, mgo.opt);
|
ParseConnectionString(&temp, &port, mgo.opt);
|
||||||
if (!StrEmpty(mgo.opt)) dedicated_host = mgo.opt;
|
if (!StrEmpty(mgo.opt)) scanner->dedicated_host = mgo.opt;
|
||||||
if (port != NULL) dedicated_port = atoi(port);
|
if (port != NULL) scanner->dedicated_port = atoi(port);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'f': _dedicated_forks = true; break;
|
case 'f': _dedicated_forks = true; break;
|
||||||
case 'n':
|
case 'n':
|
||||||
network = true;
|
scanner->network_conn = mgo.opt; // optional IP parameter, NULL if unset
|
||||||
network_conn = mgo.opt; // optional IP parameter, NULL if unset
|
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
debuglog_conn = mgo.opt;
|
debuglog_conn = mgo.opt;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
join_server_password = mgo.opt;
|
scanner->join_server_password = mgo.opt;
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
join_company_password = mgo.opt;
|
scanner->join_company_password = mgo.opt;
|
||||||
break;
|
break;
|
||||||
#endif /* ENABLE_NETWORK */
|
#endif /* ENABLE_NETWORK */
|
||||||
case 'r': ParseResolution(&resolution, mgo.opt); break;
|
case 'r': ParseResolution(&resolution, mgo.opt); break;
|
||||||
case 't': startyear = atoi(mgo.opt); break;
|
case 't': scanner->startyear = atoi(mgo.opt); break;
|
||||||
case 'd': {
|
case 'd': {
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
CreateConsole();
|
CreateConsole();
|
||||||
|
@ -531,11 +538,11 @@ int ttd_main(int argc, char *argv[])
|
||||||
|
|
||||||
_switch_mode = SM_NEWGAME;
|
_switch_mode = SM_NEWGAME;
|
||||||
/* Give a random map if no seed has been given */
|
/* Give a random map if no seed has been given */
|
||||||
if (generation_seed == GENERATE_NEW_SEED) {
|
if (scanner->generation_seed == GENERATE_NEW_SEED) {
|
||||||
generation_seed = InteractiveRandom();
|
scanner->generation_seed = InteractiveRandom();
|
||||||
}
|
}
|
||||||
break;
|
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 'c': _config_file = strdup(mgo.opt); break;
|
||||||
case 'x': save_config = false; break;
|
case 'x': save_config = false; break;
|
||||||
case 'h':
|
case 'h':
|
||||||
|
@ -556,6 +563,7 @@ int ttd_main(int argc, char *argv[])
|
||||||
BaseSounds::FindSets();
|
BaseSounds::FindSets();
|
||||||
BaseMusic::FindSets();
|
BaseMusic::FindSets();
|
||||||
ShowHelp();
|
ShowHelp();
|
||||||
|
delete scanner;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -569,22 +577,22 @@ int ttd_main(int argc, char *argv[])
|
||||||
BaseSounds::FindSets();
|
BaseSounds::FindSets();
|
||||||
BaseMusic::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) */
|
/* We must fork here, or we'll end up without some resources we need (like sockets) */
|
||||||
if (_dedicated_forks) DedicatedFork();
|
if (_dedicated_forks) DedicatedFork();
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TarScanner::DoScan();
|
TarScanner::DoScan();
|
||||||
AI::Initialize();
|
AI::Initialize();
|
||||||
LoadFromConfig();
|
LoadFromConfig();
|
||||||
AI::Uninitialize(true);
|
AI::Uninitialize(true);
|
||||||
CheckConfig();
|
|
||||||
LoadFromHighScore();
|
|
||||||
LoadHotkeysFromConfig();
|
|
||||||
|
|
||||||
if (resolution.width != 0) { _cur_resolution = resolution; }
|
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
|
* 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.width = ClampU(_cur_resolution.width, 1, UINT16_MAX);
|
||||||
_cur_resolution.height = ClampU(_cur_resolution.height, 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 */
|
/* enumerate language files */
|
||||||
InitializeLanguagePacks();
|
InitializeLanguagePacks();
|
||||||
|
|
||||||
|
@ -718,11 +716,7 @@ int ttd_main(int argc, char *argv[])
|
||||||
|
|
||||||
CheckForMissingGlyphsInLoadedLanguagePack();
|
CheckForMissingGlyphsInLoadedLanguagePack();
|
||||||
|
|
||||||
#if defined(ENABLE_NETWORK)
|
ScanNewGRFFiles(scanner);
|
||||||
ScanNewGRFFiles(new AfterNewGRFScan(network ? network_conn : NULL, join_server_password, join_company_password));
|
|
||||||
#else
|
|
||||||
ScanNewGRFFiles(new AfterNewGRFScan(NULL, NULL, NULL));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
_video_driver->MainLoop();
|
_video_driver->MainLoop();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue