OpenTTD
|
Functions/types related to saving and loading games. More...
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... |
Macros | |
#define | SL_MAX_VERSION UINT16_MAX |
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), cpp_sizeof(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, 0} |
#define | SLE_ST_INCLUDE() {false, SL_ST_INCLUDE, 0, 0, 0, SL_MAX_VERSION, NULL, 0} |
#define | SLE_END() {false, SL_END, 0, 0, 0, 0, NULL, 0} |
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, sizeof(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, 0} |
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, REF_LINK_GRAPH = 10, REF_LINK_GRAPH_JOB = 11 } |
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) |
Set the error message from outside of the actual loading/saving of the game (AfterLoadGame and friends) | |
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 UINT16_MAX |
Highest possible savegame version.
Definition at line 91 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 308 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 262 of file saveload.h.
Referenced by GetVehicleDescription().
#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 283 of file saveload.h.
Referenced by 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 339 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 251 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 273 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 241 of file saveload.h.
Referenced by GetCargoPacketDesc(), GetGoodsDesc(), and GetVehicleDescription().
#define SLE_END | ( | ) | {false, SL_END, 0, 0, 0, 0, NULL, 0} |
End marker of a struct/class save or load.
Definition at line 348 of file saveload.h.
Referenced by GetCargoPacketDesc(), GetGoodsDesc(), GetLinkGraphDesc(), GetLinkGraphJobDesc(), GetLinkGraphScheduleDesc(), and GetVehicleDescription().
#define SLE_GENERAL | ( | cmd, | |
base, | |||
variable, | |||
type, | |||
length, | |||
from, | |||
to | |||
) | {false, cmd, type, length, from, to, (void*)cpp_offsetof(base, variable), cpp_sizeof(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 231 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 325 of file saveload.h.
Referenced by GetLinkGraphScheduleDesc().
#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 331 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 299 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 317 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 291 of file saveload.h.
Referenced by GetCargoPacketDesc(), GetGoodsDesc(), GetLinkGraphDesc(), GetLinkGraphJobDesc(), 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 342 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 427 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 387 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 406 of file saveload.h.
Referenced by GetGoodsDesc().
#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 449 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 377 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 397 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 368 of file saveload.h.
Referenced by GetGoodsDesc(), and GetVehicleDescription().
#define SLEG_END | ( | ) | {true, SL_END, 0, 0, 0, 0, NULL, 0} |
End marker of global variables save or load.
Definition at line 452 of file saveload.h.
#define SLEG_GENERAL | ( | cmd, | |
variable, | |||
type, | |||
length, | |||
from, | |||
to | |||
) | {true, cmd, type, length, from, to, (void*)&variable, sizeof(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 359 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 441 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 420 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 434 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 413 of file saveload.h.
Referenced by GetLinkGraphDesc().
typedef byte SaveLoadType |
enum ChunkType |
Flags of a chunk.
Definition at line 94 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 187 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 111 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 2863 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().
|
inlinestatic |
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 499 of file saveload.h.
Referenced by SlSaveLoadConv().
|
inlinestatic |
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 520 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().
|
inlinestatic |
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 488 of file saveload.h.
Referenced by IConsoleGetSetting(), IConsoleListSettings(), IniLoadSettings(), IniSaveSettings(), IsNumericType(), IsVariableSizeRight(), ReadValue(), SetSettingValue(), SlCalcStringLen(), SlString(), Write_ValidateSetting(), and WriteValue().
|
inlinestatic |
Check if the given saveload type is a numeric type.
conv | the type to check |
Definition at line 509 of file saveload.h.
References GetVarMemType().
Referenced by LoadSettings().
|
inlinestatic |
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 460 of file saveload.h.
References _sl_minor_version, and _sl_version.
Referenced by CargoPacket::AfterLoad(), AfterLoadGame(), AfterLoadLinkGraphs(), AfterLoadStoryBook(), AfterLoadVehicles(), Order::ConvertFromOldSavegame(), CopyFromOldName(), DoLoad(), HandleOldDiffCustom(), IntToReference(), Load_ANIT(), Load_CAPR(), Load_ECMY(), Load_PRIC(), Load_SIGN(), Load_VEHS(), MoveWaypointsToBaseStations(), Ptrs_TOWN(), SaveLoad_LinkGraph(), 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 2759 of file saveload.cpp.
References SaveLoadParams::action, ClearSaveLoadState(), DoLoad(), SL_REINIT, and SLA_LOAD.
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 942 of file saveload.cpp.
References GetVarMemType(), and SLE_VAR_NULL.
Referenced by CmdChangeCompanySetting(), CmdChangeSetting(), SettingEntry::DrawSetting(), CheatWindow::DrawWidget(), GameSettingsWindow::DrawWidget(), NewsTypeData::GetDisplay(), IConsoleGetSetting(), IConsoleListSettings(), IniSaveSettings(), SettingEntry::IsVisibleByRestrictionMode(), LoadSettings(), CheatWindow::OnClick(), GameSettingsWindow::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 359 of file afterload.cpp.
References _saveload_crash_with_missing_newgrfs.
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 2779 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_ERROR, SL_LOAD, SL_LOAD_CHECK, SL_OK, SL_OLD_LOAD, SL_REINIT, SL_SAVE, SLA_LOAD, SLA_LOAD_CHECK, SLA_SAVE, SlError(), GUISettings::threaded_saves, and WL_ERROR.
Referenced by _GenerateWorld(), DEF_CONSOLE_CMD(), DoAutosave(), DoExitSave(), LoadIntroGame(), SaveLoadWindow::OnClick(), openttd_main(), 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 asynchronously. |
Definition at line 2604 of file saveload.cpp.
References SaveLoadParams::action, ClearSaveLoadState(), DoSave(), SL_ERROR, and SLA_SAVE.
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 1182 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 1630 of file saveload.cpp.
References SaveLoadParams::action, SaveLoadParams::dumper, MemoryDumper::GetSize(), SaveLoadParams::need_length, NL_CALCLENGTH, NL_WANTLENGTH, SaveLoadParams::obj_len, SLA_SAVE, SlErrorCorrupt(), and SlSetLength().
Referenced by Save_LGRJ(), Save_LGRP(), and 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 1444 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 529 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, SlNullPointers(), and stredup().
Referenced by AfterLoadGame(), DoLoad(), PacketWriter::Finish(), LZMALoadFilter::LZMALoadFilter(), LZMASaveFilter::LZMASaveFilter(), LZOLoadFilter::LZOLoadFilter(), LZOSaveFilter::LZOSaveFilter(), MoveWaypointsToBaseStations(), LZOLoadFilter::Read(), ZlibLoadFilter::Read(), LZMALoadFilter::Read(), SaveOrLoad(), SlErrorCorrupt(), PacketWriter::Write(), FileWriter::Write(), ZlibSaveFilter::WriteLoop(), LZMASaveFilter::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 557 of file saveload.cpp.
References SlError().
Referenced by AfterLoadGame(), AfterLoadVehicles(), ConvertOldMultiheadToNew(), IntToReference(), Load_CHTS(), Load_ITBL(), Load_NAME(), Load_NewGRFMapping(), 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 1620 of file saveload.cpp.
References SlObject().
Referenced by LoadSave_IBLD().
|
inlinestatic |
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 474 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 824 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_LGRJ(), Load_LGRP(), 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 1602 of file saveload.cpp.
References SaveLoad::address, SaveLoad::cmd, GetVariableAddress(), SaveLoad::global, SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, SlCalcObjLength(), and SlSetLength().
Referenced by DoSave_LGRJ(), DoSave_LGRP(), ScriptInstance::Load(), Load_CAPA(), Load_ECMY(), Load_ITBL(), Load_LGRJ(), Load_LGRP(), Load_LGRS(), Load_NewGRFMapping(), Load_PSAC(), Load_SIGN(), Load_VEHS(), LoadDelivery(), ScriptInstance::LoadEmpty(), ScriptInstance::LoadObjects(), LoadPickup(), Ptrs_LGRS(), Ptrs_TOWN(), ScriptInstance::Save(), Save_CAPA(), Save_ECMY(), Save_ITBL(), Save_LGRS(), Save_NewGRFMapping(), Save_PSAC(), Save_SIGN(), Save_VEHS(), SaveDelivery(), ScriptInstance::SaveEmpty(), SaveLoad_LinkGraph(), ScriptInstance::SaveObject(), SavePickup(), and SlGlobList().
byte SlReadByte | ( | ) |
Wrapper for reading a byte from the buffer.
Definition at line 601 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 869 of file saveload.cpp.
References SaveLoadParams::action, SaveLoadParams::block_mode, SaveLoadParams::last_array_index, SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, 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 610 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 966 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().