Initial implementation of SLXI chunk save/load

pull/155/head
Jonathan G Rennison 9 years ago
parent a3980dc6ba
commit bde094fe01

@ -7,17 +7,47 @@
* 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/>.
*/
/** @file extended_ver_sl.cpp Functions related to handling save/load extended version info. */
/** @file extended_ver_sl.cpp Functions related to handling save/load extended version info.
*
* Known extended features are stored in _sl_xv_feature_versions, features which are currently enabled/in use and their versions are stored in the savegame.
* On load, the list of features and their versions are loaded from the savegame. If the savegame contains a feature which is either unknown, or has too high a version,
* loading can be either aborted, or the feature can be ignored if the the feature flags in the savegame indicate that it can be ignored. The savegame may also list any additional
* chunk IDs which are associated with an extended feature, these can be discarded if the feature is discarded.
* This information is stored in the SLXI chunk, the contents of which has the following format:
*
* uint32 chunk version
* uint32 chunk flags
* uint32 number of sub chunks/features
* For each of N sub chunk/feature:
* uint32 feature flags (SlxiSubChunkFlags)
* uint16 feature version
* SLE_STR feature name
* uint32* extra data length [only present iff feature flags & XSCF_EXTRA_DATA_PRESENT]
* N bytes extra data
* uint32* chunk ID list count [only present iff feature flags & XSCF_CHUNK_ID_LIST_PRESENT]
* N x uint32 chunk ID list
*/
#include "../stdafx.h"
#include "../debug.h"
#include "saveload.h"
#include "extended_ver_sl.h"
#include <vector>
#include "../safeguards.h"
uint16 _sl_xv_feature_versions[XSLFI_SIZE]; ///< array of all known feature types and their current versions
bool _sl_is_ext_version; ///< is this an extended savegame version, with more info in the SLXI chunk?
bool _sl_is_faked_ext; ///< is this a faked extended savegame version, with no SLXI chunk?
std::vector<uint32> _sl_xv_discardable_chunk_ids; ///< list of chunks IDs which we can discard if no chunk loader exists
static const uint32 _sl_xv_slxi_chunk_version = 0; ///< current version os SLXI chunk
const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_NULL, XSCF_NULL, 0, 0, NULL, NULL, NULL, NULL },// This is the end marker
};
/**
* Extended save/load feature test
*
@ -26,16 +56,16 @@ std::vector<uint32> _sl_xv_discardable_chunk_ids; ///< list of chunks
* and return the combination of the two tests using the operator defined in the constructor.
* Otherwise just returns the result of the savegame version test
*/
bool ExtendedSaveLoadFeatureTest::IsFeaturePresent(uint16 savegame_version, uint16 savegame_version_from, uint16 savegame_version_to) const
bool SlXvFeatureTest::IsFeaturePresent(uint16 savegame_version, uint16 savegame_version_from, uint16 savegame_version_to) const
{
bool savegame_version_ok = savegame_version >= savegame_version_from && savegame_version <= savegame_version_to;
ExtendedSaveLoadFeatureIndex feature = static_cast<ExtendedSaveLoadFeatureIndex>(GB(this->value, 0, 16));
SlXvFeatureIndex feature = static_cast<SlXvFeatureIndex>(GB(this->value, 0, 16));
if (feature == XSLFI_NULL) return savegame_version_ok;
uint16 min_version = GB(this->value, 16, 16);
uint16 max_version = GB(this->value, 32, 16);
ExtendedSaveLoadFeatureTestOperator op = static_cast<ExtendedSaveLoadFeatureTestOperator>(GB(this->value, 48, 16));
SlXvFeatureTestOperator op = static_cast<SlXvFeatureTestOperator>(GB(this->value, 48, 16));
bool feature_ok = SlXvIsFeaturePresent(feature, min_version, max_version);
switch (op) {
@ -54,7 +84,7 @@ bool ExtendedSaveLoadFeatureTest::IsFeaturePresent(uint16 savegame_version, uint
/**
* Returns true if @p feature is present and has a version inclusively bounded by @p min_version and @p max_version
*/
bool SlXvIsFeaturePresent(ExtendedSaveLoadFeatureIndex feature, uint16 min_version, uint16 max_version)
bool SlXvIsFeaturePresent(SlXvFeatureIndex feature, uint16 min_version, uint16 max_version)
{
assert(feature < XSLFI_SIZE);
return _sl_xv_feature_versions[feature] >= min_version && _sl_xv_feature_versions[feature] <= max_version;
@ -65,6 +95,8 @@ bool SlXvIsFeaturePresent(ExtendedSaveLoadFeatureIndex feature, uint16 min_versi
*/
void SlXvResetState()
{
_sl_is_ext_version = false;
_sl_is_faked_ext = false;
memset(_sl_xv_feature_versions, 0, sizeof(_sl_xv_feature_versions));
}
@ -73,8 +105,6 @@ void SlXvResetState()
*/
void SlXvSetCurrentState()
{
extern bool _sl_is_ext_version;
SlXvResetState();
_sl_is_ext_version = true;
@ -103,3 +133,208 @@ bool SlXvIsChunkDiscardable(uint32 id)
}
return false;
}
/**
* Writes a chunk ID list string to the savegame, returns the number of chunks written
* In dry run mode, only returns the number of chunk which would have been written
*/
static uint32 WriteChunkIdList(const char *chunk_list, bool dry_run)
{
unsigned int chunk_count = 0; // number of chunks output
unsigned int id_offset = 0; // how far are we into the ID
for (; *chunk_list != 0; chunk_list++) {
if (id_offset == 4) {
assert(*chunk_list == ',');
id_offset = 0;
} else {
if (!dry_run) {
SlWriteByte(*chunk_list);
}
if (id_offset == 3) {
chunk_count++;
}
id_offset++;
}
}
assert(id_offset == 4);
return chunk_count;
}
static void Save_SLXI()
{
SlXvSetCurrentState();
static const SaveLoad _xlsi_sub_chunk_desc[] = {
SLE_VAR(SlxiSubChunkInfo, save_version, SLE_UINT16),
SLE_STR(SlxiSubChunkInfo, name, SLE_STR, 0),
SLE_END()
};
// calculate lengths
uint32 item_count = 0;
uint32 length = 12;
std::vector<uint32> extra_data_lengths;
std::vector<uint32> chunk_counts;
extra_data_lengths.resize(XSLFI_SIZE);
chunk_counts.resize(XSLFI_SIZE);
const SlxiSubChunkInfo *info = _sl_xv_sub_chunk_infos;
for (; info->index != XSLFI_NULL; ++info) {
if (info->save_version > 0) {
item_count++;
length += 4;
length += SlCalcObjLength(info, _xlsi_sub_chunk_desc);
if (info->save_proc) {
uint32 extra_data_length = info->save_proc(info, true);
if (extra_data_length) {
extra_data_lengths[info->index] = extra_data_length;
length += 4 + extra_data_length;
}
}
if (info->chunk_list) {
uint32 chunk_count = WriteChunkIdList(info->chunk_list, true);
if (chunk_count) {
chunk_counts[info->index] = chunk_count;
length += 4 * (1 + chunk_count);
}
}
}
}
// write header
SlSetLength(length);
SlWriteUint32(_sl_xv_slxi_chunk_version); // chunk version
SlWriteUint32(0); // flags
SlWriteUint32(item_count); // item count
// write data
info = _sl_xv_sub_chunk_infos;
for (; info->index != XSLFI_NULL; ++info) {
if (info->save_version > 0) {
SlxiSubChunkFlags flags = info->flags;
assert(!(flags & (XSCF_EXTRA_DATA_PRESENT | XSCF_CHUNK_ID_LIST_PRESENT)));
uint32 extra_data_length = extra_data_lengths[info->index];
uint32 chunk_count = chunk_counts[info->index];
if (extra_data_length > 0) flags |= XSCF_EXTRA_DATA_PRESENT;
if (chunk_count > 0) flags |= XSCF_CHUNK_ID_LIST_PRESENT;
SlWriteUint32(flags);
SlObject(const_cast<SlxiSubChunkInfo *>(info), _xlsi_sub_chunk_desc);
if (extra_data_length > 0) {
SlWriteUint32(extra_data_length);
size_t written = SlGetBytesWritten();
info->save_proc(info, false);
assert(SlGetBytesWritten() == written + extra_data_length);
}
if (chunk_count > 0) {
SlWriteUint32(chunk_count);
size_t written = SlGetBytesWritten();
WriteChunkIdList(info->chunk_list, false);
assert(SlGetBytesWritten() == written + (chunk_count * 4));
}
}
}
}
static void Load_SLXI()
{
if (_sl_is_faked_ext || !_sl_is_ext_version) {
SlErrorCorrupt("SXLI chunk is unexpectedly present");
}
SlXvResetState();
_sl_is_ext_version = true;
uint32 version = SlReadUint32();
if (version > _sl_xv_slxi_chunk_version) SlErrorCorruptFmt("SLXI chunk: version: %u is too new (expected max: %u)", version, _sl_xv_slxi_chunk_version);
uint32 chunk_flags = SlReadUint32();
// flags are not in use yet, reserve for future expansion
if (chunk_flags != 0) SlErrorCorruptFmt("SLXI chunk: unknown chunk header flags: 0x%X", chunk_flags);
char name_buffer[256];
const SaveLoadGlobVarList xlsi_sub_chunk_name_desc[] = {
SLEG_STR(name_buffer, SLE_STRB),
SLEG_END()
};
uint32 item_count = SlReadUint32();
for (uint32 i = 0; i < item_count; i++) {
SlxiSubChunkFlags flags = static_cast<SlxiSubChunkFlags>(SlReadUint32());
uint16 version = SlReadUint16();
SlGlobList(xlsi_sub_chunk_name_desc);
// linearly scan through feature list until found name match
bool found = false;
const SlxiSubChunkInfo *info = _sl_xv_sub_chunk_infos;
for (; info->index != XSLFI_NULL; ++info) {
if (strcmp(name_buffer, info->name) == 0) {
found = true;
break;
}
}
bool discard_chunks = false;
if (found) {
if (version > info->max_version) {
if (flags & XSCF_IGNORABLE_VERSION) {
// version too large but carry on regardless
discard_chunks = true;
if (flags & XSCF_EXTRA_DATA_PRESENT) {
SlSkipBytes(SlReadUint32()); // skip extra data field
}
DEBUG(sl, 1, "SLXI chunk: too large version for feature: '%s', version: %d, max version: %d, ignoring", name_buffer, version, info->max_version);
} else {
SlErrorCorruptFmt("SLXI chunk: too large version for feature: '%s', version: %d, max version: %d", name_buffer, version, info->max_version);
}
} else {
// success path :)
_sl_xv_feature_versions[info->index] = version;
if (flags & XSCF_EXTRA_DATA_PRESENT) {
uint32 extra_data_size = SlReadUint32();
if (extra_data_size) {
if (info->load_proc) {
size_t read = SlGetBytesRead();
info->load_proc(info, extra_data_size);
if (SlGetBytesRead() != read + extra_data_size) {
SlErrorCorruptFmt("SLXI chunk: feature: %s, version: %d, extra data length mismatch", name_buffer, version);
}
} else {
SlErrorCorruptFmt("SLXI chunk: feature: %s, version: %d, unexpectedly includes extra data", name_buffer, version);
}
}
}
DEBUG(sl, 1, "SLXI chunk: found known feature: '%s', version: %d, max version: %d", name_buffer, version, info->max_version);
}
} else {
if (flags & XSCF_IGNORABLE_UNKNOWN) {
// not found but carry on regardless
discard_chunks = true;
if (flags & XSCF_EXTRA_DATA_PRESENT) {
SlSkipBytes(SlReadUint32()); // skip extra data field
}
DEBUG(sl, 1, "SLXI chunk: unknown feature: '%s', version: %d, ignoring", name_buffer, version);
} else {
SlErrorCorruptFmt("SLXI chunk: unknown feature: %s, version: %d", name_buffer, version);
}
}
// at this point the extra data field should have been consumed
// handle chunk ID list field
if (flags & XSCF_CHUNK_ID_LIST_PRESENT) {
uint32 chunk_count = SlReadUint32();
for (uint32 j = 0; j < chunk_count; j++) {
uint32 chunk_id = SlReadUint32();
if (discard_chunks) {
_sl_xv_discardable_chunk_ids.push_back(chunk_id);
DEBUG(sl, 2, "SLXI chunk: unknown feature: '%s', discarding chunk: %c%c%c%c", name_buffer, chunk_id >> 24, chunk_id >> 16, chunk_id >> 8, chunk_id);
}
}
}
}
}
extern const ChunkHandler _version_ext_chunk_handlers[] = {
{ 'SLXI', Save_SLXI, Load_SLXI, NULL, Load_SLXI, CH_RIFF | CH_LAST},
};

@ -19,7 +19,7 @@
/**
* List of extended features, each feature has its own (16 bit) version
*/
enum ExtendedSaveLoadFeatureIndex {
enum SlXvFeatureIndex {
XSLFI_NULL = 0, ///< Unused value, to indicate that no extended feature test is in use
XSLFI_SIZE, ///< Total count of features, including null feature
@ -30,7 +30,7 @@ extern uint16 _sl_xv_feature_versions[XSLFI_SIZE];
/**
* Operator to use when combining traditional savegame number test with an extended feature version test
*/
enum ExtendedSaveLoadFeatureTestOperator {
enum SlXvFeatureTestOperator {
XSLFTO_OR = 0, ///< Test if traditional savegame version is in bounds OR extended feature is in version bounds
XSLFTO_AND ///< Test if traditional savegame version is in bounds AND extended feature is in version bounds
};
@ -38,15 +38,15 @@ enum ExtendedSaveLoadFeatureTestOperator {
/**
* Structure to describe an extended feature version test, and how it combines with a traditional savegame version test
*/
struct ExtendedSaveLoadFeatureTest {
struct SlXvFeatureTest {
private:
uint64 value;
public:
ExtendedSaveLoadFeatureTest()
SlXvFeatureTest()
: value(0) { }
ExtendedSaveLoadFeatureTest(ExtendedSaveLoadFeatureTestOperator op, ExtendedSaveLoadFeatureIndex feature, uint16 min_version = 1, uint16 max_version = 0xFFFF)
SlXvFeatureTest(SlXvFeatureTestOperator op, SlXvFeatureIndex feature, uint16 min_version = 1, uint16 max_version = 0xFFFF)
{
this->value = 0;
SB(this->value, 0, 16, feature);
@ -58,16 +58,46 @@ struct ExtendedSaveLoadFeatureTest {
bool IsFeaturePresent(uint16 savegame_version, uint16 savegame_version_from, uint16 savegame_version_to) const;
};
bool SlXvIsFeaturePresent(ExtendedSaveLoadFeatureIndex feature, uint16 min_version = 1, uint16 max_version = 0xFFFF);
bool SlXvIsFeaturePresent(SlXvFeatureIndex feature, uint16 min_version = 1, uint16 max_version = 0xFFFF);
/**
* Returns true if @p feature is missing (i.e. has a version of 0)
*/
inline bool SlXvIsFeatureMissing(ExtendedSaveLoadFeatureIndex feature)
inline bool SlXvIsFeatureMissing(SlXvFeatureIndex feature)
{
return !SlXvIsFeaturePresent(feature);
}
/**
* sub chunk flags, this is saved as-is
* (XSCF_EXTRA_DATA_PRESENT and XSCF_CHUNK_ID_LIST_PRESENT must only be set by the save code, and read by the load code)
*/
enum SlxiSubChunkFlags {
XSCF_NULL = 0, ///< zero value
XSCF_IGNORABLE_UNKNOWN = 1 << 0, ///< the loader is free to ignore this without aborting the load if it doesn't know what it is at all
XSCF_IGNORABLE_VERSION = 1 << 1, ///< the loader is free to ignore this without aborting the load if the version is greater than the maximum that can be loaded
XSCF_EXTRA_DATA_PRESENT = 1 << 2, ///< extra data field is present, extra data in some sub-chunk/feature specific format, not used for anything yet
XSCF_CHUNK_ID_LIST_PRESENT = 1 << 3, ///< chunk ID list field is present, list of chunks which this sub-chunk/feature adds to the save game, this can be used to discard the chunks if the feature is unknown
};
DECLARE_ENUM_AS_BIT_SET(SlxiSubChunkFlags)
struct SlxiSubChunkInfo;
typedef uint32 SlxiSubChunkSaveProc(const SlxiSubChunkInfo *info, bool dry_run); ///< sub chunk save procedure type, must return length and write no data when dry_run is true
typedef void SlxiSubChunkLoadProc(const SlxiSubChunkInfo *info, uint32 length); ///< sub chunk load procedure, must consume length bytes
/** Handlers and description of chunk. */
struct SlxiSubChunkInfo {
SlXvFeatureIndex index; ///< feature index, this is saved
SlxiSubChunkFlags flags; ///< flags, this is saved
uint16 save_version; ///< version to save
uint16 max_version; ///< maximum version to accept on load
const char *name; ///< feature name, this *IS* saved, so must be globally unique
SlxiSubChunkSaveProc *save_proc; ///< save procedure of the sub chunk, this may be NULL in which case no extra chunk data is saved
SlxiSubChunkLoadProc *load_proc; ///< load procedure of the sub chunk, this may be NULL in which case the extra chunk data must be missing or of 0 length
const char *chunk_list; ///< this is a list of chunks that this feature uses, which should be written to the savegame, this must be a comma-seperated list of 4-character IDs, with no spaces, or NULL
};
void SlXvResetState();
void SlXvSetCurrentState();

@ -274,10 +274,11 @@ SavegameType _savegame_type; ///< type of savegame we are loading
uint32 _ttdp_version; ///< version of TTDP savegame (if applicable)
uint16 _sl_version; ///< the major savegame version identifier
byte _sl_minor_version; ///< the minor savegame version, DO NOT USE!
bool _sl_is_ext_version; ///< is this an extended savegame version, with more info in the SLXI chunk?
char _savegame_format[8]; ///< how to compress savegames
bool _do_autosave; ///< are we doing an autosave at the moment?
extern bool _sl_is_ext_version;
/** What are we currently doing? */
enum SaveLoadAction {
SLA_LOAD, ///< loading
@ -419,7 +420,7 @@ struct SaveLoadParams {
static SaveLoadParams _sl; ///< Parameters used for/at saveload.
/* these define the chunks */
//extern const ChunkHandler _version_ext_chunk_handlers[];
extern const ChunkHandler _version_ext_chunk_handlers[];
extern const ChunkHandler _gamelog_chunk_handlers[];
extern const ChunkHandler _map_chunk_handlers[];
extern const ChunkHandler _misc_chunk_handlers[];
@ -456,7 +457,7 @@ extern const ChunkHandler _persistent_storage_chunk_handlers[];
/** Array of all chunks in a savegame, \c NULL terminated. */
static const ChunkHandler * const _chunk_handlers[] = {
// _version_ext_chunk_handlers, // this should be first, such that it is saved first, as when loading it affects the loading of subsequent chunks
_version_ext_chunk_handlers, // this should be first, such that it is saved first, as when loading it affects the loading of subsequent chunks
_gamelog_chunk_handlers,
_map_chunk_handlers,
_misc_chunk_handlers,
@ -2662,7 +2663,6 @@ static SaveOrLoadResult DoLoad(LoadFilter *reader, bool load_check)
_sl.lf->Reset();
_sl_version = 0;
_sl_minor_version = 0;
_sl_is_ext_version = false;
SlXvResetState();
/* Try to find the LZO savegame format; it uses 'OTTD' as tag. */
@ -2830,7 +2830,6 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo
if (!LoadOldSaveGame(filename)) return SL_REINIT;
_sl_version = 0;
_sl_minor_version = 0;
_sl_is_ext_version = false;
SlXvResetState();
GamelogStartAction(GLAT_LOAD);
if (!AfterLoadGame()) {

@ -216,7 +216,7 @@ struct SaveLoad {
* that is called to save it. address: global=true, offset: global=false */
void *address; ///< address of variable OR offset of variable in the struct (max offset is 65536)
size_t size; ///< the sizeof size.
ExtendedSaveLoadFeatureTest ext_feature_test; ///< extended feature test
SlXvFeatureTest ext_feature_test; ///< extended feature test
};
/** Same as #SaveLoad but global variables are used (for better readability); */
@ -230,7 +230,7 @@ typedef SaveLoad SaveLoadGlobVarList;
* @param type Storage of the data in memory and in the savegame.
* @param from First savegame version that has the field.
* @param to Last savegame version that has the field.
* @param extver ExtendedSaveLoadFeatureTest to test (along with from and to) which savegames have the field
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
* @note In general, it is better to use one of the SLE_* macros below.
*/
#define SLE_GENERAL_X(cmd, base, variable, type, length, from, to, extver) {false, cmd, type, length, from, to, (void*)cpp_offsetof(base, variable), cpp_sizeof(base, variable), extver}
@ -243,7 +243,7 @@ typedef SaveLoad SaveLoadGlobVarList;
* @param type Storage of the data in memory and in the savegame.
* @param from First savegame version that has the field.
* @param to Last savegame version that has the field.
* @param extver ExtendedSaveLoadFeatureTest to test (along with from and to) which savegames have the field
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLE_CONDVAR_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_VAR, base, variable, type, 0, from, to, extver)
#define SLE_CONDVAR(base, variable, type, from, to) SLE_CONDVAR_X(base, variable, type, from, to, {})
@ -255,7 +255,7 @@ typedef SaveLoad SaveLoadGlobVarList;
* @param type Type of the reference, a value from #SLRefType.
* @param from First savegame version that has the field.
* @param to Last savegame version that has the field.
* @param extver ExtendedSaveLoadFeatureTest to test (along with from and to) which savegames have the field
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLE_CONDREF_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_REF, base, variable, type, 0, from, to, extver)
#define SLE_CONDREF(base, variable, type, from, to) SLE_CONDREF_X(base, variable, type, from, to, {})
@ -268,7 +268,7 @@ typedef SaveLoad SaveLoadGlobVarList;
* @param length Number of elements in the array.
* @param from First savegame version that has the array.
* @param to Last savegame version that has the array.
* @param extver ExtendedSaveLoadFeatureTest to test (along with from and to) which savegames have the field
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLE_CONDARR_X(base, variable, type, length, from, to, extver) SLE_GENERAL_X(SL_ARR, base, variable, type, length, from, to, extver)
#define SLE_CONDARR(base, variable, type, length, from, to) SLE_CONDARR_X(base, variable, type, length, from, to, {})
@ -281,7 +281,7 @@ typedef SaveLoad SaveLoadGlobVarList;
* @param length Number of elements in the string (only used for fixed size buffers).
* @param from First savegame version that has the string.
* @param to Last savegame version that has the string.
* @param extver ExtendedSaveLoadFeatureTest to test (along with from and to) which savegames have the field
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLE_CONDSTR_X(base, variable, type, length, from, to, extver) SLE_GENERAL_X(SL_STR, base, variable, type, length, from, to, extver)
#define SLE_CONDSTR(base, variable, type, length, from, to) SLE_CONDSTR_X(base, variable, type, length, from, to, {})
@ -293,7 +293,7 @@ typedef SaveLoad SaveLoadGlobVarList;
* @param type Storage of the data in memory and in the savegame.
* @param from First savegame version that has the list.
* @param to Last savegame version that has the list.
* @param extver ExtendedSaveLoadFeatureTest to test (along with from and to) which savegames have the field
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLE_CONDLST_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_LST, base, variable, type, 0, from, to, extver)
#define SLE_CONDLST(base, variable, type, from, to) SLE_CONDLST_X(base, variable, type, from, to, {})
@ -351,7 +351,7 @@ typedef SaveLoad SaveLoadGlobVarList;
* @param length Length of the empty space.
* @param from First savegame version that has the empty space.
* @param to Last savegame version that has the empty space.
* @param extver ExtendedSaveLoadFeatureTest to test (along with from and to) which savegames have empty space
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have empty space
*/
#define SLE_CONDNULL_X(length, from, to, extver) SLE_CONDARR_X(NullStruct, null, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, extver)
#define SLE_CONDNULL(length, from, to) SLE_CONDNULL_X(length, from, to, {})
@ -372,7 +372,7 @@ typedef SaveLoad SaveLoadGlobVarList;
* @param type Storage of the data in memory and in the savegame.
* @param from First savegame version that has the field.
* @param to Last savegame version that has the field.
* @param extver ExtendedSaveLoadFeatureTest to test (along with from and to) which savegames have the field
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
* @note In general, it is better to use one of the SLEG_* macros below.
*/
#define SLEG_GENERAL_X(cmd, variable, type, length, from, to, extver) {true, cmd, type, length, from, to, (void*)&variable, sizeof(variable), extver}
@ -384,7 +384,7 @@ typedef SaveLoad SaveLoadGlobVarList;
* @param type Storage of the data in memory and in the savegame.
* @param from First savegame version that has the field.
* @param to Last savegame version that has the field.
* @param extver ExtendedSaveLoadFeatureTest to test (along with from and to) which savegames have the field
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLEG_CONDVAR_X(variable, type, from, to, extver) SLEG_GENERAL_X(SL_VAR, variable, type, 0, from, to, extver)
#define SLEG_CONDVAR(variable, type, from, to) SLEG_CONDVAR_X(variable, type, from, to, {})
@ -395,7 +395,7 @@ typedef SaveLoad SaveLoadGlobVarList;
* @param type Storage of the data in memory and in the savegame.
* @param from First savegame version that has the field.
* @param to Last savegame version that has the field.
* @param extver ExtendedSaveLoadFeatureTest to test (along with from and to) which savegames have the field
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLEG_CONDREF_X(variable, type, from, to, extver) SLEG_GENERAL_X(SL_REF, variable, type, 0, from, to, extver)
#define SLEG_CONDREF(variable, type, from, to) SLEG_CONDREF_X(variable, type, from, to, {})
@ -407,7 +407,7 @@ typedef SaveLoad SaveLoadGlobVarList;
* @param length Number of elements in the array.
* @param from First savegame version that has the array.
* @param to Last savegame version that has the array.
* @param extver ExtendedSaveLoadFeatureTest to test (along with from and to) which savegames have the field
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLEG_CONDARR_X(variable, type, length, from, to, extver) SLEG_GENERAL_X(SL_ARR, variable, type, length, from, to, extver)
#define SLEG_CONDARR(variable, type, length, from, to) SLEG_CONDARR_X(variable, type, length, from, to, {})
@ -419,7 +419,7 @@ typedef SaveLoad SaveLoadGlobVarList;
* @param length Number of elements in the string (only used for fixed size buffers).
* @param from First savegame version that has the string.
* @param to Last savegame version that has the string.
* @param extver ExtendedSaveLoadFeatureTest to test (along with from and to) which savegames have the field
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLEG_CONDSTR_X(variable, type, length, from, to, extver) SLEG_GENERAL_X(SL_STR, variable, type, length, from, to, extver)
#define SLEG_CONDSTR(variable, type, length, from, to) SLEG_CONDSTR_X(variable, type, length, from, to, {})
@ -430,7 +430,7 @@ typedef SaveLoad SaveLoadGlobVarList;
* @param type Storage of the data in memory and in the savegame.
* @param from First savegame version that has the list.
* @param to Last savegame version that has the list.
* @param extver ExtendedSaveLoadFeatureTest to test (along with from and to) which savegames have the field
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
*/
#define SLEG_CONDLST_X(variable, type, from, to, extver) SLEG_GENERAL_X(SL_LST, variable, type, 0, from, to, extver)
#define SLEG_CONDLST(variable, type, from, to) SLEG_CONDLST_X(variable, type, from, to, {})
@ -475,7 +475,7 @@ typedef SaveLoad SaveLoadGlobVarList;
* @param length Length of the empty space.
* @param from First savegame version that has the empty space.
* @param to Last savegame version that has the empty space.
* @param extver ExtendedSaveLoadFeatureTest to test (along with from and to) which savegames have empty space
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have empty space
*/
#define SLEG_CONDNULL(length, from, to) {true, SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, (void*)NULL, {}}
@ -502,7 +502,7 @@ static inline bool IsSavegameVersionBefore(uint16 major, byte minor = 0)
* @param version_to Highest version number that falls within the range.
* @return Active savegame version falls within the given range.
*/
static inline bool SlIsObjectCurrentlyValid(uint16 version_from, uint16 version_to, ExtendedSaveLoadFeatureTest ext_feature_test)
static inline bool SlIsObjectCurrentlyValid(uint16 version_from, uint16 version_to, SlXvFeatureTest ext_feature_test)
{
extern const uint16 SAVEGAME_VERSION;
if (!ext_feature_test.IsFeaturePresent(SAVEGAME_VERSION, version_from, version_to)) return false;

Loading…
Cancel
Save