From 69766049cee33724746efc4806c0ab0563b051b9 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 5 Dec 2010 14:43:10 +0000 Subject: (svn r21396) -Codechange: rename SafeSaveOrLoad to SaveLoad (it only did load), and add support for (safe) loading with a LoadFilter --- src/network/network_client.cpp | 4 ++-- src/openttd.cpp | 16 +++++++++------- src/video/dedicated_v.cpp | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 40e8d5668..fcbabda54 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -439,7 +439,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::SendMove(CompanyID company, co * DEF_CLIENT_RECEIVE_COMMAND has parameter: Packet *p ************/ -extern bool SafeSaveOrLoad(const char *filename, int mode, GameMode newgm, Subdirectory subdir); +extern bool SafeLoad(const char *filename, int mode, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = NULL); extern StringID _switch_mode_errorstr; DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_FULL) @@ -757,7 +757,7 @@ DEF_GAME_RECEIVE_COMMAND(Client, PACKET_SERVER_MAP_DONE) SetWindowDirty(WC_NETWORK_STATUS_WINDOW, 0); /* The map is done downloading, load it */ - bool load_success = SafeSaveOrLoad(this->download_filename, SL_LOAD, GM_NORMAL, NO_DIRECTORY); + bool load_success = SafeLoad(this->download_filename, SL_LOAD, GM_NORMAL, NO_DIRECTORY); free(this->download_filename); this->download_filename = NULL; diff --git a/src/openttd.cpp b/src/openttd.cpp index 8c938f164..14c667abf 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -866,18 +866,20 @@ extern void StartupEconomy(); * Load the specified savegame but on error do different things. * If loading fails due to corrupt savegame, bad version, etc. go back to * a previous correct state. In the menu for example load the intro game again. - * @param filename file to be loaded * @param mode mode of loading, either SL_LOAD or SL_OLD_LOAD * @param newgm switch to this mode of loading fails due to some unknown error + * @param filename file to be loaded * @param subdir default directory to look for filename, set to 0 if not needed + * @param lf Load filter to use, if NULL: use filename + subdir. */ -bool SafeSaveOrLoad(const char *filename, int mode, GameMode newgm, Subdirectory subdir) +bool SafeLoad(const char *filename, int mode, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = NULL) { + assert(mode == SL_LOAD || (lf == NULL && mode == SL_OLD_LOAD)); GameMode ogm = _game_mode; _game_mode = newgm; - assert(mode == SL_LOAD || mode == SL_OLD_LOAD); - switch (SaveOrLoad(filename, mode, subdir)) { + + switch (lf == NULL ? SaveOrLoad(filename, mode, subdir) : LoadWithFilter(lf)) { case SL_OK: return true; case SL_REINIT: @@ -938,7 +940,7 @@ static void StartScenario() ResetGRFConfig(true); /* Load game */ - if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, SCENARIO_DIR)) { + if (!SafeLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, SCENARIO_DIR)) { SetDParamStr(0, GetSaveLoadErrorString()); ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR); return; @@ -1022,7 +1024,7 @@ void SwitchToMode(SwitchMode new_mode) ResetGRFConfig(true); ResetWindowSystem(); - if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, NO_DIRECTORY)) { + if (!SafeLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, NO_DIRECTORY)) { SetDParamStr(0, GetSaveLoadErrorString()); ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR); } else { @@ -1062,7 +1064,7 @@ void SwitchToMode(SwitchMode new_mode) break; case SM_LOAD_SCENARIO: { // Load scenario from scenario editor - if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR, NO_DIRECTORY)) { + if (SafeLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR, NO_DIRECTORY)) { SetLocalCompany(OWNER_NONE); _settings_newgame.game_creation.starting_year = _cur_year; /* Cancel the saveload pausing */ diff --git a/src/video/dedicated_v.cpp b/src/video/dedicated_v.cpp index f2ebd0f00..9942a347d 100644 --- a/src/video/dedicated_v.cpp +++ b/src/video/dedicated_v.cpp @@ -137,7 +137,7 @@ static void *_dedicated_video_mem; /* Whether a fork has been done. */ bool _dedicated_forks; -extern bool SafeSaveOrLoad(const char *filename, int mode, GameMode newgm, Subdirectory subdir); +extern bool SafeLoad(const char *filename, int mode, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = NULL); extern void SwitchToMode(SwitchMode new_mode); static FVideoDriver_Dedicated iFVideoDriver_Dedicated; @@ -279,7 +279,7 @@ void VideoDriver_Dedicated::MainLoop() _switch_mode = SM_NONE; /* First we need to test if the savegame can be loaded, else we will end up playing the * intro game... */ - if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, BASE_DIR)) { + if (!SafeLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, BASE_DIR)) { /* Loading failed, pop out.. */ DEBUG(net, 0, "Loading requested map failed, aborting"); _networking = false; -- cgit v1.2.3-70-g09d2