From 796924ec329a47412fa902fe322bb3a481361107 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 15 Feb 2023 23:49:40 +0000 Subject: [PATCH] Change type of extended feature versions arrays --- src/saveload/extended_ver_sl.cpp | 28 ++++++++++++++-------------- src/saveload/extended_ver_sl.h | 13 +++++++------ src/saveload/vehicle_sl.cpp | 4 ++-- src/table/settings/settings.ini | 2 +- 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/saveload/extended_ver_sl.cpp b/src/saveload/extended_ver_sl.cpp index 6b0a194ecd..44f479abce 100644 --- a/src/saveload/extended_ver_sl.cpp +++ b/src/saveload/extended_ver_sl.cpp @@ -51,17 +51,17 @@ #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 -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? -bool _sl_maybe_chillpp; ///< is this possibly a ChillPP v8 savegame? -bool _sl_upstream_mode; ///< load game using upstream loader -std::vector _sl_xv_discardable_chunk_ids; ///< list of chunks IDs which we can discard if no chunk loader exists -std::string _sl_xv_version_label; ///< optional SLXI version label +std::array _sl_xv_feature_versions; ///< array of all known feature types and their current versions +std::array _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? +bool _sl_maybe_chillpp; ///< is this possibly a ChillPP v8 savegame? +bool _sl_upstream_mode; ///< load game using upstream loader +std::vector _sl_xv_discardable_chunk_ids; ///< list of chunks IDs which we can discard if no chunk loader exists +std::string _sl_xv_version_label; ///< optional SLXI version label -static const uint32 _sl_xv_slxi_chunk_version = 0; ///< current version of SLXI chunk +static const uint32 _sl_xv_slxi_chunk_version = 0; ///< current version of SLXI chunk static void loadVL(const SlxiSubChunkInfo *info, uint32 length); static uint32 saveVL(const SlxiSubChunkInfo *info, bool dry_run); @@ -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 &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 &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) { diff --git a/src/saveload/extended_ver_sl.h b/src/saveload/extended_ver_sl.h index d63dd9a702..c384210201 100644 --- a/src/saveload/extended_ver_sl.h +++ b/src/saveload/extended_ver_sl.h @@ -13,6 +13,7 @@ #include "../core/bitmath_func.hpp" #include "../core/enum_type.hpp" +#include #include 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 _sl_xv_feature_versions; +extern std::array _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 &); ///< 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 &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 &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 &feature_versions, SlXvFeatureIndex feature, uint16 min_version = 1) { return !SlXvIsFeaturePresent(feature_versions, feature, min_version); } diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp index 5e543473ae..a00fb8ed3d 100644 --- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -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 &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 &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)); })), diff --git a/src/table/settings/settings.ini b/src/table/settings/settings.ini index 8c36e84559..aa5e410f14 100644 --- a/src/table/settings/settings.ini +++ b/src/table/settings/settings.ini @@ -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 &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]