OpenTTD Source 20260311-master-g511d3794ce
oldloader.h File Reference

Declarations of structures and functions used in loader of old savegames. More...

#include "saveload.h"
#include "../tile_type.h"

Go to the source code of this file.

Data Structures

struct  LoadgameState
struct  OldChunks

Macros

#define OCL_SVAR(type, base, offset)
 Load 'type' to offset 'offset' in a struct of type 'base', which must also be given via base in LoadChunk() as real pointer.
#define OCL_VAR(type, amount, pointer)
 Load 'type' to a global var.
#define OCL_END()
 Every struct must end with this.
#define OCL_CNULL(type, amount)
#define OCL_CCHUNK(type, amount, proc)
#define OCL_ASSERT(type, size)
 To check if we are really at the place we expect to be.
#define OCL_NULL(amount)
 Read 'amount' of bytes and send them to /dev/null or something.
#define OCL_CHUNK(amount, proc)
 Load another proc to load a part of the savegame, 'amount' times.

Typedefs

typedef bool OldChunkProc(LoadgameState &ls, int num)
typedef void * OffsetProc(void *base)

Enumerations

enum  OldChunkType : uint32_t {
  OC_SIMPLE = 0 , OC_NULL = 1 , OC_CHUNK = 2 , OC_ASSERT = 3 ,
  OC_TTD = 1 << 4 , OC_TTO = 1 << 5 , OC_VAR_I8 = 1 << 8 , OC_VAR_U8 = 2 << 8 ,
  OC_VAR_I16 = 3 << 8 , OC_VAR_U16 = 4 << 8 , OC_VAR_I32 = 5 << 8 , OC_VAR_U32 = 6 << 8 ,
  OC_VAR_I64 = 7 << 8 , OC_VAR_U64 = 8 << 8 , OC_FILE_I8 = 1 << 16 , OC_FILE_U8 = 2 << 16 ,
  OC_FILE_I16 = 3 << 16 , OC_FILE_U16 = 4 << 16 , OC_FILE_I32 = 5 << 16 , OC_FILE_U32 = 6 << 16 ,
  OC_INT8 = OC_VAR_I8 | OC_FILE_I8 , OC_UINT8 = OC_VAR_U8 | OC_FILE_U8 , OC_INT16 = OC_VAR_I16 | OC_FILE_I16 , OC_UINT16 = OC_VAR_U16 | OC_FILE_U16 ,
  OC_INT32 = OC_VAR_I32 | OC_FILE_I32 , OC_UINT32 = OC_VAR_U32 | OC_FILE_U32 , OC_TILE = OC_VAR_U32 | OC_FILE_U16 , OC_END = 0
}
 OldChunk-Type. More...

Functions

uint8_t ReadByte (LoadgameState &ls)
 Reads a byte from the buffer and decompress if needed.
bool LoadChunk (LoadgameState &ls, void *base, const OldChunks *chunks)
 Loads a chunk from the old savegame.
bool LoadTTDMain (LoadgameState &ls)
bool LoadTTOMain (LoadgameState &ls)
uint16_t ReadUint16 (LoadgameState &ls)
uint32_t ReadUint32 (LoadgameState &ls)

Variables

static const uint BUFFER_SIZE = 4096
static const uint OLD_MAP_SIZE = 256
uint _bump_assert_value

Detailed Description

Declarations of structures and functions used in loader of old savegames.

Definition in file oldloader.h.

Macro Definition Documentation

◆ OCL_ASSERT

#define OCL_ASSERT ( type,
size )
Value:
{ OC_ASSERT | type, 1, (void *)(size_t)size, nullptr, nullptr }

To check if we are really at the place we expect to be.

. because old savegames are too binary to be sure ;)

Definition at line 121 of file oldloader.h.

◆ OCL_CCHUNK

#define OCL_CCHUNK ( type,
amount,
proc )
Value:
{ OC_CHUNK | type, amount, nullptr, nullptr, proc }

Definition at line 119 of file oldloader.h.

◆ OCL_CHUNK

#define OCL_CHUNK ( amount,
proc )
Value:
OCL_CCHUNK((OldChunkType)0, amount, proc)
OldChunkType
OldChunk-Type.
Definition oldloader.h:38

Load another proc to load a part of the savegame, 'amount' times.

Definition at line 125 of file oldloader.h.

◆ OCL_CNULL

#define OCL_CNULL ( type,
amount )
Value:
{ OC_NULL | type, amount, nullptr, nullptr, nullptr }

Definition at line 118 of file oldloader.h.

◆ OCL_END

#define OCL_END ( )
Value:
{ OC_END, 0, nullptr, nullptr, nullptr }
@ OC_END
End of the whole chunk, all 32 bits set to zero.
Definition oldloader.h:76

Every struct must end with this.

Definition at line 117 of file oldloader.h.

◆ OCL_NULL

#define OCL_NULL ( amount)
Value:
OCL_CNULL((OldChunkType)0, amount)

Read 'amount' of bytes and send them to /dev/null or something.

Definition at line 123 of file oldloader.h.

◆ OCL_SVAR

#define OCL_SVAR ( type,
base,
offset )
Value:
{ type, 1, nullptr, [] (void *b) -> void * { return std::addressof(static_cast<base *>(b)->offset); }, nullptr }

Load 'type' to offset 'offset' in a struct of type 'base', which must also be given via base in LoadChunk() as real pointer.

Definition at line 113 of file oldloader.h.

◆ OCL_VAR

#define OCL_VAR ( type,
amount,
pointer )
Value:
{ type, amount, pointer, nullptr, nullptr }

Load 'type' to a global var.

Definition at line 115 of file oldloader.h.

Typedef Documentation

◆ OffsetProc

typedef void * OffsetProc(void *base)

Definition at line 82 of file oldloader.h.

◆ OldChunkProc

typedef bool OldChunkProc(LoadgameState &ls, int num)

Definition at line 81 of file oldloader.h.

Enumeration Type Documentation

◆ OldChunkType

enum OldChunkType : uint32_t

OldChunk-Type.

Enumerator
OC_TTD 

chunk is valid ONLY for TTD savegames

OC_TTO 

-//- TTO (default is neither of these)

OC_END 

End of the whole chunk, all 32 bits set to zero.

Definition at line 38 of file oldloader.h.

Function Documentation

◆ LoadChunk()

bool LoadChunk ( LoadgameState & ls,
void * base,
const OldChunks * chunks )

Loads a chunk from the old savegame.

Parameters
lsThe state for loading the save game.
baseThe pointer to the object to load the data into, or nullptr for global objects.
chunksThe definition of the elements to load for this object.
Returns
true if the chunk was loaded without problems.

Definition at line 122 of file oldloader.cpp.

References _savegame_type, CalcOldVarLen(), Debug, GB(), OC_END, OC_TTD, OC_TTO, ReadByte(), SGT_TTO, and OldChunks::type.

Referenced by Vehicle::LoadOldVehicle.

◆ LoadTTDMain()

bool LoadTTDMain ( LoadgameState & ls)

Definition at line 1798 of file oldloader_sl.cpp.

◆ LoadTTOMain()

bool LoadTTOMain ( LoadgameState & ls)

Definition at line 1831 of file oldloader_sl.cpp.

◆ ReadByte()

uint8_t ReadByte ( LoadgameState & ls)

Reads a byte from the buffer and decompress if needed.

Parameters
lsThe state for loading the save game.
Returns
A single byte.

Definition at line 86 of file oldloader.cpp.

References ReadByteFromFile().

Referenced by LoadChunk(), LoadOldCustomString(), and Vehicle::LoadOldVehicle.

◆ ReadUint16()

uint16_t ReadUint16 ( LoadgameState & ls)
inline

Definition at line 100 of file oldloader.h.

◆ ReadUint32()

uint32_t ReadUint32 ( LoadgameState & ls)
inline

Definition at line 106 of file oldloader.h.

Variable Documentation

◆ _bump_assert_value

uint _bump_assert_value
extern

Definition at line 28 of file oldloader.cpp.

◆ BUFFER_SIZE

const uint BUFFER_SIZE = 4096
static

Definition at line 16 of file oldloader.h.

◆ OLD_MAP_SIZE

const uint OLD_MAP_SIZE = 256
static

Definition at line 17 of file oldloader.h.