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

@@ -2045,7 +2045,9 @@ static void LoadSettings(const SettingTable &settings, void *object)
{
const std::vector<SaveLoad> slt = GetSettingsDesc(settings, true);
if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() == -1) return;
SlObject(object, slt);
if (!IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY) && SlIterateArray() != -1) SlErrorCorrupt("Too many settings entries");
/* Ensure all IntSettings are valid (min/max could have changed between versions etc). */
for (auto &sd : settings) {
@@ -2070,6 +2072,7 @@ static void SaveSettings(const SettingTable &settings, void *object)
{
const std::vector<SaveLoad> slt = GetSettingsDesc(settings, false);
SlSetArrayIndex(0);
SlObject(object, slt);
}
@@ -2102,8 +2105,8 @@ static void Save_PATS()
}
static const ChunkHandler setting_chunk_handlers[] = {
{ 'OPTS', nullptr, Load_OPTS, nullptr, nullptr, CH_RIFF },
{ 'PATS', Save_PATS, Load_PATS, nullptr, Check_PATS, CH_RIFF },
{ 'OPTS', nullptr, Load_OPTS, nullptr, nullptr, CH_RIFF },
{ 'PATS', Save_PATS, Load_PATS, nullptr, Check_PATS, CH_ARRAY },
};
extern const ChunkHandlerTable _setting_chunk_handlers(setting_chunk_handlers);