OpenTTD
|
All actions handling saving and loading goes on in this file. More...
#include "../stdafx.h"
#include "../debug.h"
#include "../station_base.h"
#include "../thread/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 "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... | |
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. |
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 -> NULL) | |
void NORETURN | SlError (StringID string, const char *extra_msg) |
Error handler. | |
void NORETURN | SlErrorCorrupt (const char *msg) |
Error handler for corrupt savegames. | |
static void | SetAsyncSaveFinish (AsyncSaveFinishProc proc) |
Called by save thread to tell we finished saving. | |
void | ProcessAsyncSaveFinish () |
Handle async save finishes. | |
byte | SlReadByte () |
Wrapper for reading a byte from the buffer. | |
void | SlWriteByte (byte b) |
Wrapper for writing a byte to the dumper. | |
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 void | SlSkipBytes (size_t length) |
Read in bytes from the file/data structure but don't do anything with them, discarding them in effect. | |
static uint | SlReadSimpleGamma () |
Read in the header descriptor of an object or an array. | |
static void | SlWriteSimpleGamma (size_t i) |
Write the header descriptor of an object or an array. | |
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. | |
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. | |
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. | |
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. | |
static void | SlCopyBytes (void *ptr, size_t length) |
Save/Load bytes. | |
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. | |
void | WriteValue (void *ptr, VarType conv, int64 val) |
Write the value of a setting. | |
static void | SlSaveLoadConv (void *ptr, VarType conv) |
Handle all conversion and typechecking of variables here. | |
static size_t | SlCalcNetStringLen (const char *ptr, size_t length) |
Calculate the net length of a string. | |
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. | |
static void | SlString (void *ptr, size_t length, VarType conv) |
Save/Load a string. | |
static size_t | SlCalcArrayLen (size_t length, VarType conv) |
Return the size in bytes of a certain type of atomic array. | |
void | SlArray (void *array, size_t length, VarType conv) |
Save/Load an array. | |
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 NULL item has value 0, and all indices have +1, so vehicle 0 is saved as index 1. | |
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. | |
static size_t | SlCalcListLen (const void *list) |
Return the size in bytes of a list. | |
static void | SlList (void *list, SLRefType conv) |
Save/Load a list. | |
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? | |
size_t | SlCalcObjLength (const void *object, const SaveLoad *sld) |
Calculate the size of an object. | |
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. | |
bool | SlObjectMember (void *ptr, const SaveLoad *sld) |
void | SlObject (void *object, const SaveLoad *sld) |
Main SaveLoad function. | |
void | SlGlobList (const SaveLoadGlobVarList *sldg) |
Save or Load (a list of) global variables. | |
void | SlAutolength (AutolengthProc *proc, void *arg) |
Do something of which I have no idea what it is :P. | |
static void | SlLoadChunk (const ChunkHandler *ch) |
Load a chunk of data (eg vehicles, stations, etc.) | |
static void | SlLoadCheckChunk (const ChunkHandler *ch) |
Load a chunk of data for checking savegames. | |
static void | SlStubSaveProc2 (void *arg) |
Stub Chunk handlers to only calculate length and do nothing else. | |
static void | SlStubSaveProc () |
Stub Chunk handlers to only calculate length and do nothing else. | |
static void | SlSaveChunk (const ChunkHandler *ch) |
Save a chunk of data (eg. | |
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. | |
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. | |
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. | |
bool | LoadOldSaveGame (const char *file) |
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) | |
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. | |
static void | SaveFileToDiskThread (void *arg) |
Thread run function for saving the file to disk. | |
void | WaitTillSaved () |
static SaveOrLoadResult | DoSave (SaveFilter *writer, bool threaded) |
Actually perform the saving of the savegame. | |
SaveOrLoadResult | SaveWithFilter (SaveFilter *writer, bool threaded) |
Save the game using a (writer) filter. | |
static SaveOrLoadResult | DoLoad (LoadFilter *reader, bool load_check) |
Actually perform the loading of a "non-old" savegame. | |
SaveOrLoadResult | LoadWithFilter (LoadFilter *reader) |
Load the game using a (reader) filter. | |
SaveOrLoadResult | SaveOrLoad (const char *filename, int mode, Subdirectory sb, bool threaded) |
Main Save or Load function where the high-level saveload functions are handled. | |
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. |
Variables | |
const uint16 | SAVEGAME_VERSION = 194 |
Current savegame version of OpenTTD. | |
SavegameType | _savegame_type |
type of savegame we are loading | |
uint32 | _ttdp_version |
version of TTDP savegame (if applicable) | |
uint16 | _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, NULL terminated. | |
static AsyncSaveFinishProc | _async_save_finish = NULL |
Callback to call when the savegame loading is finished. | |
static ThreadObject * | _save_thread |
The thread we're using to compress and write a savegame. | |
static size_t | _next_offs |
static ChunkSaveLoadProc * | _stub_save_proc |
Stub Chunk handlers to only calculate length and do nothing else. | |
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. | |
static const SaveLoadFormat | _saveload_formats [] |
The different saveload formats known/understood by OpenTTD. |
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 493 of file saveload.cpp.
Referenced by SlFindChunkHandler(), SlFixPointers(), SlNullPointers(), and SlSaveChunks().
enum NeedLength |
NL_NONE |
not working in NeedLength mode |
NL_WANTLENGTH |
writing length and data |
NL_CALCLENGTH |
need to calculate the length |
Definition at line 285 of file saveload.cpp.
enum SaveLoadAction |
What are we currently doing?
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 277 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 526 of file afterload.cpp.
References _animated_tile_count, _animated_tile_list, _cur_year, _current_company, _date, _date_fract, _grfconfig, _industry_builder, _m, _me, _network_dedicated, _network_server, _networking, _old_vds, _pause_mode, _road_stop_stop_frame, _settings_client, _settings_game, _tile_type_procs, _tunnel_visibility_frame, Vehicle::acceleration, Industry::accepts_cargo, IndustrySpec::accepts_cargo, AddInflation(), CargoPacket::AfterLoad(), AfterLoadCompanyStats(), AfterLoadLinkGraphs(), AfterLoadRoadStops(), AfterLoadStoryBook(), AfterLoadVehicles(), AIR_AIRCRAFT, AircraftNextAirportPos_and_Order(), Station::airport, EconomySettings::allow_town_level_crossings, EconomySettings::allow_town_roads, SmallVector< T, S >::Append(), AT_OILRIG, CompanyProperties::avail_railtypes, Company::avail_roadtypes, StationCargoList::AvailableCount(), Subsidy::awarded, AXIS_X, AXIS_Y, AxisToDirection(), CompanyProperties::bankrupt_asked, SmallVector< T, S >::Begin(), IndustrySpec::behaviour, Depot::build_date, Object::build_date, BaseStation::build_date, Vehicle::build_year, Station::bus_stops, GroundVehicleCache::cached_total_length, CalcClosestTownFromTile(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_roadstop_pool >::CanAllocateItem(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_object_pool >::CanAllocateItem(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_cargo_payment_pool >::CanAllocateItem(), GoodsEntry::cargo, Vehicle::cargo_payment, Subsidy::cargo_type, CCF_TRACK, CeilDiv(), ChangeTileOwner(), Clamp(), SmallVector< T, S >::Clear(), CLEAR_FIELDS, ConstructionSettings::clear_frame_burst, CLEAR_GRASS, CompanyProperties::clear_limit, CLEAR_SNOW, ClearBridgeMiddle(), ClosestTownFromTile(), ClrBit(), Object::colour, ClientSettings::company, Engine::company_avail, COMPANY_FIRST, ConnectMultiheadedTrains(), Train::ConsistChanged(), GameSettings::construction, ConvertFromOldCompanyManagerFace(), Order::ConvertFromOldSavegame(), ConvertOldMultiheadToNew(), CopyFromOldName(), CopyTempEngineData(), CT_NO_REFIT, BaseConsist::cur_implicit_order_index, BaseConsist::cur_real_order_index, Vehicle::cur_speed, Vehicle::current_order, CargoPayment::current_station, Vehicle::date_of_last_service, DAY_TICKS, DAYS_TILL_ORIGINAL_BASE_YEAR, DEBUG, DeleteAnimatedTile(), Vehicle::dest_tile, DIAGDIR_END, DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, DiagDirToAxis(), DiagDirToDiagTrackBits(), DiagDirToDiagTrackdir(), DiagDirToDir(), GameSettings::difficulty, Vehicle::direction, DirToDiagDir(), VehicleSettings::disable_elrails, LinkGraphSettings::distribution_armoured, LinkGraphSettings::distribution_default, LinkGraphSettings::distribution_mail, LinkGraphSettings::distribution_pax, Station::dock_tile, DoStartupNewCompany(), Subsidy::dst, Subsidy::dst_type, DT_MANUAL, VehicleSettings::dynamic_engines, GameSettings::economy, EF_ROAD_TRAM, SmallVector< T, S >::End(), CompanySettings::engine_renew, Company::engine_renew_list, CompanySettings::engine_renew_money, CompanySettings::engine_renew_months, Vehicle::engine_type, CompanyProperties::face, FACIL_AIRPORT, FACIL_DOCK, FACIL_TRAIN, BaseStation::facilities, EconomySettings::feeder_payment_share, FindFirstCargoWithTownEffect(), SpecializedVehicle< T, Type >::First(), Vehicle::FirstShared(), FixOwnerOfRailTrack(), FixupTrainLengths(), FixVehicleInclination(), FLYING, FOR_ALL_AIRCRAFT, FOR_ALL_CARGO_PAYMENTS, FOR_ALL_DISASTERVEHICLES, FOR_ALL_ORDER_BACKUPS, FOR_ALL_VEHICLES, FOR_ALL_WAYPOINTS, PathfinderSettings::forbid_90_deg, Industry::founder, OrderList::FreeChain(), ConstructionSettings::freeform_edges, SpecializedStation< Station, false >::From(), SpecializedVehicle< Train, Type >::From(), SpecializedVehicle< RoadVehicle, Type >::From(), CargoPayment::front, GameSettings::game_creation, GamelogGRFAddList(), GamelogGRFCompatible(), GamelogGRFRemove(), GamelogOldver(), GamelogPrintDebug(), GamelogTestMode(), GamelogTestRevision(), GB(), GroundVehicle< T, Type >::gcache, GCF_COMPATIBLE, GCS_NOT_FOUND, GoodsEntry::GES_RATING, CargoSpec::Get(), SpecializedStation< Station, false >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_object_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<&_company_pool >::Get(), GetAircraftFlightLevelBounds(), BaseStation::GetByTile(), SpecializedStation< Station, false >::GetByTile(), SpecializedStation< Waypoint, true >::GetByTile(), GetClearDensity(), GetCompanyRailtypes(), GetCompanyRoadtypes(), Order::GetDestination(), OrderList::GetFirstOrder(), OverrideManagerBase::GetGRFID(), GetHouseType(), SpecializedStation< Station, false >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), GetIndustryGfx(), GetIndustrySpec(), GetIndustryType(), GetNorthernBridgeEnd(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_object_pool >::GetNumItems(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::GetNumItems(), Vehicle::GetNumOrders(), GetOtherShipDepotTile(), GetOtherTunnelBridgeEnd(), GetRailType(), GetRawClearGround(), GetRoadOwner(), GetRoadTileType(), Airport::GetSpec(), GetStationGfx(), GetStationType(), GetTargetAirportIfValid(), GetTileOwner(), GetTileTrackStatus(), GetTileType(), GetTownIndex(), GetTunnelBridgeDirection(), GetTunnelBridgeTransportType(), Order::GetUnloadType(), PersistentStorageArray< TYPE, SIZE >::GetValue(), GetWaterClass(), GetWaterTileType(), GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET, GfxLoadSprites(), GLC_ALL_GOOD, GLC_COMPATIBLE, GLC_NOT_FOUND, Town::goal, Station::goods, BasePersistentStorageArray::grfid, GroundVehicle< T, Type >::gv_flags, GVF_GOINGDOWN_BIT, GVF_GOINGUP_BIT, OrthogonalTileArea::h, HasBit(), HasSignals(), HasStationRail(), HasStationTileRail(), HasTownOwnedRoad(), Town::have_ratings, Tile::height, CompanyProperties::inaugurated_year, Object::IncTypeCount(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Station::indtype, DifficultySettings::industry_density, INDUSTRYBEH_BUILT_ONWATER, INDUSTRYBEH_PLANT_ON_BUILT, Economy::inflation_payment, Economy::inflation_prices, EconomySettings::infrastructure_maintenance, InitializeRailGUI(), InitializeWindowsAndCaches(), Engine::intro_date, INVALID_COMPANY, INVALID_DIR, INVALID_OWNER, INVALID_STRING_ID, INVALID_TILE, INVALID_TRACK, CompanyProperties::is_ai, IsAirportTile(), IsBridge(), IsBridgeTile(), IsBuoy(), IsBuoyTile(), IsClearGround(), IsDock(), IsDriveThroughStopTile(), SpecializedStation< Station, false >::IsExpected(), GroundVehicle< T, Type >::IsFreeWagon(), Vehicle::IsFrontEngine(), IsGoodGRFConfigList(), Vehicle::IsGroundVehicle(), IsHouseCompleted(), IsInsideMM(), IsLevelCrossing(), IsLevelCrossingTile(), IsLock(), Aircraft::IsNormalAircraft(), IsOilRig(), IsPlainRail(), IsPlainRailTile(), Vehicle::IsPrimaryVehicle(), IsRailDepot(), IsRailDepotTile(), IsRoadDepot(), IsRoadStop(), IsSavegameVersionBefore(), IsShipDepot(), IsShipDepotTile(), IsStandardRoadStopTile(), IsStationTileBlocked(), IsTileFlat(), IsTileOwner(), IsTileType(), IsTruckStop(), IsTunnelTile(), Order::IsType(), 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<&_industry_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), IsWater(), GameCreationSettings::landscape, Town::larger_town, EconomySettings::larger_towns, Industry::last_prod_year, GoodsEntry::last_speed, Vehicle::last_station_visited, Town::layout, lengthof, GameSettings::linkgraph, Vehicle::list, Vehicle::load_unload_ticks, LoadStringWidthTable(), GameSettings::locale, Object::location, CompanyProperties::location_of_HQ, Tile::m1, Tile::m2, Tile::m3, Tile::m4, Tile::m5, TileExtended::m7, MakeCanal(), MakeClear(), MakeDefaultName(), MakeRoadNormal(), MakeSea(), MakeShore(), MapMaxX(), MapMaxY(), MapSize(), ConstructionSettings::max_bridge_length, MAX_COMPANIES, ConstructionSettings::max_heightlevel, MAX_INFLATION, DifficultySettings::max_loan, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::MAX_SIZE, VehicleSettings::max_train_length, ConstructionSettings::max_tunnel_length, MayHaveBridgeAbove(), min(), MIN_SNOWLINE_HEIGHT, StationSettings::modified_catchment, CompanyProperties::months_of_bankruptcy, MoveBuoysToWaypoints(), MoveWaypointsToBaseStations(), MP_CLEAR, MP_HOUSE, MP_INDUSTRY, MP_OBJECT, MP_RAILWAY, MP_ROAD, MP_STATION, MP_TREES, MP_TUNNELBRIDGE, MP_VOID, MP_WATER, CompanyProperties::name, BaseStation::name, Town::name, CompanyProperties::name_1, NEW_HOUSE_OFFSET, PathfinderSettings::new_pathfinding_all, GRFConfig::next, SpecializedVehicle< T, Type >::Next(), NUM_CARGO, DifficultySettings::number_towns, OBJECT_HQ, OBJECT_STATUE, Economy::old_max_loan_unround, Economy::old_max_loan_unround_fract, OLFB_NO_LOAD, ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS, Vehicle::orders, ORIGINAL_BASE_YEAR, OSL_PLATFORM_FAR_END, OUFB_TRANSFER, OUFB_UNLOAD, BaseStation::owner, OWNER_NONE, OWNER_TOWN, OWNER_WATER, PathfinderSettings::pathfinder_for_roadvehs, PathfinderSettings::pathfinder_for_ships, PathfinderSettings::pathfinder_for_trains, GameSettings::pf, VehicleSettings::plane_crashes, VehicleSettings::plane_speed, PM_PAUSED_ERROR, PM_PAUSED_NORMAL, PM_UNPAUSED, PMB_PAUSED_NETWORK, CompanyProperties::president_name, CompanyProperties::president_name_1, Industry::produced_cargo, Vehicle::profit_last_year, Vehicle::profit_this_year, Industry::psa, Airport::psa, YAPFSettings::rail_use_yapf, RAILTYPE_ELECTRIC, RAILTYPE_RAIL, RATING_INITIAL, Town::ratings, BaseStation::rect, Subsidy::remaining, CompanySettings::renew_keep_length, Train::ReserveTrackUnderConsist(), IndustryBuildData::Reset(), ResetCompanyLivery(), ResetOldNames(), ResetSignalHandlers(), Backup< T >::Restore(), PathfinderSettings::reverse_at_signals, ReverseDiagDir(), ReverseDir(), VehicleSettings::road_side, ROAD_TILE_CROSSING, ROAD_TILE_DEPOT, ROAD_TILE_NORMAL, YAPFSettings::road_use_yapf, ROAD_X, ROAD_Y, ROADTYPE_END, ROADTYPE_ROAD, ROADTYPE_TRAM, ROADTYPES_ROAD, VehicleSettings::roadveh_acceleration_model, VehicleSettings::roadveh_slope_steepness, Vehicle::running_ticks, RVS_DRIVE_SIDE, RVS_ENTERED_STOP, RVS_IN_DT_ROAD_STOP, RVS_IN_ROAD_STOP, RVSB_IN_DEPOT, RVSB_IN_ROAD_STOP, RVSB_WORMHOLE, SB(), GameSettings::script, SetAircraftPosition(), SetAnimationFrame(), SetBit(), SetBridgeMiddle(), SetClearGroundDensity(), SetCrossingReservation(), SetDate(), SetDepotReservation(), SetFence(), SetHouseCompleted(), SetLiftPosition(), Order::SetLoadType(), Order::SetNonStopType(), SetRailStationReservation(), SetRailType(), Order::SetRefit(), SetRoadOwner(), SetRoadTypes(), SetSaveLoadError(), SetSignalHandlers(), SetSignalStates(), SetStationGfx(), Order::SetStopLocation(), SetTileOwner(), Company::settings, ScriptSettings::settings_profile, SettingsDisableElrail(), SetTownIndex(), SetTrackReservation(), SetTropicZone(), SetTunnelBridgeReservation(), Order::SetUnloadType(), SetWaterClass(), SetWaterClassDependingOnSurroundings(), CompanyProperties::share_owners, YAPFSettings::ship_use_yapf, ShowErrorMessage(), SIG_ELECTRIC, SIG_SEMAPHORE, SIGTYPE_COMBO, AirportSpec::size_x, AirportSpec::size_y, SlError(), SlErrorCorrupt(), GameCreationSettings::snow_line_height, SP_END, SP_MEDIUM, Subsidy::src, Subsidy::src_type, ST_INDUSTRY, ST_TOWN, AI::StartNew(), StartupEngines(), Aircraft::state, RoadVehicle::state, GameSettings::station, EconomySettings::station_noise_level, GoodsEntry::status, PersistentStorageArray< TYPE, SIZE >::storage, BaseStation::string_id, Vehicle::subtype, Swap(), TE_FOOD, TE_GOODS, TE_MAIL, TE_PASSENGERS, TE_WATER, ConstructionSettings::terraform_frame_burst, CompanyProperties::terraform_limit, TFP_NONE, TFP_STUCK, OrthogonalTileArea::tile, Vehicle::tile, TILE_ADDXY, TILE_HEIGHT, TILE_SIZE, TILE_UNIT_MASK, TileHash(), TileHeight(), TileVirtXY(), TileX(), TileXY(), TileY(), TL_BETTER_ROADS, TL_RANDOM, Object::town, BaseStation::town, Waypoint::town_cn, Depot::town_cn, CargoSpec::town_effect, TOWN_GROWTH_DESERT, TOWN_GROWTH_WINTER, TOWN_HOUSE_COMPLETED, EconomySettings::town_layout, GameCreationSettings::town_name, TRACK_BIT_NONE, TRACK_BIT_WORMHOLE, TRACK_BIT_X, TRACK_BIT_Y, TRACK_LOWER, TRACK_UPPER, TrackStatusToTrackBits(), VehicleSettings::train_acceleration_model, VehicleSettings::train_slope_steepness, BaseStation::train_station, TRANSPORT_RAIL, TRANSPORT_ROAD, ConstructionSettings::tree_frame_burst, TREE_GROUND_SNOW_DESERT, CompanyProperties::tree_limit, TROPICZONE_NORMAL, Station::truck_stops, Aircraft::turn_counter, Object::type, BaseVehicle::type, Industry::type, Airport::type, LocaleSettings::units_force, LocaleSettings::units_height, LocaleSettings::units_power, LocaleSettings::units_velocity, LocaleSettings::units_volume, LocaleSettings::units_weight, UpdateAircraftCache(), UpdateHousesAndTowns(), UpdateLevelCrossing(), UpdateNearestTownForRoadTiles(), UpdateOldAircraft(), Vehicle::UpdateRealOrderIndex(), UpdateStationAcceptance(), UpdateTownCargoes(), VEH_INVALID, VEH_ROAD, VEH_SHIP, VEH_TRAIN, CompanySettings::vehicle, GameSettings::vehicle, BaseConsist::vehicle_flags, Vehicle::vehstatus, VF_LOADING_FINISHED, VF_PATHFINDER_LOST, VPF_NPF, VPF_OPF, VPF_YAPF, VS_CRASHED, VS_HIDDEN, VS_STOPPED, OrthogonalTileArea::w, Train::wait_counter, PathfinderSettings::wait_for_pbs_path, PathfinderSettings::wait_oneway_signal, PathfinderSettings::wait_twoway_signal, WATER_CLASS_CANAL, WATER_CLASS_INVALID, WATER_CLASS_RIVER, WATER_CLASS_SEA, WATER_TILE_CLEAR, WATER_TILE_LOCK, WL_CRITICAL, Vehicle::x_pos, BaseStation::xy, Town::xy, XYNSToDiagDir(), Vehicle::y_pos, PathfinderSettings::yapf, YapfNotifyTrackLayoutChange(), and Vehicle::z_pos.
Referenced by DoLoad(), and SaveOrLoad().
|
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 2621 of file saveload.cpp.
References _grfconfig, _load_check_data, _savegame_type, _saveload_formats, _sl_minor_version, _sl_version, AfterLoadGame(), LoadCheckData::checkable, LoadCheckData::Clear(), ClearGRFConfigList(), ClearSaveLoadState(), DEBUG, endof, GamelogReset(), GamelogStartAction(), GamelogStopAction(), GLAT_LOAD, LoadCheckData::grf_compatibility, LoadCheckData::grfconfig, SaveLoadFormat::init_load, IsGoodGRFConfigList(), IsSavegameVersionBefore(), lastof, SaveLoadParams::lf, SaveLoadFormat::name, LoadFilter::Read(), SaveLoadParams::reader, LoadFilter::Reset(), SAVEGAME_VERSION, seprintf(), SGT_OTTD, SL_OK, SL_REINIT, SlError(), SlFixPointers(), SlLoadCheckChunks(), SlLoadChunks(), and SaveLoadFormat::tag.
Referenced by LoadWithFilter(), and SaveOrLoad().
|
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 2573 of file saveload.cpp.
References _sl_version, DEBUG, SaveLoadParams::dumper, ThreadObject::New(), SaveFileDone(), SaveFileStart(), SaveFileToDisk(), SaveFileToDiskThread(), SAVEGAME_VERSION, SaveLoadParams::saveinprogress, SaveLoadParams::sf, SL_OK, and SlSaveChunks().
Referenced by SaveOrLoad(), and 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 2863 of file saveload.cpp.
References _date, _local_company, _settings_client, GUISettings::date_format_in_default_names, ClientSettings::gui, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), SanitizeFilename(), and SetDParam().
Referenced by DoAutosave(), SaveLoadWindow::GenerateFileName(), and MakeScreenshotName().
|
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 NULL it picks the first available one |
compression_level | Output for telling what compression level we want. |
Definition at line 2383 of file saveload.cpp.
References 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 NULL 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 1270 of file saveload.cpp.
References SaveLoadParams::action, SpecializedStation< Station, false >::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<&_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<&_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<&_roadstop_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<&_enginerenew_pool >::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(), IsSavegameVersionBefore(), SpecializedStation< Station, false >::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<&_town_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<&_roadstop_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<&_orderlist_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<&_cargopacket_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_persistent_storage_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, and SlErrorCorrupt().
Referenced by SlList().
|
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 1490 of file saveload.cpp.
References SaveLoad::cmd, SaveLoad::conv, GetVarMemType(), SaveLoad::length, SaveLoad::size, SL_REF, SL_STR, 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 2759 of file saveload.cpp.
References SaveLoadParams::action, ClearSaveLoadState(), DoLoad(), SL_REINIT, and SLA_LOAD.
Referenced by SafeLoad().
int64 ReadValue | ( | const void * | ptr, |
VarType | conv | ||
) |
Return a signed-long version of the value of a setting.
ptr | pointer to the variable |
conv | type of variable, can be a non-clean type, eg one with other flags because it is parsed |
Definition at line 942 of file saveload.cpp.
References GetVarMemType(), and SLE_VAR_NULL.
Referenced by CmdChangeCompanySetting(), CmdChangeSetting(), SettingEntry::DrawSetting(), CheatWindow::DrawWidget(), GameSettingsWindow::DrawWidget(), NewsTypeData::GetDisplay(), IConsoleGetSetting(), IConsoleListSettings(), IniSaveSettings(), SettingEntry::IsVisibleByRestrictionMode(), LoadSettings(), CheatWindow::OnClick(), GameSettingsWindow::OnClick(), CheatWindow::OnQueryTextFinished(), SetCompanySetting(), SetSettingValue(), SlSaveLoadConv(), and SyncCompanySettings().
|
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 NULL 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 1237 of file saveload.cpp.
References 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.
Referenced by SlList().
|
static |
Update the gui accordingly when saving is done and release locks on saveload.
Definition at line 2469 of file saveload.cpp.
References SaveLoadParams::ff_state, InvalidateWindowData(), SaveLoadParams::saveinprogress, SBI_SAVELOAD_FINISH, SetMouseCursor(), SPR_CURSOR_MOUSE, CursorVars::sprite, and WC_STATUS_BAR.
Referenced by DoSave(), SaveFileError(), and SaveFileToDisk().
|
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 2458 of file saveload.cpp.
References SaveLoadParams::ff_state, InvalidateWindowData(), SaveLoadParams::saveinprogress, SBI_SAVELOAD_START, SetMouseCursor(), SPR_CURSOR_MOUSE, CursorVars::sprite, and WC_STATUS_BAR.
Referenced by DoSave().
|
static |
Thread run function for saving the file to disk.
Definition at line 2548 of file saveload.cpp.
References SaveFileToDisk().
Referenced by DoSave().
SaveOrLoadResult SaveOrLoad | ( | const char * | filename, |
int | mode, | ||
Subdirectory | sb, | ||
bool | threaded | ||
) |
Main Save or Load function where the high-level saveload functions are handled.
It opens the savegame, selects format and checks versions
filename | The name of the savegame being created/loaded |
mode | Save or load mode. Load can also be a TTD(Patch) game. Use SL_LOAD, SL_OLD_LOAD, SL_LOAD_CHECK, or SL_SAVE. |
sb | The sub directory to save the savegame in |
threaded | True when threaded saving is allowed |
Definition at line 2779 of file saveload.cpp.
References _date, _date_fract, _do_autosave, _grfconfig, _network_server, _settings_client, _sl_minor_version, _sl_version, SaveLoadParams::action, AfterLoadGame(), BASE_DIR, ClearGRFConfigList(), ClearSaveLoadState(), DEBUG, DoLoad(), DoSave(), FioFOpenFile(), GamelogReset(), GamelogStartAction(), GamelogStopAction(), GetSaveLoadErrorString(), GLAT_LOAD, ClientSettings::gui, INVALID_STRING_ID, SAVE_DIR, SaveLoadParams::saveinprogress, SCENARIO_DIR, ShowErrorMessage(), SL_ERROR, SL_LOAD, SL_LOAD_CHECK, SL_OK, SL_OLD_LOAD, SL_REINIT, SL_SAVE, SLA_LOAD, SLA_LOAD_CHECK, SLA_SAVE, SlError(), GUISettings::threaded_saves, and WL_ERROR.
Referenced by _GenerateWorld(), DEF_CONSOLE_CMD(), DoAutosave(), DoExitSave(), LoadIntroGame(), SaveLoadWindow::OnClick(), openttd_main(), SafeLoad(), StateGameLoop(), and CrashLog::WriteSavegame().
SaveOrLoadResult SaveWithFilter | ( | SaveFilter * | writer, |
bool | threaded | ||
) |
Save the game using a (writer) filter.
writer | The filter to write the savegame to. |
threaded | Whether to try to perform the saving asynchronously. |
Definition at line 2604 of file saveload.cpp.
References SaveLoadParams::action, ClearSaveLoadState(), DoSave(), SL_ERROR, and SLA_SAVE.
Referenced by ServerNetworkGameSocketHandler::SendMap().
|
static |
Called by save thread to tell we finished saving.
proc | The callback to call when saving is done. |
Definition at line 571 of file saveload.cpp.
Referenced by SaveFileToDisk().
void SlArray | ( | void * | array, |
size_t | length, | ||
VarType | conv | ||
) |
Save/Load an array.
array | The array being manipulated |
length | The length of the array in elements |
conv | VarType type of the atomic array (int, byte, uint64, etc.) |
Definition at line 1182 of file saveload.cpp.
References _sl_version, SaveLoadParams::action, BSWAP32(), SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, SLA_NULL, SLA_PTRS, SLA_SAVE, SlCalcArrayLen(), SlCalcConvFileLen(), SlCalcConvMemLen(), SlCopyBytes(), SlSaveLoadConv(), and SlSetLength().
Referenced by Load_ANIT(), Load_CAPR(), Load_NAME(), Load_PRIC(), ScriptInstance::LoadObjects(), Save_ANIT(), and ScriptInstance::SaveObject().
void SlAutolength | ( | AutolengthProc * | proc, |
void * | arg | ||
) |
Do something of which I have no idea what it is :P.
proc | The callback procedure that is called |
arg | The variable that will be used for the callback procedure |
Definition at line 1630 of file saveload.cpp.
References SaveLoadParams::action, SaveLoadParams::dumper, MemoryDumper::GetSize(), SaveLoadParams::need_length, NL_CALCLENGTH, NL_WANTLENGTH, SaveLoadParams::obj_len, SLA_SAVE, SlErrorCorrupt(), and SlSetLength().
Referenced by Save_LGRJ(), Save_LGRP(), and SlStubSaveProc().
|
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 1171 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 798 of file saveload.cpp.
References GB(), and lengthof.
Referenced by SlArray(), and SlCalcArrayLen().
|
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 774 of file saveload.cpp.
References GB(), lengthof, SLE_VAR_STR, SLE_VAR_STRB, SLE_VAR_STRBQ, and SLE_VAR_STRQ.
Referenced by SlArray(), and SlSkipVariableOnLoad().
|
inlinestatic |
Return the size in bytes of a list.
list | The std::list to find the size of |
Definition at line 1345 of file saveload.cpp.
References IsSavegameVersionBefore().
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 1049 of file saveload.cpp.
References min().
Referenced by SlCalcStringLen(), and SlString().
size_t SlCalcObjLength | ( | const void * | object, |
const SaveLoad * | sld | ||
) |
Calculate the size of an object.
object | to be measured |
sld | The SaveLoad description of the object so we know how to manipulate it |
Definition at line 1444 of file saveload.cpp.
References SaveLoad::cmd.
Referenced by SlObject().
|
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 1064 of file saveload.cpp.
References GetVarMemType(), SlCalcNetStringLen(), SLE_VAR_STR, SLE_VAR_STRB, SLE_VAR_STRBQ, and SLE_VAR_STRQ.
|
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 913 of file saveload.cpp.
References SaveLoadParams::action, SLA_LOAD, SLA_LOAD_CHECK, SLA_SAVE, SlReadByte(), and SlWriteByte().
Referenced by SlArray(), and SlString().
void NORETURN SlError | ( | StringID | string, |
const char * | extra_msg | ||
) |
Error handler.
Sets everything up to show an error message and to clean up the mess of a partial savegame load.
string | The translatable error message to show. |
extra_msg | An extra error message coming from one of the APIs. |
Definition at line 529 of file saveload.cpp.
References _load_check_data, SaveLoadParams::action, LoadCheckData::error, LoadCheckData::error_data, SaveLoadParams::error_str, SaveLoadParams::extra_msg, free(), SLA_LOAD, SLA_LOAD_CHECK, SLA_PTRS, SlNullPointers(), and stredup().
Referenced by AfterLoadGame(), DoLoad(), PacketWriter::Finish(), LZMALoadFilter::LZMALoadFilter(), LZMASaveFilter::LZMASaveFilter(), LZOLoadFilter::LZOLoadFilter(), LZOSaveFilter::LZOSaveFilter(), MoveWaypointsToBaseStations(), LZOLoadFilter::Read(), ZlibLoadFilter::Read(), LZMALoadFilter::Read(), SaveOrLoad(), SlErrorCorrupt(), PacketWriter::Write(), FileWriter::Write(), ZlibSaveFilter::WriteLoop(), LZMASaveFilter::WriteLoop(), ZlibLoadFilter::ZlibLoadFilter(), and ZlibSaveFilter::ZlibSaveFilter().
void NORETURN SlErrorCorrupt | ( | const char * | msg | ) |
Error handler for corrupt savegames.
Sets everything up to show the error message and to clean up the mess of a partial savegame load.
msg | Location the corruption has been spotted. |
Definition at line 557 of file saveload.cpp.
References SlError().
Referenced by AfterLoadGame(), AfterLoadVehicles(), ConvertOldMultiheadToNew(), IntToReference(), Load_CHTS(), Load_ITBL(), Load_NAME(), Load_NewGRFMapping(), Load_VEHS(), LoadOldVehicle(), LZOLoadFilter::Read(), SetWaterClassDependingOnSurroundings(), SlAutolength(), SlIterateArray(), SlLoadCheckChunk(), SlLoadCheckChunks(), SlLoadChunk(), SlLoadChunks(), and SlReadSimpleGamma().
|
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 1827 of file saveload.cpp.
References FOR_ALL_CHUNK_HANDLERS.
Referenced by SlLoadCheckChunks(), and SlLoadChunks().
void SlGlobList | ( | const SaveLoadGlobVarList * | sldg | ) |
Save or Load (a list of) global variables.
sldg | The global variable that is being loaded or saved |
Definition at line 1620 of file saveload.cpp.
References SlObject().
Referenced by LoadSave_IBLD().
int SlIterateArray | ( | ) |
Iterate through the elements of an array and read the whole thing.
Definition at line 824 of file saveload.cpp.
References SaveLoadParams::block_mode, DEBUG, ReadBuffer::GetSize(), SaveLoadParams::obj_len, SaveLoadParams::reader, and SlErrorCorrupt().
Referenced by Load_CAPA(), Load_ITBL(), Load_LGRJ(), Load_LGRP(), Load_NAME(), Load_NewGRFMapping(), Load_PSAC(), Load_SIGN(), Load_VEHS(), LoadDelivery(), LoadPickup(), and SlSkipArray().
|
static |
Save/Load a list.
list | The list being manipulated |
conv | SLRefType type of the list (Vehicle *, Station *, etc) |
Definition at line 1361 of file saveload.cpp.
References SaveLoadParams::action, IntToReference(), IsSavegameVersionBefore(), SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, ReferenceToInt(), SLA_LOAD, SLA_LOAD_CHECK, SLA_NULL, SLA_PTRS, SLA_SAVE, SlCalcListLen(), and SlSetLength().
|
static |
Load a chunk of data for checking savegames.
If the chunkhandler is NULL, the chunk is skipped.
ch | The chunkhandler that will be used for the operation |
Definition at line 1697 of file saveload.cpp.
References SaveLoadParams::block_mode, ReadBuffer::GetSize(), ChunkHandler::load_check_proc, SaveLoadParams::obj_len, SaveLoadParams::reader, SlErrorCorrupt(), SlReadByte(), SlSkipArray(), and SlSkipBytes().
Referenced by SlLoadCheckChunks().
|
static |
Load a chunk of data (eg vehicles, stations, etc.)
ch | The chunkhandler that will be used for the operation |
Definition at line 1657 of file saveload.cpp.
References SaveLoadParams::block_mode, ReadBuffer::GetSize(), ChunkHandler::load_proc, SaveLoadParams::obj_len, SaveLoadParams::reader, SlErrorCorrupt(), and SlReadByte().
Referenced by SlLoadChunks().
void SlObject | ( | void * | object, |
const SaveLoad * | sld | ||
) |
Main SaveLoad function.
object | The object that is being saved or loaded |
sld | The SaveLoad description of the object so we know how to manipulate it |
Definition at line 1602 of file saveload.cpp.
References SaveLoad::address, SaveLoad::cmd, GetVariableAddress(), SaveLoad::global, SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, SlCalcObjLength(), and SlSetLength().
Referenced by DoSave_LGRJ(), DoSave_LGRP(), ScriptInstance::Load(), Load_CAPA(), Load_ECMY(), Load_ITBL(), Load_LGRJ(), Load_LGRP(), Load_LGRS(), Load_NewGRFMapping(), Load_PSAC(), Load_SIGN(), Load_VEHS(), LoadDelivery(), ScriptInstance::LoadEmpty(), ScriptInstance::LoadObjects(), LoadPickup(), Ptrs_LGRS(), Ptrs_TOWN(), ScriptInstance::Save(), Save_CAPA(), Save_ECMY(), Save_ITBL(), Save_LGRS(), Save_NewGRFMapping(), Save_PSAC(), Save_SIGN(), Save_VEHS(), SaveDelivery(), ScriptInstance::SaveEmpty(), SaveLoad_LinkGraph(), ScriptInstance::SaveObject(), SavePickup(), and SlGlobList().
byte SlReadByte | ( | ) |
Wrapper for reading a byte from the buffer.
Definition at line 601 of file saveload.cpp.
References SaveLoadParams::reader.
Referenced by Load_CHTS(), Load_VEHS(), SlCopyBytes(), SlLoadCheckChunk(), SlLoadChunk(), SlReadSimpleGamma(), SlSaveLoadConv(), and SlSkipBytes().
|
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 671 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 1773 of file saveload.cpp.
References SaveLoadParams::block_mode, DEBUG, ChunkHandler::flags, ChunkHandler::id, SaveLoadParams::last_array_index, SaveLoadParams::need_length, NL_WANTLENGTH, ChunkHandler::save_proc, SlStubSaveProc(), and SlWriteByte().
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 992 of file saveload.cpp.
References SaveLoadParams::action, GetVarFileType(), ReadValue(), RemapOldStringID(), SLA_LOAD, SLA_LOAD_CHECK, SLA_NULL, SLA_PTRS, SLA_SAVE, SLE_FILE_STRINGID, SlReadByte(), SlWriteByte(), and WriteValue().
Referenced by SlArray().
void SlSetLength | ( | size_t | length | ) |
Sets the length of either a RIFF object or the number of items in an array.
This lets us load an object or an array of arbitrary size
length | The length of the sought object/array |
Definition at line 869 of file saveload.cpp.
References SaveLoadParams::action, SaveLoadParams::block_mode, SaveLoadParams::last_array_index, SaveLoadParams::need_length, NL_CALCLENGTH, NL_NONE, NL_WANTLENGTH, SaveLoadParams::obj_len, and SLA_SAVE.
Referenced by Save_ANIT(), Save_CHTS(), SaveSettings(), SlArray(), SlAutolength(), SlList(), and SlObject().
|
inlinestatic |
Read in bytes from the file/data structure but don't do anything with them, discarding them in effect.
length | The amount of bytes that is being treated this way |
Definition at line 657 of file saveload.cpp.
References SlReadByte().
Referenced by SlLoadCheckChunk(), SlSkipArray(), SlSkipVariableOnLoad(), and SlString().
|
inlinestatic |
Are we going to load this variable when loading a savegame or not?
Definition at line 1428 of file saveload.cpp.
References _network_server, _networking, SaveLoadParams::action, SaveLoad::conv, SaveLoad::length, SLA_SAVE, SlCalcConvMemLen(), SLF_NO_NETWORK_SYNC, and SlSkipBytes().
|
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 1093 of file saveload.cpp.
References SaveLoadParams::action, DEBUG, free(), GetVarMemType(), IsSavegameVersionBefore(), SLA_LOAD, SLA_LOAD_CHECK, SLA_NULL, SLA_PTRS, SLA_SAVE, SlCalcNetStringLen(), SlCopyBytes(), SLE_VAR_STR, SLE_VAR_STRB, SLE_VAR_STRBQ, SLE_VAR_STRQ, SLF_ALLOW_CONTROL, SLF_ALLOW_NEWLINE, SlSkipBytes(), str_fix_scc_encoded(), str_validate(), SVS_ALLOW_CONTROL_CODE, SVS_ALLOW_NEWLINE, and SVS_REPLACE_WITH_QUESTION_MARK.
|
static |
Stub Chunk handlers to only calculate length and do nothing else.
Call SlAutoLenth with our stub save proc that will eventually call the intended chunk handler.
Definition at line 1763 of file saveload.cpp.
References SlAutolength(), and SlStubSaveProc2().
Referenced by SlSaveChunk().
|
inlinestatic |
Stub Chunk handlers to only calculate length and do nothing else.
Actually call the intended chunk handler.
arg | ignored parameter. |
Definition at line 1753 of file saveload.cpp.
References _stub_save_proc.
Referenced by SlStubSaveProc().
void SlWriteByte | ( | byte | b | ) |
Wrapper for writing a byte to the dumper.
b | The byte to write. |
Definition at line 610 of file saveload.cpp.
References SaveLoadParams::dumper, and MemoryDumper::WriteByte().
Referenced by Save_CHTS(), SlCopyBytes(), SlSaveChunk(), SlSaveLoadConv(), and SlWriteSimpleGamma().
|
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 713 of file saveload.cpp.
References SlWriteByte().
void WriteValue | ( | void * | ptr, |
VarType | conv, | ||
int64 | val | ||
) |
Write the value of a setting.
ptr | pointer to the variable |
conv | type of variable, can be a non-clean type, eg with other flags. It is parsed upon read |
val | the new value being given to the variable |
Definition at line 966 of file saveload.cpp.
References CopyFromOldName(), GetVarMemType(), SLE_VAR_NAME, and SLE_VAR_NULL.
Referenced by CmdChangeCompanySetting(), CmdChangeSetting(), CheatWindow::OnClick(), CheatWindow::OnQueryTextFinished(), SlSaveLoadConv(), and Write_ValidateSetting().
|
static |
Array of all chunks in a savegame, NULL
terminated.
Definition at line 452 of file saveload.cpp.
|
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 2223 of file saveload.cpp.
|
static |
The different saveload formats known/understood by OpenTTD.
Definition at line 2347 of file saveload.cpp.
Referenced by DoLoad().
|
static |
Stub Chunk handlers to only calculate length and do nothing else.
The intended chunk handler that should be called.
Definition at line 1746 of file saveload.cpp.
Referenced by SlStubSaveProc2().
|
static |
Save in chunks of 128 KiB.
Definition at line 292 of file saveload.cpp.
Referenced by MemoryDumper::Flush(), MemoryDumper::GetSize(), MemoryDumper::WriteByte(), ZlibSaveFilter::WriteLoop(), and LZMASaveFilter::WriteLoop().