mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-10 08:00:05 +00:00
Codechange: Add support for NULL strings in SaveLoadCompat
This commit is contained in:
parent
9f8fd80112
commit
e67fc33172
@ -623,9 +623,16 @@ static inline byte SlCalcConvFileLen(VarType conv)
|
||||
{
|
||||
static const byte conv_file_size[] = {0, 1, 1, 2, 2, 4, 4, 8, 8, 2};
|
||||
|
||||
uint8_t type = GetVarFileType(conv);
|
||||
assert(type < lengthof(conv_file_size));
|
||||
return conv_file_size[type];
|
||||
switch (GetVarFileType(conv)) {
|
||||
case SLE_FILE_STRING:
|
||||
return SlReadArrayLength();
|
||||
|
||||
default:
|
||||
uint8_t type = GetVarFileType(conv);
|
||||
if (type >= lengthof(conv_file_size)) fmt::println("{}", type);
|
||||
assert(type < lengthof(conv_file_size));
|
||||
return conv_file_size[type];
|
||||
}
|
||||
}
|
||||
|
||||
/** Return the size in bytes of a reference (pointer) */
|
||||
@ -1864,7 +1871,7 @@ std::vector<SaveLoad> 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, SLE_FILE_U8 | SLE_VAR_NULL, slc.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, 0, nullptr, 0, nullptr});
|
||||
} else {
|
||||
auto sld_it = key_lookup.find(slc.name);
|
||||
/* If this branch triggers, it means that an entry in the
|
||||
|
@ -715,10 +715,11 @@ struct SaveLoad {
|
||||
* to make that happen.
|
||||
*/
|
||||
struct SaveLoadCompat {
|
||||
std::string name; ///< Name of the field.
|
||||
uint16_t length; ///< Length of the NULL field.
|
||||
std::string name; ///< Name of the field.
|
||||
VarTypes null_type; ///< The type associated with the NULL field; defaults to SLE_FILE_U8 to just count bytes.
|
||||
uint16_t null_length; ///< Length of the NULL field.
|
||||
SaveLoadVersion version_from; ///< Save/load the variable starting from this savegame version.
|
||||
SaveLoadVersion version_to; ///< Save/load the variable before this savegame version.
|
||||
SaveLoadVersion version_to; ///< Save/load the variable before this savegame version.
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1183,18 +1184,26 @@ inline constexpr bool SlCheckVarSize(SaveLoadType cmd, VarType type, size_t leng
|
||||
* Field name where the real SaveLoad can be located.
|
||||
* @param name The name of the field.
|
||||
*/
|
||||
#define SLC_VAR(name) {name, 0, SL_MIN_VERSION, SL_MAX_VERSION}
|
||||
#define SLC_VAR(name) {name, SLE_FILE_U8, 0, SL_MIN_VERSION, SL_MAX_VERSION}
|
||||
|
||||
/**
|
||||
* Empty space in every savegame version.
|
||||
* @param length Length of the empty space.
|
||||
* @param length Length of the empty space in bytes.
|
||||
* @param from First savegame version that has the empty space.
|
||||
* @param to Last savegame version that has the empty space.
|
||||
*/
|
||||
#define SLC_NULL(length, from, to) {{}, length, from, to}
|
||||
#define SLC_NULL(length, from, to) {{}, SLE_FILE_U8, length, from, to}
|
||||
|
||||
/**
|
||||
* Empty space in every savegame version that was filled with a string.
|
||||
* @param length Number of strings in the empty space.
|
||||
* @param from First savegame version that has the empty space.
|
||||
* @param to Last savegame version that has the empty space.
|
||||
*/
|
||||
#define SLC_NULL_STR(length, from, to) {{}, SLE_FILE_STRING, length, from, to}
|
||||
|
||||
/** End marker of compat variables save or load. */
|
||||
#define SLC_END() {{}, 0, SL_MIN_VERSION, SL_MIN_VERSION}
|
||||
#define SLC_END() {{}, 0, 0, SL_MIN_VERSION, SL_MIN_VERSION}
|
||||
|
||||
/**
|
||||
* Checks whether the savegame is below \a major.\a minor.
|
||||
|
Loading…
Reference in New Issue
Block a user