Change type of extended feature versions arrays

This commit is contained in:
Jonathan G Rennison
2023-02-15 23:49:40 +00:00
parent 633450f620
commit 796924ec32
4 changed files with 24 additions and 23 deletions

View File

@@ -51,8 +51,8 @@
#include "../safeguards.h"
uint16 _sl_xv_feature_versions[XSLFI_SIZE]; ///< array of all known feature types and their current versions
uint16 _sl_xv_feature_static_versions[XSLFI_SIZE]; ///< array of all known feature types and their static current version versions
std::array<uint16, XSLFI_SIZE> _sl_xv_feature_versions; ///< array of all known feature types and their current versions
std::array<uint16, XSLFI_SIZE> _sl_xv_feature_static_versions; ///< array of all known feature types and their static current version 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? See: SlXvCheckSpecialSavegameVersions.
bool _sl_maybe_springpp; ///< is this possibly a SpringPP savegame?
@@ -195,7 +195,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
* 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 SlXvFeatureTest::IsFeaturePresent(uint16 feature_versions[XSLFI_SIZE], SaveLoadVersion savegame_version, SaveLoadVersion savegame_version_from, SaveLoadVersion savegame_version_to) const
bool SlXvFeatureTest::IsFeaturePresent(const std::array<uint16, XSLFI_SIZE> &feature_versions, SaveLoadVersion savegame_version, SaveLoadVersion savegame_version_from, SaveLoadVersion savegame_version_to) const
{
bool savegame_version_ok = savegame_version >= savegame_version_from && savegame_version < savegame_version_to;
@@ -221,7 +221,7 @@ bool SlXvFeatureTest::IsFeaturePresent(uint16 feature_versions[XSLFI_SIZE], Save
/**
* Returns true if @p feature is present and has a version inclusively bounded by @p min_version and @p max_version
*/
bool SlXvIsFeaturePresent(uint16 feature_versions[XSLFI_SIZE], SlXvFeatureIndex feature, uint16 min_version, uint16 max_version)
bool SlXvIsFeaturePresent(const std::array<uint16, XSLFI_SIZE> &feature_versions, SlXvFeatureIndex feature, uint16 min_version, uint16 max_version)
{
assert(feature < XSLFI_SIZE);
return feature_versions[feature] >= min_version && feature_versions[feature] <= max_version;
@@ -252,7 +252,7 @@ void SlXvResetState()
_sl_maybe_chillpp = false;
_sl_upstream_mode = false;
_sl_xv_discardable_chunk_ids.clear();
memset(_sl_xv_feature_versions, 0, sizeof(_sl_xv_feature_versions));
std::fill(_sl_xv_feature_versions.begin(), _sl_xv_feature_versions.end(), 0);
_sl_xv_version_label.clear();
}
@@ -278,7 +278,7 @@ void SlXvSetCurrentState()
*/
void SlXvSetStaticCurrentVersions()
{
memset(_sl_xv_feature_static_versions, 0, sizeof(_sl_xv_feature_static_versions));
std::fill(_sl_xv_feature_static_versions.begin(), _sl_xv_feature_static_versions.end(), 0);
const SlxiSubChunkInfo *info = _sl_xv_sub_chunk_infos;
for (; info->index != XSLFI_NULL; ++info) {

View File

@@ -13,6 +13,7 @@
#include "../core/bitmath_func.hpp"
#include "../core/enum_type.hpp"
#include <array>
#include <vector>
enum SaveLoadVersion : uint16;
@@ -152,8 +153,8 @@ enum SlXvFeatureIndex {
XSLFI_SIZE, ///< Total count of features, including null feature
};
extern uint16 _sl_xv_feature_versions[XSLFI_SIZE];
extern uint16 _sl_xv_feature_static_versions[XSLFI_SIZE];
extern std::array<uint16, XSLFI_SIZE> _sl_xv_feature_versions;
extern std::array<uint16, XSLFI_SIZE> _sl_xv_feature_static_versions;
/**
* Operator to use when combining traditional savegame number test with an extended feature version test
@@ -167,7 +168,7 @@ enum SlXvFeatureTestOperator {
* Structure to describe an extended feature version test, and how it combines with a traditional savegame version test
*/
struct SlXvFeatureTest {
using TestFunctorPtr = bool (*)(uint16, bool, uint16[XSLFI_SIZE]); ///< Return true if feature present, first parameter is standard savegame version, second is whether standard savegame version is within bounds
using TestFunctorPtr = bool (*)(uint16, bool, const std::array<uint16, XSLFI_SIZE> &); ///< Return true if feature present, first parameter is standard savegame version, second is whether standard savegame version is within bounds
private:
uint16 min_version;
@@ -186,7 +187,7 @@ struct SlXvFeatureTest {
SlXvFeatureTest(TestFunctorPtr functor_)
: min_version(0), max_version(0), feature(XSLFI_NULL), op(XSLFTO_OR), functor(functor_) { }
bool IsFeaturePresent(uint16 feature_versions[XSLFI_SIZE], SaveLoadVersion savegame_version, SaveLoadVersion savegame_version_from, SaveLoadVersion savegame_version_to) const;
bool IsFeaturePresent(const std::array<uint16, XSLFI_SIZE> &feature_versions, SaveLoadVersion savegame_version, SaveLoadVersion savegame_version_from, SaveLoadVersion savegame_version_to) const;
inline bool IsFeaturePresent(SaveLoadVersion savegame_version, SaveLoadVersion savegame_version_from, SaveLoadVersion savegame_version_to) const
{
@@ -194,7 +195,7 @@ struct SlXvFeatureTest {
}
};
bool SlXvIsFeaturePresent(uint16 feature_versions[XSLFI_SIZE], SlXvFeatureIndex feature, uint16 min_version = 1, uint16 max_version = 0xFFFF);
bool SlXvIsFeaturePresent(const std::array<uint16, XSLFI_SIZE> &feature_versions, SlXvFeatureIndex feature, uint16 min_version = 1, uint16 max_version = 0xFFFF);
inline bool SlXvIsFeaturePresent(SlXvFeatureIndex feature, uint16 min_version = 1, uint16 max_version = 0xFFFF)
{
@@ -212,7 +213,7 @@ inline bool SlXvIsFeatureMissing(SlXvFeatureIndex feature, uint16 min_version =
/**
* Returns true if @p feature is missing (i.e. has a version of 0, or less than the specified minimum version)
*/
inline bool SlXvIsFeatureMissing(uint16 feature_versions[XSLFI_SIZE], SlXvFeatureIndex feature, uint16 min_version = 1)
inline bool SlXvIsFeatureMissing(const std::array<uint16, XSLFI_SIZE> &feature_versions, SlXvFeatureIndex feature, uint16 min_version = 1)
{
return !SlXvIsFeaturePresent(feature_versions, feature, min_version);
}

View File

@@ -704,10 +704,10 @@ SaveLoadTable GetVehicleDescription(VehicleType vt)
SLE_VAR(Vehicle, day_counter, SLE_UINT8),
SLE_VAR(Vehicle, tick_counter, SLE_UINT8),
SLE_CONDVAR_X(Vehicle, running_ticks, SLE_FILE_U8 | SLE_VAR_U16, SLV_88, SL_MAX_VERSION, SlXvFeatureTest([](uint16 version, bool version_in_range, uint16 feature_versions[XSLFI_SIZE]) -> bool {
SLE_CONDVAR_X(Vehicle, running_ticks, SLE_FILE_U8 | SLE_VAR_U16, SLV_88, SL_MAX_VERSION, SlXvFeatureTest([](uint16 version, bool version_in_range, const std::array<uint16, XSLFI_SIZE> &feature_versions) -> bool {
return version_in_range && !(SlXvIsFeaturePresent(feature_versions, XSLFI_SPRINGPP, 3) || SlXvIsFeaturePresent(feature_versions, XSLFI_JOKERPP) || SlXvIsFeaturePresent(feature_versions, XSLFI_CHILLPP) || SlXvIsFeaturePresent(feature_versions, XSLFI_VARIABLE_DAY_LENGTH, 2));
})),
SLE_CONDVAR_X(Vehicle, running_ticks, SLE_UINT16, SLV_88, SL_MAX_VERSION, SlXvFeatureTest([](uint16 version, bool version_in_range, uint16 feature_versions[XSLFI_SIZE]) -> bool {
SLE_CONDVAR_X(Vehicle, running_ticks, SLE_UINT16, SLV_88, SL_MAX_VERSION, SlXvFeatureTest([](uint16 version, bool version_in_range, const std::array<uint16, XSLFI_SIZE> &feature_versions) -> bool {
return version_in_range && (SlXvIsFeaturePresent(feature_versions, XSLFI_SPRINGPP, 2) || SlXvIsFeaturePresent(feature_versions, XSLFI_JOKERPP) || SlXvIsFeaturePresent(feature_versions, XSLFI_CHILLPP) || SlXvIsFeaturePresent(feature_versions, XSLFI_VARIABLE_DAY_LENGTH, 2));
})),

View File

@@ -1098,7 +1098,7 @@ var = linkgraph.recalc_not_scaled_by_daylength
def = true
str = STR_CONFIG_SETTING_LINKGRAPH_NOT_DAYLENGTH_SCALED
strhelp = STR_CONFIG_SETTING_LINKGRAPH_NOT_DAYLENGTH_SCALED_HELPTEXT
extver = SlXvFeatureTest([](uint16 version, bool version_in_range, uint16 feature_versions[XSLFI_SIZE]) -> bool { return version_in_range && SlXvIsFeaturePresent(feature_versions, XSLFI_LINKGRAPH_DAY_SCALE) && !SlXvIsFeaturePresent(feature_versions, XSLFI_JOKERPP); })
extver = SlXvFeatureTest([](uint16 version, bool version_in_range, const std::array<uint16, XSLFI_SIZE> &feature_versions) -> bool { return version_in_range && SlXvIsFeaturePresent(feature_versions, XSLFI_LINKGRAPH_DAY_SCALE) && !SlXvIsFeaturePresent(feature_versions, XSLFI_JOKERPP); })
patxname = ""linkgraph_day_scale.linkgraph.recalc_not_scaled_by_daylength""
[SDT_ENUM]