diff options
author | Patric Stout <truebrain@openttd.org> | 2021-06-06 09:59:33 +0200 |
---|---|---|
committer | Patric Stout <github@truebrain.nl> | 2021-06-15 19:36:15 +0200 |
commit | 88edfd4ef16bedd98a07a2142e693ab50fbdcef2 (patch) | |
tree | f39b00764786763b3350dd06c2c4014605678ca1 /src/saveload/animated_tile_sl.cpp | |
parent | b9ab9e4d051eea7d6aedfb60930b039b778568af (diff) | |
download | openttd-88edfd4ef16bedd98a07a2142e693ab50fbdcef2.tar.xz |
Change: rework several CH_RIFF chunks to use CH_ARRAY instead
This adds two byte extra to those chunks, and might feel a bit
silly at first. But in later changes we will prefix CH_ARRAY with
a table header, and then this change shines.
Without this, we could still add headers to these chunks, but any
external reader wouldn't know if the CH_RIFF has them or not. This
way is much more practical, as they are now more like any other
chunk.
Diffstat (limited to 'src/saveload/animated_tile_sl.cpp')
-rw-r--r-- | src/saveload/animated_tile_sl.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/saveload/animated_tile_sl.cpp b/src/saveload/animated_tile_sl.cpp index 89eb881b1..7f05eaeeb 100644 --- a/src/saveload/animated_tile_sl.cpp +++ b/src/saveload/animated_tile_sl.cpp @@ -18,13 +18,17 @@ extern std::vector<TileIndex> _animated_tiles; +static const SaveLoad _animated_tile_desc[] = { + SLEG_VECTOR(_animated_tiles, SLE_UINT32), +}; + /** * Save the ANIT chunk. */ static void Save_ANIT() { - SlSetLength(_animated_tiles.size() * sizeof(_animated_tiles.front())); - SlCopy(_animated_tiles.data(), _animated_tiles.size(), SLE_UINT32); + SlSetArrayIndex(0); + SlGlobList(_animated_tile_desc); } /** @@ -45,10 +49,17 @@ static void Load_ANIT() return; } - uint count = (uint)SlGetFieldLength() / sizeof(_animated_tiles.front()); - _animated_tiles.clear(); - _animated_tiles.resize(_animated_tiles.size() + count); - SlCopy(_animated_tiles.data(), count, SLE_UINT32); + if (IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY)) { + size_t count = SlGetFieldLength() / sizeof(_animated_tiles.front()); + _animated_tiles.clear(); + _animated_tiles.resize(_animated_tiles.size() + count); + SlCopy(_animated_tiles.data(), count, SLE_UINT32); + return; + } + + if (SlIterateArray() == -1) return; + SlGlobList(_animated_tile_desc); + if (SlIterateArray() != -1) SlErrorCorrupt("Too many ANIT entries"); } /** @@ -56,7 +67,7 @@ static void Load_ANIT() * the animated tile table. */ static const ChunkHandler animated_tile_chunk_handlers[] = { - { 'ANIT', Save_ANIT, Load_ANIT, nullptr, nullptr, CH_RIFF }, + { 'ANIT', Save_ANIT, Load_ANIT, nullptr, nullptr, CH_ARRAY }, }; extern const ChunkHandlerTable _animated_tile_chunk_handlers(animated_tile_chunk_handlers); |