OpenTTD Source: src/saveload/animated_tile_sl.cpp Source File

OpenTTD Source 1.11.0-RC1

animated_tile_sl.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
10 #include "../stdafx.h"
11 #include "../tile_type.h"
12 #include "../core/alloc_func.hpp"
13 #include "../core/smallvec_type.hpp"
14
15 #include "saveload.h"
16
17 #include "../safeguards.h"
18
19 extern std::vector<TileIndex> _animated_tiles;
20
24 static void Save_ANIT()
25 {
26 SlSetLength(_animated_tiles.size() * sizeof(_animated_tiles.front()));
27 SlArray(_animated_tiles.data(), _animated_tiles.size(), SLE_UINT32);
28 }
29
33 static void Load_ANIT()
34 {
35 /* Before version 80 we did NOT have a variable length animated tile table */
36 if (IsSavegameVersionBefore(SLV_80)) {
37 /* In pre version 6, we has 16bit per tile, now we have 32bit per tile, convert it ;) */
38 TileIndex anim_list[256];
39 SlArray(anim_list, 256, IsSavegameVersionBefore(SLV_6) ? (SLE_FILE_U16 | SLE_VAR_U32) : SLE_UINT32);
40
41 for (int i = 0; i < 256; i++) {
42 if (anim_list[i] == 0) break;
43 _animated_tiles.push_back(anim_list[i]);
44 }
45 return;
46 }
47
48 uint count = (uint)SlGetFieldLength() / sizeof(_animated_tiles.front());
49 _animated_tiles.clear();
50 _animated_tiles.resize(_animated_tiles.size() + count);
51 SlArray(_animated_tiles.data(), count, SLE_UINT32);
52 }
53
58 extern const ChunkHandler _animated_tile_chunk_handlers[] = {
59 { 'ANIT', Save_ANIT, Load_ANIT, nullptr, nullptr, CH_RIFF | CH_LAST},
60 };
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
CH_LAST
@ CH_LAST
Last chunk in this array.
Definition: saveload.h:410
saveload.h
_animated_tiles
std::vector< TileIndex > _animated_tiles
The table/list with animated tiles.
Definition: animated_tile.cpp:20
ChunkHandler
Handlers and description of chunk.
Definition: saveload.h:379
SlSetLength
void SlSetLength(size_t length)
Sets the length of either a RIFF object or the number of items in an array.
Definition: saveload.cpp:676
IsSavegameVersionBefore
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:815
_animated_tile_chunk_handlers
const ChunkHandler _animated_tile_chunk_handlers[]
"Definition" imported by the saveload code to be able to load and save the animated tile table.
SlGetFieldLength
size_t SlGetFieldLength()
Get the length of the current object.
Definition: saveload.cpp:737
SLV_6
@ SLV_6
6.0 1721 6.1 1768
Definition: saveload.h:46
SLV_80
@ SLV_80
80 11228
Definition: saveload.h:139
Load_ANIT
static void Load_ANIT()
Load the ANIT chunk; the chunk containing the animated tiles.
Definition: animated_tile_sl.cpp:33
Save_ANIT
static void Save_ANIT()
Save the ANIT chunk.
Definition: animated_tile_sl.cpp:24
SlArray
void SlArray(void *array, size_t length, VarType conv)
Save/Load an array.
Definition: saveload.cpp:1051