From 74047028dd942141c58ac98e0ee598795ffeedcf Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 14 Jul 2024 18:00:47 +0100 Subject: [PATCH] Saveload: Remove unused size field from struct SaveLoad --- src/saveload/saveload.cpp | 4 ++-- src/saveload/saveload.h | 9 ++++----- src/saveload/settings_sl.cpp | 4 ++-- src/sl/saveload.cpp | 2 +- src/sl/saveload.h | 8 ++++---- src/sl/saveload_types.h | 1 - 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 2b5bd2168b..fabbbaba3c 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -1680,7 +1680,7 @@ std::vector SlTableHeader(const SaveLoadTable &slt) } /* We don't know this field, so read to nothing. */ - saveloads.push_back({key, saveload_type, ((VarType)type & SLE_FILE_TYPE_MASK) | SLE_VAR_NULL, 1, SL_MIN_VERSION, SL_MAX_VERSION, 0, nullptr, 0, handler}); + saveloads.push_back({key, saveload_type, ((VarType)type & SLE_FILE_TYPE_MASK) | SLE_VAR_NULL, 1, SL_MIN_VERSION, SL_MAX_VERSION, nullptr, 0, handler}); continue; } @@ -1787,7 +1787,7 @@ std::vector SlCompatTableHeader(const SaveLoadTable &slt, const SaveLo /* In old savegames there can be data we no longer care for. We * skip this by simply reading the amount of bytes indicated and * send those to /dev/null. */ - saveloads.push_back({"", SL_NULL, GetVarFileType(slc.null_type) | SLE_VAR_NULL, slc.null_length, slc.version_from, slc.version_to, 0, nullptr, 0, nullptr}); + saveloads.push_back({"", SL_NULL, GetVarFileType(slc.null_type) | SLE_VAR_NULL, slc.null_length, slc.version_from, slc.version_to, nullptr, 0, nullptr}); } else { auto sld_it = key_lookup.find(slc.name); /* If this branch triggers, it means that an entry in the diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index 50abc9804f..c4aabf6266 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -296,7 +296,6 @@ struct SaveLoad { uint16_t length; ///< (Conditional) length of the variable (eg. arrays) (max array size is 65536 elements). SaveLoadVersion version_from; ///< Save/load the variable starting from this savegame version. SaveLoadVersion version_to; ///< Save/load the variable before this savegame version. - size_t size; ///< The sizeof size. SaveLoadAddrProc *address_proc; ///< Callback proc the get the actual variable address in memory. size_t extra_data; ///< Extra data for the callback proc. std::shared_ptr handler; ///< Custom handler for Save/Load procs. @@ -415,7 +414,7 @@ inline constexpr bool SlCheckVarSize(SaveLoadType cmd, VarType type, size_t leng * @note In general, it is better to use one of the SLE_* macros below. */ #define SLE_GENERAL_NAME(cmd, name, base, variable, type, length, from, to, extra) \ - SaveLoad {name, cmd, type, length, from, to, cpp_sizeof(base, variable), [] (void *b, size_t) -> void * { \ + SaveLoad {name, cmd, type, length, from, to, [] (void *b, size_t) -> void * { \ static_assert(SlCheckVarSize(cmd, type, length, sizeof(static_cast(b)->variable))); \ assert(b != nullptr); \ return const_cast(static_cast(std::addressof(static_cast(b)->variable))); \ @@ -638,7 +637,7 @@ inline constexpr bool SlCheckVarSize(SaveLoadType cmd, VarType type, size_t leng * @note In general, it is better to use one of the SLEG_* macros below. */ #define SLEG_GENERAL(name, cmd, variable, type, length, from, to, extra) \ - SaveLoad {name, cmd, type, length, from, to, sizeof(variable), [] (void *, size_t) -> void * { \ + SaveLoad {name, cmd, type, length, from, to, [] (void *, size_t) -> void * { \ static_assert(SlCheckVarSize(cmd, type, length, sizeof(variable))); \ return static_cast(std::addressof(variable)); }, extra, nullptr} @@ -701,7 +700,7 @@ inline constexpr bool SlCheckVarSize(SaveLoadType cmd, VarType type, size_t leng * @param from First savegame version that has the struct. * @param to Last savegame version that has the struct. */ -#define SLEG_CONDSTRUCT(name, handler, from, to) SaveLoad {name, SL_STRUCT, 0, 0, from, to, 0, nullptr, 0, std::make_shared()} +#define SLEG_CONDSTRUCT(name, handler, from, to) SaveLoad {name, SL_STRUCT, 0, 0, from, to, nullptr, 0, std::make_shared()} /** * Storage of a global reference list in some savegame versions. @@ -750,7 +749,7 @@ inline constexpr bool SlCheckVarSize(SaveLoadType cmd, VarType type, size_t leng * @param from First savegame version that has the list. * @param to Last savegame version that has the list. */ -#define SLEG_CONDSTRUCTLIST(name, handler, from, to) SaveLoad {name, SL_STRUCTLIST, 0, 0, from, to, 0, nullptr, 0, std::make_shared()} +#define SLEG_CONDSTRUCTLIST(name, handler, from, to) SaveLoad {name, SL_STRUCTLIST, 0, 0, from, to, nullptr, 0, std::make_shared()} /** * Storage of a global variable in every savegame version. diff --git a/src/saveload/settings_sl.cpp b/src/saveload/settings_sl.cpp index af2527e9ac..e8b237db46 100644 --- a/src/saveload/settings_sl.cpp +++ b/src/saveload/settings_sl.cpp @@ -139,7 +139,7 @@ static std::vector GetSettingsDesc(bool is_loading) if (is_loading && (sd->flags & SF_NO_NETWORK_SYNC) && _networking && !_network_server) { if (IsSavegameVersionBefore(SLV_TABLE_CHUNKS)) { /* We don't want to read this setting, so we do need to skip over it. */ - saveloads.push_back({sd->name, new_cmd, GetVarFileType(new_type) | SLE_VAR_NULL, sd->save.length, SL_MIN_VERSION, SL_MAX_VERSION, 0, nullptr, 0, nullptr}); + saveloads.push_back({sd->name, new_cmd, GetVarFileType(new_type) | SLE_VAR_NULL, sd->save.length, SL_MIN_VERSION, SL_MAX_VERSION, nullptr, 0, nullptr}); } continue; } @@ -147,7 +147,7 @@ static std::vector GetSettingsDesc(bool is_loading) SaveLoadAddrProc *address_proc = [](void *base, size_t extra) -> void* { return const_cast((const uint8_t *)base + (ptrdiff_t)extra); }; - saveloads.push_back({sd->name, new_cmd, new_type, sd->save.length, SL_MIN_VERSION, SL_MAX_VERSION, sd->save.size, address_proc, reinterpret_cast(sd->save.address), nullptr}); + saveloads.push_back({sd->name, new_cmd, new_type, sd->save.length, SL_MIN_VERSION, SL_MAX_VERSION, address_proc, reinterpret_cast(sd->save.address), nullptr}); } return saveloads; diff --git a/src/sl/saveload.cpp b/src/sl/saveload.cpp index 5f26856071..d96f92e8f1 100644 --- a/src/sl/saveload.cpp +++ b/src/sl/saveload.cpp @@ -2277,7 +2277,7 @@ std::vector SlTableHeader(const NamedSaveLoadTable &slt, TableHeaderSp } /* We don't know this field, so read to nothing. */ - saveloads.push_back({ true, saveload_type, ((VarType)type & SLE_FILE_TYPE_MASK) | SLE_VAR_NULL, 1, SL_MIN_VERSION, SL_MAX_VERSION, SLTAG_TABLE_UNKNOWN, nullptr, 0, SlXvFeatureTest() }); + saveloads.push_back({ true, saveload_type, ((VarType)type & SLE_FILE_TYPE_MASK) | SLE_VAR_NULL, 1, SL_MIN_VERSION, SL_MAX_VERSION, SLTAG_TABLE_UNKNOWN, nullptr, SlXvFeatureTest() }); continue; } diff --git a/src/sl/saveload.h b/src/sl/saveload.h index ce842a2043..b63d685fdf 100644 --- a/src/sl/saveload.h +++ b/src/sl/saveload.h @@ -501,7 +501,7 @@ inline constexpr void *SlVarWrapper(void* ptr) * @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) SaveLoad {false, cmd, type, length, from, to, SLTAG_DEFAULT, SlVarWrapper((void*)cpp_offsetof(base, variable)), sizeof(base::variable), extver} +#define SLE_GENERAL_X(cmd, base, variable, type, length, from, to, extver) SaveLoad {false, cmd, type, length, from, to, SLTAG_DEFAULT, SlVarWrapper((void*)cpp_offsetof(base, variable)), extver} #define SLE_GENERAL(cmd, base, variable, type, length, from, to) SLE_GENERAL_X(cmd, base, variable, type, length, from, to, SlXvFeatureTest()) /** @@ -719,8 +719,8 @@ inline constexpr void *SlVarWrapper(void* ptr) /** Translate values ingame to different values in the savegame and vv. */ #define SLE_WRITEBYTE(base, variable) SLE_GENERAL(SL_WRITEBYTE, base, variable, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION) -#define SLE_VEH_INCLUDE() {false, SL_VEH_INCLUDE, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, SLTAG_DEFAULT, nullptr, 0, SlXvFeatureTest()} -#define SLE_ST_INCLUDE() {false, SL_ST_INCLUDE, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, SLTAG_DEFAULT, nullptr, 0, SlXvFeatureTest()} +#define SLE_VEH_INCLUDE() SaveLoad { false, SL_VEH_INCLUDE, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, SLTAG_DEFAULT, nullptr, SlXvFeatureTest()} +#define SLE_ST_INCLUDE() SaveLoad { false, SL_ST_INCLUDE, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, SLTAG_DEFAULT, nullptr, SlXvFeatureTest()} /** * Storage of global simple variables, references (pointers), and arrays. @@ -732,7 +732,7 @@ inline constexpr void *SlVarWrapper(void* ptr) * @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) SaveLoad {true, cmd, type, length, from, to, SLTAG_DEFAULT, SlVarWrapper((void*)&variable), sizeof(variable), extver} +#define SLEG_GENERAL_X(cmd, variable, type, length, from, to, extver) SaveLoad {true, cmd, type, length, from, to, SLTAG_DEFAULT, SlVarWrapper((void*)&variable), extver} #define SLEG_GENERAL(cmd, variable, type, length, from, to) SLEG_GENERAL_X(cmd, variable, type, length, from, to, SlXvFeatureTest()) /** diff --git a/src/sl/saveload_types.h b/src/sl/saveload_types.h index 0928cfc781..3235dc3818 100644 --- a/src/sl/saveload_types.h +++ b/src/sl/saveload_types.h @@ -137,7 +137,6 @@ struct SaveLoad { * during runtime. Decision on which one to use is controlled by the function * 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. SlXvFeatureTest ext_feature_test; ///< extended feature test };