From 178249e7cc415f94efe07b9c14b1c0a700b91884 Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Thu, 22 Dec 2022 00:38:30 +0100 Subject: [PATCH] Codechange: Saveload macros for entries with a custom table name. --- src/saveload/saveload.h | 27 ++++++++++++++++++++++++++- src/table/settings.h.preamble | 3 +++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index de27caa8de..f6672a9ad3 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -687,6 +687,7 @@ struct SaveLoadCompat { /** * Storage of simple variables, references (pointers), and arrays. * @param cmd Load/save type. @see SaveLoadType + * @param name Field name for table chunks. * @param base Name of the class or struct containing the variable. * @param variable Name of the variable in the class or struct referenced by \a base. * @param type Storage of the data in memory and in the savegame. @@ -695,7 +696,20 @@ struct SaveLoadCompat { * @param extra Extra data to pass to the address callback function. * @note In general, it is better to use one of the SLE_* macros below. */ -#define SLE_GENERAL(cmd, base, variable, type, length, from, to, extra) SaveLoad {#variable, cmd, type, length, from, to, cpp_sizeof(base, variable), [] (void *b, size_t) -> void * { assert(b != nullptr); return const_cast(static_cast(std::addressof(static_cast(b)->variable))); }, extra, nullptr} +#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 * { assert(b != nullptr); return const_cast(static_cast(std::addressof(static_cast(b)->variable))); }, extra, nullptr} + +/** + * Storage of simple variables, references (pointers), and arrays with a custom name. + * @param cmd Load/save type. @see SaveLoadType + * @param base Name of the class or struct containing the variable. + * @param variable Name of the variable in the class or struct referenced by \a base. + * @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 extra Extra data to pass to the address callback function. + * @note In general, it is better to use one of the SLE_* macros below. + */ +#define SLE_GENERAL(cmd, base, variable, type, length, from, to, extra) SLE_GENERAL_NAME(cmd, #variable, base, variable, type, length, from, to, extra) /** * Storage of a variable in some savegame versions. @@ -707,6 +721,17 @@ struct SaveLoadCompat { */ #define SLE_CONDVAR(base, variable, type, from, to) SLE_GENERAL(SL_VAR, base, variable, type, 0, from, to, 0) +/** + * Storage of a variable in some savegame versions. + * @param base Name of the class or struct containing the variable. + * @param variable Name of the variable in the class or struct referenced by \a base. + * @param name Field name for table chunks. + * @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. + */ +#define SLE_CONDVARNAME(base, variable, name, type, from, to) SLE_GENERAL_NAME(SL_VAR, name, base, variable, type, 0, from, to, 0) + /** * Storage of a reference in some savegame versions. * @param base Name of the class or struct containing the variable. diff --git a/src/table/settings.h.preamble b/src/table/settings.h.preamble index dca29cf88c..dd978727ed 100644 --- a/src/table/settings.h.preamble +++ b/src/table/settings.h.preamble @@ -79,6 +79,9 @@ static size_t ConvertLandscape(const char *value); #define SDT_VAR(base, var, type, flags, def, min, max, interval, str, strhelp, strval, pre_check, post_callback, from, to, cat, extra, startup)\ NSD(Int, SLE_GENERAL(SL_VAR, base, var, type, 1, from, to, extra), flags, startup, def, min, max, interval, str, strhelp, strval, cat, pre_check, post_callback) +#define SDT_VAR_NAME(base, var, type, flags, def, min, max, interval, str, strhelp, strval, pre_check, post_callback, from, to, cat, extra, startup, name)\ + NSD(Int, SLE_GENERAL_NAME(SL_VAR, name, base, var, type, 1, from, to, extra), flags, startup, def, min, max, interval, str, strhelp, strval, cat, pre_check, post_callback) + #define SDT_BOOL(base, var, flags, def, str, strhelp, strval, pre_check, post_callback, from, to, cat, extra, startup)\ NSD(Bool, SLE_GENERAL(SL_VAR, base, var, SLE_BOOL, 1, from, to, extra), flags, startup, def, str, strhelp, strval, cat, pre_check, post_callback)