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.
This commit is contained in:
Patric Stout
2021-06-06 09:59:33 +02:00
committed by Patric Stout
parent b9ab9e4d05
commit 88edfd4ef1
10 changed files with 97 additions and 32 deletions

View File

@@ -20,7 +20,7 @@
static uint32 _map_dim_x;
static uint32 _map_dim_y;
static const SaveLoad _map_dimensions[] = {
static const SaveLoad _map_desc[] = {
SLEG_CONDVAR(_map_dim_x, SLE_UINT32, SLV_6, SL_MAX_VERSION),
SLEG_CONDVAR(_map_dim_y, SLE_UINT32, SLV_6, SL_MAX_VERSION),
};
@@ -29,18 +29,26 @@ static void Save_MAPS()
{
_map_dim_x = MapSizeX();
_map_dim_y = MapSizeY();
SlGlobList(_map_dimensions);
SlSetArrayIndex(0);
SlGlobList(_map_desc);
}
static void Load_MAPS()
{
SlGlobList(_map_dimensions);
if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() == -1) return;
SlGlobList(_map_desc);
if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() != -1) SlErrorCorrupt("Too many MAPS entries");
AllocateMap(_map_dim_x, _map_dim_y);
}
static void Check_MAPS()
{
SlGlobList(_map_dimensions);
if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() == -1) return;
SlGlobList(_map_desc);
if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() != -1) SlErrorCorrupt("Too many MAPS entries");
_load_check_data.map_size_x = _map_dim_x;
_load_check_data.map_size_y = _map_dim_y;
}
@@ -295,7 +303,7 @@ static void Save_MAP8()
static const ChunkHandler map_chunk_handlers[] = {
{ 'MAPS', Save_MAPS, Load_MAPS, nullptr, Check_MAPS, CH_RIFF },
{ 'MAPS', Save_MAPS, Load_MAPS, nullptr, Check_MAPS, CH_ARRAY },
{ 'MAPT', Save_MAPT, Load_MAPT, nullptr, nullptr, CH_RIFF },
{ 'MAPH', Save_MAPH, Load_MAPH, nullptr, nullptr, CH_RIFF },
{ 'MAPO', Save_MAP1, Load_MAP1, nullptr, nullptr, CH_RIFF },