OpenTTD Source
20241121-master-g67a0fccfad
|
All actions handling saving and loading goes on in this file. More...
#include "../stdafx.h"
#include "../debug.h"
#include "../station_base.h"
#include "../thread.h"
#include "../town.h"
#include "../network/network.h"
#include "../window_func.h"
#include "../strings_func.h"
#include "../core/endian_func.hpp"
#include "../vehicle_base.h"
#include "../company_func.h"
#include "../timer/timer_game_economy.h"
#include "../autoreplace_base.h"
#include "../roadstop_base.h"
#include "../linkgraph/linkgraph.h"
#include "../linkgraph/linkgraphjob.h"
#include "../statusbar_gui.h"
#include "../fileio_func.h"
#include "../gamelog.h"
#include "../string_func.h"
#include "../fios.h"
#include "../error.h"
#include <atomic>
#include "table/strings.h"
#include "saveload_internal.h"
#include "saveload_filter.h"
#include "../safeguards.h"
#include <lzo/lzo1x.h>
#include <zlib.h>
#include <lzma.h>
Go to the source code of this file.
Data Structures | |
struct | ReadBuffer |
A buffer for reading (and buffering) savegame data. More... | |
struct | MemoryDumper |
Container for dumping the savegame (quickly) to memory. More... | |
struct | SaveLoadParams |
The saveload struct, containing reader-writer functions, buffer, version, etc. More... | |
class | SlStorageHelper< Tstorage, Tvar, Tallocator > |
Template class to help with list-like types. More... | |
class | SlSkipHandler |
Handler that is assigned when there is a struct read in the savegame which is not known to the code. More... | |
struct | FileReader |
Yes, simply reading from a file. More... | |
struct | FileWriter |
Yes, simply writing to a file. More... | |
struct | LZOLoadFilter |
Filter using LZO compression. More... | |
struct | LZOSaveFilter |
Filter using LZO compression. More... | |
struct | NoCompLoadFilter |
Filter without any compression. More... | |
struct | NoCompSaveFilter |
Filter without any compression. More... | |
struct | ZlibLoadFilter |
Filter using Zlib compression. More... | |
struct | ZlibSaveFilter |
Filter using Zlib compression. More... | |
struct | LZMALoadFilter |
Filter without any compression. More... | |
struct | LZMASaveFilter |
Filter using LZMA compression. More... | |
struct | SaveLoadFormat |
The format for a reader/writer type of a savegame. More... | |
Typedefs | |
typedef void(* | AsyncSaveFinishProc) () |
Callback for when the savegame loading is finished. | |
Enumerations | |
enum | SaveLoadAction { SLA_LOAD , SLA_SAVE , SLA_PTRS , SLA_NULL , SLA_LOAD_CHECK } |
What are we currently doing? More... | |
enum | NeedLength { NL_NONE = 0 , NL_WANTLENGTH = 1 , NL_CALCLENGTH = 2 } |
Functions | |
static const std::vector< ChunkHandlerRef > & | ChunkHandlers () |
static void | SlNullPointers () |
Null all pointers (convert index -> nullptr) | |
void | SlError (StringID string, const std::string &extra_msg) |
Error handler. More... | |
void | SlErrorCorrupt (const std::string &msg) |
Error handler for corrupt savegames. More... | |
static void | SetAsyncSaveFinish (AsyncSaveFinishProc proc) |
Called by save thread to tell we finished saving. More... | |
void | ProcessAsyncSaveFinish () |
Handle async save finishes. | |
uint8_t | SlReadByte () |
Wrapper for reading a byte from the buffer. More... | |
void | SlWriteByte (uint8_t b) |
Wrapper for writing a byte to the dumper. More... | |
static int | SlReadUint16 () |
static uint32_t | SlReadUint32 () |
static uint64_t | SlReadUint64 () |
static void | SlWriteUint16 (uint16_t v) |
static void | SlWriteUint32 (uint32_t v) |
static void | SlWriteUint64 (uint64_t x) |
static uint | SlReadSimpleGamma () |
Read in the header descriptor of an object or an array. More... | |
static void | SlWriteSimpleGamma (size_t i) |
Write the header descriptor of an object or an array. More... | |
static uint | SlGetGammaLength (size_t i) |
Return how many bytes used to encode a gamma value. | |
static uint | SlReadSparseIndex () |
static void | SlWriteSparseIndex (uint index) |
static uint | SlReadArrayLength () |
static void | SlWriteArrayLength (size_t length) |
static uint | SlGetArrayLength (size_t length) |
static uint8_t | GetSavegameFileType (const SaveLoad &sld) |
Return the type as saved/loaded inside the savegame. | |
static uint | SlCalcConvMemLen (VarType conv) |
Return the size in bytes of a certain type of normal/atomic variable as it appears in memory. More... | |
static uint8_t | SlCalcConvFileLen (VarType conv) |
Return the size in bytes of a certain type of normal/atomic variable as it appears in a saved game. More... | |
static size_t | SlCalcRefLen () |
Return the size in bytes of a reference (pointer) | |
void | SlSetArrayIndex (uint index) |
int | SlIterateArray () |
Iterate through the elements of an array and read the whole thing. More... | |
void | SlSkipArray () |
Skip an array or sparse array. | |
void | SlSetLength (size_t length) |
Sets the length of either a RIFF object or the number of items in an array. More... | |
static void | SlCopyBytes (void *ptr, size_t length) |
Save/Load bytes. More... | |
size_t | SlGetFieldLength () |
Get the length of the current object. | |
int64_t | ReadValue (const void *ptr, VarType conv) |
Return a signed-long version of the value of a setting. More... | |
void | WriteValue (void *ptr, VarType conv, int64_t val) |
Write the value of a setting. More... | |
static void | SlSaveLoadConv (void *ptr, VarType conv) |
Handle all conversion and typechecking of variables here. More... | |
static size_t | SlCalcStdStringLen (const void *ptr) |
Calculate the gross length of the string that it will occupy in the savegame. More... | |
static void | FixSCCEncoded (std::string &str) |
Scan the string for old values of SCC_ENCODED and fix it to it's new, value. More... | |
static void | SlStdString (void *ptr, VarType conv) |
Save/Load a std::string . More... | |
static void | SlCopyInternal (void *object, size_t length, VarType conv) |
Internal function to save/Load a list of SL_VARs. More... | |
void | SlCopy (void *object, size_t length, VarType conv) |
Copy a list of SL_VARs to/from a savegame. More... | |
static size_t | SlCalcArrayLen (size_t length, VarType conv) |
Return the size in bytes of a certain type of atomic array. More... | |
static void | SlArray (void *array, size_t length, VarType conv) |
Save/Load the length of the array followed by the array of SL_VAR elements. More... | |
static size_t | ReferenceToInt (const void *obj, SLRefType rt) |
Pointers cannot be saved to a savegame, so this functions gets the index of the item, and if not available, it hussles with pointers (looks really bad :() Remember that a nullptr item has value 0, and all indices have +1, so vehicle 0 is saved as index 1. More... | |
static void * | IntToReference (size_t index, SLRefType rt) |
Pointers cannot be loaded from a savegame, so this function gets the index from the savegame and returns the appropriate pointer from the already loaded base. More... | |
void | SlSaveLoadRef (void *ptr, VarType conv) |
Handle conversion for references. More... | |
static size_t | SlCalcRefListLen (const void *list, VarType conv) |
Return the size in bytes of a list. More... | |
static void | SlRefList (void *list, VarType conv) |
Save/Load a list. More... | |
static size_t | SlCalcDequeLen (const void *deque, VarType conv) |
Return the size in bytes of a std::deque. More... | |
static void | SlDeque (void *deque, VarType conv) |
Save/load a std::deque. More... | |
static size_t | SlCalcVectorLen (const void *vector, VarType conv) |
Return the size in bytes of a std::vector. More... | |
static void | SlVector (void *vector, VarType conv) |
Save/load a std::vector. More... | |
static bool | SlIsObjectValidInSavegame (const SaveLoad &sld) |
Are we going to save this object or not? | |
static size_t | SlCalcTableHeader (const SaveLoadTable &slt) |
Calculate the size of the table header. More... | |
size_t | SlCalcObjLength (const void *object, const SaveLoadTable &slt) |
Calculate the size of an object. More... | |
size_t | SlCalcObjMemberLength (const void *object, const SaveLoad &sld) |
static bool | SlObjectMember (void *object, const SaveLoad &sld) |
void | SlSetStructListLength (size_t length) |
Set the length of this list. More... | |
size_t | SlGetStructListLength (size_t limit) |
Get the length of this list; if it exceeds the limit, error out. More... | |
void | SlObject (void *object, const SaveLoadTable &slt) |
Main SaveLoad function. More... | |
std::vector< SaveLoad > | SlTableHeader (const SaveLoadTable &slt) |
Save or Load a table header. More... | |
std::vector< SaveLoad > | SlCompatTableHeader (const SaveLoadTable &slt, const SaveLoadCompatTable &slct) |
Load a table header in a savegame compatible way. More... | |
void | SlGlobList (const SaveLoadTable &slt) |
Save or Load (a list of) global variables. More... | |
void | SlAutolength (AutolengthProc *proc, int arg) |
Do something of which I have no idea what it is :P. More... | |
static void | SlLoadChunk (const ChunkHandler &ch) |
Load a chunk of data (eg vehicles, stations, etc.) More... | |
static void | SlLoadCheckChunk (const ChunkHandler &ch) |
Load a chunk of data for checking savegames. More... | |
static void | SlSaveChunk (const ChunkHandler &ch) |
Save a chunk of data (eg. More... | |
static void | SlSaveChunks () |
Save all chunks. | |
static const ChunkHandler * | SlFindChunkHandler (uint32_t id) |
Find the ChunkHandler that will be used for processing the found chunk in the savegame or in memory. More... | |
static void | SlLoadChunks () |
Load all chunks. | |
static void | SlLoadCheckChunks () |
Load all chunks for savegame checking. | |
static void | SlFixPointers () |
Fix all pointers (convert index -> pointer) | |
static std::pair< const SaveLoadFormat &, uint8_t > | GetSavegameFormat (const std::string &full_name) |
Return the savegameformat of the game. More... | |
void | InitializeGame (uint size_x, uint size_y, bool reset_date, bool reset_settings) |
bool | AfterLoadGame () |
Perform a (large) amount of savegame conversion magic in order to load older savegames and to fill the caches for various purposes. More... | |
bool | LoadOldSaveGame (const std::string &file) |
static void | ResetSaveloadData () |
Clear temporary data that is passed between various saveload phases. | |
static void | ClearSaveLoadState () |
Clear/free saveload state. | |
static void | SaveFileStart () |
Update the gui accordingly when starting saving and set locks on saveload. | |
static void | SaveFileDone () |
Update the gui accordingly when saving is done and release locks on saveload. | |
void | SetSaveLoadError (StringID str) |
Set the error message from outside of the actual loading/saving of the game (AfterLoadGame and friends) | |
StringID | GetSaveLoadErrorType () |
Return the appropriate initial string for an error depending on whether we are saving or loading. | |
StringID | GetSaveLoadErrorMessage () |
Return the description of the error. | |
static void | SaveFileError () |
Show a gui message when saving has failed. | |
static SaveOrLoadResult | SaveFileToDisk (bool threaded) |
We have written the whole game into memory, _memory_savegame, now find and appropriate compressor and start writing to file. | |
void | WaitTillSaved () |
static SaveOrLoadResult | DoSave (std::shared_ptr< SaveFilter > writer, bool threaded) |
Actually perform the saving of the savegame. More... | |
SaveOrLoadResult | SaveWithFilter (std::shared_ptr< SaveFilter > writer, bool threaded) |
Save the game using a (writer) filter. More... | |
static const SaveLoadFormat * | DetermineSaveLoadFormat (uint32_t tag, uint32_t raw_version) |
Determines the SaveLoadFormat that is connected to the given tag. More... | |
static SaveOrLoadResult | DoLoad (std::shared_ptr< LoadFilter > reader, bool load_check) |
Actually perform the loading of a "non-old" savegame. More... | |
SaveOrLoadResult | LoadWithFilter (std::shared_ptr< LoadFilter > reader) |
Load the game using a (reader) filter. More... | |
SaveOrLoadResult | SaveOrLoad (const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded) |
Main Save or Load function where the high-level saveload functions are handled. More... | |
void | DoAutoOrNetsave (FiosNumberedSaveName &counter) |
Create an autosave or netsave. More... | |
void | DoExitSave () |
Do a save when exiting the game (_settings_client.gui.autosave_on_exit) | |
std::string | GenerateDefaultSaveName () |
Get the default name for a savegame or screenshot. | |
Variables | |
const SaveLoadVersion | SAVEGAME_VERSION = (SaveLoadVersion)(SL_MAX_VERSION - 1) |
Current savegame version of OpenTTD. | |
SavegameType | _savegame_type |
type of savegame we are loading | |
FileToSaveLoad | _file_to_saveload |
File to save or load in the openttd loop. | |
uint32_t | _ttdp_version |
version of TTDP savegame (if applicable) | |
SaveLoadVersion | _sl_version |
the major savegame version identifier | |
uint8_t | _sl_minor_version |
the minor savegame version, DO NOT USE! | |
std::string | _savegame_format |
how to compress savegames | |
bool | _do_autosave |
are we doing an autosave at the moment? | |
static const size_t | MEMORY_CHUNK_SIZE = 128 * 1024 |
Save in chunks of 128 KiB. | |
static SaveLoadParams | _sl |
Parameters used for/at saveload. | |
static std::atomic< AsyncSaveFinishProc > | _async_save_finish |
Callback to call when the savegame loading is finished. | |
static std::thread | _save_thread |
The thread we're using to compress and write a savegame. | |
static size_t | _next_offs |
static const uint | LZO_BUFFER_SIZE = 8192 |
Buffer size for the LZO compressor. | |
static const lzma_stream | _lzma_init = LZMA_STREAM_INIT |
Have a copy of an initialised LZMA stream. More... | |
static const uint32_t | SAVEGAME_TAG_LZO = TO_BE32X('OTTD') |
static const uint32_t | SAVEGAME_TAG_NONE = TO_BE32X('OTTN') |
static const uint32_t | SAVEGAME_TAG_ZLIB = TO_BE32X('OTTZ') |
static const uint32_t | SAVEGAME_TAG_LZMA = TO_BE32X('OTTX') |
static const SaveLoadFormat | _saveload_formats [] |
The different saveload formats known/understood by OpenTTD. More... | |
All actions handling saving and loading goes on in this file.
The general actions are as follows for saving a game (loading is analogous):
Definition in file saveload.cpp.
enum NeedLength |
Enumerator | |
---|---|
NL_NONE | not working in NeedLength mode |
NL_WANTLENGTH | writing length and data |
NL_CALCLENGTH | need to calculate the length |
Definition at line 77 of file saveload.cpp.
enum SaveLoadAction |
What are we currently doing?
Enumerator | |
---|---|
SLA_LOAD | loading |
SLA_SAVE | saving |
SLA_PTRS | fixing pointers |
SLA_NULL | null all pointers (on loading error) |
SLA_LOAD_CHECK | partial loading into _load_check_data |
Definition at line 69 of file saveload.cpp.
bool AfterLoadGame | ( | ) |
Perform a (large) amount of savegame conversion magic in order to load older savegames and to fill the caches for various purposes.
< Flag for coast.
Definition at line 565 of file afterload.cpp.
References SetSignalHandlers().
|
static |
List of all chunks in a savegame.
Definition at line 202 of file saveload.cpp.
Referenced by SlFindChunkHandler(), SlFixPointers(), SlNullPointers(), and SlSaveChunks().
|
static |
Determines the SaveLoadFormat that is connected to the given tag.
When the given tag is known, that format is chosen and a check on the validity of the version is performed. Otherwise a fallback to an ancient buggy format using LZO is chosen.
tag | The tag from the header describing the savegame compression/format. |
raw_version | The raw version from the savegame header. |
Definition at line 2936 of file saveload.cpp.
References _saveload_formats, and _sl_version.
Referenced by DoLoad().
void DoAutoOrNetsave | ( | FiosNumberedSaveName & | counter | ) |
Create an autosave or netsave.
counter | A reference to the counter variable to be used for rotating the file name. |
netsave | Indicates if this is a regular autosave or a netsave. |
Definition at line 3188 of file saveload.cpp.
References _settings_client, AUTOSAVE_DIR, Debug, DFT_GAME_FILE, FiosNumberedSaveName::Extension(), FiosNumberedSaveName::Filename(), GenerateDefaultSaveName(), ClientSettings::gui, INVALID_STRING_ID, GUISettings::keep_all_autosave, SaveOrLoad(), ShowErrorMessage(), SL_OK, SLO_SAVE, and WL_ERROR.
Referenced by ClientNetworkEmergencySave().
|
static |
Actually perform the loading of a "non-old" savegame.
reader | The filter to read the savegame from. |
load_check | Whether to perform the checking ("preview") or actually load the game. |
Definition at line 2977 of file saveload.cpp.
References _load_check_data, _sl, LoadCheckData::checkable, LoadCheckData::Clear(), DetermineSaveLoadFormat(), SaveLoadFormat::init_load, SaveLoadParams::lf, SaveLoadFormat::name, SaveLoadParams::reader, and SlError().
Referenced by LoadWithFilter().
|
static |
Actually perform the saving of the savegame.
General tactics is to first save the game to memory, then write it to file using the writer, either in threaded mode if possible, or single-threaded.
writer | The filter to write the savegame to. |
threaded | Whether to try to perform the saving asynchronously. |
Definition at line 2885 of file saveload.cpp.
References _sl, _sl_version, SaveLoadParams::dumper, SAVEGAME_VERSION, SaveLoadParams::saveinprogress, and SaveLoadParams::sf.
Referenced by SaveWithFilter().
|
static |
Scan the string for old values of SCC_ENCODED and fix it to it's new, value.
Note that at the moment this runs, the string has not been validated yet because the validation looks for SCC_ENCODED. If there is something invalid, just bail out and do not continue trying to replace the tokens.
str | the string to fix. |
Definition at line 914 of file saveload.cpp.
References Utf8Decode(), Utf8Encode(), and Utf8EncodedCharLen().
|
static |
Return the savegameformat of the game.
Whether it was created with ZLIB compression uncompressed, or another type
full_name | Name of the savegame format. If empty it picks the first available one |
Definition at line 2710 of file saveload.cpp.
References _saveload_formats, Clamp(), SaveLoadFormat::default_compression, SaveLoadFormat::name, SetDParamStr(), ShowErrorMessage(), SlError(), and WL_CRITICAL.
Referenced by SaveFileToDisk().
|
static |
Pointers cannot be loaded from a savegame, so this function gets the index from the savegame and returns the appropriate pointer from the already loaded base.
Remember that an index of 0 is a nullptr pointer so all indices are +1 so vehicle 0 is saved as 1.
index | The index that is being converted to a pointer |
rt | SLRefType type of the object the pointer is sought of |
Definition at line 1138 of file saveload.cpp.
References _sl, SaveLoadParams::action, SpecializedStation< Station, false >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_link_graph_job_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_persistent_storage_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_orderlist_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_cargopacket_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_roadstop_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_link_graph_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_enginerenew_pool >::Get(), IsSavegameVersionBefore(), SpecializedStation< Station, false >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_cargopacket_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_orderlist_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_persistent_storage_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_enginerenew_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_link_graph_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_link_graph_job_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_roadstop_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_order_pool >::IsValidID(), REF_CARGO_PACKET, REF_ENGINE_RENEWS, REF_LINK_GRAPH, REF_LINK_GRAPH_JOB, REF_ORDER, REF_ORDERLIST, REF_ROADSTOPS, REF_STATION, REF_STORAGE, REF_TOWN, REF_VEHICLE, REF_VEHICLE_OLD, SLA_PTRS, SlErrorCorrupt(), SLV_4, and SLV_5.
SaveOrLoadResult LoadWithFilter | ( | std::shared_ptr< LoadFilter > | reader | ) |
Load the game using a (reader) filter.
reader | The filter to read the savegame from. |
Definition at line 3077 of file saveload.cpp.
References _sl, SaveLoadParams::action, ClearSaveLoadState(), DoLoad(), SL_REINIT, and SLA_LOAD.
int64_t 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 793 of file saveload.cpp.
References GetVarMemType().
Referenced by IntSettingDesc::Read().
|
static |
Pointers cannot be saved to a savegame, so this functions gets the index of the item, and if not available, it hussles with pointers (looks really bad :() Remember that a nullptr item has value 0, and all indices have +1, so vehicle 0 is saved as index 1.
obj | The object that we want to get the index of |
rt | SLRefType type of the object the index is being sought of |
Definition at line 1105 of file saveload.cpp.
References _sl, SaveLoadParams::action, REF_CARGO_PACKET, REF_ENGINE_RENEWS, REF_LINK_GRAPH, REF_LINK_GRAPH_JOB, REF_ORDER, REF_ORDERLIST, REF_ROADSTOPS, REF_STATION, REF_STORAGE, REF_TOWN, REF_VEHICLE, REF_VEHICLE_OLD, and SLA_SAVE.
SaveOrLoadResult SaveOrLoad | ( | const std::string & | filename, |
SaveLoadOperation | fop, | ||
DetailedFileType | dft, | ||
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 |
fop | Save or load mode. Load can also be a TTD(Patch) game. |
sb | The sub directory to save the savegame in |
threaded | True when threaded saving is allowed |
Definition at line 3097 of file saveload.cpp.
References _do_autosave, _sl, DFT_GAME_FILE, INVALID_STRING_ID, SaveLoadParams::saveinprogress, ShowErrorMessage(), SL_OK, SLO_SAVE, and WL_ERROR.
Referenced by DEF_CONSOLE_CMD(), DoAutoOrNetsave(), DoExitSave(), and CrashLog::WriteSavegame().
SaveOrLoadResult SaveWithFilter | ( | std::shared_ptr< 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 2917 of file saveload.cpp.
References _sl, SaveLoadParams::action, ClearSaveLoadState(), DoSave(), SL_ERROR, and SLA_SAVE.
|
static |
Called by save thread to tell we finished saving.
proc | The callback to call when saving is done. |
Definition at line 365 of file saveload.cpp.
|
static |
Save/Load the length of the array followed by the array of SL_VAR elements.
array | The array being manipulated |
length | The length of the array in elements |
conv | VarType type of the atomic array (int, uint8_t, uint64_t, etc.) |
Definition at line 1059 of file saveload.cpp.
References _sl, SaveLoadParams::action, and SLA_SAVE.
void SlAutolength | ( | AutolengthProc * | proc, |
int | 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 1957 of file saveload.cpp.
|
inlinestatic |
Return the size in bytes of a certain type of atomic array.
length | The length of the array counted in elements |
conv | VarType type of the variable that is used in calculating the size |
Definition at line 1048 of file saveload.cpp.
References SlCalcConvFileLen().
|
inlinestatic |
Return the size in bytes of a certain type of normal/atomic variable as it appears in a saved game.
See VarTypes
conv | VarType type of variable that is used for calculating the size |
Definition at line 617 of file saveload.cpp.
References GetVarFileType(), and SLE_FILE_END.
Referenced by SlCalcArrayLen(), SlCalcTableHeader(), SlCopy(), and SlCopyInternal().
|
inlinestatic |
Return the size in bytes of a certain type of normal/atomic variable as it appears in memory.
See VarTypes
conv | VarType type of variable that is used for calculating the size |
Definition at line 587 of file saveload.cpp.
References GetVarMemType().
|
inlinestatic |
Return the size in bytes of a std::deque.
deque | The std::deque to find the size of |
conv | VarType type of variable that is used for calculating the size |
Definition at line 1360 of file saveload.cpp.
References GetVarMemType().
size_t SlCalcObjLength | ( | const void * | object, |
const SaveLoadTable & | slt | ||
) |
Calculate the size of an object.
object | to be measured. |
slt | The SaveLoad table with objects to save/load. |
Definition at line 1511 of file saveload.cpp.
Referenced by SlObject().
|
inlinestatic |
Return the size in bytes of a list.
list | The std::list to find the size of. |
conv | VarType type of variable that is used for calculating the size. |
Definition at line 1333 of file saveload.cpp.
References SL_REF, and SlStorageHelper< Tstorage, Tvar, Tallocator >::SlCalcLen().
Referenced by SlRefList().
|
inlinestatic |
Calculate the gross length of the string that it will occupy in the savegame.
This includes the real length, returned by SlCalcNetStringLen and the length that the index will occupy.
ptr | Pointer to the std::string . |
Definition at line 898 of file saveload.cpp.
|
static |
Calculate the size of the table header.
slt | The SaveLoad table with objects to save/load. |
Definition at line 1482 of file saveload.cpp.
References SlCalcConvFileLen(), and SlIsObjectValidInSavegame().
|
inlinestatic |
Return the size in bytes of a std::vector.
vector | The std::vector to find the size of |
conv | VarType type of variable that is used for calculating the size |
Definition at line 1418 of file saveload.cpp.
References GetVarMemType().
std::vector<SaveLoad> SlCompatTableHeader | ( | const SaveLoadTable & | slt, |
const SaveLoadCompatTable & | slct | ||
) |
Load a table header in a savegame compatible way.
If the savegame was made before table headers were added, it will fall back to the SaveLoadCompatTable for the order of fields while loading.
slt | The SaveLoad table with objects to save/load. |
slct | The SaveLoadCompat table the original order of the fields. |
Definition at line 1893 of file saveload.cpp.
References _sl, SaveLoadParams::action, SaveLoadParams::block_mode, SLA_LOAD, and SLA_LOAD_CHECK.
Referenced by AIPLChunkHandler::Load(), ERNWChunkHandler::Load(), CMDLChunkHandler::Load(), CMPUChunkHandler::Load(), CAPAChunkHandler::Load(), CHTSChunkHandler::Load(), PLYRChunkHandler::Load(), DEPTChunkHandler::Load(), ECMYChunkHandler::Load(), CAPYChunkHandler::Load(), ENGNChunkHandler::Load(), EIDSChunkHandler::Load(), GSDTChunkHandler::Load(), GSTRChunkHandler::Load(), GOALChunkHandler::Load(), GRPSChunkHandler::Load(), INDYChunkHandler::Load(), IBLDChunkHandler::Load(), ITBLChunkHandler::Load(), RAILChunkHandler::Load(), ROTTChunkHandler::Load(), LGRPChunkHandler::Load(), LGRJChunkHandler::Load(), LGRSChunkHandler::Load(), MAPSChunkHandler::Load(), VIEWChunkHandler::Load(), NewGRFMappingChunkHandler::Load(), OBJSChunkHandler::Load(), ORDLChunkHandler::Load(), BKORChunkHandler::Load(), SIGNChunkHandler::Load(), STNSChunkHandler::Load(), STNNChunkHandler::Load(), ROADChunkHandler::Load(), PSACChunkHandler::Load(), STPEChunkHandler::Load(), STPAChunkHandler::Load(), SUBSChunkHandler::Load(), CITYChunkHandler::Load(), VEHSChunkHandler::Load(), PLYRChunkHandler::LoadCheck(), MAPSChunkHandler::LoadCheck(), and LoadSettings().
void SlCopy | ( | void * | object, |
size_t | length, | ||
VarType | conv | ||
) |
Copy a list of SL_VARs to/from a savegame.
These entries are copied as-is, and you as caller have to make sure things like length-fields are calculated correctly.
object | The object being manipulated. |
length | The length of the object in elements |
conv | VarType type of the items. |
Definition at line 1029 of file saveload.cpp.
References _sl, SaveLoadParams::action, SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, SLA_NULL, SLA_PTRS, SlCalcConvFileLen(), SlCopyInternal(), and SlSetLength().
Referenced by ANITChunkHandler::Load(), ENGSChunkHandler::Load(), MAPTChunkHandler::Load(), MAPHChunkHandler::Load(), MAPOChunkHandler::Load(), MAP2ChunkHandler::Load(), M3LOChunkHandler::Load(), M3HIChunkHandler::Load(), MAP5ChunkHandler::Load(), MAPEChunkHandler::Load(), MAP7ChunkHandler::Load(), MAP8ChunkHandler::Load(), NAMEChunkHandler::Load(), ScriptInstance::LoadObjects(), and ScriptInstance::SaveObject().
|
static |
Save/Load bytes.
These do not need to be converted to Little/Big Endian so directly write them or read them to/from file
ptr | The source or destination of the object being manipulated |
length | number of bytes this fast CopyBytes lasts |
Definition at line 764 of file saveload.cpp.
References _sl, SaveLoadParams::action, SLA_LOAD, SLA_LOAD_CHECK, SLA_SAVE, SlReadByte(), and SlWriteByte().
|
static |
Internal function to save/Load a list of SL_VARs.
SlCopy() and SlArray() are very similar, with the exception of the header. This function represents the common part.
object | The object being manipulated. |
length | The length of the object in elements |
conv | VarType type of the items. |
Definition at line 980 of file saveload.cpp.
References _sl, _sl_version, SaveLoadParams::action, GetVarMemType(), SLA_SAVE, SlCalcConvFileLen(), SLE_VAR_NULL, and SlSkipBytes().
Referenced by SlCopy().
|
static |
Save/load a std::deque.
deque | The std::deque being manipulated |
conv | VarType type of variable that is used for calculating the size |
Definition at line 1387 of file saveload.cpp.
References GetVarMemType().
void SlError | ( | StringID | string, |
const std::string & | 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 321 of file saveload.cpp.
References _gamelog, _load_check_data, _sl, SaveLoadParams::action, LoadCheckData::error, LoadCheckData::error_msg, SaveLoadParams::error_str, SaveLoadParams::extra_msg, SLA_LOAD, SLA_LOAD_CHECK, SLA_PTRS, and SlNullPointers().
Referenced by DoLoad(), PacketWriter::Finish(), GetSavegameFormat(), LZMALoadFilter::LZMALoadFilter(), LZMASaveFilter::LZMASaveFilter(), LZOLoadFilter::LZOLoadFilter(), LZOSaveFilter::LZOSaveFilter(), MoveWaypointsToBaseStations(), LZMALoadFilter::Read(), LZOLoadFilter::Read(), SlErrorCorrupt(), PacketWriter::Write(), FileWriter::Write(), ZlibSaveFilter::WriteLoop(), LZMASaveFilter::WriteLoop(), ZlibLoadFilter::ZlibLoadFilter(), and ZlibSaveFilter::ZlibSaveFilter().
void SlErrorCorrupt | ( | const std::string & | 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 351 of file saveload.cpp.
References SlError().
Referenced by IntToReference(), CHTSChunkHandler::Load(), IBLDChunkHandler::Load(), ITBLChunkHandler::Load(), LGRSChunkHandler::Load(), NewGRFMappingChunkHandler::Load(), NAMEChunkHandler::Load(), LoadSettings(), MoveWaypointsToBaseStations(), SetWaterClassDependingOnSurroundings(), and SlReadSimpleGamma().
|
static |
Find the ChunkHandler that will be used for processing the found chunk in the savegame or in memory.
id | the chunk in question |
Definition at line 2160 of file saveload.cpp.
References ChunkHandlers().
size_t SlGetStructListLength | ( | size_t | limit | ) |
Get the length of this list; if it exceeds the limit, error out.
limit | The maximum size the list can be. |
Definition at line 1689 of file saveload.cpp.
Referenced by VectorSaveLoadHandler< TImpl, TObject, TElementType, MAX_LENGTH >::GetLength(), SlStationSpecList< T >::GetLength(), SlStationGoods::GetNumCargo(), and SlTownSupplied::GetNumCargo().
void SlGlobList | ( | const SaveLoadTable & | slt | ) |
Save or Load (a list of) global variables.
slt | The SaveLoad table with objects to save/load. |
Definition at line 1947 of file saveload.cpp.
References SlObject().
Referenced by IBLDChunkHandler::Load().
int SlIterateArray | ( | ) |
Iterate through the elements of an array and read the whole thing.
Definition at line 658 of file saveload.cpp.
Referenced by CMDLChunkHandler::Load(), CMPUChunkHandler::Load(), CAPAChunkHandler::Load(), CHTSChunkHandler::Load(), IBLDChunkHandler::Load(), ITBLChunkHandler::Load(), LGRPChunkHandler::Load(), LGRJChunkHandler::Load(), LGRSChunkHandler::Load(), NewGRFMappingChunkHandler::Load(), SIGNChunkHandler::Load(), PSACChunkHandler::Load(), NAMEChunkHandler::Load(), LoadSettings(), and SlSkipArray().
|
static |
Load a chunk of data for checking savegames.
If the chunkhandler is nullptr, the chunk is skipped.
ch | The chunkhandler that will be used for the operation |
Definition at line 2057 of file saveload.cpp.
References _sl, SaveLoadParams::block_mode, CH_TYPE_MASK, SaveLoadParams::expect_table_header, SaveLoadParams::obj_len, and SlReadByte().
|
static |
Load a chunk of data (eg vehicles, stations, etc.)
ch | The chunkhandler that will be used for the operation |
Definition at line 2004 of file saveload.cpp.
References _sl, SaveLoadParams::block_mode, CH_TYPE_MASK, SaveLoadParams::expect_table_header, SaveLoadParams::obj_len, and SlReadByte().
void SlObject | ( | void * | object, |
const SaveLoadTable & | slt | ||
) |
Main SaveLoad function.
object | The object that is being saved or loaded. |
slt | The SaveLoad table with objects to save/load. |
Definition at line 1702 of file saveload.cpp.
References _sl, SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, SlCalcObjLength(), and SlSetLength().
Referenced by ERNWChunkHandler::FixPointers(), PLYRChunkHandler::FixPointers(), DEPTChunkHandler::FixPointers(), CAPYChunkHandler::FixPointers(), INDYChunkHandler::FixPointers(), LGRSChunkHandler::FixPointers(), OBJSChunkHandler::FixPointers(), ORDRChunkHandler::FixPointers(), ORDLChunkHandler::FixPointers(), BKORChunkHandler::FixPointers(), STNSChunkHandler::FixPointers(), STNNChunkHandler::FixPointers(), ROADChunkHandler::FixPointers(), CITYChunkHandler::FixPointers(), VEHSChunkHandler::FixPointers(), CHKPChunkHandler::FixPointers(), CMDLChunkHandler::Load(), CMPUChunkHandler::Load(), CAPAChunkHandler::Load(), CHTSChunkHandler::Load(), ITBLChunkHandler::Load(), LGRPChunkHandler::Load(), LGRJChunkHandler::Load(), LGRSChunkHandler::Load(), NewGRFMappingChunkHandler::Load(), SIGNChunkHandler::Load(), PSACChunkHandler::Load(), ScriptInstance::Load(), ScriptInstance::LoadEmpty(), ScriptInstance::LoadObjects(), LoadSettings(), ScriptInstance::Save(), ScriptInstance::SaveEmpty(), ScriptInstance::SaveObject(), and SlGlobList().
uint8_t SlReadByte | ( | ) |
Wrapper for reading a byte from the buffer.
Definition at line 392 of file saveload.cpp.
References _sl, and SaveLoadParams::reader.
Referenced by SlCopyBytes(), SlLoadCheckChunk(), SlLoadChunk(), SlReadSimpleGamma(), and SlSkipBytes().
|
static |
Read in the header descriptor of an object or an array.
If the highest bit is set (7), then the index is bigger than 127 elements, so use the next byte to read in the real value. The actual value is then both bytes added with the first shifted 8 bits to the left, and dropping the highest bit (which only indicated a big index). x = ((x & 0x7F) << 8) + SlReadByte();
Definition at line 452 of file saveload.cpp.
References HasBit(), SlErrorCorrupt(), and SlReadByte().
|
static |
Save/Load a list.
list | The list being manipulated. |
conv | VarType type of variable that is used for calculating the size. |
Definition at line 1343 of file saveload.cpp.
References _sl, SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, SL_REF, SlCalcRefListLen(), SlStorageHelper< Tstorage, Tvar, Tallocator >::SlSaveLoad(), and SlSetLength().
|
static |
Save a chunk of data (eg.
vehicles, stations, etc.). Each chunk is prefixed by an ID identifying it, followed by data, and terminator where appropriate
ch | The chunkhandler that will be used for the operation |
Definition at line 2108 of file saveload.cpp.
References CH_READONLY, and ChunkHandler::type.
Referenced by SlSaveChunks().
|
static |
Handle all conversion and typechecking of variables here.
In the case of saving, read in the actual value from the struct and then write them to file, endian safely. Loading a value goes exactly the opposite way
ptr | The object being filled/read |
conv | VarType type of the current element of the struct |
Definition at line 843 of file saveload.cpp.
References _sl, SaveLoadParams::action, and SLA_SAVE.
void SlSaveLoadRef | ( | void * | ptr, |
VarType | conv | ||
) |
Handle conversion for references.
ptr | The object being filled/read. |
conv | VarType type of the current element of the struct. |
Definition at line 1214 of file saveload.cpp.
References _sl, SaveLoadParams::action, and SLA_SAVE.
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 712 of file saveload.cpp.
References _sl, SaveLoadParams::action, SaveLoadParams::block_mode, SaveLoadParams::need_length, NL_NONE, NL_WANTLENGTH, and SLA_SAVE.
Referenced by MAPTChunkHandler::Save(), MAPHChunkHandler::Save(), MAPOChunkHandler::Save(), MAP2ChunkHandler::Save(), M3LOChunkHandler::Save(), M3HIChunkHandler::Save(), MAP5ChunkHandler::Save(), MAPEChunkHandler::Save(), MAP7ChunkHandler::Save(), MAP8ChunkHandler::Save(), SlCopy(), SlObject(), SlRefList(), and SlSetStructListLength().
void SlSetStructListLength | ( | size_t | length | ) |
Set the length of this list.
The | length of the list. |
Definition at line 1673 of file saveload.cpp.
References _sl, SaveLoadParams::need_length, NL_NONE, and SlSetLength().
|
static |
Save/Load a std::string
.
ptr | the string being manipulated |
conv | must be SLE_FILE_STRING |
Definition at line 932 of file saveload.cpp.
References _sl, SaveLoadParams::action, and SLA_SAVE.
std::vector<SaveLoad> SlTableHeader | ( | const SaveLoadTable & | slt | ) |
Save or Load a table header.
slt | The SaveLoad table with objects to save/load. |
Definition at line 1755 of file saveload.cpp.
References _sl, and SaveLoadParams::block_mode.
Referenced by LEAEChunkHandler::Load(), LEATChunkHandler::Load(), SRNDChunkHandler::Load(), WaterRegionChunkHandler::Load(), AIPLChunkHandler::Save(), ANITChunkHandler::Save(), ERNWChunkHandler::Save(), CMDLChunkHandler::Save(), CMPUChunkHandler::Save(), CAPAChunkHandler::Save(), CHTSChunkHandler::Save(), PLYRChunkHandler::Save(), DEPTChunkHandler::Save(), ECMYChunkHandler::Save(), CAPYChunkHandler::Save(), ENGNChunkHandler::Save(), EIDSChunkHandler::Save(), GSDTChunkHandler::Save(), GSTRChunkHandler::Save(), GLOGChunkHandler::Save(), GOALChunkHandler::Save(), GRPSChunkHandler::Save(), INDYChunkHandler::Save(), IBLDChunkHandler::Save(), ITBLChunkHandler::Save(), RAILChunkHandler::Save(), ROTTChunkHandler::Save(), LEAEChunkHandler::Save(), LEATChunkHandler::Save(), LGRPChunkHandler::Save(), LGRJChunkHandler::Save(), LGRSChunkHandler::Save(), MAPSChunkHandler::Save(), DATEChunkHandler::Save(), VIEWChunkHandler::Save(), NGRFChunkHandler::Save(), NewGRFMappingChunkHandler::Save(), OBJSChunkHandler::Save(), SRNDChunkHandler::Save(), SIGNChunkHandler::Save(), STNNChunkHandler::Save(), ROADChunkHandler::Save(), PSACChunkHandler::Save(), STPEChunkHandler::Save(), STPAChunkHandler::Save(), SUBSChunkHandler::Save(), CITYChunkHandler::Save(), VEHSChunkHandler::Save(), and SaveSettings().
|
static |
Save/load a std::vector.
vector | The std::vector being manipulated |
conv | VarType type of variable that is used for calculating the size |
Definition at line 1445 of file saveload.cpp.
References GetVarMemType().
void SlWriteByte | ( | uint8_t | b | ) |
Wrapper for writing a byte to the dumper.
b | The byte to write. |
Definition at line 401 of file saveload.cpp.
References _sl, and SaveLoadParams::dumper.
Referenced by SlCopyBytes(), and SlWriteSimpleGamma().
|
static |
Write the header descriptor of an object or an array.
If the element is bigger than 127, use 2 bytes for saving and use the highest byte of the first written one as a notice that the length consists of 2 bytes, etc.. like this: 0xxxxxxx 10xxxxxx xxxxxxxx 110xxxxx xxxxxxxx xxxxxxxx 1110xxxx xxxxxxxx xxxxxxxx xxxxxxxx 11110— xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx We could extend the scheme ad infinum to support arbitrarily large chunks, but as sizeof(size_t) == 4 is still very common we don't support anything above 32 bits. That's why in the last case the 3 most significant bits are unused.
i | Index being written |
Definition at line 494 of file saveload.cpp.
References SlWriteByte().
void WriteValue | ( | void * | ptr, |
VarType | conv, | ||
int64_t | 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 817 of file saveload.cpp.
References GetVarMemType().
Referenced by LoadIntList(), and IntSettingDesc::Write().
|
static |
Have a copy of an initialised LZMA stream.
We need this as it's impossible to "re"-assign LZMA_STREAM_INIT to a variable in some compilers, i.e. LZMA_STREAM_INIT can't be used to set something. This var has to be used instead.
Definition at line 2546 of file saveload.cpp.
|
static |
The different saveload formats known/understood by OpenTTD.
Definition at line 2675 of file saveload.cpp.
Referenced by DetermineSaveLoadFormat(), and GetSavegameFormat().