OpenTTD Source
1.11.2
|
#include <deque>
#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 "../date_func.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 <string>
#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 | SlDequeHelper< T > |
Template class to help with std::deque. 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... | |
Macros | |
#define | FOR_ALL_CHUNK_HANDLERS(ch) |
Iterate over all chunk handlers. 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 void | SlNullPointers () |
Null all pointers (convert index -> nullptr) | |
void NORETURN | SlError (StringID string, const char *extra_msg) |
Error handler. More... | |
void NORETURN | SlErrorCorrupt (const char *msg) |
Error handler for corrupt savegames. More... | |
void NORETURN | SlErrorCorruptFmt (const char *format,...) |
Issue an SlErrorCorrupt with a format string. More... | |
static void | SetAsyncSaveFinish (AsyncSaveFinishProc proc) |
Called by save thread to tell we finished saving. More... | |
void | ProcessAsyncSaveFinish () |
Handle async save finishes. | |
byte | SlReadByte () |
Wrapper for reading a byte from the buffer. More... | |
void | SlWriteByte (byte b) |
Wrapper for writing a byte to the dumper. More... | |
static int | SlReadUint16 () |
static uint32 | SlReadUint32 () |
static uint64 | SlReadUint64 () |
static void | SlWriteUint16 (uint16 v) |
static void | SlWriteUint32 (uint32 v) |
static void | SlWriteUint64 (uint64 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 uint | SlCalcConvMemLen (VarType conv) |
Return the size in bytes of a certain type of normal/atomic variable as it appears in memory. More... | |
static byte | 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 | 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 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 | SlCalcNetStringLen (const char *ptr, size_t length) |
Calculate the net length of a string. More... | |
static size_t | SlCalcStringLen (const void *ptr, size_t length, VarType conv) |
Calculate the gross length of the string that it will occupy in the savegame. 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 | SlString (void *ptr, size_t length, VarType conv) |
Save/Load a string. More... | |
static void | SlStdString (void *ptr, VarType conv) |
Save/Load a std::string . More... | |
static size_t | SlCalcArrayLen (size_t length, VarType conv) |
Return the size in bytes of a certain type of atomic array. More... | |
void | SlArray (void *array, size_t length, VarType conv) |
Save/Load an array. 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... | |
static size_t | SlCalcListLen (const void *list) |
Return the size in bytes of a list. More... | |
static void | SlList (void *list, SLRefType 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 bool | SlIsObjectValidInSavegame (const SaveLoad *sld) |
Are we going to save this object or not? | |
static bool | SlSkipVariableOnLoad (const SaveLoad *sld) |
Are we going to load this variable when loading a savegame or not? More... | |
size_t | SlCalcObjLength (const void *object, const SaveLoad *sld) |
Calculate the size of an object. More... | |
size_t | SlCalcObjMemberLength (const void *object, const SaveLoad *sld) |
static bool | IsVariableSizeRight (const SaveLoad *sld) |
Check whether the variable size of the variable in the saveload configuration matches with the actual variable size. More... | |
bool | SlObjectMember (void *ptr, const SaveLoad *sld) |
void | SlObject (void *object, const SaveLoad *sld) |
Main SaveLoad function. More... | |
void | SlGlobList (const SaveLoadGlobVarList *sldg) |
Save or Load (a list of) global variables. More... | |
void | SlAutolength (AutolengthProc *proc, void *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 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 const SaveLoadFormat * | GetSavegameFormat (char *s, byte *compression_level) |
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. More... | |
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) | |
const char * | GetSaveLoadErrorString () |
Get the string representation of the error message. | |
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 (SaveFilter *writer, bool threaded) |
Actually perform the saving of the savegame. More... | |
SaveOrLoadResult | SaveWithFilter (SaveFilter *writer, bool threaded) |
Save the game using a (writer) filter. More... | |
static SaveOrLoadResult | DoLoad (LoadFilter *reader, bool load_check) |
Actually perform the loading of a "non-old" savegame. More... | |
SaveOrLoadResult | LoadWithFilter (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 | DoExitSave () |
Do a save when exiting the game (_settings_client.gui.autosave_on_exit) | |
void | GenerateDefaultSaveName (char *buf, const char *last) |
Fill the buffer with the default name for a savegame or screenshot. More... | |
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 | _ttdp_version |
version of TTDP savegame (if applicable) | |
SaveLoadVersion | _sl_version |
the major savegame version identifier | |
byte | _sl_minor_version |
the minor savegame version, DO NOT USE! | |
char | _savegame_format [8] |
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. | |
const ChunkHandler | _gamelog_chunk_handlers [] |
const ChunkHandler | _map_chunk_handlers [] |
const ChunkHandler | _misc_chunk_handlers [] |
const ChunkHandler | _name_chunk_handlers [] |
const ChunkHandler | _cheat_chunk_handlers [] |
const ChunkHandler | _setting_chunk_handlers [] |
const ChunkHandler | _company_chunk_handlers [] |
const ChunkHandler | _engine_chunk_handlers [] |
const ChunkHandler | _veh_chunk_handlers [] |
const ChunkHandler | _waypoint_chunk_handlers [] |
const ChunkHandler | _depot_chunk_handlers [] |
const ChunkHandler | _order_chunk_handlers [] |
const ChunkHandler | _town_chunk_handlers [] |
const ChunkHandler | _sign_chunk_handlers [] |
const ChunkHandler | _station_chunk_handlers [] |
const ChunkHandler | _industry_chunk_handlers [] |
const ChunkHandler | _economy_chunk_handlers [] |
const ChunkHandler | _subsidy_chunk_handlers [] |
const ChunkHandler | _cargomonitor_chunk_handlers [] |
const ChunkHandler | _goal_chunk_handlers [] |
const ChunkHandler | _story_page_chunk_handlers [] |
const ChunkHandler | _ai_chunk_handlers [] |
const ChunkHandler | _game_chunk_handlers [] |
const ChunkHandler | _animated_tile_chunk_handlers [] |
const ChunkHandler | _newgrf_chunk_handlers [] |
const ChunkHandler | _group_chunk_handlers [] |
const ChunkHandler | _cargopacket_chunk_handlers [] |
const ChunkHandler | _autoreplace_chunk_handlers [] |
const ChunkHandler | _labelmaps_chunk_handlers [] |
const ChunkHandler | _linkgraph_chunk_handlers [] |
const ChunkHandler | _airport_chunk_handlers [] |
const ChunkHandler | _object_chunk_handlers [] |
const ChunkHandler | _persistent_storage_chunk_handlers [] |
static const ChunkHandler *const | _chunk_handlers [] |
Array of all chunks in a savegame, nullptr terminated. | |
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 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.
#define FOR_ALL_CHUNK_HANDLERS | ( | ch | ) |
Iterate over all chunk handlers.
ch | the chunk handler iterator |
Definition at line 294 of 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 79 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 71 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.
Definition at line 543 of file afterload.cpp.
References MapSize(), and SetSignalHandlers().
|
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 2603 of file saveload.cpp.
References _load_check_data, _saveload_formats, _sl, _sl_minor_version, _sl_version, LoadCheckData::checkable, LoadCheckData::Clear(), DEBUG, endof, SaveLoadParams::lf, LoadFilter::Read(), LoadFilter::Reset(), SL_MIN_VERSION, 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 2554 of file saveload.cpp.
References _sl, _sl_version, SaveLoadParams::dumper, SAVEGAME_VERSION, SaveLoadParams::saveinprogress, and SaveLoadParams::sf.
Referenced by SaveWithFilter().
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 2861 of file saveload.cpp.
References _local_company, _settings_client, GUISettings::date_format_in_default_names, ClientSettings::gui, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Iterate(), and SetDParam().
Referenced by SaveLoadWindow::GenerateFileName().
|
static |
Return the savegameformat of the game.
Whether it was created with ZLIB compression uncompressed, or another type
s | Name of the savegame format. If nullptr it picks the first available one |
compression_level | Output for telling what compression level we want. |
Definition at line 2358 of file saveload.cpp.
References _saveload_formats, Clamp(), SaveLoadFormat::default_compression, endof, SaveLoadFormat::init_write, lastof, SaveLoadFormat::name, SetDParamStr(), ShowErrorMessage(), StrEmpty(), 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 1139 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<&_cargopacket_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<&_link_graph_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<&_link_graph_job_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<&_order_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<&_enginerenew_pool >::Get(), IsSavegameVersionBefore(), SpecializedStation< Station, false >::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<&_link_graph_job_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<&_persistent_storage_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<&_town_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(), 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<&_cargopacket_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.
|
static |
Check whether the variable size of the variable in the saveload configuration matches with the actual variable size.
sld | The saveload configuration to test. |
Definition at line 1488 of file saveload.cpp.
References SaveLoad::cmd, SaveLoad::conv, GetVarMemType(), and SL_VAR.
SaveOrLoadResult LoadWithFilter | ( | LoadFilter * | reader | ) |
Load the game using a (reader) filter.
reader | The filter to read the savegame from. |
Definition at line 2744 of file saveload.cpp.
References _sl, SaveLoadParams::action, ClearSaveLoadState(), DoLoad(), SL_REINIT, and SLA_LOAD.
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 749 of file saveload.cpp.
References GetVarMemType().
Referenced by NewsTypeData::GetDisplay().
|
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 1106 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.
|
static |
Update the gui accordingly when starting saving and set locks on saveload.
Also turn off fast-forward cause with that saving takes Aaaaages
Definition at line 2443 of file saveload.cpp.
References _game_speed, _sl, SaveLoadParams::game_speed, InvalidateWindowData(), SaveLoadParams::saveinprogress, SBI_SAVELOAD_START, SetMouseCursorBusy(), and WC_STATUS_BAR.
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 2764 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 ClientNetworkEmergencySave(), DEF_CONSOLE_CMD(), DoExitSave(), VideoDriver_Dedicated::MainLoop(), 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 2586 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 391 of file saveload.cpp.
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 1051 of file saveload.cpp.
References _sl, _sl_version, SaveLoadParams::action, SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, SLA_NULL, SLA_PTRS, SLA_SAVE, SlCalcArrayLen(), and SlSetLength().
Referenced by Load_ANIT(), Load_NAME(), 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 1640 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 1040 of file saveload.cpp.
References SlCalcConvFileLen().
Referenced by SlArray().
|
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 605 of file saveload.cpp.
References GB(), and lengthof.
Referenced by SlCalcArrayLen(), and SlDequeHelper< T >::SlCalcDequeLen().
|
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 581 of file saveload.cpp.
References GB(), SLE_VAR_STR, SLE_VAR_STRB, SLE_VAR_STRBQ, and SLE_VAR_STRQ.
Referenced by SlSkipVariableOnLoad().
|
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 1352 of file saveload.cpp.
References GetVarMemType().
|
inlinestatic |
Return the size in bytes of a list.
list | The std::list to find the size of |
Definition at line 1214 of file saveload.cpp.
References IsSavegameVersionBefore(), and SLV_69.
Referenced by SlList().
|
inlinestatic |
Calculate the net length of a string.
This is in almost all cases just strlen(), but if the string is not properly terminated, we'll resort to the maximum length of the buffer.
ptr | pointer to the stringbuffer |
length | maximum length of the string (buffer). If -1 we don't care about a maximum length, but take string length as it is. |
Definition at line 856 of file saveload.cpp.
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 1436 of file saveload.cpp.
References SaveLoad::cmd.
Referenced by SlObject().
|
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 901 of file saveload.cpp.
|
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 stringbuffer |
length | maximum length of the string (buffer size, etc.) |
conv | type of data been used |
Definition at line 871 of file saveload.cpp.
References GetVarMemType().
|
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 720 of file saveload.cpp.
References _sl, SaveLoadParams::action, SLA_LOAD, SLA_LOAD_CHECK, SLA_SAVE, SlReadByte(), and SlWriteByte().
|
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 1379 of file saveload.cpp.
References GetVarMemType().
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 326 of file saveload.cpp.
References _load_check_data, _sl, 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 DoLoad(), PacketWriter::Finish(), LZMALoadFilter::LZMALoadFilter(), LZMASaveFilter::LZMASaveFilter(), LZOLoadFilter::LZOLoadFilter(), LZOSaveFilter::LZOSaveFilter(), LZMALoadFilter::Read(), SlErrorCorrupt(), PacketWriter::Write(), FileWriter::Write(), ZlibSaveFilter::WriteLoop(), LZMASaveFilter::WriteLoop(), 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 358 of file saveload.cpp.
References SlError().
Referenced by IntToReference(), Load_CHTS(), Load_ITBL(), Load_NAME(), Load_NewGRFMapping(), SetWaterClassDependingOnSurroundings(), SlErrorCorruptFmt(), and SlReadSimpleGamma().
void NORETURN SlErrorCorruptFmt | ( | const char * | format, |
... | |||
) |
Issue an SlErrorCorrupt with a format string.
format | format string |
... | arguments to format string |
Definition at line 370 of file saveload.cpp.
References lastof, SlErrorCorrupt(), and vseprintf().
|
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 1805 of file saveload.cpp.
References FOR_ALL_CHUNK_HANDLERS.
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 1630 of file saveload.cpp.
References SlObject().
Referenced by LoadSave_IBLD().
int SlIterateArray | ( | ) |
Iterate through the elements of an array and read the whole thing.
Definition at line 631 of file saveload.cpp.
Referenced by Load_CAPA(), Load_ITBL(), Load_LGRJ(), Load_LGRP(), Load_NAME(), Load_NewGRFMapping(), Load_PSAC(), Load_SIGN(), LoadDelivery(), LoadPickup(), and SlSkipArray().
|
static |
Save/Load a list.
list | The list being manipulated |
conv | SLRefType type of the list (Vehicle *, Station *, etc) |
Definition at line 1230 of file saveload.cpp.
References _sl, SaveLoadParams::action, SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, SLA_SAVE, SlCalcListLen(), and SlSetLength().
|
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 1707 of file saveload.cpp.
References _sl, SaveLoadParams::block_mode, 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 1667 of file saveload.cpp.
References _sl, SaveLoadParams::block_mode, SaveLoadParams::obj_len, and SlReadByte().
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 1612 of file saveload.cpp.
References _sl, SaveLoad::cmd, SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, SlCalcObjLength(), and SlSetLength().
Referenced by DoSave_LGRJ(), ScriptInstance::Load(), Load_CAPA(), Load_ECMY(), Load_ITBL(), Load_LGRS(), Load_NewGRFMapping(), Load_PSAC(), Load_SIGN(), LoadDelivery(), ScriptInstance::LoadEmpty(), ScriptInstance::LoadObjects(), LoadPickup(), Ptrs_LGRS(), Ptrs_TOWN(), ScriptInstance::Save(), Save_ECMY(), Save_LGRS(), ScriptInstance::SaveEmpty(), SaveLoad_LinkGraph(), ScriptInstance::SaveObject(), and SlGlobList().
byte SlReadByte | ( | ) |
Wrapper for reading a byte from the buffer.
Definition at line 418 of file saveload.cpp.
References _sl, and SaveLoadParams::reader.
Referenced by Load_CHTS(), 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 478 of file saveload.cpp.
References HasBit(), SlErrorCorrupt(), and SlReadByte().
|
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 1757 of file saveload.cpp.
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 799 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 676 of file saveload.cpp.
References _sl, SaveLoadParams::action, SaveLoadParams::block_mode, SaveLoadParams::need_length, NL_NONE, NL_WANTLENGTH, and SLA_SAVE.
Referenced by Save_ANIT(), Save_CHTS(), SlArray(), SlList(), and SlObject().
|
inlinestatic |
Are we going to load this variable when loading a savegame or not?
Definition at line 1420 of file saveload.cpp.
References _network_server, _networking, _sl, SaveLoadParams::action, SaveLoad::conv, SaveLoad::length, SLA_SAVE, SlCalcConvMemLen(), SLF_NO_NETWORK_SYNC, and SlSkipBytes().
|
static |
Save/Load a std::string
.
ptr | the string being manipulated |
conv | must be SLE_FILE_STRING |
Definition at line 993 of file saveload.cpp.
References _sl, SaveLoadParams::action, and SLA_SAVE.
|
static |
Save/Load a string.
ptr | the string being manipulated |
length | of the string (full length) |
conv | must be SLE_FILE_STRING |
Definition at line 915 of file saveload.cpp.
References _sl, SaveLoadParams::action, GetVarMemType(), and SLA_SAVE.
void SlWriteByte | ( | byte | b | ) |
Wrapper for writing a byte to the dumper.
b | The byte to write. |
Definition at line 427 of file saveload.cpp.
References _sl, SaveLoadParams::dumper, and MemoryDumper::WriteByte().
Referenced by Save_CHTS(), and SlCopyBytes().
|
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 520 of file saveload.cpp.
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 773 of file saveload.cpp.
References GetVarMemType().
|
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 2198 of file saveload.cpp.
|
static |
The different saveload formats known/understood by OpenTTD.
Definition at line 2322 of file saveload.cpp.
Referenced by DoLoad(), and GetSavegameFormat().