openttd updated to 1.5.0-beta2
--HG-- branch : openttd
This commit is contained in:
109
src/openttd.cpp
109
src/openttd.cpp
@@ -1,4 +1,4 @@
|
||||
/* $Id: openttd.cpp 26371 2014-02-23 22:03:08Z frosch $ */
|
||||
/* $Id: openttd.cpp 26828 2014-09-16 17:14:07Z rubidium $ */
|
||||
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
@@ -68,6 +68,8 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
void CallLandscapeTick();
|
||||
void IncreaseDate();
|
||||
void DoPaletteAnimations();
|
||||
@@ -91,11 +93,11 @@ void CDECL usererror(const char *s, ...)
|
||||
char buf[512];
|
||||
|
||||
va_start(va, s);
|
||||
vsnprintf(buf, lengthof(buf), s, va);
|
||||
vseprintf(buf, lastof(buf), s, va);
|
||||
va_end(va);
|
||||
|
||||
ShowOSErrorBox(buf, false);
|
||||
if (_video_driver != NULL) _video_driver->Stop();
|
||||
if (VideoDriver::GetInstance() != NULL) VideoDriver::GetInstance()->Stop();
|
||||
|
||||
exit(1);
|
||||
}
|
||||
@@ -111,7 +113,7 @@ void CDECL error(const char *s, ...)
|
||||
char buf[512];
|
||||
|
||||
va_start(va, s);
|
||||
vsnprintf(buf, lengthof(buf), s, va);
|
||||
vseprintf(buf, lastof(buf), s, va);
|
||||
va_end(va);
|
||||
|
||||
ShowOSErrorBox(buf, true);
|
||||
@@ -130,7 +132,7 @@ void CDECL ShowInfoF(const char *str, ...)
|
||||
va_list va;
|
||||
char buf[1024];
|
||||
va_start(va, str);
|
||||
vsnprintf(buf, lengthof(buf), str, va);
|
||||
vseprintf(buf, lastof(buf), str, va);
|
||||
va_end(va);
|
||||
ShowInfo(buf);
|
||||
}
|
||||
@@ -341,7 +343,7 @@ static void LoadIntroGame(bool load_newgrfs = true)
|
||||
CheckForMissingGlyphs();
|
||||
|
||||
/* Play main theme */
|
||||
if (_music_driver->IsSongPlaying()) ResetMusic();
|
||||
if (MusicDriver::GetInstance()->IsSongPlaying()) ResetMusic();
|
||||
}
|
||||
|
||||
void MakeNewgameSettingsLive()
|
||||
@@ -434,7 +436,7 @@ struct AfterNewGRFScan : NewGRFScanCallback {
|
||||
*save_config_ptr = save_config;
|
||||
|
||||
/* restore saved music volume */
|
||||
_music_driver->SetVolume(_settings_client.music.music_vol);
|
||||
MusicDriver::GetInstance()->SetVolume(_settings_client.music.music_vol);
|
||||
|
||||
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;
|
||||
@@ -442,7 +444,7 @@ struct AfterNewGRFScan : NewGRFScanCallback {
|
||||
#if defined(ENABLE_NETWORK)
|
||||
if (dedicated_host != NULL) {
|
||||
_network_bind_list.Clear();
|
||||
*_network_bind_list.Append() = strdup(dedicated_host);
|
||||
*_network_bind_list.Append() = stredup(dedicated_host);
|
||||
}
|
||||
if (dedicated_port != 0) _settings_client.network.server_port = dedicated_port;
|
||||
#endif /* ENABLE_NETWORK */
|
||||
@@ -561,23 +563,23 @@ int openttd_main(int argc, char *argv[])
|
||||
int i;
|
||||
while ((i = mgo.GetOpt()) != -1) {
|
||||
switch (i) {
|
||||
case 'I': free(graphics_set); graphics_set = strdup(mgo.opt); break;
|
||||
case 'S': free(sounds_set); sounds_set = strdup(mgo.opt); break;
|
||||
case 'M': free(music_set); music_set = strdup(mgo.opt); break;
|
||||
case 'm': free(musicdriver); musicdriver = strdup(mgo.opt); break;
|
||||
case 's': free(sounddriver); sounddriver = strdup(mgo.opt); break;
|
||||
case 'v': free(videodriver); videodriver = strdup(mgo.opt); break;
|
||||
case 'b': free(blitter); blitter = strdup(mgo.opt); break;
|
||||
case 'I': free(graphics_set); graphics_set = stredup(mgo.opt); break;
|
||||
case 'S': free(sounds_set); sounds_set = stredup(mgo.opt); break;
|
||||
case 'M': free(music_set); music_set = stredup(mgo.opt); break;
|
||||
case 'm': free(musicdriver); musicdriver = stredup(mgo.opt); break;
|
||||
case 's': free(sounddriver); sounddriver = stredup(mgo.opt); break;
|
||||
case 'v': free(videodriver); videodriver = stredup(mgo.opt); break;
|
||||
case 'b': free(blitter); blitter = stredup(mgo.opt); break;
|
||||
#if defined(ENABLE_NETWORK)
|
||||
case 'D':
|
||||
free(musicdriver);
|
||||
free(sounddriver);
|
||||
free(videodriver);
|
||||
free(blitter);
|
||||
musicdriver = strdup("null");
|
||||
sounddriver = strdup("null");
|
||||
videodriver = strdup("dedicated");
|
||||
blitter = strdup("null");
|
||||
musicdriver = stredup("null");
|
||||
sounddriver = stredup("null");
|
||||
videodriver = stredup("dedicated");
|
||||
blitter = stredup("null");
|
||||
dedicated = true;
|
||||
SetDebugString("net=6");
|
||||
if (mgo.opt != NULL) {
|
||||
@@ -665,7 +667,7 @@ int openttd_main(int argc, char *argv[])
|
||||
goto exit_noshutdown;
|
||||
}
|
||||
case 'G': scanner->generation_seed = atoi(mgo.opt); break;
|
||||
case 'c': _config_file = strdup(mgo.opt); break;
|
||||
case 'c': free(_config_file); _config_file = stredup(mgo.opt); break;
|
||||
case 'x': scanner->save_config = false; break;
|
||||
case 'h':
|
||||
i = -2; // Force printing of help.
|
||||
@@ -737,7 +739,7 @@ int openttd_main(int argc, char *argv[])
|
||||
InitWindowSystem();
|
||||
|
||||
BaseGraphics::FindSets();
|
||||
if (graphics_set == NULL && BaseGraphics::ini_set != NULL) graphics_set = strdup(BaseGraphics::ini_set);
|
||||
if (graphics_set == NULL && BaseGraphics::ini_set != NULL) graphics_set = stredup(BaseGraphics::ini_set);
|
||||
if (!BaseGraphics::SetSet(graphics_set)) {
|
||||
if (!StrEmpty(graphics_set)) {
|
||||
BaseGraphics::SetSet(NULL);
|
||||
@@ -753,10 +755,17 @@ int openttd_main(int argc, char *argv[])
|
||||
GfxInitPalettes();
|
||||
|
||||
DEBUG(misc, 1, "Loading blitter...");
|
||||
if (blitter == NULL && _ini_blitter != NULL) blitter = strdup(_ini_blitter);
|
||||
if (blitter == NULL && _ini_blitter != NULL) blitter = stredup(_ini_blitter);
|
||||
_blitter_autodetected = StrEmpty(blitter);
|
||||
/* If we have a 32 bpp base set, try to select the 32 bpp blitter first, but only if we autoprobe the blitter. */
|
||||
if (!_blitter_autodetected || BaseGraphics::GetUsedSet() == NULL || BaseGraphics::GetUsedSet()->blitter == BLT_8BPP || BlitterFactory::SelectBlitter("32bpp-anim") == NULL) {
|
||||
/* Activate the initial blitter.
|
||||
* This is only some initial guess, after NewGRFs have been loaded SwitchNewGRFBlitter may switch to a different one.
|
||||
* - Never guess anything, if the user specified a blitter. (_blitter_autodetected)
|
||||
* - Use 32bpp blitter if baseset or 8bpp-support settings says so.
|
||||
* - Use 8bpp blitter otherwise.
|
||||
*/
|
||||
if (!_blitter_autodetected ||
|
||||
(_support8bpp != S8BPP_NONE && (BaseGraphics::GetUsedSet() == NULL || BaseGraphics::GetUsedSet()->blitter == BLT_8BPP)) ||
|
||||
BlitterFactory::SelectBlitter("32bpp-anim") == NULL) {
|
||||
if (BlitterFactory::SelectBlitter(blitter) == NULL) {
|
||||
StrEmpty(blitter) ?
|
||||
usererror("Failed to autoprobe blitter") :
|
||||
@@ -765,13 +774,8 @@ int openttd_main(int argc, char *argv[])
|
||||
}
|
||||
free(blitter);
|
||||
|
||||
if (videodriver == NULL && _ini_videodriver != NULL) videodriver = strdup(_ini_videodriver);
|
||||
_video_driver = (VideoDriver*)DriverFactoryBase::SelectDriver(videodriver, Driver::DT_VIDEO);
|
||||
if (_video_driver == NULL) {
|
||||
StrEmpty(videodriver) ?
|
||||
usererror("Failed to autoprobe video driver") :
|
||||
usererror("Failed to select requested video driver '%s'", videodriver);
|
||||
}
|
||||
if (videodriver == NULL && _ini_videodriver != NULL) videodriver = stredup(_ini_videodriver);
|
||||
DriverFactoryBase::SelectDriver(videodriver, Driver::DT_VIDEO);
|
||||
free(videodriver);
|
||||
|
||||
InitializeSpriteSorter();
|
||||
@@ -802,13 +806,13 @@ int openttd_main(int argc, char *argv[])
|
||||
goto exit_bootstrap;
|
||||
}
|
||||
|
||||
_video_driver->ClaimMousePointer();
|
||||
VideoDriver::GetInstance()->ClaimMousePointer();
|
||||
|
||||
/* initialize screenshot formats */
|
||||
InitializeScreenshotFormats();
|
||||
|
||||
BaseSounds::FindSets();
|
||||
if (sounds_set == NULL && BaseSounds::ini_set != NULL) sounds_set = strdup(BaseSounds::ini_set);
|
||||
if (sounds_set == NULL && BaseSounds::ini_set != NULL) sounds_set = stredup(BaseSounds::ini_set);
|
||||
if (!BaseSounds::SetSet(sounds_set)) {
|
||||
if (StrEmpty(sounds_set) || !BaseSounds::SetSet(NULL)) {
|
||||
usererror("Failed to find a sounds set. Please acquire a sounds set for OpenTTD. See section 4.1 of readme.txt.");
|
||||
@@ -821,7 +825,7 @@ int openttd_main(int argc, char *argv[])
|
||||
free(sounds_set);
|
||||
|
||||
BaseMusic::FindSets();
|
||||
if (music_set == NULL && BaseMusic::ini_set != NULL) music_set = strdup(BaseMusic::ini_set);
|
||||
if (music_set == NULL && BaseMusic::ini_set != NULL) music_set = stredup(BaseMusic::ini_set);
|
||||
if (!BaseMusic::SetSet(music_set)) {
|
||||
if (StrEmpty(music_set) || !BaseMusic::SetSet(NULL)) {
|
||||
usererror("Failed to find a music set. Please acquire a music set for OpenTTD. See section 4.1 of readme.txt.");
|
||||
@@ -833,22 +837,12 @@ int openttd_main(int argc, char *argv[])
|
||||
}
|
||||
free(music_set);
|
||||
|
||||
if (sounddriver == NULL && _ini_sounddriver != NULL) sounddriver = strdup(_ini_sounddriver);
|
||||
_sound_driver = (SoundDriver*)DriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND);
|
||||
if (_sound_driver == NULL) {
|
||||
StrEmpty(sounddriver) ?
|
||||
usererror("Failed to autoprobe sound driver") :
|
||||
usererror("Failed to select requested sound driver '%s'", sounddriver);
|
||||
}
|
||||
if (sounddriver == NULL && _ini_sounddriver != NULL) sounddriver = stredup(_ini_sounddriver);
|
||||
DriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND);
|
||||
free(sounddriver);
|
||||
|
||||
if (musicdriver == NULL && _ini_musicdriver != NULL) musicdriver = strdup(_ini_musicdriver);
|
||||
_music_driver = (MusicDriver*)DriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC);
|
||||
if (_music_driver == NULL) {
|
||||
StrEmpty(musicdriver) ?
|
||||
usererror("Failed to autoprobe music driver") :
|
||||
usererror("Failed to select requested music driver '%s'", musicdriver);
|
||||
}
|
||||
if (musicdriver == NULL && _ini_musicdriver != NULL) musicdriver = stredup(_ini_musicdriver);
|
||||
DriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC);
|
||||
free(musicdriver);
|
||||
|
||||
/* Take our initial lock on whatever we might want to do! */
|
||||
@@ -866,7 +860,7 @@ int openttd_main(int argc, char *argv[])
|
||||
ScanNewGRFFiles(scanner);
|
||||
scanner = NULL;
|
||||
|
||||
_video_driver->MainLoop();
|
||||
VideoDriver::GetInstance()->MainLoop();
|
||||
|
||||
WaitTillSaved();
|
||||
|
||||
@@ -934,7 +928,7 @@ static void MakeNewGameDone()
|
||||
SettingsDisableElrail(_settings_game.vehicle.disable_elrails);
|
||||
|
||||
/* In a dedicated server, the server does not play */
|
||||
if (!_video_driver->HasGUI()) {
|
||||
if (!VideoDriver::GetInstance()->HasGUI()) {
|
||||
SetLocalCompany(COMPANY_SPECTATOR);
|
||||
if (_settings_client.gui.pause_on_newgame) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
|
||||
IConsoleCmdExec("exec scripts/game_start.scr 0");
|
||||
@@ -964,6 +958,7 @@ static void MakeNewGameDone()
|
||||
if (_settings_client.gui.pause_on_newgame) DoCommandP(0, PM_PAUSED_NORMAL, 1, CMD_PAUSE);
|
||||
|
||||
CheckEngines();
|
||||
CheckIndustries();
|
||||
MarkWholeScreenDirty();
|
||||
}
|
||||
|
||||
@@ -1088,7 +1083,7 @@ void SwitchToMode(SwitchMode new_mode)
|
||||
case SM_NEWGAME: // New Game --> 'Random game'
|
||||
#ifdef ENABLE_NETWORK
|
||||
if (_network_server) {
|
||||
snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "Random Map");
|
||||
seprintf(_network_game_info.map_name, lastof(_network_game_info.map_name), "Random Map");
|
||||
}
|
||||
#endif /* ENABLE_NETWORK */
|
||||
MakeNewGame(false, new_mode == SM_NEWGAME);
|
||||
@@ -1115,7 +1110,7 @@ void SwitchToMode(SwitchMode new_mode)
|
||||
DoCommandP(0, PM_PAUSED_SAVELOAD, 0, CMD_PAUSE);
|
||||
#ifdef ENABLE_NETWORK
|
||||
if (_network_server) {
|
||||
snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded game)", _file_to_saveload.title);
|
||||
seprintf(_network_game_info.map_name, lastof(_network_game_info.map_name), "%s (Loaded game)", _file_to_saveload.title);
|
||||
}
|
||||
#endif /* ENABLE_NETWORK */
|
||||
}
|
||||
@@ -1125,7 +1120,7 @@ void SwitchToMode(SwitchMode new_mode)
|
||||
case SM_START_HEIGHTMAP: // Load a heightmap and start a new game from it
|
||||
#ifdef ENABLE_NETWORK
|
||||
if (_network_server) {
|
||||
snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Heightmap)", _file_to_saveload.title);
|
||||
seprintf(_network_game_info.map_name, lastof(_network_game_info.map_name), "%s (Heightmap)", _file_to_saveload.title);
|
||||
}
|
||||
#endif /* ENABLE_NETWORK */
|
||||
MakeNewGame(true, true);
|
||||
@@ -1155,7 +1150,7 @@ void SwitchToMode(SwitchMode new_mode)
|
||||
LoadIntroGame();
|
||||
if (BaseSounds::ini_set == NULL && BaseSounds::GetUsedSet()->fallback) {
|
||||
ShowErrorMessage(STR_WARNING_FALLBACK_SOUNDSET, INVALID_STRING_ID, WL_CRITICAL);
|
||||
BaseSounds::ini_set = strdup(BaseSounds::GetUsedSet()->name);
|
||||
BaseSounds::ini_set = stredup(BaseSounds::GetUsedSet()->name);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1371,7 +1366,7 @@ void StateGameLoop()
|
||||
if (_debug_desync_level > 2 && _date_fract == 0 && (_date & 0x1F) == 0) {
|
||||
/* Save the desync savegame if needed. */
|
||||
char name[MAX_PATH];
|
||||
snprintf(name, lengthof(name), "dmp_cmds_%08x_%08x.sav", _settings_game.game_creation.generation_seed, _date);
|
||||
seprintf(name, lastof(name), "dmp_cmds_%08x_%08x.sav", _settings_game.game_creation.generation_seed, _date);
|
||||
SaveOrLoad(name, SL_SAVE, AUTOSAVE_DIR, false);
|
||||
}
|
||||
|
||||
@@ -1423,7 +1418,7 @@ static void DoAutosave()
|
||||
static int _autosave_ctr = 0;
|
||||
|
||||
/* generate a savegame name and number according to _settings_client.gui.max_num_autosaves */
|
||||
snprintf(buf, sizeof(buf), "autosave%d.sav", _autosave_ctr);
|
||||
seprintf(buf, lastof(buf), "autosave%d.sav", _autosave_ctr);
|
||||
|
||||
if (++_autosave_ctr >= _settings_client.gui.max_num_autosaves) _autosave_ctr = 0;
|
||||
}
|
||||
@@ -1500,6 +1495,6 @@ void GameLoop()
|
||||
|
||||
InputLoop();
|
||||
|
||||
_sound_driver->MainLoop();
|
||||
SoundDriver::GetInstance()->MainLoop();
|
||||
MusicLoop();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user