diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/console_cmds.cpp | 2 | ||||
-rw-r--r-- | src/crashlog.cpp | 2 | ||||
-rw-r--r-- | src/fileio_type.h | 7 | ||||
-rw-r--r-- | src/fios_gui.cpp | 4 | ||||
-rw-r--r-- | src/genworld.cpp | 2 | ||||
-rw-r--r-- | src/genworld_gui.cpp | 2 | ||||
-rw-r--r-- | src/heightmap.cpp | 35 | ||||
-rw-r--r-- | src/heightmap.h | 6 | ||||
-rw-r--r-- | src/landscape.cpp | 2 | ||||
-rw-r--r-- | src/network/network_client.cpp | 4 | ||||
-rw-r--r-- | src/openttd.cpp | 28 | ||||
-rw-r--r-- | src/saveload/afterload.cpp | 2 | ||||
-rw-r--r-- | src/saveload/saveload.cpp | 90 | ||||
-rw-r--r-- | src/saveload/saveload.h | 23 | ||||
-rw-r--r-- | src/saveload/signs_sl.cpp | 2 | ||||
-rw-r--r-- | src/video/dedicated_v.cpp | 4 |
16 files changed, 114 insertions, 101 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index a486ea282..c26f17f29 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -318,7 +318,7 @@ DEF_CONSOLE_CMD(ConSave) char *filename = str_fmt("%s.sav", argv[1]); IConsolePrint(CC_DEFAULT, "Saving map..."); - if (SaveOrLoad(filename, SL_SAVE, SAVE_DIR) != SL_OK) { + if (SaveOrLoad(filename, FOP_SAVE, DFT_GAME_FILE, SAVE_DIR) != SL_OK) { IConsolePrint(CC_ERROR, "Saving map failed"); } else { IConsolePrintF(CC_DEFAULT, "Map successfully saved to %s", filename); diff --git a/src/crashlog.cpp b/src/crashlog.cpp index 4000cfb03..83beb94ff 100644 --- a/src/crashlog.cpp +++ b/src/crashlog.cpp @@ -388,7 +388,7 @@ bool CrashLog::WriteSavegame(char *filename, const char *filename_last) const seprintf(filename, filename_last, "%scrash.sav", _personal_dir); /* Don't do a threaded saveload. */ - return SaveOrLoad(filename, SL_SAVE, NO_DIRECTORY, false) == SL_OK; + return SaveOrLoad(filename, FOP_SAVE, DFT_GAME_FILE, NO_DIRECTORY, false) == SL_OK; } catch (...) { return false; } diff --git a/src/fileio_type.h b/src/fileio_type.h index 4fae7b392..0c4602bba 100644 --- a/src/fileio_type.h +++ b/src/fileio_type.h @@ -47,8 +47,11 @@ enum DetailedFileType { /** Operation performed on the file. */ enum FileOperation { - FOP_LOAD, ///< File is being loaded. - FOP_SAVE, ///< File is being saved. + FOP_CHECK, ///< Load file for checking and/or preview. + FOP_LOAD, ///< File is being loaded. + FOP_SAVE, ///< File is being saved. + + FOP_INVALID, ///< Unknown file operation. }; /** diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index a4e495b49..0c09f96ab 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -584,7 +584,7 @@ public: if (GetDetailedFileType(file->type) == DFT_GAME_FILE) { /* Other detailed file types cannot be checked before. */ - SaveOrLoad(name, SL_LOAD_CHECK, NO_DIRECTORY, false); + SaveOrLoad(name, FOP_CHECK, DFT_GAME_FILE, NO_DIRECTORY, false); } this->InvalidateData(1); @@ -777,7 +777,7 @@ void ShowSaveLoadDialog(AbstractFileType abstract_filetype, FileOperation fop) sld = (abstract_filetype == FT_HEIGHTMAP) ? &_load_heightmap_dialog_desc : &_load_dialog_desc; } - _file_to_saveload.filetype = abstract_filetype; + _file_to_saveload.abstract_ftype = abstract_filetype; new SaveLoadWindow(sld, abstract_filetype, fop); } diff --git a/src/genworld.cpp b/src/genworld.cpp index 2b2dfb5fd..95e28fcdf 100644 --- a/src/genworld.cpp +++ b/src/genworld.cpp @@ -204,7 +204,7 @@ static void _GenerateWorld(void *) if (_debug_desync_level > 0) { char name[MAX_PATH]; seprintf(name, lastof(name), "dmp_cmds_%08x_%08x.sav", _settings_game.game_creation.generation_seed, _date); - SaveOrLoad(name, SL_SAVE, AUTOSAVE_DIR, false); + SaveOrLoad(name, FOP_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR, false); } } catch (...) { BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP, true); diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index 61e114311..359709e36 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -833,7 +833,7 @@ static void _ShowGenerateLandscape(GenerateLandscapeWindowMode mode) if (mode == GLWM_HEIGHTMAP) { /* If the function returns negative, it means there was a problem loading the heightmap */ - if (!GetHeightmapDimensions(_file_to_saveload.name, &x, &y)) return; + if (!GetHeightmapDimensions(_file_to_saveload.detail_ftype, _file_to_saveload.name, &x, &y)) return; } WindowDesc *desc = (mode == GLWM_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc; diff --git a/src/heightmap.cpp b/src/heightmap.cpp index ec3125728..630dc69d7 100644 --- a/src/heightmap.cpp +++ b/src/heightmap.cpp @@ -102,7 +102,7 @@ static void ReadHeightmapPNGImageData(byte *map, png_structp png_ptr, png_infop * If map == NULL only the size of the PNG is read, otherwise a map * with grayscale pixels is allocated and assigned to *map. */ -static bool ReadHeightmapPNG(char *filename, uint *x, uint *y, byte **map) +static bool ReadHeightmapPNG(const char *filename, uint *x, uint *y, byte **map) { FILE *fp; png_structp png_ptr = NULL; @@ -232,7 +232,7 @@ static void ReadHeightmapBMPImageData(byte *map, BmpInfo *info, BmpData *data) * If map == NULL only the size of the BMP is read, otherwise a map * with grayscale pixels is allocated and assigned to *map. */ -static bool ReadHeightmapBMP(char *filename, uint *x, uint *y, byte **map) +static bool ReadHeightmapBMP(const char *filename, uint *x, uint *y, byte **map) { FILE *f; BmpInfo info; @@ -444,45 +444,56 @@ void FixSlopes() } /** - * Reads the heightmap with the correct file reader + * Reads the heightmap with the correct file reader. + * @param dft Type of image file. + * @param filename Name of the file to load. + * @param [out] x Length of the image. + * @param [out] y Height of the image. + * @param [inout] map If not \c NULL, destination to store the loaded block of image data. + * @return Whether loading was successful. */ -static bool ReadHeightMap(char *filename, uint *x, uint *y, byte **map) +static bool ReadHeightMap(DetailedFileType dft, const char *filename, uint *x, uint *y, byte **map) { - switch (_file_to_saveload.mode) { - default: NOT_REACHED(); + switch (dft) { + default: + NOT_REACHED(); + #ifdef WITH_PNG - case SL_PNG: + case DFT_HEIGHTMAP_PNG: return ReadHeightmapPNG(filename, x, y, map); #endif /* WITH_PNG */ - case SL_BMP: + + case DFT_HEIGHTMAP_BMP: return ReadHeightmapBMP(filename, x, y, map); } } /** * Get the dimensions of a heightmap. + * @param dft Type of image file. * @param filename to query * @param x dimension x * @param y dimension y * @return Returns false if loading of the image failed. */ -bool GetHeightmapDimensions(char *filename, uint *x, uint *y) +bool GetHeightmapDimensions(DetailedFileType dft, const char *filename, uint *x, uint *y) { - return ReadHeightMap(filename, x, y, NULL); + return ReadHeightMap(dft, filename, x, y, NULL); } /** * Load a heightmap from file and change the map in his current dimensions * to a landscape representing the heightmap. * It converts pixels to height. The brighter, the higher. + * @param dft Type of image file. * @param filename of the heightmap file to be imported */ -void LoadHeightmap(char *filename) +void LoadHeightmap(DetailedFileType dft, const char *filename) { uint x, y; byte *map = NULL; - if (!ReadHeightMap(filename, &x, &y, &map)) { + if (!ReadHeightMap(dft, filename, &x, &y, &map)) { free(map); return; } diff --git a/src/heightmap.h b/src/heightmap.h index 08ae200ec..67349df48 100644 --- a/src/heightmap.h +++ b/src/heightmap.h @@ -12,6 +12,8 @@ #ifndef HEIGHTMAP_H #define HEIGHTMAP_H +#include "fileio_type.h" + /** * Order of these enums has to be the same as in lang/english.txt * Otherwise you will get inconsistent behaviour. @@ -21,8 +23,8 @@ enum HeightmapRotation { HM_CLOCKWISE, ///< Rotate the map clockwise 45 degrees }; -bool GetHeightmapDimensions(char *filename, uint *x, uint *y); -void LoadHeightmap(char *filename); +bool GetHeightmapDimensions(DetailedFileType dft, const char *filename, uint *x, uint *y); +void LoadHeightmap(DetailedFileType dft, const char *filename); void FlatEmptyWorld(byte tile_height); void FixSlopes(); diff --git a/src/landscape.cpp b/src/landscape.cpp index d2b1b98cd..185e84a80 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -1222,7 +1222,7 @@ void GenerateLandscape(byte mode) if (mode == GWM_HEIGHTMAP) { SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_HEIGHTMAP); - LoadHeightmap(_file_to_saveload.name); + LoadHeightmap(_file_to_saveload.detail_ftype, _file_to_saveload.name); IncreaseGeneratingWorldProgress(GWP_LANDSCAPE); } else if (_settings_game.game_creation.land_generator == LG_TERRAGENESIS) { SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_TERRAGENESIS); diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index d4d294146..a33e5c681 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -520,7 +520,7 @@ bool ClientNetworkGameSocketHandler::IsConnected() * DEF_CLIENT_RECEIVE_COMMAND has parameter: Packet *p ************/ -extern bool SafeLoad(const char *filename, int mode, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = NULL); +extern bool SafeLoad(const char *filename, FileOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = NULL); NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FULL(Packet *p) { @@ -836,7 +836,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet /* The map is done downloading, load it */ ClearErrorMessages(); - bool load_success = SafeLoad(NULL, SL_LOAD, GM_NORMAL, NO_DIRECTORY, lf); + bool load_success = SafeLoad(NULL, FOP_LOAD, DFT_GAME_FILE, GM_NORMAL, NO_DIRECTORY, lf); /* Long savegame loads shouldn't affect the lag calculation! */ this->last_packet = _realtime_tick; diff --git a/src/openttd.cpp b/src/openttd.cpp index bd8ac4253..4464e8016 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -328,7 +328,7 @@ static void LoadIntroGame(bool load_newgrfs = true) SetupColoursAndInitialWindow(); /* Load the default opening screen savegame */ - if (SaveOrLoad("opntitle.dat", SL_LOAD, BASESET_DIR) != SL_OK) { + if (SaveOrLoad("opntitle.dat", FOP_LOAD, DFT_GAME_FILE, BASESET_DIR) != SL_OK) { GenerateWorld(GWM_EMPTY, 64, 64); // if failed loading, make empty world. WaitTillGeneratedWorld(); SetLocalCompany(COMPANY_SPECTATOR); @@ -619,8 +619,9 @@ int openttd_main(int argc, char *argv[]) case 'g': if (mgo.opt != NULL) { strecpy(_file_to_saveload.name, mgo.opt, lastof(_file_to_saveload.name)); - _switch_mode = (_switch_mode == SM_EDITOR || _switch_mode == SM_LOAD_SCENARIO ? SM_LOAD_SCENARIO : SM_LOAD_GAME); - _file_to_saveload.mode = SL_LOAD; + bool is_scenario = _switch_mode == SM_EDITOR || _switch_mode == SM_LOAD_SCENARIO; + _switch_mode = is_scenario ? SM_LOAD_SCENARIO : SM_LOAD_GAME; + _file_to_saveload.SetMode(FOP_LOAD, is_scenario ? FT_SCENARIO : FT_SAVEGAME, DFT_GAME_FILE); /* if the file doesn't exist or it is not a valid savegame, let the saveload code show an error */ const char *t = strrchr(_file_to_saveload.name, '.'); @@ -650,7 +651,7 @@ int openttd_main(int argc, char *argv[]) FiosGetSavegameListCallback(FOP_LOAD, mgo.opt, strrchr(mgo.opt, '.'), title, lastof(title)); _load_check_data.Clear(); - SaveOrLoadResult res = SaveOrLoad(mgo.opt, SL_LOAD_CHECK, SAVE_DIR, false); + SaveOrLoadResult res = SaveOrLoad(mgo.opt, FOP_CHECK, DFT_GAME_FILE, SAVE_DIR, false); if (res != SL_OK || _load_check_data.HasErrors()) { fprintf(stderr, "Failed to open savegame\n"); if (_load_check_data.HasErrors()) { @@ -997,14 +998,15 @@ static void MakeNewEditorWorld() * @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 SafeLoad(const char *filename, int mode, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = NULL) +bool SafeLoad(const char *filename, FileOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = NULL) { - assert(mode == SL_LOAD || (lf == NULL && mode == SL_OLD_LOAD)); + assert(fop == FOP_LOAD); + assert(dft == DFT_GAME_FILE || (lf == NULL && dft == DFT_OLD_GAME_FILE)); GameMode ogm = _game_mode; _game_mode = newgm; - switch (lf == NULL ? SaveOrLoad(filename, mode, subdir) : LoadWithFilter(lf)) { + switch (lf == NULL ? SaveOrLoad(filename, fop, dft, subdir) : LoadWithFilter(lf)) { case SL_OK: return true; case SL_REINIT: @@ -1093,11 +1095,11 @@ void SwitchToMode(SwitchMode new_mode) ResetGRFConfig(true); ResetWindowSystem(); - if (!SafeLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, NO_DIRECTORY)) { + if (!SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.detail_ftype, GM_NORMAL, NO_DIRECTORY)) { SetDParamStr(0, GetSaveLoadErrorString()); ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR); } else { - if (_file_to_saveload.filetype == FT_SCENARIO) { + if (_file_to_saveload.abstract_ftype == FT_SCENARIO) { /* Reset engine pool to simplify changing engine NewGRFs in scenario editor. */ EngineOverrideManager::ResetToCurrentNewGRFConfig(); } @@ -1134,7 +1136,7 @@ void SwitchToMode(SwitchMode new_mode) break; case SM_LOAD_SCENARIO: { // Load scenario from scenario editor - if (SafeLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR, NO_DIRECTORY)) { + if (SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.detail_ftype, GM_EDITOR, NO_DIRECTORY)) { SetLocalCompany(OWNER_NONE); _settings_newgame.game_creation.starting_year = _cur_year; /* Cancel the saveload pausing */ @@ -1156,7 +1158,7 @@ void SwitchToMode(SwitchMode new_mode) case SM_SAVE_GAME: // Save game. /* Make network saved games on pause compatible to singleplayer */ - if (SaveOrLoad(_file_to_saveload.name, SL_SAVE, NO_DIRECTORY) != SL_OK) { + if (SaveOrLoad(_file_to_saveload.name, FOP_SAVE, DFT_GAME_FILE, NO_DIRECTORY) != SL_OK) { SetDParamStr(0, GetSaveLoadErrorString()); ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR); } else { @@ -1367,7 +1369,7 @@ void StateGameLoop() /* Save the desync savegame if needed. */ char name[MAX_PATH]; seprintf(name, lastof(name), "dmp_cmds_%08x_%08x.sav", _settings_game.game_creation.generation_seed, _date); - SaveOrLoad(name, SL_SAVE, AUTOSAVE_DIR, false); + SaveOrLoad(name, FOP_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR, false); } CheckCaches(); @@ -1424,7 +1426,7 @@ static void DoAutosave() } DEBUG(sl, 2, "Autosaving to '%s'", buf); - if (SaveOrLoad(buf, SL_SAVE, AUTOSAVE_DIR) != SL_OK) { + if (SaveOrLoad(buf, FOP_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR) != SL_OK) { ShowErrorMessage(STR_ERROR_AUTOSAVE_FAILED, INVALID_STRING_ID, WL_ERROR); } } diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 969048115..de3f7ccff 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -248,7 +248,7 @@ static void InitializeWindowsAndCaches() /* For each company, verify (while loading a scenario) that the inauguration date is the current year and set it * accordingly if it is not the case. No need to set it on companies that are not been used already, * thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */ - if (_file_to_saveload.filetype == FT_SCENARIO && c->inaugurated_year != MIN_YEAR) { + if (_file_to_saveload.abstract_ftype == FT_SCENARIO && c->inaugurated_year != MIN_YEAR) { c->inaugurated_year = _cur_year; } } diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index b5fdda27a..4dd8a4c7b 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -2778,10 +2778,10 @@ SaveOrLoadResult LoadWithFilter(LoadFilter *reader) * @param threaded True when threaded saving is allowed * @return Return the result of the action. #SL_OK, #SL_ERROR, or #SL_REINIT ("unload" the game) */ -SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, bool threaded) +SaveOrLoadResult SaveOrLoad(const char *filename, FileOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded) { /* An instance of saving is already active, so don't go saving again */ - if (_sl.saveinprogress && mode == SL_SAVE && threaded) { + if (_sl.saveinprogress && fop == FOP_SAVE && dft == DFT_GAME_FILE && threaded) { /* if not an autosave, but a user action, show error message */ if (!_do_autosave) ShowErrorMessage(STR_ERROR_SAVE_STILL_IN_PROGRESS, INVALID_STRING_ID, WL_ERROR); return SL_OK; @@ -2790,7 +2790,7 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo try { /* Load a TTDLX or TTDPatch game */ - if (mode == SL_OLD_LOAD) { + if (fop == FOP_LOAD && dft == DFT_OLD_GAME_FILE) { InitializeGame(256, 256, true, true); // set a mapsize of 256x256 for TTDPatch games or it might get confused /* TTD/TTO savegames have no NewGRFs, TTDP savegame have them @@ -2811,25 +2811,35 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo return SL_OK; } - switch (mode) { - case SL_LOAD_CHECK: _sl.action = SLA_LOAD_CHECK; break; - case SL_LOAD: _sl.action = SLA_LOAD; break; - case SL_SAVE: _sl.action = SLA_SAVE; break; + assert(dft == DFT_GAME_FILE); + switch (dft) { + case FOP_CHECK: + _sl.action = SLA_LOAD_CHECK; + break; + + case FOP_LOAD: + _sl.action = SLA_LOAD; + break; + + case FOP_SAVE: + _sl.action = SLA_SAVE; + break; + default: NOT_REACHED(); } - FILE *fh = (mode == SL_SAVE) ? FioFOpenFile(filename, "wb", sb) : FioFOpenFile(filename, "rb", sb); + FILE *fh = (fop == FOP_SAVE) ? FioFOpenFile(filename, "wb", sb) : FioFOpenFile(filename, "rb", sb); /* Make it a little easier to load savegames from the console */ - if (fh == NULL && mode != SL_SAVE) fh = FioFOpenFile(filename, "rb", SAVE_DIR); - if (fh == NULL && mode != SL_SAVE) fh = FioFOpenFile(filename, "rb", BASE_DIR); - if (fh == NULL && mode != SL_SAVE) fh = FioFOpenFile(filename, "rb", SCENARIO_DIR); + if (fh == NULL && fop != FOP_SAVE) fh = FioFOpenFile(filename, "rb", SAVE_DIR); + if (fh == NULL && fop != FOP_SAVE) fh = FioFOpenFile(filename, "rb", BASE_DIR); + if (fh == NULL && fop != FOP_SAVE) fh = FioFOpenFile(filename, "rb", SCENARIO_DIR); if (fh == NULL) { - SlError(mode == SL_SAVE ? STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE : STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE); + SlError(fop == FOP_SAVE ? STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE : STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE); } - if (mode == SL_SAVE) { // SAVE game + if (fop == FOP_SAVE) { // SAVE game DEBUG(desync, 1, "save: %08x; %02x; %s", _date, _date_fract, filename); if (_network_server || !_settings_client.gui.threaded_saves) threaded = false; @@ -2837,24 +2847,25 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo } /* LOAD game */ - assert(mode == SL_LOAD || mode == SL_LOAD_CHECK); + assert(fop == FOP_LOAD || fop == FOP_CHECK); DEBUG(desync, 1, "load: %s", filename); - return DoLoad(new FileReader(fh), mode == SL_LOAD_CHECK); + return DoLoad(new FileReader(fh), fop == FOP_CHECK); } catch (...) { + /* This code may be executed both for old and new save games. */ ClearSaveLoadState(); /* Skip the "colour" character */ - if (mode != SL_LOAD_CHECK) DEBUG(sl, 0, "%s", GetSaveLoadErrorString() + 3); + if (fop != FOP_CHECK) DEBUG(sl, 0, "%s", GetSaveLoadErrorString() + 3); /* A saver/loader exception!! reinitialize all variables to prevent crash! */ - return (mode == SL_LOAD || mode == SL_OLD_LOAD) ? SL_REINIT : SL_ERROR; + return (fop == FOP_LOAD) ? SL_REINIT : SL_ERROR; } } /** Do a save when exiting the game (_settings_client.gui.autosave_on_exit) */ void DoExitSave() { - SaveOrLoad("exit.sav", SL_SAVE, AUTOSAVE_DIR); + SaveOrLoad("exit.sav", FOP_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR); } /** @@ -2898,34 +2909,27 @@ void GenerateDefaultSaveName(char *buf, const char *last) */ void FileToSaveLoad::SetMode(FiosType ft) { - switch (ft) { - case FIOS_TYPE_FILE: - case FIOS_TYPE_SCENARIO: - this->mode = SL_LOAD; - break; - - case FIOS_TYPE_OLDFILE: - case FIOS_TYPE_OLD_SCENARIO: - this->mode = SL_OLD_LOAD; - break; - -#ifdef WITH_PNG - case FIOS_TYPE_PNG: - this->mode = SL_PNG; - break; -#endif /* WITH_PNG */ - - case FIOS_TYPE_BMP: - this->mode = SL_BMP; - break; + this->SetMode(FOP_LOAD, GetAbstractFileType(ft), GetDetailedFileType(ft)); +} - default: - this->mode = SL_INVALID; - break; +/** + * Set the mode and file type of the file to save or load. + * @param fop File operation being performed. + * @param aft Abstract file type. + * @param dft Detailed file type. + */ +void FileToSaveLoad::SetMode(FileOperation fop, AbstractFileType aft, DetailedFileType dft) +{ + if (aft == FT_INVALID || aft == FT_NONE) { + this->file_op = FOP_INVALID; + this->detail_ftype = DFT_INVALID; + this->abstract_ftype = FT_INVALID; + return; } - this->filetype = GetAbstractFileType(ft); - if (this->filetype == FT_NONE) this->filetype = FT_INVALID; + this->file_op = fop; + this->detail_ftype = dft; + this->abstract_ftype = aft; } #if 0 diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index 43b9d5d3c..7b0ae8f48 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -22,25 +22,16 @@ enum SaveOrLoadResult { SL_REINIT = 2, ///< error that was caught in the middle of updating game state, need to clear it. (can only happen during load) }; -/** Save or load mode. @see SaveOrLoad */ -enum SaveOrLoadMode { - SL_INVALID = -1, ///< Invalid mode. - SL_LOAD = 0, ///< Load game. - SL_SAVE = 1, ///< Save game. - SL_OLD_LOAD = 2, ///< Load old game. - SL_PNG = 3, ///< Load PNG file (height map). - SL_BMP = 4, ///< Load BMP file (height map). - SL_LOAD_CHECK = 5, ///< Load for game preview. -}; - /** Deals with the type of the savegame, independent of extension */ struct FileToSaveLoad { - SaveOrLoadMode mode; ///< savegame/scenario type (old, new) - AbstractFileType filetype; ///< what type of file are we dealing with - char name[MAX_PATH]; ///< name - char title[255]; ///< internal name of the game + FileOperation file_op; ///< File operation to perform. + DetailedFileType detail_ftype; ///< Concrete file type (PNG, BMP, old save, etc). + AbstractFileType abstract_ftype; ///< Abstract type of file (scenario, heightmap, etc). + char name[MAX_PATH]; ///< Name of the file. + char title[255]; ///< Internal name of the game. void SetMode(FiosType ft); + void SetMode(FileOperation fop, AbstractFileType aft, DetailedFileType dft); }; /** Types of save games. */ @@ -58,7 +49,7 @@ extern FileToSaveLoad _file_to_saveload; void GenerateDefaultSaveName(char *buf, const char *last); void SetSaveLoadError(uint16 str); const char *GetSaveLoadErrorString(); -SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, bool threaded = true); +SaveOrLoadResult SaveOrLoad(const char *filename, FileOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded = true); void WaitTillSaved(); void ProcessAsyncSaveFinish(); void DoExitSave(); diff --git a/src/saveload/signs_sl.cpp b/src/saveload/signs_sl.cpp index 077d34501..132ac181e 100644 --- a/src/saveload/signs_sl.cpp +++ b/src/saveload/signs_sl.cpp @@ -60,7 +60,7 @@ static void Load_SIGN() } /* Signs placed in scenario editor shall now be OWNER_DEITY */ - if (IsSavegameVersionBefore(171) && si->owner == OWNER_NONE && _file_to_saveload.filetype == FT_SCENARIO) { + if (IsSavegameVersionBefore(171) && si->owner == OWNER_NONE && _file_to_saveload.abstract_ftype == FT_SCENARIO) { si->owner = OWNER_DEITY; } } diff --git a/src/video/dedicated_v.cpp b/src/video/dedicated_v.cpp index bfe853e9a..95d40cd00 100644 --- a/src/video/dedicated_v.cpp +++ b/src/video/dedicated_v.cpp @@ -142,7 +142,7 @@ static void *_dedicated_video_mem; /* Whether a fork has been done. */ bool _dedicated_forks; -extern bool SafeLoad(const char *filename, int mode, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = NULL); +extern bool SafeLoad(const char *filename, FileOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = NULL); static FVideoDriver_Dedicated iFVideoDriver_Dedicated; @@ -286,7 +286,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 (!SafeLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, BASE_DIR)) { + if (!SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.detail_ftype, GM_NORMAL, BASE_DIR)) { /* Loading failed, pop out.. */ DEBUG(net, 0, "Loading requested map failed, aborting"); _networking = false; |