File diff r25584:37056c3329ca → r25585:53810459092f
src/saveload/saveload.h
Show inline comments
 
@@ -9,12 +9,13 @@
 

	
 
#ifndef SAVELOAD_H
 
#define SAVELOAD_H
 

	
 
#include "../fileio_type.h"
 
#include "../strings_type.h"
 
#include "../core/span_type.hpp"
 
#include <string>
 

	
 
/** SaveLoad versions
 
 * Previous savegame versions, the trunk revision where they were
 
 * introduced and the released version that had that particular
 
 * savegame version.
 
@@ -503,13 +504,12 @@ enum SaveLoadType : byte {
 
	SL_DEQUE       =  5, ///< Save/load a deque.
 
	SL_STDSTR      =  6, ///< Save/load a \c std::string.
 
	/* non-normal save-load types */
 
	SL_WRITEBYTE   =  8,
 
	SL_VEH_INCLUDE =  9,
 
	SL_ST_INCLUDE  = 10,
 
	SL_END         = 15
 
};
 

	
 
typedef void *SaveLoadAddrProc(void *base, size_t extra);
 

	
 
/** SaveLoad type struct. Do NOT use this directly but use the SLE_ macros defined just below! */
 
struct SaveLoad {
 
@@ -520,14 +520,14 @@ struct SaveLoad {
 
	SaveLoadVersion version_to;     ///< save/load the variable until this savegame version
 
	size_t size;                    ///< the sizeof size.
 
	SaveLoadAddrProc *address_proc; ///< callback proc the get the actual variable address in memory
 
	size_t extra_data;              ///< extra data for the callback proc
 
};
 

	
 
/** Same as #SaveLoad but global variables are used (for better readability); */
 
typedef SaveLoad SaveLoadGlobVarList;
 
/** A table of SaveLoad entries. */
 
using SaveLoadTable = span<const SaveLoad>;
 

	
 
/**
 
 * Storage of simple variables, references (pointers), and arrays.
 
 * @param cmd      Load/save type. @see SaveLoadType
 
 * @param base     Name of the class or struct containing the variable.
 
 * @param variable Name of the variable in the class or struct referenced by \a base.
 
@@ -678,15 +678,12 @@ typedef SaveLoad SaveLoadGlobVarList;
 
/** Translate values ingame to different values in the savegame and vv. */
 
#define SLE_WRITEBYTE(base, variable) SLE_GENERAL(SL_WRITEBYTE, base, variable, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, 0)
 

	
 
#define SLE_VEH_INCLUDE() {SL_VEH_INCLUDE, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, 0, [] (void *b, size_t) { return b; }, 0}
 
#define SLE_ST_INCLUDE() {SL_ST_INCLUDE, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, 0, [] (void *b, size_t) { return b; }, 0}
 

	
 
/** End marker of a struct/class save or load. */
 
#define SLE_END() {SL_END, 0, 0, SL_MIN_VERSION, SL_MIN_VERSION, 0, nullptr, 0}
 

	
 
/**
 
 * Storage of global simple variables, references (pointers), and arrays.
 
 * @param cmd      Load/save type. @see SaveLoadType
 
 * @param variable Name of the global variable.
 
 * @param type     Storage of the data in memory and in the savegame.
 
 * @param from     First savegame version that has the field.
 
@@ -799,15 +796,12 @@ typedef SaveLoad SaveLoadGlobVarList;
 
 * @param length Length of the empty space.
 
 * @param from   First savegame version that has the empty space.
 
 * @param to     Last savegame version that has the empty space.
 
 */
 
#define SLEG_CONDNULL(length, from, to) {SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, 0, nullptr, 0}
 

	
 
/** End marker of global variables save or load. */
 
#define SLEG_END() {SL_END, 0, 0, SL_MIN_VERSION, SL_MIN_VERSION, 0, nullptr, 0}
 

	
 
/**
 
 * Checks whether the savegame is below \a major.\a minor.
 
 * @param major Major number of the version to check against.
 
 * @param minor Minor number of the version to check against. If \a minor is 0 or not specified, only the major number is checked.
 
 * @return Savegame version is earlier than the specified version.
 
 */
 
@@ -880,44 +874,44 @@ static inline bool IsNumericType(VarType
 

	
 
/**
 
 * Get the address of the variable. Null-variables don't have an address,
 
 * everything else has a callback function that returns the address based
 
 * on the saveload data and the current object for non-globals.
 
 */
 
static inline void *GetVariableAddress(const void *object, const SaveLoad *sld)
 
static inline void *GetVariableAddress(const void *object, const SaveLoad &sld)
 
{
 
	/* Entry is a null-variable, mostly used to read old savegames etc. */
 
	if (GetVarMemType(sld->conv) == SLE_VAR_NULL) {
 
		assert(sld->address_proc == nullptr);
 
	if (GetVarMemType(sld.conv) == SLE_VAR_NULL) {
 
		assert(sld.address_proc == nullptr);
 
		return nullptr;
 
	}
 

	
 
	/* Everything else should be a non-null pointer. */
 
	assert(sld->address_proc != nullptr);
 
	return sld->address_proc(const_cast<void *>(object), sld->extra_data);
 
	assert(sld.address_proc != nullptr);
 
	return sld.address_proc(const_cast<void *>(object), sld.extra_data);
 
}
 

	
 
int64 ReadValue(const void *ptr, VarType conv);
 
void WriteValue(void *ptr, VarType conv, int64 val);
 

	
 
void SlSetArrayIndex(uint index);
 
int SlIterateArray();
 

	
 
void SlAutolength(AutolengthProc *proc, void *arg);
 
size_t SlGetFieldLength();
 
void SlSetLength(size_t length);
 
size_t SlCalcObjMemberLength(const void *object, const SaveLoad *sld);
 
size_t SlCalcObjLength(const void *object, const SaveLoad *sld);
 
size_t SlCalcObjMemberLength(const void *object, const SaveLoad &sld);
 
size_t SlCalcObjLength(const void *object, const SaveLoadTable &slt);
 

	
 
byte SlReadByte();
 
void SlWriteByte(byte b);
 

	
 
void SlGlobList(const SaveLoadGlobVarList *sldg);
 
void SlGlobList(const SaveLoadTable &slt);
 
void SlArray(void *array, size_t length, VarType conv);
 
void SlObject(void *object, const SaveLoad *sld);
 
bool SlObjectMember(void *object, const SaveLoad *sld);
 
void SlObject(void *object, const SaveLoadTable &slt);
 
bool SlObjectMember(void *object, const SaveLoad &sld);
 
void NORETURN SlError(StringID string, const char *extra_msg = nullptr);
 
void NORETURN SlErrorCorrupt(const char *msg);
 
void NORETURN SlErrorCorruptFmt(const char *format, ...) WARN_FORMAT(1, 2);
 

	
 
bool SaveloadCrashWithMissingNewGRFs();