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 "../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 <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... | |
Defines | |
#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) |
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 = SL_EXT_RATING |
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 | _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 | ) |
for (const ChunkHandler * const *chsc = _chunk_handlers; *chsc != NULL; chsc++) \ for (const ChunkHandler *ch = *chsc; ch != NULL; ch = (ch->flags & CH_LAST) ? NULL : ch + 1)
Iterate over all chunk handlers.
ch | the chunk handler iterator |
Definition at line 472 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 266 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 258 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 480 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, GoodsEntry::acceptance_pickup, IndustrySpec::accepts_cargo, Industry::accepts_cargo, AddInflation(), CargoPacket::AfterLoad(), AfterLoadCompanyStats(), AfterLoadLinkGraphs(), AfterLoadRoadStops(), AfterLoadVehicles(), AIR_AIRCRAFT, AircraftNextAirportPos_and_Order(), Station::airport, EconomySettings::allow_town_roads, CompanyProperties::avail_railtypes, Company::avail_roadtypes, Subsidy::awarded, AXIS_X, AxisToDirection(), CompanyProperties::bankrupt_asked, 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<&_cargo_payment_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<&_roadstop_pool >::CanAllocateItem(), GoodsEntry::cargo, Vehicle::cargo_payment, Subsidy::cargo_type, CeilDiv(), ChangeTileOwner(), Clamp(), 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(), CargoList< Tinst, Tcont >::Count(), 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, DEBUG, DeleteAnimatedTile(), Vehicle::dest_tile, DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, DiagDirToAxis(), DiagDirToDiagTrackBits(), DiagDirToDiagTrackdir(), DiagDirToDir(), GameSettings::difficulty, Vehicle::direction, DirToDiagDir(), VehicleSettings::disable_elrails, Station::dock_tile, DoStartupNewCompany(), Subsidy::dst, Subsidy::dst_type, VehicleSettings::dynamic_engines, GameSettings::economy, EF_ROAD_TRAM, 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, FindFirstCargoWithTownEffect(), SpecializedVehicle< T, Type >::First(), Vehicle::FirstShared(), FixOwnerOfRailTrack(), FixupTrainLengths(), FixVehicleInclination(), FLYING, FOR_ALL_AIRCRAFT, FOR_ALL_CARGO_PAYMENTS, FOR_ALL_DISASTERVEHICLES, FOR_ALL_VEHICLES, FOR_ALL_WAYPOINTS, PathfinderSettings::forbid_90_deg, Industry::founder, OrderList::FreeChain(), ConstructionSettings::freeform_edges, SpecializedVehicle< RoadVehicle, Type >::From(), SpecializedVehicle< Train, Type >::From(), SpecializedStation< Station, false >::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_PICKUP, CargoSpec::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(), SpecializedStation< Station, false >::Get(), GetAircraftFlyingAltitude(), SpecializedStation< Waypoint, true >::GetByTile(), SpecializedStation< Station, false >::GetByTile(), BaseStation::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<&_vehicle_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_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(), GetObjectType(), GetOtherShipDepotTile(), GetOtherTunnelBridgeEnd(), GetRailType(), GetRawClearGround(), GetRoadOwner(), GetRoadTileType(), Airport::GetSpec(), GetStationGfx(), GetStationType(), GetTargetAirportIfValid(), GetTileOwner(), GetTileSlope(), 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, PersistentStorage::grfid, GroundVehicle< T, Type >::gv_flags, GVF_GOINGDOWN_BIT, GVF_GOINGUP_BIT, TileArea::h, HasBit(), HasSignals(), HasStationRail(), HasTownOwnedRoad(), Town::have_ratings, 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_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(), IsStatueTile(), IsTileOwner(), IsTileType(), IsTruckStop(), IsTunnelTile(), Order::IsType(), 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<&_town_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, Vehicle::list, Vehicle::load_unload_ticks, LoadStringWidthTable(), 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(), MAX_COMPANIES, MAX_INFLATION, DifficultySettings::max_loan, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::MAX_SIZE, VehicleSettings::max_train_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, BaseStation::name, CompanyProperties::name, CompanyProperties::name_1, PathfinderSettings::new_pathfinding_all, GRFConfig::next, 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_speed, PM_PAUSED_ERROR, PM_PAUSED_NORMAL, PM_UNPAUSED, CompanyProperties::president_name, CompanyProperties::president_name_1, Industry::produced_cargo, Vehicle::profit_last_year, Vehicle::profit_this_year, Airport::psa, Industry::psa, YAPFSettings::rail_use_yapf, RAILTYPE_ELECTRIC, 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_ROAD, ROADTYPE_TRAM, ROADTYPES_ROAD, VehicleSettings::roadveh_acceleration_model, 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(), SetFenceNE(), SetFenceNW(), 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(), SLOPE_FLAT, GameCreationSettings::snow_line_height, SP_END, SP_MEDIUM, Subsidy::src, Subsidy::src_type, AI::StartNew(), StartupEngines(), Aircraft::state, RoadVehicle::state, GameSettings::station, 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, Vehicle::tile, TileArea::tile, TILE_ADDXY, TILE_HEIGHT, TILE_SIZE, TILE_UNIT_MASK, TileHash(), TileHeight(), TileVirtXY(), TileX(), TileXY(), TileY(), TL_RANDOM, BaseStation::town, Object::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_X, TRACK_BIT_Y, TRACK_LOWER, TRACK_UPPER, TRACK_X, TrackStatusToTrackBits(), VehicleSettings::train_acceleration_model, 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, Industry::type, BaseVehicle::type, Airport::type, UpdateAircraftCache(), UpdateHousesAndTowns(), UpdateLevelCrossing(), UpdateNearestTownForRoadTiles(), UpdateOldAircraft(), Vehicle::UpdateRealOrderIndex(), UpdateStationAcceptance(), UpdateTownCargoes(), VEH_ROAD, VEH_SHIP, VEH_TRAIN, CompanySettings::vehicle, GameSettings::vehicle, BaseConsist::vehicle_flags, Vehicle::vehstatus, VF_LOADING_FINISHED, VF_PATHFINDER_LOST, VPF_NPF, VS_CRASHED, VS_STOPPED, TileArea::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, Town::xy, BaseStation::xy, XYNSToDiagDir(), Vehicle::y_pos, PathfinderSettings::yapf, YapfNotifyTrackLayoutChange(), and Vehicle::z_pos.
Referenced by DoLoad(), and SaveOrLoad().
static SaveOrLoadResult DoLoad | ( | LoadFilter * | reader, | |
bool | load_check | |||
) | [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 2531 of file saveload.cpp.
References _grfconfig, _load_check_data, _savegame_type, _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(), lengthof, SaveLoadParams::lf, SaveLoadFormat::name, LoadFilter::Read(), SaveLoadParams::reader, LoadFilter::Reset(), SAVEGAME_VERSION, SlError(), SlFixPointers(), SlLoadCheckChunks(), SlLoadChunks(), and SaveLoadFormat::tag.
Referenced by LoadWithFilter(), and SaveOrLoad().
static SaveOrLoadResult DoSave | ( | SaveFilter * | writer, | |
bool | threaded | |||
) | [static] |
Actually perform the saving of the savegame.
General tactic 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 asynchroniously. |
Definition at line 2483 of file saveload.cpp.
References _sl_version, DEBUG, SaveLoadParams::dumper, ThreadObject::New(), SaveFileDone(), SaveFileStart(), SaveFileToDisk(), SaveFileToDiskThread(), SAVEGAME_VERSION, SaveLoadParams::saveinprogress, SaveLoadParams::sf, 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 2773 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 const SaveLoadFormat* GetSavegameFormat | ( | char * | s, | |
byte * | compression_level | |||
) | [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 2293 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 void* IntToReference | ( | size_t | index, | |
SLRefType | rt | |||
) | [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 1233 of file saveload.cpp.
References SaveLoadParams::action, 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<&_cargopacket_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<&_roadstop_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::Get(), 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<&_order_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_orderlist_pool >::Get(), IsSavegameVersionBefore(), 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<&_cargopacket_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<&_roadstop_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_town_pool >::IsValidID(), SpecializedStation< Station, false >::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<&_order_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_orderlist_pool >::IsValidID(), REF_CARGO_PACKET, REF_ENGINE_RENEWS, REF_ORDER, REF_ORDERLIST, REF_ROADSTOPS, REF_STATION, REF_STORAGE, REF_TOWN, REF_VEHICLE, REF_VEHICLE_OLD, SLA_PTRS, and SlErrorCorrupt().
Referenced by SlList().
SaveOrLoadResult LoadWithFilter | ( | LoadFilter * | reader | ) |
Load the game using a (reader) filter.
reader | The filter to read the savegame from. |
Definition at line 2669 of file saveload.cpp.
References SaveLoadParams::action, ClearSaveLoadState(), and DoLoad().
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 907 of file saveload.cpp.
References GetVarMemType(), and SLE_VAR_NULL.
Referenced by CmdChangeCompanySetting(), CmdChangeSetting(), SettingEntry::DrawSetting(), GameSettingsWindow::DrawWidget(), CheatWindow::DrawWidget(), NewsTypeData::GetDisplay(), IConsoleGetSetting(), IConsoleListSettings(), IniSaveSettings(), SettingEntry::IsVisibleByRestrictionMode(), LoadSettings(), GameSettingsWindow::OnClick(), CheatWindow::OnClick(), CheatWindow::OnQueryTextFinished(), SetCompanySetting(), SetSettingValue(), SlSaveLoadConv(), and SyncCompanySettings().
static size_t ReferenceToInt | ( | const void * | obj, | |
SLRefType | rt | |||
) | [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 1202 of file saveload.cpp.
References SaveLoadParams::action, REF_CARGO_PACKET, REF_ENGINE_RENEWS, REF_ORDER, REF_ORDERLIST, REF_ROADSTOPS, REF_STATION, REF_STORAGE, REF_TOWN, REF_VEHICLE, REF_VEHICLE_OLD, and SLA_SAVE.
Referenced by SlList().
static void SaveFileDone | ( | ) | [static] |
Update the gui accordingly when saving is done and release locks on saveload.
Definition at line 2379 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 void SaveFileStart | ( | ) | [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 2368 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 void SaveFileToDiskThread | ( | void * | arg | ) | [static] |
Thread run function for saving the file to disk.
Definition at line 2458 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 2689 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_LOAD, SL_LOAD_CHECK, SL_OLD_LOAD, SL_REINIT, SL_SAVE, SlError(), GUISettings::threaded_saves, and WL_ERROR.
Referenced by _GenerateWorld(), DEF_CONSOLE_CMD(), DoAutosave(), DoExitSave(), LoadIntroGame(), SaveLoadWindow::OnClick(), 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 asynchroniously. |
Definition at line 2514 of file saveload.cpp.
References SaveLoadParams::action, ClearSaveLoadState(), and DoSave().
Referenced by ServerNetworkGameSocketHandler::SendMap().
static void SetAsyncSaveFinish | ( | AsyncSaveFinishProc | proc | ) | [static] |
Called by save thread to tell we finished saving.
proc | The callback to call when saving is done. |
Definition at line 550 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 1147 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 1544 of file saveload.cpp.
References SaveLoadParams::action, SaveLoadParams::dumper, MemoryDumper::GetSize(), SaveLoadParams::need_length, SaveLoadParams::obj_len, SLA_SAVE, SlErrorCorrupt(), and SlSetLength().
Referenced by SlStubSaveProc().
static size_t SlCalcArrayLen | ( | size_t | length, | |
VarType | conv | |||
) | [inline, static] |
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 1136 of file saveload.cpp.
References SlCalcConvFileLen().
Referenced by SlArray().
static byte SlCalcConvFileLen | ( | VarType | conv | ) | [inline, static] |
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 763 of file saveload.cpp.
References GB(), and lengthof.
Referenced by SlArray(), and SlCalcArrayLen().
static uint SlCalcConvMemLen | ( | VarType | conv | ) | [inline, static] |
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 739 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().
static size_t SlCalcListLen | ( | const void * | list | ) | [inline, static] |
Return the size in bytes of a list.
list | The std::list to find the size of |
Definition at line 1300 of file saveload.cpp.
References IsSavegameVersionBefore().
Referenced by SlList().
static size_t SlCalcNetStringLen | ( | const char * | ptr, | |
size_t | length | |||
) | [inline, static] |
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 1014 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 1399 of file saveload.cpp.
References SaveLoad::cmd.
Referenced by SlObject().
static size_t SlCalcStringLen | ( | const void * | ptr, | |
size_t | length, | |||
VarType | conv | |||
) | [inline, static] |
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 1029 of file saveload.cpp.
References GetVarMemType(), SlCalcNetStringLen(), SLE_VAR_STR, SLE_VAR_STRB, SLE_VAR_STRBQ, and SLE_VAR_STRQ.
static void SlCopyBytes | ( | void * | ptr, | |
size_t | length | |||
) | [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 878 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 508 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, and SlNullPointers().
Referenced by AfterLoadGame(), DoLoad(), PacketWriter::Finish(), LZMALoadFilter::LZMALoadFilter(), LZMASaveFilter::LZMASaveFilter(), LZOLoadFilter::LZOLoadFilter(), LZOSaveFilter::LZOSaveFilter(), MoveWaypointsToBaseStations(), LZMALoadFilter::Read(), ZlibLoadFilter::Read(), LZOLoadFilter::Read(), SaveOrLoad(), SlErrorCorrupt(), FileWriter::Write(), PacketWriter::Write(), LZMASaveFilter::WriteLoop(), ZlibSaveFilter::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 536 of file saveload.cpp.
References SlError().
Referenced by AfterLoadGame(), AfterLoadVehicles(), ConvertOldMultiheadToNew(), IntToReference(), Load_CHTS(), Load_NAME(), Load_VEHS(), LoadOldVehicle(), LZOLoadFilter::Read(), SetWaterClassDependingOnSurroundings(), SlAutolength(), SlIterateArray(), SlLoadCheckChunk(), SlLoadCheckChunks(), SlLoadChunk(), SlLoadChunks(), and SlReadSimpleGamma().
static const ChunkHandler* SlFindChunkHandler | ( | uint32 | id | ) | [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 1739 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 1534 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 789 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_NAME(), Load_NewGRFMapping(), Load_PSAC(), Load_SIGN(), Load_VEHS(), LoadDelivery(), LoadPickup(), and SlSkipArray().
static void SlList | ( | void * | list, | |
SLRefType | conv | |||
) | [static] |
Save/Load a list.
list | The list being manipulated | |
conv | SLRefType type of the list (Vehicle *, Station *, etc) |
Definition at line 1316 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 void SlLoadCheckChunk | ( | const ChunkHandler * | ch | ) | [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 1609 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 void SlLoadChunk | ( | const ChunkHandler * | ch | ) | [static] |
Load a chunk of data (eg vehicles, stations, etc.
)
ch | The chunkhandler that will be used for the operation |
Definition at line 1571 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 1516 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_LGRP(), ScriptInstance::Load(), Load_CAPA(), Load_ECMY(), Load_ITBL(), Load_LGRP(), Load_NewGRFMapping(), Load_PSAC(), Load_SIGN(), Load_VEHS(), LoadDelivery(), ScriptInstance::LoadEmpty(), ScriptInstance::LoadObjects(), LoadPickup(), Ptrs_TOWN(), ScriptInstance::Save(), Save_CAPA(), Save_ECMY(), Save_ITBL(), Save_NewGRFMapping(), Save_PSAC(), Save_SIGN(), Save_VEHS(), SaveDelivery(), ScriptInstance::SaveEmpty(), SaveLoad_LinkGraphComponent(), ScriptInstance::SaveObject(), SavePickup(), and SlGlobList().
byte SlReadByte | ( | ) |
Wrapper for reading a byte from the buffer.
Definition at line 580 of file saveload.cpp.
References SaveLoadParams::reader.
Referenced by Load_CHTS(), Load_VEHS(), SlCopyBytes(), SlLoadCheckChunk(), SlLoadChunk(), SlReadSimpleGamma(), SlSaveLoadConv(), and SlSkipBytes().
static uint SlReadSimpleGamma | ( | ) | [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 650 of file saveload.cpp.
References HasBit(), SlErrorCorrupt(), and SlReadByte().
static void SlSaveChunk | ( | const ChunkHandler * | ch | ) | [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 1685 of file saveload.cpp.
References SaveLoadParams::block_mode, DEBUG, ChunkHandler::flags, ChunkHandler::id, SaveLoadParams::last_array_index, SaveLoadParams::need_length, ChunkHandler::save_proc, and SlWriteByte().
Referenced by SlSaveChunks().
static void SlSaveLoadConv | ( | void * | ptr, | |
VarType | conv | |||
) | [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 957 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 834 of file saveload.cpp.
References SaveLoadParams::action, SaveLoadParams::block_mode, SaveLoadParams::last_array_index, SaveLoadParams::need_length, NL_CALCLENGTH, NL_WANTLENGTH, SaveLoadParams::obj_len, and SLA_SAVE.
Referenced by Save_ANIT(), Save_CHTS(), SaveSettings(), SlArray(), SlAutolength(), SlList(), and SlObject().
static void SlSkipBytes | ( | size_t | length | ) | [inline, static] |
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 636 of file saveload.cpp.
References SlReadByte().
Referenced by SlLoadCheckChunk(), SlSkipArray(), SlSkipVariableOnLoad(), and SlString().
static bool SlSkipVariableOnLoad | ( | const SaveLoad * | sld | ) | [inline, static] |
Are we going to load this variable when loading a savegame or not?
Definition at line 1383 of file saveload.cpp.
References _network_server, _networking, SaveLoadParams::action, SaveLoad::conv, SaveLoad::length, SLA_SAVE, SlCalcConvMemLen(), SLF_NO_NETWORK_SYNC, and SlSkipBytes().
static void SlString | ( | void * | ptr, | |
size_t | length, | |||
VarType | conv | |||
) | [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 1058 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(), and str_validate().
static void SlStubSaveProc | ( | ) | [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 1675 of file saveload.cpp.
References SlAutolength(), and SlStubSaveProc2().
static void SlStubSaveProc2 | ( | void * | arg | ) | [inline, static] |
Stub Chunk handlers to only calculate length and do nothing else.
Actually call the intended chunk handler.
arg | ignored parameter. |
Definition at line 1665 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 589 of file saveload.cpp.
References SaveLoadParams::dumper, and MemoryDumper::WriteByte().
Referenced by Save_CHTS(), SlCopyBytes(), SlSaveChunk(), SlSaveLoadConv(), and SlWriteSimpleGamma().
static void SlWriteSimpleGamma | ( | size_t | i | ) | [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
i | Index being written |
Definition at line 683 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 931 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().
const ChunkHandler* const _chunk_handlers[] [static] |
Array of all chunks in a savegame, NULL
terminated.
Definition at line 432 of file saveload.cpp.
const lzma_stream _lzma_init = LZMA_STREAM_INIT [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 2133 of file saveload.cpp.
const SaveLoadFormat _saveload_formats[] [static] |
{ {"lzo", TO_BE32X('OTTD'), CreateLoadFilter<LZOLoadFilter>, CreateSaveFilter<LZOSaveFilter>, 0, 0, 0}, {"none", TO_BE32X('OTTN'), CreateLoadFilter<NoCompLoadFilter>, CreateSaveFilter<NoCompSaveFilter>, 0, 0, 0}, {"zlib", TO_BE32X('OTTZ'), CreateLoadFilter<ZlibLoadFilter>, CreateSaveFilter<ZlibSaveFilter>, 0, 6, 9}, {"lzma", TO_BE32X('OTTX'), CreateLoadFilter<LZMALoadFilter>, CreateSaveFilter<LZMASaveFilter>, 0, 2, 9}, }
The different saveload formats known/understood by OpenTTD.
Definition at line 2257 of file saveload.cpp.
ChunkSaveLoadProc* _stub_save_proc [static] |
Stub Chunk handlers to only calculate length and do nothing else.
The intended chunk handler that should be called.
Definition at line 1658 of file saveload.cpp.
Referenced by SlStubSaveProc2().
const size_t MEMORY_CHUNK_SIZE = 128 * 1024 [static] |
Save in chunks of 128 KiB.
Definition at line 273 of file saveload.cpp.
Referenced by MemoryDumper::Flush(), MemoryDumper::GetSize(), MemoryDumper::WriteByte(), LZMASaveFilter::WriteLoop(), and ZlibSaveFilter::WriteLoop().