src/openttd.cpp
changeset 10983 e734f891d1f6
parent 10839 a62547c31fdb
child 11115 026e6754540e
equal deleted inserted replaced
10982:e8358ed0f98e 10983:e734f891d1f6
   283  * Extract the resolution from the given string and store
   283  * Extract the resolution from the given string and store
   284  * it in the 'res' parameter.
   284  * it in the 'res' parameter.
   285  * @param res variable to store the resolution in.
   285  * @param res variable to store the resolution in.
   286  * @param s   the string to decompose.
   286  * @param s   the string to decompose.
   287  */
   287  */
   288 static void ParseResolution(int res[2], const char *s)
   288 static void ParseResolution(Dimension *res, const char *s)
   289 {
   289 {
   290 	const char *t = strchr(s, 'x');
   290 	const char *t = strchr(s, 'x');
   291 	if (t == NULL) {
   291 	if (t == NULL) {
   292 		ShowInfoF("Invalid resolution '%s'", s);
   292 		ShowInfoF("Invalid resolution '%s'", s);
   293 		return;
   293 		return;
   294 	}
   294 	}
   295 
   295 
   296 	res[0] = max(strtoul(s, NULL, 0), 64UL);
   296 	res->width  = max(strtoul(s, NULL, 0), 64UL);
   297 	res[1] = max(strtoul(t + 1, NULL, 0), 64UL);
   297 	res->height = max(strtoul(t + 1, NULL, 0), 64UL);
   298 }
   298 }
   299 
   299 
   300 static void InitializeDynamicVariables()
   300 static void InitializeDynamicVariables()
   301 {
   301 {
   302 	/* Dynamic stuff needs to be initialized somewhere... */
   302 	/* Dynamic stuff needs to be initialized somewhere... */
   377 int ttd_main(int argc, char *argv[])
   377 int ttd_main(int argc, char *argv[])
   378 {
   378 {
   379 	int i;
   379 	int i;
   380 	const char *optformat;
   380 	const char *optformat;
   381 	char musicdriver[32], sounddriver[32], videodriver[32], blitter[32];
   381 	char musicdriver[32], sounddriver[32], videodriver[32], blitter[32];
   382 	int resolution[2] = {0, 0};
   382 	Dimension resolution = {0, 0};
   383 	Year startyear = INVALID_YEAR;
   383 	Year startyear = INVALID_YEAR;
   384 	uint generation_seed = GENERATE_NEW_SEED;
   384 	uint generation_seed = GENERATE_NEW_SEED;
   385 	bool save_config = true;
   385 	bool save_config = true;
   386 #if defined(ENABLE_NETWORK)
   386 #if defined(ENABLE_NETWORK)
   387 	bool dedicated = false;
   387 	bool dedicated = false;
   442 			break;
   442 			break;
   443 		case 'l':
   443 		case 'l':
   444 			debuglog_conn = mgo.opt;
   444 			debuglog_conn = mgo.opt;
   445 			break;
   445 			break;
   446 #endif /* ENABLE_NETWORK */
   446 #endif /* ENABLE_NETWORK */
   447 		case 'r': ParseResolution(resolution, mgo.opt); break;
   447 		case 'r': ParseResolution(&resolution, mgo.opt); break;
   448 		case 't': startyear = atoi(mgo.opt); break;
   448 		case 't': startyear = atoi(mgo.opt); break;
   449 		case 'd': {
   449 		case 'd': {
   450 #if defined(WIN32)
   450 #if defined(WIN32)
   451 				CreateConsole();
   451 				CreateConsole();
   452 #endif
   452 #endif
   495 	/* override config? */
   495 	/* override config? */
   496 	if (!StrEmpty(musicdriver)) ttd_strlcpy(_ini_musicdriver, musicdriver, sizeof(_ini_musicdriver));
   496 	if (!StrEmpty(musicdriver)) ttd_strlcpy(_ini_musicdriver, musicdriver, sizeof(_ini_musicdriver));
   497 	if (!StrEmpty(sounddriver)) ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver));
   497 	if (!StrEmpty(sounddriver)) ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver));
   498 	if (!StrEmpty(videodriver)) ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver));
   498 	if (!StrEmpty(videodriver)) ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver));
   499 	if (!StrEmpty(blitter))     ttd_strlcpy(_ini_blitter, blitter, sizeof(_ini_blitter));
   499 	if (!StrEmpty(blitter))     ttd_strlcpy(_ini_blitter, blitter, sizeof(_ini_blitter));
   500 	if (resolution[0] != 0) { _cur_resolution[0] = resolution[0]; _cur_resolution[1] = resolution[1]; }
   500 	if (resolution.width != 0) { _cur_resolution = resolution; }
   501 	if (startyear != INVALID_YEAR) _settings_newgame.game_creation.starting_year = startyear;
   501 	if (startyear != INVALID_YEAR) _settings_newgame.game_creation.starting_year = startyear;
   502 	if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed;
   502 	if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed;
   503 
   503 
   504 	/* The width and height must be at least 1 pixel, this
   504 	/* The width and height must be at least 1 pixel, this
   505 	 * way all internal drawing routines work correctly. */
   505 	 * way all internal drawing routines work correctly. */
   506 	if (_cur_resolution[0] == 0) _cur_resolution[0] = 1;
   506 	if (_cur_resolution.width  <= 0) _cur_resolution.width  = 1;
   507 	if (_cur_resolution[1] == 0) _cur_resolution[1] = 1;
   507 	if (_cur_resolution.height <= 0) _cur_resolution.height = 1;
   508 
   508 
   509 #if defined(ENABLE_NETWORK)
   509 #if defined(ENABLE_NETWORK)
   510 	if (dedicated_host) snprintf(_settings_client.network.server_bind_ip, sizeof(_settings_client.network.server_bind_ip), "%s", dedicated_host);
   510 	if (dedicated_host) snprintf(_settings_client.network.server_bind_ip, sizeof(_settings_client.network.server_bind_ip), "%s", dedicated_host);
   511 	if (dedicated_port) _settings_client.network.server_port = dedicated_port;
   511 	if (dedicated_port) _settings_client.network.server_port = dedicated_port;
   512 	if (_dedicated_forks && !dedicated) _dedicated_forks = false;
   512 	if (_dedicated_forks && !dedicated) _dedicated_forks = false;