summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Nelson <peter1138@openttd.org>2019-01-29 00:56:28 +0000
committerPeterN <peter@fuzzle.org>2019-02-02 21:39:06 +0000
commit0f37a683a2360c7cb3d56fc828b96d7ee7e997f0 (patch)
tree77ed348a0142cf9bc3b03127de415eaa9f1f500f /src
parent9de12521ecec338160c37920e65fd02c0c742bef (diff)
downloadopenttd-0f37a683a2360c7cb3d56fc828b96d7ee7e997f0.tar.xz
Codechange: Additional type safety for saveload version variables.
Diffstat (limited to 'src')
-rw-r--r--src/gamelog.cpp8
-rw-r--r--src/openttd.cpp2
-rw-r--r--src/saveload/saveload.cpp20
-rw-r--r--src/saveload/saveload.h6
4 files changed, 18 insertions, 18 deletions
diff --git a/src/gamelog.cpp b/src/gamelog.cpp
index 621117f01..05653910d 100644
--- a/src/gamelog.cpp
+++ b/src/gamelog.cpp
@@ -23,13 +23,13 @@
#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 byte _sl_minor_version; ///< the minor savegame version, DO NOT USE!
+extern uint32 _ttdp_version; ///< version of TTDP savegame (if applicable)
+extern SaveLoadVersion _sl_version; ///< the major savegame version identifier
+extern byte _sl_minor_version; ///< the minor savegame version, DO NOT USE!
static GamelogActionType _gamelog_action_type = GLAT_NONE; ///< action to record if anything changes
diff --git a/src/openttd.cpp b/src/openttd.cpp
index 585bcd427..e876ffda7 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -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;
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 1d5eff8ba..9be9506b1 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -53,16 +53,16 @@
#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
-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?
+uint32 _ttdp_version; ///< version of TTDP savegame (if applicable)
+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?
/** What are we currently doing? */
enum SaveLoadAction {
@@ -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(LoadFilter *reader, bool load_check)
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(LoadFilter *reader, bool load_check)
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 *filename, SaveLoadOperation fop, Detaile
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()) {
diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h
index f14f884d5..0f4b80274 100644
--- a/src/saveload/saveload.h
+++ b/src/saveload/saveload.h
@@ -750,8 +750,8 @@ typedef SaveLoad SaveLoadGlobVarList;
*/
static inline bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor = 0)
{
- extern uint16 _sl_version;
- extern byte _sl_minor_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 IsSavegameVersionBefore(SaveLoadVersion major, byte minor = 0
*/
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;