|
OpenTTD Source 20260917-master-gec444f7315
|
#include <saveload.h>
Public Types | |
| template<typename R = void> | |
| using | AddressFunction = const R *(*)(const void *base, size_t extra) |
| Function that returns the address of a variable. | |
Static Public Member Functions | |
| static constexpr bool | IsIntegralFileType (VarFileType file_type) |
| Check whether the given file type is stored as a simple number. | |
| template<typename T, VarFileType file_type> | |
| static constexpr VarMemType | DetermineMemType () |
Determine the VarMemType type given the variable's decltype and occasionally the file type to distinguish options. | |
| template<typename T> | |
| static constexpr bool | IsValidRefType (SLRefType ref_type) |
| Checks whether the memory type and given reference type match. | |
| template<typename T> | |
| static constexpr AddressFunction | ToAddressFunction (AddressFunction< T > address_func) |
| To be able to get the type information into the SaveLoad constructing functions, we need some infrastructure. | |
| template<VarFileType file_type, typename T> | |
| static SaveLoad | Variable (std::string name, AddressFunction< T > address_func, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion, size_t extra=0) |
| Storage of a variable in some savegame versions. | |
| template<SLRefType type, typename T> | |
| static SaveLoad | Reference (std::string name, AddressFunction< T > address_func, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion) |
| Storage of a reference to a pool element in some savegame versions. | |
| template<typename T> | |
| static SaveLoad | String (std::string name, AddressFunction< T > address_func, StringValidationSettings string_validation_settings={}, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion, size_t extra=0) |
| Storage of a string in some savegame versions. | |
| template<typename T> requires std::is_base_of_v<SaveLoadHandler, T> | |
| static SaveLoad | Struct (std::string name, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion) |
| Storage of a structs, optionally in some savegame versions. | |
| template<VarFileType file_type, uint16_t length, typename T> | |
| static SaveLoad | Array (std::string name, AddressFunction< T > address_func, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion, size_t extra=0) |
| Storage of an array in some savegame versions. | |
| template<VarFileType file_type, typename T> | |
| static SaveLoad | Vector (std::string name, AddressFunction< T > address_func, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion) |
| Storage of a vector in some savegame versions. | |
| template<SLRefType type, typename T> | |
| static SaveLoad | ReferenceList (std::string name, AddressFunction< T > address_func, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion) |
| Storage of a list of references to pool elements in some savegame versions. | |
| template<typename T> requires std::is_base_of_v<SaveLoadHandler, T> | |
| static SaveLoad | StructList (std::string name, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion) |
| Storage of a list of structs, optionally in some savegame versions. | |
| template<typename T> | |
| static SaveLoad | SaveByte (std::string name, AddressFunction< T > address_func, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion) |
| Storage of a byte variable in some savegame versions that is not automatically read by the SaveLoad code. | |
| template<SLRefType type, typename T> | |
| static SaveLoad | ReferenceVector (std::string name, AddressFunction< T > address_func, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion) |
| Storage of a vector of references to pool elements in some savegame versions. | |
Data Fields | |
| std::string | name |
| Name of this field (optional, used for tables). | |
| SaveLoadType | cmd |
| The action to take with the saved/loaded type, All types need different action. | |
| VarType | conv {} |
| Type of the variable to be saved; this field combines both FileVarType and MemVarType. | |
| uint16_t | length {} |
| (Conditional) length of the variable (eg. arrays) (max array size is 65536 elements). | |
| SaveLoadVersion | version_from |
| Save/load the variable starting from this savegame version. | |
| SaveLoadVersion | version_to |
| Save/load the variable before this savegame version. | |
| AddressFunction | address_func = nullptr |
| Callback function the get the actual variable address in memory. | |
| size_t | extra_data = 0 |
| Extra data for the callback proc. | |
| std::shared_ptr< SaveLoadHandler > | handler {} |
| Custom handler for Save/Load procs. | |
SaveLoad type struct.
Do NOT use this directly but use the SLE_ macros defined just below!
Definition at line 764 of file saveload.h.
| using SaveLoad::AddressFunction = const R *(*)(const void *base, size_t extra) |
Function that returns the address of a variable.
| R | The return type of the function. |
| base | In case the variable comes from an object, this is the pointer to the begin of that object. Will be non-nullptr for objects, can be both non-nullptr and nullptr for global variables. |
| extra | An extra offset to apply. Mostly 0, except for a few LinkGraph settings variables. |
Definition at line 774 of file saveload.h.
|
inlinestatic |
Storage of an array in some savegame versions.
| file_type | Storage type of the array's elements in the savegame. |
| length | The length of the array. |
| T | The type of the field in memory. This is automatically deduced and used for validation. |
| name | Field name for table chunks. |
| address_func | Function to get the address of the array. |
| from | First savegame version that has the field. Defaults to the first version. |
| to | Last savegame version that has the field. Defaults to the last version. |
| extra | Arbitrary extra data to pass to the address_func. |
Definition at line 1026 of file saveload.h.
References address_func, Array, DetermineMemType(), length, MaxVersion, MinVersion, name, SlVarSize(), T, and ToAddressFunction().
|
inlinestaticconstexpr |
Determine the VarMemType type given the variable's decltype and occasionally the file type to distinguish options.
If feasible a sanity check is do to check the file type against the variable's decltype, for example to prevent a bool to be saved as string.
| T | The variable's decltype. |
| file_type | The way this variable will be/is stored in the save file. |
VarMemType. Definition at line 818 of file saveload.h.
References Bool, DetermineMemType(), I16, I32, I64, I8, IsIntegralFileType(), Label, Name, Str, String, StringID, T, U16, U32, U64, and U8.
Referenced by Array(), DetermineMemType(), SaveByte(), Variable(), and Vector().
|
inlinestaticconstexpr |
Check whether the given file type is stored as a simple number.
| file_type | The file type to check. |
true iff signed or unsigned 8, 16, 32 or 64 bit integer. Definition at line 791 of file saveload.h.
References I16, I32, I64, I8, U16, U32, U64, and U8.
Referenced by DetermineMemType().
|
inlinestaticconstexpr |
Checks whether the memory type and given reference type match.
| T | The type of the reference in memory. |
| ref_type | The specified reference type. |
true iff the memory and reference type match. Definition at line 879 of file saveload.h.
References CargoPacket, EngineRenew, LinkGraph, LinkGraphJob, OldVehicle, OrderList, RoadStop, Station, Storage, Town, and Vehicle.
Referenced by ReferenceList(), and ReferenceVector().
|
inlinestatic |
Storage of a reference to a pool element in some savegame versions.
| type | The type of reference. |
| T | The type of the reference in memory. This is automatically deduced and used for validation. |
| name | Field name for table chunks. |
| address_func | Function to get the address of the reference. |
| from | First savegame version that has the field. Defaults to the first version. |
| to | Last savegame version that has the field. Defaults to the last version. |
Definition at line 951 of file saveload.h.
References address_func, MaxVersion, MinVersion, name, Reference, and ToAddressFunction().
Referenced by OrderBackup::GetOrderBackupDescription.
|
inlinestatic |
Storage of a list of references to pool elements in some savegame versions.
| type | The type of reference. |
| T | The type of the field in memory. This is automatically deduced and used for validation. |
| name | Field name for table chunks. |
| address_func | Function to get the address of the list. |
| from | First savegame version that has the field. Defaults to the first version. |
| to | Last savegame version that has the field. Defaults to the last version. |
Definition at line 1078 of file saveload.h.
References address_func, IsValidRefType(), MaxVersion, MinVersion, name, ReferenceList, T, and ToAddressFunction().
Referenced by LinkGraphSchedule::GetLinkGraphScheduleDesc.
|
inlinestatic |
Storage of a vector of references to pool elements in some savegame versions.
| type | The type of reference. |
| T | The type of the field in memory. This is automatically deduced and used for validation. |
| name | Field name for table chunks. |
| address_func | Function to get the address of the vector. |
| from | First savegame version that has the field. Defaults to the first version. |
| to | Last savegame version that has the field. Defaults to the last version. |
Definition at line 1149 of file saveload.h.
References address_func, IsValidRefType(), MaxVersion, MinVersion, name, ReferenceVector, T, and ToAddressFunction().
|
inlinestatic |
Storage of a byte variable in some savegame versions that is not automatically read by the SaveLoad code.
| T | The type of the variable in memory. This is automatically deduced and used for validation. |
| name | Field name for table chunks. |
| address_func | Function to get the address of the variable. |
| from | First savegame version that has the field. Defaults to the first version. |
| to | Last savegame version that has the field. Defaults to the last version. |
Definition at line 1125 of file saveload.h.
References address_func, DetermineMemType(), MaxVersion, MinVersion, name, SaveByte, ToAddressFunction(), and U8.
|
inlinestatic |
Storage of a string in some savegame versions.
| T | The type of the field in memory. This is automatically deduced and used for validation. |
| name | Field name for table chunks. |
| address_func | Function to get the address of the string. |
| string_validation_settings | Settings to the string validation that is performed. |
| from | First savegame version that has the field. Defaults to the first version. |
| to | Last savegame version that has the field. Defaults to the last version. |
| extra | Arbitrary extra data to pass to the address_func. |
Definition at line 977 of file saveload.h.
References address_func, and name.
Referenced by OrderBackup::GetOrderBackupDescription.
|
inlinestatic |
Storage of a structs, optionally in some savegame versions.
| T | SaveLoadHandler for the structs. |
| name | The name of the field. |
| from | First savegame version that has the field. Defaults to the first version. |
| to | Last savegame version that has the field. Defaults to the last version. |
Definition at line 1001 of file saveload.h.
References MaxVersion, MinVersion, name, and Struct.
Referenced by LinkGraph::GetLinkGraphJobDesc.
|
inlinestatic |
Storage of a list of structs, optionally in some savegame versions.
| T | SaveLoadHandler for the list of structs. |
| name | The name of the field. |
| from | First savegame version that has the field. Defaults to the first version. |
| to | Last savegame version that has the field. Defaults to the last version. |
Definition at line 1103 of file saveload.h.
References MaxVersion, MinVersion, name, and StructList.
Referenced by LinkGraph::GetLinkGraphDesc, OrderBackup::GetOrderBackupDescription, and OrderList::GetOrderListDescription.
|
inlinestaticconstexpr |
To be able to get the type information into the SaveLoad constructing functions, we need some infrastructure.
The easiest way to achieve this is not casting away the type information in the lambda that gets our address, however to store this we need to erase this type. This function practically erases this type.
| T | Return type of the given address function. |
| address_func | The function to convert. |
AddressFunction. Definition at line 906 of file saveload.h.
References address_func, and ToAddressFunction().
Referenced by Array(), Reference(), ReferenceList(), ReferenceVector(), SaveByte(), ToAddressFunction(), Variable(), and Vector().
|
inlinestatic |
Storage of a variable in some savegame versions.
| file_type | Storage type of the variable in the savegame. |
| T | The type of the variable in memory. This is automatically deduced and used for validation. |
| name | Field name for table chunks. |
| address_func | Function to get the address of the variable. |
| from | First savegame version that has the field. Defaults to the first version. |
| to | Last savegame version that has the field. Defaults to the last version. |
| extra | Arbitrary extra data to pass to the address_func. |
Definition at line 926 of file saveload.h.
References address_func, DetermineMemType(), MaxVersion, MinVersion, name, ToAddressFunction(), and Variable.
Referenced by CargoPacket::GetCargoPacketDesc, LinkGraph::GetLinkGraphDesc, LinkGraph::GetLinkGraphJobDesc, OrderBackup::GetOrderBackupDescription, Order::GetOrderDescription, and OrderList::GetOrderListDescription.
|
inlinestatic |
Storage of a vector in some savegame versions.
| file_type | Storage type of the vector's elements in the savegame. |
| T | The type of the field in memory. This is automatically deduced and used for validation. |
| name | Field name for table chunks. |
| address_func | Function to get the address of the vector. |
| from | First savegame version that has the field. Defaults to the first version. |
| to | Last savegame version that has the field. Defaults to the last version. |
Definition at line 1053 of file saveload.h.
References address_func, DetermineMemType(), MaxVersion, MinVersion, name, T, ToAddressFunction(), and Vector.
| AddressFunction SaveLoad::address_func = nullptr |
Callback function the get the actual variable address in memory.
Definition at line 782 of file saveload.h.
Referenced by Array(), GetVariableAddress(), Reference(), ReferenceList(), ReferenceVector(), SaveByte(), String(), ToAddressFunction(), Variable(), and Vector().
| SaveLoadType SaveLoad::cmd |
The action to take with the saved/loaded type, All types need different action.
Definition at line 777 of file saveload.h.
Referenced by GetSavegameFileType(), GetSettingsDesc(), SlCompatTableHeader(), and SlTableHeader().
| VarType SaveLoad::conv {} |
Type of the variable to be saved; this field combines both FileVarType and MemVarType.
Definition at line 778 of file saveload.h.
Referenced by GetSavegameFileType(), and GetVariableAddress().
| size_t SaveLoad::extra_data = 0 |
Extra data for the callback proc.
Definition at line 783 of file saveload.h.
Referenced by GetVariableAddress().
| std::shared_ptr<SaveLoadHandler> SaveLoad::handler {} |
Custom handler for Save/Load procs.
Definition at line 784 of file saveload.h.
Referenced by SlCompatTableHeader(), and SlTableHeader().
| uint16_t SaveLoad::length {} |
(Conditional) length of the variable (eg. arrays) (max array size is 65536 elements).
Definition at line 779 of file saveload.h.
Referenced by Array(), and GetSettingsDesc().
| std::string SaveLoad::name |
Name of this field (optional, used for tables).
Definition at line 776 of file saveload.h.
Referenced by Array(), SettingDesc::GetName(), Reference(), ReferenceList(), ReferenceVector(), SaveByte(), SlCompatTableHeader(), SlTableHeader(), String(), Struct(), StructList(), Variable(), and Vector().
| SaveLoadVersion SaveLoad::version_from |
Save/load the variable starting from this savegame version.
Definition at line 780 of file saveload.h.
Referenced by CmdChangeSetting(), GetSaveLoadFromSettingTable(), GetSettingFromName(), GetSettingsDesc(), IniLoadSettings(), IniSaveSettings(), LoadSettings(), SlIsObjectValidInSavegame(), and SurveySettingsTable().
| SaveLoadVersion SaveLoad::version_to |
Save/load the variable before this savegame version.
Definition at line 781 of file saveload.h.
Referenced by CmdChangeSetting(), GetSaveLoadFromSettingTable(), GetSettingFromName(), GetSettingsDesc(), IniLoadSettings(), IniSaveSettings(), LoadSettings(), SlIsObjectValidInSavegame(), and SurveySettingsTable().