Functions/types related to saving and loading games. More...
#include "../fileio_type.h"
#include "../strings_type.h"
Go to the source code of this file.
Data Structures | |
struct | ChunkHandler |
Handlers and description of chunk. More... | |
struct | NullStruct |
struct | SaveLoad |
SaveLoad type struct. More... | |
Defines | |
#define | SL_MAX_VERSION 255 |
Highest possible savegame version. | |
#define | SLE_GENERAL(cmd, base, variable, type, length, from, to) {false, cmd, type, length, from, to, (void*)cpp_offsetof(base, variable)} |
Storage of simple variables, references (pointers), and arrays. | |
#define | SLE_CONDVAR(base, variable, type, from, to) SLE_GENERAL(SL_VAR, base, variable, type, 0, from, to) |
Storage of a variable in some savegame versions. | |
#define | SLE_CONDREF(base, variable, type, from, to) SLE_GENERAL(SL_REF, base, variable, type, 0, from, to) |
Storage of a reference in some savegame versions. | |
#define | SLE_CONDARR(base, variable, type, length, from, to) SLE_GENERAL(SL_ARR, base, variable, type, length, from, to) |
Storage of an array in some savegame versions. | |
#define | SLE_CONDSTR(base, variable, type, length, from, to) SLE_GENERAL(SL_STR, base, variable, type, length, from, to) |
Storage of a string in some savegame versions. | |
#define | SLE_CONDLST(base, variable, type, from, to) SLE_GENERAL(SL_LST, base, variable, type, 0, from, to) |
Storage of a list in some savegame versions. | |
#define | SLE_VAR(base, variable, type) SLE_CONDVAR(base, variable, type, 0, SL_MAX_VERSION) |
Storage of a variable in every version of a savegame. | |
#define | SLE_REF(base, variable, type) SLE_CONDREF(base, variable, type, 0, SL_MAX_VERSION) |
Storage of a reference in every version of a savegame. | |
#define | SLE_ARR(base, variable, type, length) SLE_CONDARR(base, variable, type, length, 0, SL_MAX_VERSION) |
Storage of an array in every version of a savegame. | |
#define | SLE_STR(base, variable, type, length) SLE_CONDSTR(base, variable, type, length, 0, SL_MAX_VERSION) |
Storage of a string in every savegame version. | |
#define | SLE_LST(base, variable, type) SLE_CONDLST(base, variable, type, 0, SL_MAX_VERSION) |
Storage of a list in every savegame version. | |
#define | SLE_NULL(length) SLE_CONDNULL(length, 0, SL_MAX_VERSION) |
Empty space in every savegame version. | |
#define | SLE_CONDNULL(length, from, to) SLE_CONDARR(NullStruct, null, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to) |
Empty space in some savegame versions. | |
#define | SLE_WRITEBYTE(base, variable, value) SLE_GENERAL(SL_WRITEBYTE, base, variable, 0, 0, value, value) |
Translate values ingame to different values in the savegame and vv. | |
#define | SLE_VEH_INCLUDE() {false, SL_VEH_INCLUDE, 0, 0, 0, SL_MAX_VERSION, NULL} |
#define | SLE_ST_INCLUDE() {false, SL_ST_INCLUDE, 0, 0, 0, SL_MAX_VERSION, NULL} |
#define | SLE_END() {false, SL_END, 0, 0, 0, 0, NULL} |
End marker of a struct/class save or load. | |
#define | SLEG_GENERAL(cmd, variable, type, length, from, to) {true, cmd, type, length, from, to, (void*)&variable} |
Storage of global simple variables, references (pointers), and arrays. | |
#define | SLEG_CONDVAR(variable, type, from, to) SLEG_GENERAL(SL_VAR, variable, type, 0, from, to) |
Storage of a global variable in some savegame versions. | |
#define | SLEG_CONDREF(variable, type, from, to) SLEG_GENERAL(SL_REF, variable, type, 0, from, to) |
Storage of a global reference in some savegame versions. | |
#define | SLEG_CONDARR(variable, type, length, from, to) SLEG_GENERAL(SL_ARR, variable, type, length, from, to) |
Storage of a global array in some savegame versions. | |
#define | SLEG_CONDSTR(variable, type, length, from, to) SLEG_GENERAL(SL_STR, variable, type, length, from, to) |
Storage of a global string in some savegame versions. | |
#define | SLEG_CONDLST(variable, type, from, to) SLEG_GENERAL(SL_LST, variable, type, 0, from, to) |
Storage of a global list in some savegame versions. | |
#define | SLEG_VAR(variable, type) SLEG_CONDVAR(variable, type, 0, SL_MAX_VERSION) |
Storage of a global variable in every savegame version. | |
#define | SLEG_REF(variable, type) SLEG_CONDREF(variable, type, 0, SL_MAX_VERSION) |
Storage of a global reference in every savegame version. | |
#define | SLEG_ARR(variable, type) SLEG_CONDARR(variable, type, lengthof(variable), 0, SL_MAX_VERSION) |
Storage of a global array in every savegame version. | |
#define | SLEG_STR(variable, type) SLEG_CONDSTR(variable, type, lengthof(variable), 0, SL_MAX_VERSION) |
Storage of a global string in every savegame version. | |
#define | SLEG_LST(variable, type) SLEG_CONDLST(variable, type, 0, SL_MAX_VERSION) |
Storage of a global list in every savegame version. | |
#define | SLEG_CONDNULL(length, from, to) {true, SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, (void*)NULL} |
Empty global space in some savegame versions. | |
#define | SLEG_END() {true, SL_END, 0, 0, 0, 0, NULL} |
End marker of global variables save or load. | |
Typedefs | |
typedef void | ChunkSaveLoadProc () |
typedef void | AutolengthProc (void *arg) |
typedef uint32 | VarType |
typedef byte | SaveLoadType |
Save/load type. | |
typedef SaveLoad | SaveLoadGlobVarList |
Same as SaveLoad but global variables are used (for better readability);. | |
Enumerations | |
enum | SaveOrLoadResult { SL_OK = 0, SL_ERROR = 1, SL_REINIT = 2 } |
Save or load result codes. More... | |
enum | SaveOrLoadMode { SL_INVALID = -1, SL_LOAD = 0, SL_SAVE = 1, SL_OLD_LOAD = 2, SL_PNG = 3, SL_BMP = 4, SL_LOAD_CHECK = 5 } |
Save or load mode. More... | |
enum | SavegameType { SGT_TTD, SGT_TTDP1, SGT_TTDP2, SGT_OTTD, SGT_TTO, SGT_INVALID = 0xFF } |
Types of save games. More... | |
enum | SLRefType { REF_ORDER = 0, REF_VEHICLE = 1, REF_STATION = 2, REF_TOWN = 3, REF_VEHICLE_OLD = 4, REF_ROADSTOPS = 5, REF_ENGINE_RENEWS = 6, REF_CARGO_PACKET = 7, REF_ORDERLIST = 8, REF_STORAGE = 9 } |
Type of reference (SLE_REF, SLE_CONDREF). More... | |
enum | ChunkType { CH_RIFF = 0, CH_ARRAY = 1, CH_SPARSE_ARRAY = 2, CH_TYPE_MASK = 3, CH_LAST = 8, CH_AUTO_LENGTH = 16 } |
Flags of a chunk. More... | |
enum | VarTypes { SLE_FILE_I8 = 0, SLE_FILE_U8 = 1, SLE_FILE_I16 = 2, SLE_FILE_U16 = 3, SLE_FILE_I32 = 4, SLE_FILE_U32 = 5, SLE_FILE_I64 = 6, SLE_FILE_U64 = 7, SLE_FILE_STRINGID = 8, SLE_FILE_STRING = 9, SLE_VAR_BL = 0 << 4, SLE_VAR_I8 = 1 << 4, SLE_VAR_U8 = 2 << 4, SLE_VAR_I16 = 3 << 4, SLE_VAR_U16 = 4 << 4, SLE_VAR_I32 = 5 << 4, SLE_VAR_U32 = 6 << 4, SLE_VAR_I64 = 7 << 4, SLE_VAR_U64 = 8 << 4, SLE_VAR_NULL = 9 << 4, SLE_VAR_STRB = 10 << 4, SLE_VAR_STRBQ = 11 << 4, SLE_VAR_STR = 12 << 4, SLE_VAR_STRQ = 13 << 4, SLE_VAR_NAME = 14 << 4, SLE_VAR_CHAR = SLE_VAR_I8, SLE_BOOL = SLE_FILE_I8 | SLE_VAR_BL, SLE_INT8 = SLE_FILE_I8 | SLE_VAR_I8, SLE_UINT8 = SLE_FILE_U8 | SLE_VAR_U8, SLE_INT16 = SLE_FILE_I16 | SLE_VAR_I16, SLE_UINT16 = SLE_FILE_U16 | SLE_VAR_U16, SLE_INT32 = SLE_FILE_I32 | SLE_VAR_I32, SLE_UINT32 = SLE_FILE_U32 | SLE_VAR_U32, SLE_INT64 = SLE_FILE_I64 | SLE_VAR_I64, SLE_UINT64 = SLE_FILE_U64 | SLE_VAR_U64, SLE_CHAR = SLE_FILE_I8 | SLE_VAR_CHAR, SLE_STRINGID = SLE_FILE_STRINGID | SLE_VAR_U16, SLE_STRINGBUF = SLE_FILE_STRING | SLE_VAR_STRB, SLE_STRINGBQUOTE = SLE_FILE_STRING | SLE_VAR_STRBQ, SLE_STRING = SLE_FILE_STRING | SLE_VAR_STR, SLE_STRINGQUOTE = SLE_FILE_STRING | SLE_VAR_STRQ, SLE_NAME = SLE_FILE_STRINGID | SLE_VAR_NAME, SLE_UINT = SLE_UINT32, SLE_INT = SLE_INT32, SLE_STRB = SLE_STRINGBUF, SLE_STRBQ = SLE_STRINGBQUOTE, SLE_STR = SLE_STRING, SLE_STRQ = SLE_STRINGQUOTE, SLF_NOT_IN_SAVE = 1 << 8, SLF_NOT_IN_CONFIG = 1 << 9, SLF_NO_NETWORK_SYNC = 1 << 10, SLF_ALLOW_CONTROL = 1 << 11, SLF_ALLOW_NEWLINE = 1 << 12 } |
VarTypes is the general bitmasked magic type that tells us certain characteristics about the variable it refers to. More... | |
enum | SaveLoadTypes { SL_VAR = 0, SL_REF = 1, SL_ARR = 2, SL_STR = 3, SL_LST = 4, SL_WRITEBYTE = 8, SL_VEH_INCLUDE = 9, SL_ST_INCLUDE = 10, SL_END = 15 } |
Type of data saved. More... | |
Functions | |
void | GenerateDefaultSaveName (char *buf, const char *last) |
Fill the buffer with the default name for a savegame *or* screenshot. | |
void | SetSaveLoadError (uint16 str) |
const char * | GetSaveLoadErrorString () |
Get the string representation of the error message. | |
SaveOrLoadResult | SaveOrLoad (const char *filename, int mode, Subdirectory sb, bool threaded=true) |
Main Save or Load function where the high-level saveload functions are handled. | |
void | WaitTillSaved () |
void | ProcessAsyncSaveFinish () |
Handle async save finishes. | |
void | DoExitSave () |
Do a save when exiting the game (_settings_client.gui.autosave_on_exit). | |
SaveOrLoadResult | SaveWithFilter (struct SaveFilter *writer, bool threaded) |
Save the game using a (writer) filter. | |
SaveOrLoadResult | LoadWithFilter (struct LoadFilter *reader) |
Load the game using a (reader) filter. | |
static bool | IsSavegameVersionBefore (uint16 major, byte minor=0) |
Checks whether the savegame is below major. | |
static bool | SlIsObjectCurrentlyValid (uint16 version_from, uint16 version_to) |
Checks if some version from/to combination falls within the range of the active savegame version. | |
static VarType | GetVarMemType (VarType type) |
Get the NumberType of a setting. | |
static VarType | GetVarFileType (VarType type) |
Get the FileType of a setting. | |
static bool | IsNumericType (VarType conv) |
Check if the given saveload type is a numeric type. | |
static void * | GetVariableAddress (const void *object, const SaveLoad *sld) |
Get the address of the variable. | |
int64 | ReadValue (const void *ptr, VarType conv) |
Return a signed-long version of the value of a setting. | |
void | WriteValue (void *ptr, VarType conv, int64 val) |
Write the value of a setting. | |
void | SlSetArrayIndex (uint index) |
int | SlIterateArray () |
Iterate through the elements of an array and read the whole thing. | |
void | SlAutolength (AutolengthProc *proc, void *arg) |
Do something of which I have no idea what it is :P. | |
size_t | SlGetFieldLength () |
Get the length of the current object. | |
void | SlSetLength (size_t length) |
Sets the length of either a RIFF object or the number of items in an array. | |
size_t | SlCalcObjMemberLength (const void *object, const SaveLoad *sld) |
size_t | SlCalcObjLength (const void *object, const SaveLoad *sld) |
Calculate the size of an object. | |
byte | SlReadByte () |
Wrapper for reading a byte from the buffer. | |
void | SlWriteByte (byte b) |
Wrapper for writing a byte to the dumper. | |
void | SlGlobList (const SaveLoadGlobVarList *sldg) |
Save or Load (a list of) global variables. | |
void | SlArray (void *array, size_t length, VarType conv) |
Save/Load an array. | |
void | SlObject (void *object, const SaveLoad *sld) |
Main SaveLoad function. | |
bool | SlObjectMember (void *object, const SaveLoad *sld) |
void NORETURN | SlError (StringID string, const char *extra_msg=NULL) |
Error handler. | |
void NORETURN | SlErrorCorrupt (const char *msg) |
Error handler for corrupt savegames. | |
bool | SaveloadCrashWithMissingNewGRFs () |
Did loading the savegame cause a crash? If so, were NewGRFs missing? | |
Variables | |
char | _savegame_format [8] |
how to compress savegames | |
bool | _do_autosave |
are we doing an autosave at the moment? |
Functions/types related to saving and loading games.
Definition in file saveload.h.
#define SL_MAX_VERSION 255 |
Highest possible savegame version.
Definition at line 89 of file saveload.h.
Referenced by GetCargoPacketDesc(), GetGoodsDesc(), and GetVehicleDescription().
#define SLE_ARR | ( | base, | ||
variable, | ||||
type, | ||||
length | ||||
) | SLE_CONDARR(base, variable, type, length, 0, SL_MAX_VERSION) |
Storage of an array in every version of a savegame.
base | Name of the class or struct containing the array. | |
variable | Name of the variable in the class or struct referenced by base. | |
type | Storage of the data in memory and in the savegame. | |
length | Number of elements in the array. |
Definition at line 305 of file saveload.h.
#define SLE_CONDARR | ( | base, | ||
variable, | ||||
type, | ||||
length, | ||||
from, | ||||
to | ||||
) | SLE_GENERAL(SL_ARR, base, variable, type, length, from, to) |
Storage of an array in some savegame versions.
base | Name of the class or struct containing the array. | |
variable | Name of the variable in the class or struct referenced by base. | |
type | Storage of the data in memory and in the savegame. | |
length | Number of elements in the array. | |
from | First savegame version that has the array. | |
to | Last savegame version that has the array. |
Definition at line 259 of file saveload.h.
#define SLE_CONDLST | ( | base, | ||
variable, | ||||
type, | ||||
from, | ||||
to | ||||
) | SLE_GENERAL(SL_LST, base, variable, type, 0, from, to) |
Storage of a list in some savegame versions.
base | Name of the class or struct containing the list. | |
variable | Name of the variable in the class or struct referenced by base. | |
type | Storage of the data in memory and in the savegame. | |
from | First savegame version that has the list. | |
to | Last savegame version that has the list. |
Definition at line 280 of file saveload.h.
Referenced by GetGoodsDesc(), and GetVehicleDescription().
#define SLE_CONDNULL | ( | length, | ||
from, | ||||
to | ||||
) | SLE_CONDARR(NullStruct, null, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to) |
Empty space in some savegame versions.
length | Length of the empty space. | |
from | First savegame version that has the empty space. | |
to | Last savegame version that has the empty space. |
Definition at line 336 of file saveload.h.
Referenced by GetCargoPacketDesc(), GetGoodsDesc(), and GetVehicleDescription().
#define SLE_CONDREF | ( | base, | ||
variable, | ||||
type, | ||||
from, | ||||
to | ||||
) | SLE_GENERAL(SL_REF, base, variable, type, 0, from, to) |
Storage of a reference in some savegame versions.
base | Name of the class or struct containing the variable. | |
variable | Name of the variable in the class or struct referenced by base. | |
type | Type of the reference, a value from SLRefType. | |
from | First savegame version that has the field. | |
to | Last savegame version that has the field. |
Definition at line 248 of file saveload.h.
Referenced by GetVehicleDescription().
#define SLE_CONDSTR | ( | base, | ||
variable, | ||||
type, | ||||
length, | ||||
from, | ||||
to | ||||
) | SLE_GENERAL(SL_STR, base, variable, type, length, from, to) |
Storage of a string in some savegame versions.
base | Name of the class or struct containing the string. | |
variable | Name of the variable in the class or struct referenced by base. | |
type | Storage of the data in memory and in the savegame. | |
length | Number of elements in the string (only used for fixed size buffers). | |
from | First savegame version that has the string. | |
to | Last savegame version that has the string. |
Definition at line 270 of file saveload.h.
Referenced by GetVehicleDescription().
#define SLE_CONDVAR | ( | base, | ||
variable, | ||||
type, | ||||
from, | ||||
to | ||||
) | SLE_GENERAL(SL_VAR, base, variable, type, 0, from, to) |
Storage of a variable in some savegame versions.
base | Name of the class or struct containing the variable. | |
variable | Name of the variable in the class or struct referenced by base. | |
type | Storage of the data in memory and in the savegame. | |
from | First savegame version that has the field. | |
to | Last savegame version that has the field. |
Definition at line 238 of file saveload.h.
Referenced by GetCargoPacketDesc(), GetGoodsDesc(), and GetVehicleDescription().
#define SLE_END | ( | ) | {false, SL_END, 0, 0, 0, 0, NULL} |
End marker of a struct/class save or load.
Definition at line 345 of file saveload.h.
Referenced by GetCargoPacketDesc(), GetGoodsDesc(), and GetVehicleDescription().
#define SLE_GENERAL | ( | cmd, | ||
base, | ||||
variable, | ||||
type, | ||||
length, | ||||
from, | ||||
to | ||||
) | {false, cmd, type, length, from, to, (void*)cpp_offsetof(base, variable)} |
Storage of simple variables, references (pointers), and arrays.
cmd | Load/save type. |
base | Name of the class or struct containing the variable. | |
variable | Name of the variable in the class or struct referenced by base. | |
type | Storage of the data in memory and in the savegame. | |
from | First savegame version that has the field. | |
to | Last savegame version that has the field. |
Definition at line 228 of file saveload.h.
#define SLE_LST | ( | base, | ||
variable, | ||||
type | ||||
) | SLE_CONDLST(base, variable, type, 0, SL_MAX_VERSION) |
Storage of a list in every savegame version.
base | Name of the class or struct containing the list. | |
variable | Name of the variable in the class or struct referenced by base. | |
type | Storage of the data in memory and in the savegame. |
Definition at line 322 of file saveload.h.
#define SLE_NULL | ( | length | ) | SLE_CONDNULL(length, 0, SL_MAX_VERSION) |
Empty space in every savegame version.
length | Length of the empty space. |
Definition at line 328 of file saveload.h.
#define SLE_REF | ( | base, | ||
variable, | ||||
type | ||||
) | SLE_CONDREF(base, variable, type, 0, SL_MAX_VERSION) |
Storage of a reference in every version of a savegame.
base | Name of the class or struct containing the variable. | |
variable | Name of the variable in the class or struct referenced by base. | |
type | Type of the reference, a value from SLRefType. |
Definition at line 296 of file saveload.h.
Referenced by GetVehicleDescription().
#define SLE_STR | ( | base, | ||
variable, | ||||
type, | ||||
length | ||||
) | SLE_CONDSTR(base, variable, type, length, 0, SL_MAX_VERSION) |
Storage of a string in every savegame version.
base | Name of the class or struct containing the string. | |
variable | Name of the variable in the class or struct referenced by base. | |
type | Storage of the data in memory and in the savegame. | |
length | Number of elements in the string (only used for fixed size buffers). |
Definition at line 314 of file saveload.h.
Referenced by GetVehicleDescription().
#define SLE_VAR | ( | base, | ||
variable, | ||||
type | ||||
) | SLE_CONDVAR(base, variable, type, 0, SL_MAX_VERSION) |
Storage of a variable in every version of a savegame.
base | Name of the class or struct containing the variable. | |
variable | Name of the variable in the class or struct referenced by base. | |
type | Storage of the data in memory and in the savegame. |
Definition at line 288 of file saveload.h.
Referenced by GetCargoPacketDesc(), GetGoodsDesc(), and GetVehicleDescription().
#define SLE_WRITEBYTE | ( | base, | ||
variable, | ||||
value | ||||
) | SLE_GENERAL(SL_WRITEBYTE, base, variable, 0, 0, value, value) |
Translate values ingame to different values in the savegame and vv.
Definition at line 339 of file saveload.h.
Referenced by GetVehicleDescription().
#define SLEG_ARR | ( | variable, | ||
type | ||||
) | SLEG_CONDARR(variable, type, lengthof(variable), 0, SL_MAX_VERSION) |
Storage of a global array in every savegame version.
variable | Name of the global variable. | |
type | Storage of the data in memory and in the savegame. |
Definition at line 424 of file saveload.h.
#define SLEG_CONDARR | ( | variable, | ||
type, | ||||
length, | ||||
from, | ||||
to | ||||
) | SLEG_GENERAL(SL_ARR, variable, type, length, from, to) |
Storage of a global array in some savegame versions.
variable | Name of the global variable. | |
type | Storage of the data in memory and in the savegame. | |
length | Number of elements in the array. | |
from | First savegame version that has the array. | |
to | Last savegame version that has the array. |
Definition at line 384 of file saveload.h.
#define SLEG_CONDLST | ( | variable, | ||
type, | ||||
from, | ||||
to | ||||
) | SLEG_GENERAL(SL_LST, variable, type, 0, from, to) |
Storage of a global list in some savegame versions.
variable | Name of the global variable. | |
type | Storage of the data in memory and in the savegame. | |
from | First savegame version that has the list. | |
to | Last savegame version that has the list. |
Definition at line 403 of file saveload.h.
#define SLEG_CONDNULL | ( | length, | ||
from, | ||||
to | ||||
) | {true, SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, (void*)NULL} |
Empty global space in some savegame versions.
length | Length of the empty space. | |
from | First savegame version that has the empty space. | |
to | Last savegame version that has the empty space. |
Definition at line 446 of file saveload.h.
#define SLEG_CONDREF | ( | variable, | ||
type, | ||||
from, | ||||
to | ||||
) | SLEG_GENERAL(SL_REF, variable, type, 0, from, to) |
Storage of a global reference in some savegame versions.
variable | Name of the global variable. | |
type | Storage of the data in memory and in the savegame. | |
from | First savegame version that has the field. | |
to | Last savegame version that has the field. |
Definition at line 374 of file saveload.h.
#define SLEG_CONDSTR | ( | variable, | ||
type, | ||||
length, | ||||
from, | ||||
to | ||||
) | SLEG_GENERAL(SL_STR, variable, type, length, from, to) |
Storage of a global string in some savegame versions.
variable | Name of the global variable. | |
type | Storage of the data in memory and in the savegame. | |
length | Number of elements in the string (only used for fixed size buffers). | |
from | First savegame version that has the string. | |
to | Last savegame version that has the string. |
Definition at line 394 of file saveload.h.
#define SLEG_CONDVAR | ( | variable, | ||
type, | ||||
from, | ||||
to | ||||
) | SLEG_GENERAL(SL_VAR, variable, type, 0, from, to) |
Storage of a global variable in some savegame versions.
variable | Name of the global variable. | |
type | Storage of the data in memory and in the savegame. | |
from | First savegame version that has the field. | |
to | Last savegame version that has the field. |
Definition at line 365 of file saveload.h.
Referenced by GetGoodsDesc(), and GetVehicleDescription().
#define SLEG_END | ( | ) | {true, SL_END, 0, 0, 0, 0, NULL} |
End marker of global variables save or load.
Definition at line 449 of file saveload.h.
#define SLEG_GENERAL | ( | cmd, | ||
variable, | ||||
type, | ||||
length, | ||||
from, | ||||
to | ||||
) | {true, cmd, type, length, from, to, (void*)&variable} |
Storage of global simple variables, references (pointers), and arrays.
cmd | Load/save type. |
variable | Name of the global variable. | |
type | Storage of the data in memory and in the savegame. | |
from | First savegame version that has the field. | |
to | Last savegame version that has the field. |
Definition at line 356 of file saveload.h.
#define SLEG_LST | ( | variable, | ||
type | ||||
) | SLEG_CONDLST(variable, type, 0, SL_MAX_VERSION) |
Storage of a global list in every savegame version.
variable | Name of the global variable. | |
type | Storage of the data in memory and in the savegame. |
Definition at line 438 of file saveload.h.
#define SLEG_REF | ( | variable, | ||
type | ||||
) | SLEG_CONDREF(variable, type, 0, SL_MAX_VERSION) |
Storage of a global reference in every savegame version.
variable | Name of the global variable. | |
type | Storage of the data in memory and in the savegame. |
Definition at line 417 of file saveload.h.
#define SLEG_STR | ( | variable, | ||
type | ||||
) | SLEG_CONDSTR(variable, type, lengthof(variable), 0, SL_MAX_VERSION) |
Storage of a global string in every savegame version.
variable | Name of the global variable. | |
type | Storage of the data in memory and in the savegame. |
Definition at line 431 of file saveload.h.
#define SLEG_VAR | ( | variable, | ||
type | ||||
) | SLEG_CONDVAR(variable, type, 0, SL_MAX_VERSION) |
Storage of a global variable in every savegame version.
variable | Name of the global variable. | |
type | Storage of the data in memory and in the savegame. |
Definition at line 410 of file saveload.h.
typedef byte SaveLoadType |
enum ChunkType |
Flags of a chunk.
Definition at line 92 of file saveload.h.
enum SavegameType |
Types of save games.
Definition at line 37 of file saveload.h.
enum SaveLoadTypes |
Type of data saved.
SL_VAR |
Save/load a variable. |
SL_REF |
Save/load a reference. |
SL_ARR |
Save/load an array. |
SL_STR |
Save/load a string. |
SL_LST |
Save/load a list. |
Definition at line 185 of file saveload.h.
enum SaveOrLoadMode |
Save or load mode.
SL_INVALID |
Invalid mode. |
SL_LOAD |
Load game. |
SL_SAVE |
Save game. |
SL_OLD_LOAD |
Load old game. |
SL_PNG |
Load PNG file (height map). |
SL_BMP |
Load BMP file (height map). |
SL_LOAD_CHECK |
Load for game preview. |
Definition at line 26 of file saveload.h.
enum SaveOrLoadResult |
Save or load result codes.
Definition at line 19 of file saveload.h.
enum SLRefType |
Type of reference (SLE_REF, SLE_CONDREF).
Definition at line 75 of file saveload.h.
enum VarTypes |
VarTypes is the general bitmasked magic type that tells us certain characteristics about the variable it refers to.
For example SLE_FILE_* gives the size(type) as it would be in the savegame and SLE_VAR_* the size(type) as it is in memory during runtime. These are the first 8 bits (0-3 SLE_FILE, 4-7 SLE_VAR). Bits 8-15 are reserved for various flags as explained below
Definition at line 109 of file saveload.h.
void GenerateDefaultSaveName | ( | char * | buf, | |
const char * | last | |||
) |
Fill the buffer with the default name for a savegame *or* screenshot.
buf | the buffer to write to. | |
last | the last element in the buffer. |
Definition at line 2771 of file saveload.cpp.
References _date, _local_company, _settings_client, GUISettings::date_format_in_default_names, ClientSettings::gui, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), SanitizeFilename(), and SetDParam().
Referenced by DoAutosave(), SaveLoadWindow::GenerateFileName(), and MakeScreenshotName().
static VarType GetVarFileType | ( | VarType | type | ) | [inline, static] |
Get the FileType of a setting.
This describes the integer type as it is represented in a savegame/file
type | VarType holding information about the file-type | |
return | the SLE_FILE_* part of a variable-type description |
Definition at line 496 of file saveload.h.
Referenced by SlSaveLoadConv().
static void* GetVariableAddress | ( | const void * | object, | |
const SaveLoad * | sld | |||
) | [inline, static] |
Get the address of the variable.
Which one to pick depends on the object pointer. If it is NULL we are dealing with global variables so the address is taken. If non-null only the offset is stored in the union and we need to add this to the address of the object
Definition at line 517 of file saveload.h.
References SaveLoad::address, and SaveLoad::global.
Referenced by CmdChangeCompanySetting(), CmdChangeSetting(), NewsTypeData::GetDisplay(), HandleOldDiffCustom(), IConsoleGetSetting(), IConsoleListSettings(), IniLoadSettings(), IniSaveSettings(), LoadSettings(), SaveSettings(), SetCompanySetting(), SetDefaultCompanySettings(), SetSettingValue(), SlObject(), and SyncCompanySettings().
static VarType GetVarMemType | ( | VarType | type | ) | [inline, static] |
Get the NumberType of a setting.
This describes the integer type as it is represented in memory
type | VarType holding information about the variable-type |
Definition at line 485 of file saveload.h.
Referenced by IConsoleGetSetting(), IConsoleListSettings(), IniLoadSettings(), IniSaveSettings(), IsNumericType(), ReadValue(), SetSettingValue(), SlCalcStringLen(), SlString(), Write_ValidateSetting(), and WriteValue().
static bool IsNumericType | ( | VarType | conv | ) | [inline, static] |
Check if the given saveload type is a numeric type.
conv | the type to check |
Definition at line 506 of file saveload.h.
References GetVarMemType().
Referenced by LoadSettings().
static bool IsSavegameVersionBefore | ( | uint16 | major, | |
byte | minor = 0 | |||
) | [inline, static] |
Checks whether the savegame is below major.
minor.
major | Major number of the version to check against. | |
minor | Minor number of the version to check against. If minor is 0 or not specified, only the major number is checked. |
Definition at line 457 of file saveload.h.
References _sl_minor_version, and _sl_version.
Referenced by CargoPacket::AfterLoad(), AfterLoadGame(), AfterLoadVehicles(), Order::ConvertFromOldSavegame(), CopyFromOldName(), DoLoad(), HandleOldDiffCustom(), IntToReference(), Load_ANIT(), Load_CAPR(), Load_ECMY(), Load_PRIC(), Load_SIGN(), Load_VEHS(), MoveWaypointsToBaseStations(), Ptrs_TOWN(), SlCalcListLen(), SlCalcRefLen(), SlList(), and SlString().
SaveOrLoadResult LoadWithFilter | ( | LoadFilter * | reader | ) |
Load the game using a (reader) filter.
reader | The filter to read the savegame from. |
Definition at line 2667 of file saveload.cpp.
References SaveLoadParams::action, ClearSaveLoadState(), and DoLoad().
Referenced by SafeLoad().
int64 ReadValue | ( | const void * | ptr, | |
VarType | conv | |||
) |
Return a signed-long version of the value of a setting.
ptr | pointer to the variable | |
conv | type of variable, can be a non-clean type, eg one with other flags because it is parsed |
Definition at line 905 of file saveload.cpp.
References GetVarMemType(), and SLE_VAR_NULL.
Referenced by CmdChangeCompanySetting(), CmdChangeSetting(), SettingEntry::DrawSetting(), GameSettingsWindow::DrawWidget(), CheatWindow::DrawWidget(), NewsTypeData::GetDisplay(), IConsoleGetSetting(), IConsoleListSettings(), IniSaveSettings(), SettingEntry::IsVisibleByRestrictionMode(), LoadSettings(), GameSettingsWindow::OnClick(), CheatWindow::OnClick(), CheatWindow::OnQueryTextFinished(), SetCompanySetting(), SetSettingValue(), SlSaveLoadConv(), and SyncCompanySettings().
bool SaveloadCrashWithMissingNewGRFs | ( | ) |
Did loading the savegame cause a crash? If so, were NewGRFs missing?
Definition at line 325 of file afterload.cpp.
Referenced by HandleCrash().
SaveOrLoadResult SaveOrLoad | ( | const char * | filename, | |
int | mode, | |||
Subdirectory | sb, | |||
bool | threaded | |||
) |
Main Save or Load function where the high-level saveload functions are handled.
It opens the savegame, selects format and checks versions
filename | The name of the savegame being created/loaded | |
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. | |
sb | The sub directory to save the savegame in | |
threaded | True when threaded saving is allowed |
Definition at line 2687 of file saveload.cpp.
References _date, _date_fract, _do_autosave, _grfconfig, _network_server, _settings_client, _sl_minor_version, _sl_version, SaveLoadParams::action, AfterLoadGame(), BASE_DIR, ClearGRFConfigList(), ClearSaveLoadState(), DEBUG, DoLoad(), DoSave(), FioFOpenFile(), GamelogReset(), GamelogStartAction(), GamelogStopAction(), GetSaveLoadErrorString(), GLAT_LOAD, ClientSettings::gui, INVALID_STRING_ID, SAVE_DIR, SaveLoadParams::saveinprogress, SCENARIO_DIR, ShowErrorMessage(), SL_LOAD, SL_LOAD_CHECK, SL_OLD_LOAD, SL_REINIT, SL_SAVE, SlError(), GUISettings::threaded_saves, and WL_ERROR.
Referenced by _GenerateWorld(), DEF_CONSOLE_CMD(), DoAutosave(), DoExitSave(), LoadIntroGame(), SaveLoadWindow::OnClick(), SafeLoad(), StateGameLoop(), and CrashLog::WriteSavegame().
SaveOrLoadResult SaveWithFilter | ( | SaveFilter * | writer, | |
bool | threaded | |||
) |
Save the game using a (writer) filter.
writer | The filter to write the savegame to. | |
threaded | Whether to try to perform the saving asynchroniously. |
Definition at line 2512 of file saveload.cpp.
References SaveLoadParams::action, ClearSaveLoadState(), and DoSave().
Referenced by ServerNetworkGameSocketHandler::SendMap().
void SlArray | ( | void * | array, | |
size_t | length, | |||
VarType | conv | |||
) |
Save/Load an array.
array | The array being manipulated | |
length | The length of the array in elements | |
conv | VarType type of the atomic array (int, byte, uint64, etc.) |
Definition at line 1145 of file saveload.cpp.
References _sl_version, SaveLoadParams::action, BSWAP32(), SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, SLA_NULL, SLA_PTRS, SLA_SAVE, SlCalcArrayLen(), SlCalcConvFileLen(), SlCalcConvMemLen(), SlCopyBytes(), SlSaveLoadConv(), and SlSetLength().
Referenced by Load_ANIT(), Load_CAPR(), Load_NAME(), Load_PRIC(), ScriptInstance::LoadObjects(), Save_ANIT(), and ScriptInstance::SaveObject().
void SlAutolength | ( | AutolengthProc * | proc, | |
void * | arg | |||
) |
Do something of which I have no idea what it is :P.
proc | The callback procedure that is called | |
arg | The variable that will be used for the callback procedure |
Definition at line 1542 of file saveload.cpp.
References SaveLoadParams::action, SaveLoadParams::dumper, MemoryDumper::GetSize(), SaveLoadParams::need_length, SaveLoadParams::obj_len, SLA_SAVE, SlErrorCorrupt(), and SlSetLength().
Referenced by SlStubSaveProc().
size_t SlCalcObjLength | ( | const void * | object, | |
const SaveLoad * | sld | |||
) |
Calculate the size of an object.
object | to be measured | |
sld | The SaveLoad description of the object so we know how to manipulate it |
Definition at line 1397 of file saveload.cpp.
References SaveLoad::cmd.
Referenced by SlObject().
void NORETURN SlError | ( | StringID | string, | |
const char * | extra_msg | |||
) |
Error handler.
Sets everything up to show an error message and to clean up the mess of a partial savegame load.
string | The translatable error message to show. | |
extra_msg | An extra error message coming from one of the APIs. |
Definition at line 506 of file saveload.cpp.
References _load_check_data, SaveLoadParams::action, LoadCheckData::error, LoadCheckData::error_data, SaveLoadParams::error_str, SaveLoadParams::extra_msg, free(), SLA_LOAD, SLA_LOAD_CHECK, SLA_PTRS, and SlNullPointers().
Referenced by AfterLoadGame(), DoLoad(), PacketWriter::Finish(), LZMALoadFilter::LZMALoadFilter(), LZMASaveFilter::LZMASaveFilter(), LZOLoadFilter::LZOLoadFilter(), LZOSaveFilter::LZOSaveFilter(), MoveWaypointsToBaseStations(), LZMALoadFilter::Read(), ZlibLoadFilter::Read(), LZOLoadFilter::Read(), SaveOrLoad(), SlErrorCorrupt(), FileWriter::Write(), PacketWriter::Write(), LZMASaveFilter::WriteLoop(), ZlibSaveFilter::WriteLoop(), ZlibLoadFilter::ZlibLoadFilter(), and ZlibSaveFilter::ZlibSaveFilter().
void NORETURN SlErrorCorrupt | ( | const char * | msg | ) |
Error handler for corrupt savegames.
Sets everything up to show the error message and to clean up the mess of a partial savegame load.
msg | Location the corruption has been spotted. |
Definition at line 534 of file saveload.cpp.
References SlError().
Referenced by AfterLoadGame(), AfterLoadVehicles(), ConvertOldMultiheadToNew(), IntToReference(), Load_CHTS(), Load_NAME(), Load_VEHS(), LoadOldVehicle(), LZOLoadFilter::Read(), SetWaterClassDependingOnSurroundings(), SlAutolength(), SlIterateArray(), SlLoadCheckChunk(), SlLoadCheckChunks(), SlLoadChunk(), SlLoadChunks(), and SlReadSimpleGamma().
void SlGlobList | ( | const SaveLoadGlobVarList * | sldg | ) |
Save or Load (a list of) global variables.
sldg | The global variable that is being loaded or saved |
Definition at line 1532 of file saveload.cpp.
References SlObject().
Referenced by LoadSave_IBLD().
static bool SlIsObjectCurrentlyValid | ( | uint16 | version_from, | |
uint16 | version_to | |||
) | [inline, static] |
Checks if some version from/to combination falls within the range of the active savegame version.
version_from | Lowest version number that falls within the range. | |
version_to | Highest version number that falls within the range. |
Definition at line 471 of file saveload.h.
References SAVEGAME_VERSION.
Referenced by CmdChangeSetting(), GetSettingFromName(), HandleOldDiffCustom(), IConsoleListSettings(), IniLoadSettings(), and IniSaveSettings().
int SlIterateArray | ( | ) |
Iterate through the elements of an array and read the whole thing.
Definition at line 787 of file saveload.cpp.
References SaveLoadParams::block_mode, DEBUG, ReadBuffer::GetSize(), SaveLoadParams::obj_len, SaveLoadParams::reader, and SlErrorCorrupt().
Referenced by Load_CAPA(), Load_ITBL(), Load_NAME(), Load_NewGRFMapping(), Load_PSAC(), Load_SIGN(), Load_VEHS(), LoadDelivery(), LoadPickup(), and SlSkipArray().
void SlObject | ( | void * | object, | |
const SaveLoad * | sld | |||
) |
Main SaveLoad function.
object | The object that is being saved or loaded | |
sld | The SaveLoad description of the object so we know how to manipulate it |
Definition at line 1514 of file saveload.cpp.
References SaveLoad::address, SaveLoad::cmd, GetVariableAddress(), SaveLoad::global, SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, SlCalcObjLength(), and SlSetLength().
Referenced by ScriptInstance::Load(), Load_CAPA(), Load_ECMY(), Load_ITBL(), Load_NewGRFMapping(), Load_PSAC(), Load_SIGN(), Load_VEHS(), LoadDelivery(), ScriptInstance::LoadEmpty(), ScriptInstance::LoadObjects(), LoadPickup(), Ptrs_TOWN(), ScriptInstance::Save(), Save_CAPA(), Save_ECMY(), Save_ITBL(), Save_NewGRFMapping(), Save_PSAC(), Save_SIGN(), Save_VEHS(), SaveDelivery(), ScriptInstance::SaveEmpty(), ScriptInstance::SaveObject(), SavePickup(), and SlGlobList().
byte SlReadByte | ( | ) |
Wrapper for reading a byte from the buffer.
Definition at line 578 of file saveload.cpp.
References SaveLoadParams::reader.
Referenced by Load_CHTS(), Load_VEHS(), SlCopyBytes(), SlLoadCheckChunk(), SlLoadChunk(), SlReadSimpleGamma(), SlSaveLoadConv(), and SlSkipBytes().
void SlSetLength | ( | size_t | length | ) |
Sets the length of either a RIFF object or the number of items in an array.
This lets us load an object or an array of arbitrary size
length | The length of the sought object/array |
Definition at line 832 of file saveload.cpp.
References SaveLoadParams::action, SaveLoadParams::block_mode, SaveLoadParams::last_array_index, SaveLoadParams::need_length, NL_CALCLENGTH, NL_WANTLENGTH, SaveLoadParams::obj_len, and SLA_SAVE.
Referenced by Save_ANIT(), Save_CHTS(), SaveSettings(), SlArray(), SlAutolength(), SlList(), and SlObject().
void SlWriteByte | ( | byte | b | ) |
Wrapper for writing a byte to the dumper.
b | The byte to write. |
Definition at line 587 of file saveload.cpp.
References SaveLoadParams::dumper, and MemoryDumper::WriteByte().
Referenced by Save_CHTS(), SlCopyBytes(), SlSaveChunk(), SlSaveLoadConv(), and SlWriteSimpleGamma().
void WriteValue | ( | void * | ptr, | |
VarType | conv, | |||
int64 | val | |||
) |
Write the value of a setting.
ptr | pointer to the variable | |
conv | type of variable, can be a non-clean type, eg with other flags. It is parsed upon read | |
val | the new value being given to the variable |
Definition at line 929 of file saveload.cpp.
References CopyFromOldName(), GetVarMemType(), SLE_VAR_NAME, and SLE_VAR_NULL.
Referenced by CmdChangeCompanySetting(), CmdChangeSetting(), CheatWindow::OnClick(), CheatWindow::OnQueryTextFinished(), SlSaveLoadConv(), and Write_ValidateSetting().