15 #include "../fileio_type.h" 16 #include "../strings_type.h" 315 void SetName(
const char *name);
335 void WaitTillSaved();
342 typedef void ChunkSaveLoadProc();
343 typedef void AutolengthProc(
void *arg);
348 ChunkSaveLoadProc *save_proc;
349 ChunkSaveLoadProc *load_proc;
350 ChunkSaveLoadProc *ptrs_proc;
351 ChunkSaveLoadProc *load_check_proc;
411 SLE_VAR_I16 = 3 << 4,
412 SLE_VAR_U16 = 4 << 4,
413 SLE_VAR_I32 = 5 << 4,
414 SLE_VAR_U32 = 6 << 4,
415 SLE_VAR_I64 = 7 << 4,
416 SLE_VAR_U64 = 8 << 4,
426 SLE_VAR_CHAR = SLE_VAR_I8,
431 SLE_BOOL = SLE_FILE_I8 | SLE_VAR_BL,
432 SLE_INT8 = SLE_FILE_I8 | SLE_VAR_I8,
433 SLE_UINT8 = SLE_FILE_U8 | SLE_VAR_U8,
434 SLE_INT16 = SLE_FILE_I16 | SLE_VAR_I16,
435 SLE_UINT16 = SLE_FILE_U16 | SLE_VAR_U16,
436 SLE_INT32 = SLE_FILE_I32 | SLE_VAR_I32,
437 SLE_UINT32 = SLE_FILE_U32 | SLE_VAR_U32,
438 SLE_INT64 = SLE_FILE_I64 | SLE_VAR_I64,
439 SLE_UINT64 = SLE_FILE_U64 | SLE_VAR_U64,
440 SLE_CHAR = SLE_FILE_I8 | SLE_VAR_CHAR,
449 SLE_UINT = SLE_UINT32,
451 SLE_STRB = SLE_STRINGBUF,
452 SLE_STRBQ = SLE_STRINGBQUOTE,
454 SLE_STRQ = SLE_STRINGQUOTE,
466 typedef uint32 VarType;
514 #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)} 524 #define SLE_CONDVAR(base, variable, type, from, to) SLE_GENERAL(SL_VAR, base, variable, type, 0, from, to) 534 #define SLE_CONDREF(base, variable, type, from, to) SLE_GENERAL(SL_REF, base, variable, type, 0, from, to) 545 #define SLE_CONDARR(base, variable, type, length, from, to) SLE_GENERAL(SL_ARR, base, variable, type, length, from, to) 556 #define SLE_CONDSTR(base, variable, type, length, from, to) SLE_GENERAL(SL_STR, base, variable, type, length, from, to) 566 #define SLE_CONDLST(base, variable, type, from, to) SLE_GENERAL(SL_LST, base, variable, type, 0, from, to) 576 #define SLE_CONDDEQUE(base, variable, type, from, to) SLE_GENERAL(SL_DEQUE, base, variable, type, 0, from, to) 584 #define SLE_VAR(base, variable, type) SLE_CONDVAR(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION) 592 #define SLE_REF(base, variable, type) SLE_CONDREF(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION) 601 #define SLE_ARR(base, variable, type, length) SLE_CONDARR(base, variable, type, length, SL_MIN_VERSION, SL_MAX_VERSION) 610 #define SLE_STR(base, variable, type, length) SLE_CONDSTR(base, variable, type, length, SL_MIN_VERSION, SL_MAX_VERSION) 618 #define SLE_LST(base, variable, type) SLE_CONDLST(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION) 624 #define SLE_NULL(length) SLE_CONDNULL(length, SL_MIN_VERSION, SL_MAX_VERSION) 632 #define SLE_CONDNULL(length, from, to) SLE_CONDARR(NullStruct, null, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to) 635 #define SLE_WRITEBYTE(base, variable) SLE_GENERAL(SL_WRITEBYTE, base, variable, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION) 637 #define SLE_VEH_INCLUDE() {false, SL_VEH_INCLUDE, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, NULL, 0} 638 #define SLE_ST_INCLUDE() {false, SL_ST_INCLUDE, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, NULL, 0} 641 #define SLE_END() {false, SL_END, 0, 0, SL_MIN_VERSION, SL_MIN_VERSION, NULL, 0} 652 #define SLEG_GENERAL(cmd, variable, type, length, from, to) {true, cmd, type, length, from, to, (void*)&variable, sizeof(variable)} 661 #define SLEG_CONDVAR(variable, type, from, to) SLEG_GENERAL(SL_VAR, variable, type, 0, from, to) 670 #define SLEG_CONDREF(variable, type, from, to) SLEG_GENERAL(SL_REF, variable, type, 0, from, to) 680 #define SLEG_CONDARR(variable, type, length, from, to) SLEG_GENERAL(SL_ARR, variable, type, length, from, to) 690 #define SLEG_CONDSTR(variable, type, length, from, to) SLEG_GENERAL(SL_STR, variable, type, length, from, to) 699 #define SLEG_CONDLST(variable, type, from, to) SLEG_GENERAL(SL_LST, variable, type, 0, from, to) 706 #define SLEG_VAR(variable, type) SLEG_CONDVAR(variable, type, SL_MIN_VERSION, SL_MAX_VERSION) 713 #define SLEG_REF(variable, type) SLEG_CONDREF(variable, type, SL_MIN_VERSION, SL_MAX_VERSION) 720 #define SLEG_ARR(variable, type) SLEG_CONDARR(variable, type, lengthof(variable), SL_MIN_VERSION, SL_MAX_VERSION) 727 #define SLEG_STR(variable, type) SLEG_CONDSTR(variable, type, sizeof(variable), SL_MIN_VERSION, SL_MAX_VERSION) 734 #define SLEG_LST(variable, type) SLEG_CONDLST(variable, type, SL_MIN_VERSION, SL_MAX_VERSION) 742 #define SLEG_CONDNULL(length, from, to) {true, SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, (void*)NULL} 745 #define SLEG_END() {true, SL_END, 0, 0, SL_MIN_VERSION, SL_MIN_VERSION, NULL, 0} 757 return _sl_version < major || (minor > 0 && _sl_version == major && _sl_minor_version < minor);
770 if (SAVEGAME_VERSION < version_from || SAVEGAME_VERSION >= version_to)
return false;
815 return const_cast<byte *
>((
const byte*)(sld->
global ? NULL :
object) + (ptrdiff_t)sld->
address);
818 int64
ReadValue(
const void *ptr, VarType conv);
819 void WriteValue(
void *ptr, VarType conv, int64 val);
821 void SlSetArrayIndex(uint index);
827 size_t SlCalcObjMemberLength(
const void *
object,
const SaveLoad *sld);
834 void SlArray(
void *array,
size_t length, VarType conv);
836 bool SlObjectMember(
void *
object,
const SaveLoad *sld);
void ProcessAsyncSaveFinish()
Handle async save finishes.
FiosType
Elements of a file system that are recognized.
AbstractFileType
The different abstract types of files that the system knows about.
void SetSaveLoadError(StringID str)
Set the error message from outside of the actual loading/saving of the game (AfterLoadGame and friend...
void SlGlobList(const SaveLoadGlobVarList *sldg)
Save or Load (a list of) global variables.
char _savegame_format[8]
how to compress savegames
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
size_t SlGetFieldLength()
Get the length of the current object.
SaveLoadVersion version_from
save/load the variable starting from this savegame version
204 PR#7065 Add extra rotation stages for ships.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
2.0 0.3.0 2.1 0.3.1, 0.3.2
SaveLoadVersion
SaveLoad versions Previous savegame versions, the trunk revision where they were introduced and the r...
string (with pre-allocated buffer)
uint32 flags
Flags of the chunk.
void SetName(const char *name)
Set the name of the file.
void NORETURN SlErrorCorrupt(const char *msg)
Error handler for corrupt savegames.
SaveLoadTypes
Type of data saved.
VarTypes
VarTypes is the general bitmasked magic type that tells us certain characteristics about the variable...
do not synchronize over network (but it is saved if SLF_NOT_IN_SAVE is not set)
uint32 id
Unique ID (4 letters).
SaveOrLoadResult SaveWithFilter(struct SaveFilter *writer, bool threaded)
Save the game using a (writer) filter.
SaveLoadVersion _sl_version
the major savegame version identifier
char title[255]
Internal name of the game.
SaveOrLoadResult SaveOrLoad(const char *filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded=true)
Main Save or Load function where the high-level saveload functions are handled.
188 26169 FS#5831 Unify RV travel time
Load/save a reference to a link graph job.
Load/save an old-style reference to a vehicle (for pre-4.4 savegames).
191 26636 FS#6026 Fix disaster vehicle storage (No bump) 191 26646 FS#6041 Linkgraph - store location...
void * address
address of variable OR offset of variable in the struct (max offset is 65536)
TTD savegame (can be detected incorrectly)
do not save to config file
void NORETURN SlErrorCorruptFmt(const char *format,...)
Issue an SlErrorCorrupt with a format string.
Load/save a reference to a town.
SavegameType
Types of save games.
void WriteValue(void *ptr, VarType conv, int64 val)
Write the value of a setting.
int64 ReadValue(const void *ptr, VarType conv)
Return a signed-long version of the value of a setting.
Deals with the type of the savegame, independent of extension.
size_t size
the sizeof size.
206 PR#7150 Ship/lock movement changes.
void SlArray(void *array, size_t length, VarType conv)
Save/Load an array.
void SlAutolength(AutolengthProc *proc, void *arg)
Do something of which I have no idea what it is :P.
Interface for filtering a savegame till it is loaded.
uint16 length
(conditional) length of the variable (eg. arrays) (max array size is 65536 elements) ...
Load/save a reference to a bus/truck stop.
207 PR#7175 Cargo monitor data packing fix to support 64 cargotypes.
ChunkType
Flags of a chunk.
void NORETURN SlError(StringID string, const char *extra_msg=NULL)
Error handler.
bool global
should we load a global variable or a non-global one
Load/save a reference to an engine renewal (autoreplace).
void SetTitle(const char *title)
Set the title of the file.
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
VarType conv
type of the variable to be saved, int
byte SaveLoadType
Save/load type.
SLRefType
Type of reference (SLE_REF, SLE_CONDREF).
void GenerateDefaultSaveName(char *buf, const char *last)
Fill the buffer with the default name for a savegame or screenshot.
allow new lines in the strings
Highest possible saveload version.
SaveOrLoadResult
Save or load result codes.
do not save with savegame, basically client-based
205 PR#7108 Livery storage change and group liveries.
allow control codes in the strings
5.0 1429 5.1 1440 5.2 1525 0.3.6
StringID offset into strings-array.
189 26450 Heirarchical vehicle subgroups
byte _sl_minor_version
the minor savegame version, DO NOT USE!
202 PR#6867 Increase industry cargo slots to 16 in, 16 out
Load/save a reference to a station.
TTDP savegame in new format (data at SE border)
Load/save a reference to an order.
byte SlReadByte()
Wrapper for reading a byte from the buffer.
static VarType GetVarFileType(VarType type)
Get the FileType of a setting.
const SaveLoadVersion SAVEGAME_VERSION
current savegame version
const char * GetSaveLoadErrorString()
Get the string representation of the error message.
static VarType GetVarMemType(VarType type)
Get the NumberType of a setting.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
static bool IsNumericType(VarType conv)
Check if the given saveload type is a numeric type.
SaveOrLoadResult LoadWithFilter(struct LoadFilter *reader)
Load the game using a (reader) filter.
SaveLoadOperation
Operation performed on the file.
Load/save a reference to a vehicle.
Handlers and description of chunk.
string enclosed in quotes (with pre-allocated buffer)
201 PR#6885 Extend NewGRF persistant storages.
static void * GetVariableAddress(const void *object, const SaveLoad *sld)
Get the address of the variable.
Load/save a reference to a cargo packet.
TTDP savegame ( -//- ) (data at NW border)
186 25833 Objects storage
SaveLoadVersion version_to
save/load the variable until this savegame version
static bool SlIsObjectCurrentlyValid(SaveLoadVersion version_from, SaveLoadVersion version_to)
Checks if some version from/to combination falls within the range of the active savegame version...
190 26547 Separate order travel and wait times
void DoExitSave()
Do a save when exiting the game (_settings_client.gui.autosave_on_exit)
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
useful to write zeros in savegame.
string pointer enclosed in quotes
broken savegame (used internally)
bool SaveloadCrashWithMissingNewGRFs()
Did loading the savegame cause a crash? If so, were NewGRFs missing?
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
SaveLoadType cmd
the action to take with the saved/loaded type, All types need different action
184 25508 Unit localisation split
198 PR#6763 Switch town growth rate and counter to actual game ticks
char name[MAX_PATH]
Name of the file.
SaveLoadOperation file_op
File operation to perform.
void SlWriteByte(byte b)
Wrapper for writing a byte to the dumper.
AbstractFileType abstract_ftype
Abstract type of file (scenario, heightmap, etc).
void SlSetLength(size_t length)
Sets the length of either a RIFF object or the number of items in an array.
192 26700 FS#6066 Fix saving of order backups
Load/save a reference to an orderlist.
Load/save a reference to a link graph.
203 PR#7072 Add path cache for ships
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
void SetMode(FiosType ft)
Set the mode and file type of the file to save or load based on the type of file entry at the file sy...
DetailedFileType detail_ftype
Concrete file type (PNG, BMP, old save, etc).
182 25115 FS#5492, r25259, r25296 Goal status
199 PR#6802 Extend cargotypes to 64
Interface for filtering a savegame till it is written.
187 25899 Linkgraph - restricted flows
error that was caught before internal structures were modified
200 PR#6805 Extend railtypes to 64, adding uint16 to map array.
DetailedFileType
Kinds of files in each AbstractFileType.
SaveLoad SaveLoadGlobVarList
Same as SaveLoad but global variables are used (for better readability);.
size_t SlCalcObjLength(const void *object, const SaveLoad *sld)
Calculate the size of an object.
old custom name to be converted to a char pointer
Last chunk in this array.
4.0 1 4.1 122 0.3.3, 0.3.4 4.2 1222 0.3.5 4.3 1417 4.4 1426
bool _do_autosave
are we doing an autosave at the moment?
Load/save a reference to a persistent storage.
error that was caught in the middle of updating game state, need to clear it. (can only happen during...