1 /* $Id: oldloader.h 23595 2011-12-19 17:48:04Z rubidium $ */
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 /** @file oldloader.h Declarations of strctures and function used in loader of old savegames */
16 #include "../tile_type.h"
18 static const uint BUFFER_SIZE
= 4096;
19 static const uint OLD_MAP_SIZE
= 256 * 256;
21 struct LoadgameState
{
31 byte buffer
[BUFFER_SIZE
];
42 /* 4 bits allocated (16 max) */
44 OC_TTD
= 1 << 4, ///< chunk is valid ONLY for TTD savegames
45 OC_TTO
= 1 << 5, ///< -//- TTO (default is neither of these)
46 /* 4 bits allocated */
56 /* 8 bits allocated (256 max) */
60 OC_FILE_I16
= 3 << 16,
61 OC_FILE_U16
= 4 << 16,
62 OC_FILE_I32
= 5 << 16,
63 OC_FILE_U32
= 6 << 16,
64 /* 8 bits allocated (256 max) */
66 OC_INT8
= OC_VAR_I8
| OC_FILE_I8
,
67 OC_UINT8
= OC_VAR_U8
| OC_FILE_U8
,
68 OC_INT16
= OC_VAR_I16
| OC_FILE_I16
,
69 OC_UINT16
= OC_VAR_U16
| OC_FILE_U16
,
70 OC_INT32
= OC_VAR_I32
| OC_FILE_I32
,
71 OC_UINT32
= OC_VAR_U32
| OC_FILE_U32
,
73 OC_TILE
= OC_VAR_U32
| OC_FILE_U16
,
76 * Dereference the pointer once before writing to it,
77 * so we do not have to use big static arrays.
79 OC_DEREFERENCE_POINTER
= 1 << 31,
81 OC_END
= 0, ///< End of the whole chunk, all 32 bits set to zero
84 DECLARE_ENUM_AS_BIT_SET(OldChunkType
)
86 typedef bool OldChunkProc(LoadgameState
*ls
, int num
);
89 OldChunkType type
; ///< Type of field
90 uint32 amount
; ///< Amount of fields
92 void *ptr
; ///< Pointer where to save the data (may only be set if offset is 0)
93 uint offset
; ///< Offset from basepointer (may only be set if ptr is NULL)
94 OldChunkProc
*proc
; ///< Pointer to function that is called with OC_CHUNK
97 /* If it fails, check lines above.. */
98 assert_compile(sizeof(TileIndex
) == 4);
100 extern uint _bump_assert_value
;
101 byte
ReadByte(LoadgameState
*ls
);
102 bool LoadChunk(LoadgameState
*ls
, void *base
, const OldChunks
*chunks
);
104 bool LoadTTDMain(LoadgameState
*ls
);
105 bool LoadTTOMain(LoadgameState
*ls
);
107 static inline uint16
ReadUint16(LoadgameState
*ls
)
109 byte x
= ReadByte(ls
);
110 return x
| ReadByte(ls
) << 8;
113 static inline uint32
ReadUint32(LoadgameState
*ls
)
115 uint16 x
= ReadUint16(ls
);
116 return x
| ReadUint16(ls
) << 16;
120 * - OCL_SVAR: load 'type' to offset 'offset' in a struct of type 'base', which must also
121 * be given via base in LoadChunk() as real pointer
122 * - OCL_VAR: load 'type' to a global var
123 * - OCL_END: every struct must end with this
124 * - OCL_NULL: read 'amount' of bytes and send them to /dev/null or something
125 * - OCL_CHUNK: load another proc to load a part of the savegame, 'amount' times
126 * - OCL_ASSERT: to check if we are really at the place we expect to be.. because old savegames are too binary to be sure ;)
128 #define OCL_SVAR(type, base, offset) { type, 1, NULL, (uint)cpp_offsetof(base, offset), NULL }
129 #define OCL_VAR(type, amount, pointer) { type, amount, pointer, 0, NULL }
130 #define OCL_END() { OC_END, 0, NULL, 0, NULL }
131 #define OCL_CNULL(type, amount) { OC_NULL | type, amount, NULL, 0, NULL }
132 #define OCL_CCHUNK(type, amount, proc) { OC_CHUNK | type, amount, NULL, 0, proc }
133 #define OCL_ASSERT(type, size) { OC_ASSERT | type, 1, NULL, size, NULL }
134 #define OCL_NULL(amount) OCL_CNULL((OldChunkType)0, amount)
135 #define OCL_CHUNK(amount, proc) OCL_CCHUNK((OldChunkType)0, amount, proc)
137 #endif /* OLDLOADER_H */