Changeset - r26919:4c5461cdf009
[Not reviewed]
master
0 2 0
Michael Lutz - 2 years ago 2022-12-21 23:38:30
michi@icosahedron.de
Codechange: Saveload macros for entries with a custom table name.
2 files changed with 29 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/saveload/saveload.h
Show inline comments
 
@@ -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<void *>(static_cast<const void *>(std::addressof(static_cast<base *>(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<void *>(static_cast<const void *>(std::addressof(static_cast<base *>(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.
 
@@ -708,6 +722,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.
 
 * @param variable Name of the variable in the class or struct referenced by \a base.
src/table/settings.h.preamble
Show inline comments
 
@@ -79,6 +79,9 @@ static size_t ConvertLandscape(const cha
 
#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)
 

	
0 comments (0 inline, 0 general)