Changeset - r23265:870f15a9d0bc
[Not reviewed]
master
0 4 0
Peter Nelson - 6 years ago 2019-01-29 00:56:28
peter1138@openttd.org
Codechange: Additional type safety for saveload version variables.
4 files changed with 11 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/gamelog.cpp
Show inline comments
 
@@ -23,12 +23,12 @@
 

	
 
#include "safeguards.h"
 

	
 
extern const uint16 SAVEGAME_VERSION;  ///< current savegame version
 
extern const SaveLoadVersion SAVEGAME_VERSION;  ///< current savegame version
 

	
 
extern SavegameType _savegame_type; ///< type of savegame we are loading
 

	
 
extern uint32 _ttdp_version;     ///< version of TTDP savegame (if applicable)
 
extern uint16 _sl_version;       ///< the major savegame version identifier
 
extern SaveLoadVersion _sl_version; ///< the major savegame version identifier
 
extern byte   _sl_minor_version; ///< the minor savegame version, DO NOT USE!
 

	
 

	
src/openttd.cpp
Show inline comments
 
@@ -223,7 +223,7 @@ static void ShowHelp()
 

	
 
static void WriteSavegameInfo(const char *name)
 
{
 
	extern uint16 _sl_version;
 
	extern SaveLoadVersion _sl_version;
 
	uint32 last_ottd_rev = 0;
 
	byte ever_modified = 0;
 
	bool removed_newgrfs = false;
src/saveload/saveload.cpp
Show inline comments
 
@@ -53,13 +53,13 @@
 

	
 
#include "../safeguards.h"
 

	
 
extern const uint16 SAVEGAME_VERSION = SL_MAX_VERSION - 1; ///< Current savegame version of OpenTTD.
 
extern const SaveLoadVersion SAVEGAME_VERSION = (SaveLoadVersion)(SL_MAX_VERSION - 1); ///< Current savegame version of OpenTTD.
 

	
 
SavegameType _savegame_type; ///< type of savegame we are loading
 
FileToSaveLoad _file_to_saveload; ///< File to save or load in the openttd loop.
 

	
 
uint32 _ttdp_version;     ///< version of TTDP savegame (if applicable)
 
uint16 _sl_version;       ///< the major savegame version identifier
 
SaveLoadVersion _sl_version; ///< the major savegame version identifier
 
byte   _sl_minor_version; ///< the minor savegame version, DO NOT USE!
 
char _savegame_format[8]; ///< how to compress savegames
 
bool _do_autosave;        ///< are we doing an autosave at the moment?
 
@@ -1915,7 +1915,7 @@ struct LZOLoadFilter : LoadFilter {
 
		/* Check if size is bad */
 
		((uint32*)out)[0] = size = tmp[1];
 

	
 
		if (_sl_version != 0) {
 
		if (_sl_version != SL_MIN_VERSION) {
 
			tmp[0] = TO_BE32(tmp[0]);
 
			size = TO_BE32(size);
 
		}
 
@@ -2562,7 +2562,7 @@ static SaveOrLoadResult DoLoad(LoadFilte
 
		if (fmt == endof(_saveload_formats)) {
 
			DEBUG(sl, 0, "Unknown savegame type, trying to load it as the buggy format");
 
			_sl.lf->Reset();
 
			_sl_version = 0;
 
			_sl_version = SL_MIN_VERSION;
 
			_sl_minor_version = 0;
 

	
 
			/* Try to find the LZO savegame format; it uses 'OTTD' as tag. */
 
@@ -2580,7 +2580,7 @@ static SaveOrLoadResult DoLoad(LoadFilte
 

	
 
		if (fmt->tag == hdr[0]) {
 
			/* check version number */
 
			_sl_version = TO_BE32(hdr[1]) >> 16;
 
			_sl_version = (SaveLoadVersion)(TO_BE32(hdr[1]) >> 16);
 
			/* Minor is not used anymore from version 18.0, but it is still needed
 
			 * in versions before that (4 cases) which can't be removed easy.
 
			 * Therefore it is loaded, but never saved (or, it saves a 0 in any scenario). */
 
@@ -2721,7 +2721,7 @@ SaveOrLoadResult SaveOrLoad(const char *
 
			ClearGRFConfigList(&_grfconfig);
 
			GamelogReset();
 
			if (!LoadOldSaveGame(filename)) return SL_REINIT;
 
			_sl_version = 0;
 
			_sl_version = SL_MIN_VERSION;
 
			_sl_minor_version = 0;
 
			GamelogStartAction(GLAT_LOAD);
 
			if (!AfterLoadGame()) {
src/saveload/saveload.h
Show inline comments
 
@@ -750,7 +750,7 @@ typedef SaveLoad SaveLoadGlobVarList;
 
 */
 
static inline bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor = 0)
 
{
 
	extern uint16 _sl_version;
 
	extern SaveLoadVersion _sl_version;
 
	extern byte   _sl_minor_version;
 
	return _sl_version < major || (minor > 0 && _sl_version == major && _sl_minor_version < minor);
 
}
 
@@ -764,7 +764,7 @@ static inline bool IsSavegameVersionBefo
 
 */
 
static inline bool SlIsObjectCurrentlyValid(SaveLoadVersion version_from, SaveLoadVersion version_to)
 
{
 
	extern const uint16 SAVEGAME_VERSION;
 
	extern const SaveLoadVersion SAVEGAME_VERSION;
 
	if (SAVEGAME_VERSION < version_from || SAVEGAME_VERSION >= version_to) return false;
 

	
 
	return true;
0 comments (0 inline, 0 general)