OpenTTD Source 20261112-master-gbcbec5e63f
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "../stdafx.h"
11
12#include "saveload.h"
13#include "saveload_error.hpp"
15
16#include "../tile_type.h"
17
18#include "../safeguards.h"
19
20extern std::vector<TileIndex> _animated_tiles;
21
22static const SaveLoad _animated_tile_desc[] = {
24};
25
26struct ANITChunkHandler : ChunkHandler {
27 ANITChunkHandler() : ChunkHandler("ANIT", ChunkType::Table) {}
28
29 void Save() const override
30 {
31 SlTableHeader(_animated_tile_desc);
32
33 SlSetArrayIndex(0);
34 SlGlobList(_animated_tile_desc);
35 }
36
37 void Load() const override
38 {
39 /* Before version 80 we did NOT have a variable length animated tile table */
41 /* In pre version 6, we has 16bit per tile, now we have 32bit per tile, convert it ;) */
42 TileIndex anim_list[256];
44
45 for (int i = 0; i < 256; i++) {
46 if (anim_list[i] == 0) break;
47 _animated_tiles.push_back(anim_list[i]);
48 }
49 return;
50 }
51
53 size_t count = SlGetFieldLength() / sizeof(_animated_tiles.front());
54 _animated_tiles.clear();
55 _animated_tiles.resize(count);
57 return;
58 }
59
60 const std::vector<SaveLoad> slt = SlCompatTableHeader(_animated_tile_desc, _animated_tile_sl_compat);
61
62 if (SlIterateArray() == -1) return;
63 SlGlobList(slt);
64 if (SlIterateArray() != -1) SlErrorCorrupt("Too many ANIT entries");
65 }
66};
67
68
69static const ANITChunkHandler ANIT;
70static const ChunkHandlerRef animated_tile_chunk_handlers[] = {
71 ANIT,
72};
73
74extern const ChunkHandlerTable _animated_tile_chunk_handlers(animated_tile_chunk_handlers);
std::vector< TileIndex > _animated_tiles
The table/list with animated tiles.
std::vector< TileIndex > _animated_tiles
The table/list with animated tiles.
Loading for animated_tile chunks before table headers were added.
const SaveLoadCompat _animated_tile_sl_compat[]
Original field order for _animated_tile_desc.
A number of safeguards to prevent using unsafe methods.
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition saveload.cpp:748
void SlCopy(void *object, size_t length, VarType conv)
Copy a list of SaveLoadType::Variables to/from a savegame.
size_t SlGetFieldLength()
Get the length of the current object.
Definition saveload.cpp:874
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
Definition saveload.cpp:372
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
void SlGlobList(const SaveLoadTable &slt)
Save or Load (a list of) global variables.
Functions/types related to saving and loading games.
@ U32
A 32 bit unsigned int.
Definition saveload.h:664
@ U16
A 16 bit unsigned int.
Definition saveload.h:644
#define SLE_GLOBAL_ADDRESS(variable)
Macro to be able to pass the variable type and construct the SaveLoad::AddressFunction given a global...
Definition saveload.h:760
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
Definition saveload.h:512
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
Definition saveload.h:515
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
Definition saveload.h:1225
@ MultipleRoadStops
Saveload version: 6.0, SVN revision: 1721 Multi tile road stops, and some map size related fixes.
Definition saveload.h:52
@ NewGRFMoreAnimation
Saveload version: 80, SVN revision: 11228 Support more types of animation for NewGRF industries.
Definition saveload.h:145
@ RiffToArray
Saveload version: 294, GitHub pull request: 9375 Changed many ChunkType::Riff chunks to ChunkType::A...
Definition saveload.h:337
@ Table
An Array with a header describing the elements.
Definition saveload.h:449
Functions/types related to errors from savegames.
Definition of base types and functions in a cross-platform compatible way.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
ChunkHandler(ChunkId id, ChunkType type)
Create this ChunkHandler.
Definition saveload.h:469
SaveLoad type struct.
Definition saveload.h:763
static SaveLoad Vector(std::string name, AddressFunction< T > address_func, SaveLoadVersion from=SaveLoadVersion::MinVersion, SaveLoadVersion to=SaveLoadVersion::MaxVersion)
Storage of a vector in some savegame versions.
Definition saveload.h:1052
Container of a variable's characteristics about a variable's storage.
Definition saveload.h:674
static constexpr VarType U32
Store a 32 bits unsigned int.
Definition saveload.h:719
Types related to tiles.
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92