Changeset - r22443:89afba6ce61a
[Not reviewed]
master
0 16 0
alberth - 8 years ago 2016-09-04 12:57:43
alberth@openttd.org
(svn r27650) -Codechange: Replace SaveOrLoadMode by FileOperation and DetailedFileType.
16 files changed with 115 insertions and 102 deletions:
0 comments (0 inline, 0 general)
src/console_cmds.cpp
Show inline comments
 
@@ -309,25 +309,25 @@ DEF_CONSOLE_CMD(ConScrollToTile)
 
 */
 
DEF_CONSOLE_CMD(ConSave)
 
{
 
	if (argc == 0) {
 
		IConsoleHelp("Save the current game. Usage: 'save <filename>'");
 
		return true;
 
	}
 

	
 
	if (argc == 2) {
 
		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);
 
		}
 
		free(filename);
 
		return true;
 
	}
 

	
 
	return false;
 
}
 

	
 
/**
src/crashlog.cpp
Show inline comments
 
@@ -379,25 +379,25 @@ bool CrashLog::WriteCrashLog(const char 
 
bool CrashLog::WriteSavegame(char *filename, const char *filename_last) const
 
{
 
	/* If the map array doesn't exist, saving will fail too. If the map got
 
	 * initialised, there is a big chance the rest is initialised too. */
 
	if (_m == NULL) return false;
 

	
 
	try {
 
		GamelogEmergency();
 

	
 
		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;
 
	}
 
}
 

	
 
/**
 
 * Write the (crash) screenshot to a file.
 
 * @note On success the filename will be filled with the full path of the
 
 *       screenshot. Make sure filename is at least \c MAX_PATH big.
 
 * @param filename      Output for the filename of the written file.
 
 * @param filename_last The last position in the filename buffer.
 
 * @return true when the crash screenshot was successfully made.
src/fileio_type.h
Show inline comments
 
@@ -38,26 +38,29 @@ enum DetailedFileType {
 

	
 
	/* fios 'files' */
 
	DFT_FIOS_DRIVE,  ///< A drive (letter) entry.
 
	DFT_FIOS_PARENT, ///< A parent directory entry.
 
	DFT_FIOS_DIR,    ///< A directory entry.
 
	DFT_FIOS_DIRECT, ///< Direct filename.
 

	
 
	DFT_INVALID = 255, ///< Unknown or invalid file.
 
};
 

	
 
/** 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.
 
};
 

	
 
/**
 
 * Construct an enum value for #FiosType as a combination of an abstract and a detailed file type.
 
 * @param abstract Abstract file type (one of #AbstractFileType).
 
 * @param detailed Detailed file type (one of #DetailedFileType).
 
 */
 
#define MAKE_FIOS_TYPE(abstract, detailed) ((abstract) | ((detailed) << FT_NUMBITS))
 

	
 
/**
 
 * Elements of a file system that are recognized.
 
 * Values are a combination of #AbstractFileType and #DetailedFileType.
src/fios_gui.cpp
Show inline comments
 
@@ -575,25 +575,25 @@ public:
 

	
 
				const FiosItem *file = this->fios_items.Get(y);
 

	
 
				const char *name = FiosBrowseTo(file);
 
				if (name != NULL) {
 
					if (click_count == 1) {
 
						if (this->selected != file) {
 
							this->selected = file;
 
							_load_check_data.Clear();
 

	
 
							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);
 
						}
 
						if (this->fop == FOP_SAVE) {
 
							/* Copy clicked name to editbox */
 
							this->filename_editbox.text.Assign(file->title);
 
							this->SetWidgetDirty(WID_SL_SAVE_OSK_TITLE);
 
						}
 
					} else if (!_load_check_data.HasErrors()) {
 
						this->selected = file;
 
						if (this->fop == FOP_LOAD) {
 
@@ -768,16 +768,16 @@ static WindowDesc _save_dialog_desc(
 
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, FileOperation fop)
 
{
 
	DeleteWindowById(WC_SAVELOAD, 0);
 

	
 
	WindowDesc *sld;
 
	if (fop == FOP_SAVE) {
 
		sld = &_save_dialog_desc;
 
	} else {
 
		/* Dialogue for loading a file. */
 
		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);
 
}
src/genworld.cpp
Show inline comments
 
@@ -195,25 +195,25 @@ static void _GenerateWorld(void *)
 

	
 
		CleanupGeneration();
 
		_modal_progress_work_mutex->EndCritical();
 

	
 
		ShowNewGRFError();
 

	
 
		if (_network_dedicated) DEBUG(net, 1, "Map generated, starting game");
 
		DEBUG(desync, 1, "new_map: %08x", _settings_game.game_creation.generation_seed);
 

	
 
		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);
 
		if (_cur_company.IsValid()) _cur_company.Restore();
 
		_generating_world = false;
 
		_modal_progress_work_mutex->EndCritical();
 
		throw;
 
	}
 
}
 

	
 
/**
 
 * Set here the function, if any, that you want to be called when landscape
src/genworld_gui.cpp
Show inline comments
 
@@ -824,25 +824,25 @@ static WindowDesc _heightmap_load_desc(
 
static void _ShowGenerateLandscape(GenerateLandscapeWindowMode mode)
 
{
 
	uint x = 0;
 
	uint y = 0;
 

	
 
	DeleteWindowByClass(WC_GENERATE_LANDSCAPE);
 

	
 
	/* Generate a new seed when opening the window */
 
	_settings_newgame.game_creation.generation_seed = InteractiveRandom();
 

	
 
	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;
 
	GenerateLandscapeWindow *w = AllocateWindowDescFront<GenerateLandscapeWindow>(desc, mode, true);
 

	
 
	if (mode == GLWM_HEIGHTMAP) {
 
		w->x = x;
 
		w->y = y;
 
		strecpy(w->name, _file_to_saveload.title, lastof(w->name));
 
	}
 

	
 
	SetWindowDirty(WC_GENERATE_LANDSCAPE, mode);
src/heightmap.cpp
Show inline comments
 
@@ -93,25 +93,25 @@ static void ReadHeightmapPNGImageData(by
 
			} else {
 
				*pixel = row_pointers[y][x_offset];
 
			}
 
		}
 
	}
 
}
 

	
 
/**
 
 * Reads the heightmap and/or size of the heightmap from a PNG file.
 
 * 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;
 
	png_infop info_ptr  = NULL;
 

	
 
	fp = FioFOpenFile(filename, "rb", HEIGHTMAP_DIR);
 
	if (fp == NULL) {
 
		ShowErrorMessage(STR_ERROR_PNGMAP, STR_ERROR_PNGMAP_FILE_NOT_FOUND, WL_ERROR);
 
		return false;
 
	}
 

	
 
	png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
 
@@ -223,25 +223,25 @@ static void ReadHeightmapBMPImageData(by
 
				*pixel++ = RGBToGrayscale(*bitmap, *(bitmap + 1), *(bitmap + 2));
 
				bitmap += 3;
 
			}
 
		}
 
	}
 
}
 

	
 
/**
 
 * Reads the heightmap and/or size of the heightmap from a BMP file.
 
 * 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;
 
	BmpData data;
 
	BmpBuffer buffer;
 

	
 
	/* Init BmpData */
 
	memset(&data, 0, sizeof(data));
 

	
 
	f = FioFOpenFile(filename, "rb", HEIGHTMAP_DIR);
 
	if (f == NULL) {
 
		ShowErrorMessage(STR_ERROR_BMPMAP, STR_ERROR_PNGMAP_FILE_NOT_FOUND, WL_ERROR);
 
@@ -435,63 +435,74 @@ void FixSlopes()
 
			}
 

	
 
			/* Does the height differ more than one? */
 
			if (TileHeight(TileXY(col, row)) >= (uint)current_tile + 2) {
 
				/* Then change the height to be no more than one */
 
				SetTileHeight(TileXY(col, row), current_tile + 1);
 
			}
 
		}
 
	}
 
}
 

	
 
/**
 
 * 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;
 
	}
 

	
 
	GrayscaleToMapHeights(x, y, map);
 
	free(map);
 

	
 
	FixSlopes();
 
	MarkWholeScreenDirty();
 
}
 

	
 
/**
src/heightmap.h
Show inline comments
 
@@ -3,27 +3,29 @@
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file heightmap.h Functions related to creating heightmaps from files. */
 

	
 
#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.
 
 */
 
enum HeightmapRotation {
 
	HM_COUNTER_CLOCKWISE, ///< Rotate the map counter clockwise 45 degrees
 
	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();
 

	
 
#endif /* HEIGHTMAP_H */
src/landscape.cpp
Show inline comments
 
@@ -1213,25 +1213,25 @@ void GenerateLandscape(byte mode)
 
	/** Number of steps of landscape generation */
 
	enum GenLandscapeSteps {
 
		GLS_HEIGHTMAP    =  3, ///< Loading a heightmap
 
		GLS_TERRAGENESIS =  5, ///< Terragenesis generator
 
		GLS_ORIGINAL     =  2, ///< Original generator
 
		GLS_TROPIC       = 12, ///< Extra steps needed for tropic landscape
 
		GLS_OTHER        =  0, ///< Extra steps for other landscapes
 
	};
 
	uint steps = (_settings_game.game_creation.landscape == LT_TROPIC) ? GLS_TROPIC : GLS_OTHER;
 

	
 
	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);
 
		GenerateTerrainPerlin();
 
	} else {
 
		SetGeneratingWorldProgress(GWP_LANDSCAPE, steps + GLS_ORIGINAL);
 
		if (_settings_game.construction.freeform_edges) {
 
			for (uint x = 0; x < MapSizeX(); x++) MakeVoid(TileXY(x, 0));
 
			for (uint y = 0; y < MapSizeY(); y++) MakeVoid(TileXY(0, y));
 
		}
 
		switch (_settings_game.game_creation.landscape) {
 
			case LT_ARCTIC: {
src/network/network_client.cpp
Show inline comments
 
@@ -511,25 +511,25 @@ NetworkRecvStatus ClientNetworkGameSocke
 
 */
 
bool ClientNetworkGameSocketHandler::IsConnected()
 
{
 
	return my_client != NULL && my_client->status == STATUS_ACTIVE;
 
}
 

	
 

	
 
/***********
 
 * Receiving functions
 
 *   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)
 
{
 
	/* We try to join a server which is full */
 
	ShowErrorMessage(STR_NETWORK_ERROR_SERVER_FULL, INVALID_STRING_ID, WL_CRITICAL);
 
	DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
 

	
 
	return NETWORK_RECV_STATUS_SERVER_FULL;
 
}
 

	
 
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_BANNED(Packet *p)
 
{
 
@@ -827,25 +827,25 @@ NetworkRecvStatus ClientNetworkGameSocke
 
	 * Make sure everything is set for reading.
 
	 *
 
	 * We need the local copy and reset this->savegame because when
 
	 * loading fails the network gets reset upon loading the intro
 
	 * game, which would cause us to free this->savegame twice.
 
	 */
 
	LoadFilter *lf = this->savegame;
 
	this->savegame = NULL;
 
	lf->Reset();
 

	
 
	/* 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;
 

	
 
	if (!load_success) {
 
		DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
 
		ShowErrorMessage(STR_NETWORK_ERROR_SAVEGAMEERROR, INVALID_STRING_ID, WL_CRITICAL);
 
		return NETWORK_RECV_STATUS_SAVEGAME;
 
	}
 
	/* If the savegame has successfully loaded, ALL windows have been removed,
 
	 * only toolbar/statusbar and gamefield are visible */
 

	
src/openttd.cpp
Show inline comments
 
@@ -319,25 +319,25 @@ static void ShutdownGame()
 
 */
 
static void LoadIntroGame(bool load_newgrfs = true)
 
{
 
	_game_mode = GM_MENU;
 

	
 
	if (load_newgrfs) ResetGRFConfig(false);
 

	
 
	/* Setup main window */
 
	ResetWindowSystem();
 
	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);
 
	} else {
 
		SetLocalCompany(COMPANY_FIRST);
 
	}
 

	
 
	_pause_mode = PM_UNPAUSED;
 
	_cursor.fix_at = false;
 

	
 
	if (load_newgrfs) CheckForMissingSprites();
 
	CheckForMissingGlyphs();
 
@@ -610,26 +610,27 @@ int openttd_main(int argc, char *argv[])
 
		case 't': scanner->startyear = atoi(mgo.opt); break;
 
		case 'd': {
 
#if defined(WIN32)
 
				CreateConsole();
 
#endif
 
				if (mgo.opt != NULL) SetDebugString(mgo.opt);
 
				break;
 
			}
 
		case 'e': _switch_mode = (_switch_mode == SM_LOAD_GAME || _switch_mode == SM_LOAD_SCENARIO ? SM_LOAD_SCENARIO : SM_EDITOR); break;
 
		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, '.');
 
				if (t != NULL) {
 
					FiosType ft = FiosGetSavegameListCallback(FOP_LOAD, _file_to_saveload.name, t, NULL, NULL);
 
					if (ft != FIOS_TYPE_INVALID) _file_to_saveload.SetMode(ft);
 
				}
 

	
 
				break;
 
			}
 

	
 
			_switch_mode = SM_NEWGAME;
 
@@ -641,25 +642,25 @@ int openttd_main(int argc, char *argv[])
 
		case 'q': {
 
			DeterminePaths(argv[0]);
 
			if (StrEmpty(mgo.opt)) {
 
				ret = 1;
 
				goto exit_noshutdown;
 
			}
 

	
 
			char title[80];
 
			title[0] = '\0';
 
			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()) {
 
					char buf[256];
 
					SetDParamStr(0, _load_check_data.error_data);
 
					GetString(buf, _load_check_data.error, lastof(buf));
 
					fprintf(stderr, "%s\n", buf);
 
				}
 
				goto exit_noshutdown;
 
			}
 

	
 
			WriteSavegameInfo(title);
 
@@ -988,32 +989,33 @@ static void MakeNewEditorWorld()
 
}
 

	
 
/**
 
 * 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 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 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:
 
#ifdef ENABLE_NETWORK
 
			if (_network_dedicated) {
 
				/*
 
				 * We need to reinit a network map...
 
				 * We can't simply load the intro game here as that game has many
 
				 * special cases which make clients desync immediately. So we fall
 
				 * back to just generating a new game with the current settings.
 
				 */
 
				DEBUG(net, 0, "Loading game failed, so a new (random) game will be started!");
 
@@ -1084,29 +1086,29 @@ void SwitchToMode(SwitchMode new_mode)
 
#ifdef ENABLE_NETWORK
 
			if (_network_server) {
 
				seprintf(_network_game_info.map_name, lastof(_network_game_info.map_name), "Random Map");
 
			}
 
#endif /* ENABLE_NETWORK */
 
			MakeNewGame(false, new_mode == SM_NEWGAME);
 
			break;
 

	
 
		case SM_LOAD_GAME: { // Load game, Play Scenario
 
			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();
 
				}
 
				/* Update the local company for a loaded game. It is either always
 
				 * company #1 (eg 0) or in the case of a dedicated server a spectator */
 
				SetLocalCompany(_network_dedicated ? COMPANY_SPECTATOR : COMPANY_FIRST);
 
				/* Execute the game-start script */
 
				IConsoleCmdExec("exec scripts/game_start.scr 0");
 
				/* Decrease pause counter (was increased from opening load dialog) */
 
				DoCommandP(0, PM_PAUSED_SAVELOAD, 0, CMD_PAUSE);
 
#ifdef ENABLE_NETWORK
 
				if (_network_server) {
 
@@ -1125,47 +1127,47 @@ void SwitchToMode(SwitchMode new_mode)
 
#endif /* ENABLE_NETWORK */
 
			MakeNewGame(true, true);
 
			break;
 

	
 
		case SM_LOAD_HEIGHTMAP: // Load heightmap from scenario editor
 
			SetLocalCompany(OWNER_NONE);
 

	
 
			GenerateWorld(GWM_HEIGHTMAP, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
 
			MarkWholeScreenDirty();
 
			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 */
 
				DoCommandP(0, PM_PAUSED_SAVELOAD, 0, CMD_PAUSE);
 
			} else {
 
				SetDParamStr(0, GetSaveLoadErrorString());
 
				ShowErrorMessage(STR_JUST_RAW_STRING, INVALID_STRING_ID, WL_ERROR);
 
			}
 
			break;
 
		}
 

	
 
		case SM_MENU: // Switch to game intro menu
 
			LoadIntroGame();
 
			if (BaseSounds::ini_set == NULL && BaseSounds::GetUsedSet()->fallback) {
 
				ShowErrorMessage(STR_WARNING_FALLBACK_SOUNDSET, INVALID_STRING_ID, WL_CRITICAL);
 
				BaseSounds::ini_set = stredup(BaseSounds::GetUsedSet()->name);
 
			}
 
			break;
 

	
 
		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 {
 
				DeleteWindowById(WC_SAVELOAD, 0);
 
			}
 
			break;
 

	
 
		case SM_SAVE_HEIGHTMAP: // Save heightmap.
 
			MakeHeightmapScreenshot(_file_to_saveload.name);
 
			DeleteWindowById(WC_SAVELOAD, 0);
 
			break;
 

	
 
@@ -1358,25 +1360,25 @@ void StateGameLoop()
 
		CallVehicleTicks();
 
		CallLandscapeTick();
 
		BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP);
 
		UpdateLandscapingLimits();
 

	
 
		CallWindowTickEvent();
 
		NewsLoop();
 
	} else {
 
		if (_debug_desync_level > 2 && _date_fract == 0 && (_date & 0x1F) == 0) {
 
			/* 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();
 

	
 
		/* All these actions has to be done from OWNER_NONE
 
		 *  for multiplayer compatibility */
 
		Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE);
 

	
 
		BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP);
 
		AnimateAnimatedTiles();
 
		IncreaseDate();
 
		RunTileLoop();
 
@@ -1415,25 +1417,25 @@ static void DoAutosave()
 
		GenerateDefaultSaveName(buf, lastof(buf));
 
		strecat(buf, ".sav", lastof(buf));
 
	} else {
 
		static int _autosave_ctr = 0;
 

	
 
		/* generate a savegame name and number according to _settings_client.gui.max_num_autosaves */
 
		seprintf(buf, lastof(buf), "autosave%d.sav", _autosave_ctr);
 

	
 
		if (++_autosave_ctr >= _settings_client.gui.max_num_autosaves) _autosave_ctr = 0;
 
	}
 

	
 
	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);
 
	}
 
}
 

	
 
void GameLoop()
 
{
 
	if (_game_mode == GM_BOOTSTRAP) {
 
#ifdef ENABLE_NETWORK
 
		/* Check for UDP stuff */
 
		if (_network_available) NetworkBackgroundLoop();
 
#endif
 
		InputLoop();
src/saveload/afterload.cpp
Show inline comments
 
@@ -239,25 +239,25 @@ static void InitializeWindowsAndCaches()
 
	ResetWindowSystem();
 
	SetupColoursAndInitialWindow();
 

	
 
	/* Update coordinates of the signs. */
 
	UpdateAllVirtCoords();
 
	ResetViewportAfterLoadGame();
 

	
 
	Company *c;
 
	FOR_ALL_COMPANIES(c) {
 
		/* 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;
 
		}
 
	}
 

	
 
	/* Count number of objects per type */
 
	Object *o;
 
	FOR_ALL_OBJECTS(o) {
 
		Object::IncTypeCount(o->type);
 
	}
 

	
 
	/* Identify owners of persistent storage arrays */
 
	Industry *i;
src/saveload/saveload.cpp
Show inline comments
 
@@ -2769,101 +2769,112 @@ SaveOrLoadResult LoadWithFilter(LoadFilt
 
	}
 
}
 

	
 
/**
 
 * Main Save or Load function where the high-level saveload functions are
 
 * handled. It opens the savegame, selects format and checks versions
 
 * @param filename The name of the savegame being created/loaded
 
 * @param mode Save or load mode. Load can also be a TTD(Patch) game. Use #SL_LOAD, #SL_OLD_LOAD, #SL_LOAD_CHECK, or #SL_SAVE.
 
 * @param sb The sub directory to save the savegame in
 
 * @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;
 
	}
 
	WaitTillSaved();
 

	
 
	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
 
			 * and if so a new NewGRF list will be made in LoadOldSaveGame.
 
			 * Note: this is done here because AfterLoadGame is also called
 
			 * for OTTD savegames which have their own NewGRF logic. */
 
			ClearGRFConfigList(&_grfconfig);
 
			GamelogReset();
 
			if (!LoadOldSaveGame(filename)) return SL_REINIT;
 
			_sl_version = 0;
 
			_sl_minor_version = 0;
 
			GamelogStartAction(GLAT_LOAD);
 
			if (!AfterLoadGame()) {
 
				GamelogStopAction();
 
				return SL_REINIT;
 
			}
 
			GamelogStopAction();
 
			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;
 

	
 
			return DoSave(new FileWriter(fh), threaded);
 
		}
 

	
 
		/* 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);
 
}
 

	
 
/**
 
 * Fill the buffer with the default name for a savegame *or* screenshot.
 
 * @param buf the buffer to write to.
 
 * @param last the last element in the buffer.
 
 */
 
void GenerateDefaultSaveName(char *buf, const char *last)
 
{
 
	/* Check if we have a name for this map, which is the name of the first
 
	 * available company. When there's no company available we'll use
 
	 * 'Spectator' as "company" name. */
 
@@ -2889,52 +2900,45 @@ void GenerateDefaultSaveName(char *buf, 
 

	
 
	/* Get the correct string (special string for when there's not company) */
 
	GetString(buf, !Company::IsValidID(cid) ? STR_SAVEGAME_NAME_SPECTATOR : STR_SAVEGAME_NAME_DEFAULT, last);
 
	SanitizeFilename(buf);
 
}
 

	
 
/**
 
 * Set the mode and file type of the file to save or load based on the type of file entry at the file system.
 
 * @param ft Type of file entry of the file system.
 
 */
 
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;
 

	
 
		default:
 
			this->mode = SL_INVALID;
 
			break;
 
	this->SetMode(FOP_LOAD, GetAbstractFileType(ft), GetDetailedFileType(ft));
 
}
 

	
 
/**
 
 * 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
 
/**
 
 * Function to get the type of the savegame by looking at the file header.
 
 * NOTICE: Not used right now, but could be used if extensions of savegames are garbled
 
 * @param file Savegame to be checked
 
 * @return SL_OLD_LOAD or SL_LOAD of the file
 
 */
 
int GetSavegameType(char *file)
 
{
 
	const SaveLoadFormat *fmt;
src/saveload/saveload.h
Show inline comments
 
@@ -13,61 +13,52 @@
 
#define SAVELOAD_H
 

	
 
#include "../fileio_type.h"
 
#include "../strings_type.h"
 

	
 
/** Save or load result codes. */
 
enum SaveOrLoadResult {
 
	SL_OK     = 0, ///< completed successfully
 
	SL_ERROR  = 1, ///< error that was caught before internal structures were modified
 
	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. */
 
enum SavegameType {
 
	SGT_TTD,    ///< TTD  savegame (can be detected incorrectly)
 
	SGT_TTDP1,  ///< TTDP savegame ( -//- ) (data at NW border)
 
	SGT_TTDP2,  ///< TTDP savegame in new format (data at SE border)
 
	SGT_OTTD,   ///< OTTD savegame
 
	SGT_TTO,    ///< TTO savegame
 
	SGT_INVALID = 0xFF, ///< broken savegame (used internally)
 
};
 

	
 
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();
 

	
 
SaveOrLoadResult SaveWithFilter(struct SaveFilter *writer, bool threaded);
 
SaveOrLoadResult LoadWithFilter(struct LoadFilter *reader);
 

	
 
typedef void ChunkSaveLoadProc();
 
typedef void AutolengthProc(void *arg);
 

	
 
/** Handlers and description of chunk. */
 
struct ChunkHandler {
src/saveload/signs_sl.cpp
Show inline comments
 
@@ -51,22 +51,22 @@ static void Load_SIGN()
 
		SlObject(si, _sign_desc);
 
		/* Before version 6.1, signs didn't have owner.
 
		 * Before version 83, invalid signs were determined by si->str == 0.
 
		 * Before version 103, owner could be a bankrupted company.
 
		 *  - we can't use IsValidCompany() now, so this is fixed in AfterLoadGame()
 
		 * All signs that were saved are valid (including those with just 'Sign' and INVALID_OWNER).
 
		 *  - so set owner to OWNER_NONE if needed (signs from pre-version 6.1 would be lost) */
 
		if (IsSavegameVersionBefore(6, 1) || (IsSavegameVersionBefore(83) && si->owner == INVALID_OWNER)) {
 
			si->owner = OWNER_NONE;
 
		}
 

	
 
		/* 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;
 
		}
 
	}
 
}
 

	
 
/** Chunk handlers related to signs. */
 
extern const ChunkHandler _sign_chunk_handlers[] = {
 
	{ 'SIGN', Save_SIGN, Load_SIGN, NULL, NULL, CH_ARRAY | CH_LAST},
 
};
src/video/dedicated_v.cpp
Show inline comments
 
@@ -133,25 +133,25 @@ static void CloseWindowsConsoleThread()
 
}
 

	
 
#endif
 

	
 
#include "../safeguards.h"
 

	
 

	
 
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;
 

	
 

	
 
const char *VideoDriver_Dedicated::Start(const char * const *parm)
 
{
 
	int bpp = BlitterFactory::GetCurrentBlitter()->GetScreenDepth();
 
	_dedicated_video_mem = (bpp == 0) ? NULL : MallocT<byte>(_cur_resolution.width * _cur_resolution.height * (bpp / 8));
 

	
 
	_screen.width  = _screen.pitch = _cur_resolution.width;
 
	_screen.height = _cur_resolution.height;
 
	_screen.dst_ptr = _dedicated_video_mem;
 
@@ -277,25 +277,25 @@ void VideoDriver_Dedicated::MainLoop()
 
	_network_dedicated = true;
 
	_current_company = _local_company = COMPANY_SPECTATOR;
 

	
 
	/* If SwitchMode is SM_LOAD_GAME, it means that the user used the '-g' options */
 
	if (_switch_mode != SM_LOAD_GAME) {
 
		StartNewGameWithoutGUI(GENERATE_NEW_SEED);
 
		SwitchToMode(_switch_mode);
 
		_switch_mode = SM_NONE;
 
	} else {
 
		_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;
 
		} else {
 
			/* We can load this game, so go ahead */
 
			SwitchToMode(SM_LOAD_GAME);
 
		}
 
	}
 

	
 
	/* Done loading, start game! */
 

	
 
	if (!_networking) {
0 comments (0 inline, 0 general)