Merge branch 'master' into jgrpp

# Conflicts:
#	.github/workflows/ci-build.yml
#	src/ai/ai_gui.cpp
#	src/blitter/32bpp_optimized.cpp
#	src/blitter/32bpp_simple.cpp
#	src/blitter/32bpp_sse2.cpp
#	src/blitter/8bpp_optimized.cpp
#	src/blitter/8bpp_simple.cpp
#	src/blitter/null.cpp
#	src/blitter/null.hpp
#	src/company_gui.cpp
#	src/game/game_gui.cpp
#	src/genworld_gui.cpp
#	src/gfx.cpp
#	src/gfx_func.h
#	src/graph_gui.cpp
#	src/industry_gui.cpp
#	src/linkgraph/linkgraphjob.cpp
#	src/network/network_gui.cpp
#	src/newgrf_debug_gui.cpp
#	src/openttd.cpp
#	src/pathfinder/npf/aystar.h
#	src/road_gui.cpp
#	src/saveload/order_sl.cpp
#	src/saveload/saveload.cpp
#	src/saveload/saveload.h
#	src/script/api/script_log.cpp
#	src/script/api/script_town.cpp
#	src/script/script_gui.cpp
#	src/settings.cpp
#	src/settings_gui.cpp
#	src/settings_table.cpp
#	src/settings_type.h
#	src/smallmap_gui.cpp
#	src/sortlist_type.h
#	src/spritecache.cpp
#	src/spriteloader/grf.cpp
#	src/spriteloader/grf.hpp
#	src/spriteloader/spriteloader.hpp
#	src/station_cmd.cpp
#	src/station_cmd.h
#	src/station_gui.cpp
#	src/strings.cpp
#	src/toolbar_gui.cpp
#	src/town_cmd.cpp
#	src/town_gui.cpp
#	src/vehicle_gui.cpp
#	src/vehicle_gui_base.h
#	src/video/opengl.cpp
#	src/video/opengl.h
#	src/widgets/dropdown.cpp
#	src/widgets/dropdown_type.h
#	src/window_gui.h
This commit is contained in:
Jonathan G Rennison
2023-12-23 13:26:55 +00:00
249 changed files with 2737 additions and 2156 deletions

View File

@@ -198,7 +198,7 @@ SaveLoadTable GetOrderBackupDescription()
SLE_VAR(OrderBackup, group, SLE_UINT16),
SLE_CONDVAR(OrderBackup, service_interval, SLE_FILE_U32 | SLE_VAR_U16, SL_MIN_VERSION, SLV_192),
SLE_CONDVAR(OrderBackup, service_interval, SLE_UINT16, SLV_192, SL_MAX_VERSION),
SLE_SSTR(OrderBackup, name, SLE_STR),
SLE_STR(OrderBackup, name, SLE_STR, 0),
SLE_CONDREF(OrderBackup, clone, REF_VEHICLE, SLV_192, SL_MAX_VERSION),
SLE_VAR(OrderBackup, cur_real_order_index, SLE_FILE_U8 | SLE_VAR_U16),
SLE_CONDVAR(OrderBackup, cur_implicit_order_index, SLE_FILE_U8 | SLE_VAR_U16, SLV_176, SL_MAX_VERSION),

View File

@@ -1421,58 +1421,8 @@ size_t SlCalcObjMemberLength(const void *object, const SaveLoad &sld)
return 0;
}
/**
* Check whether the variable size of the variable in the saveload configuration
* matches with the actual variable size.
* @param sld The saveload configuration to test.
*/
[[maybe_unused]] static bool IsVariableSizeRight(const SaveLoad &sld)
{
if (GetVarMemType(sld.conv) == SLE_VAR_NULL) return true;
switch (sld.cmd) {
case SL_VAR:
switch (GetVarMemType(sld.conv)) {
case SLE_VAR_BL:
return sld.size == sizeof(bool);
case SLE_VAR_I8:
case SLE_VAR_U8:
return sld.size == sizeof(int8);
case SLE_VAR_I16:
case SLE_VAR_U16:
return sld.size == sizeof(int16);
case SLE_VAR_I32:
case SLE_VAR_U32:
return sld.size == sizeof(int32);
case SLE_VAR_I64:
case SLE_VAR_U64:
return sld.size == sizeof(int64);
case SLE_VAR_NAME:
return sld.size == sizeof(std::string);
default:
return sld.size == sizeof(void *);
}
case SL_REF:
/* These should all be pointer sized. */
return sld.size == sizeof(void *);
case SL_STR:
/* These should be pointer sized, or fixed array. */
return sld.size == sizeof(void *) || sld.size == sld.length;
case SL_STDSTR:
/* These should be all pointers to std::string. */
return sld.size == sizeof(std::string);
default:
return true;
}
}
static bool SlObjectMember(void *object, const SaveLoad &sld)
{
assert_msg(IsVariableSizeRight(sld), "%s, size: %u, length: %u, cmd: %u, conv: 0x%02X", sld.name.c_str(), (uint) sld.size, sld.length, sld.cmd, sld.conv);
if (!SlIsObjectValidInSavegame(sld)) return false;
VarType conv = GB(sld.conv, 0, 8);

View File

@@ -15,9 +15,11 @@
#include "../fios.h"
#include "../strings_type.h"
#include "../core/span_type.hpp"
#include "../core/ring_buffer.hpp"
#include <optional>
#include <string>
#include <vector>
#include <list>
extern SaveLoadVersion _sl_version;
extern byte _sl_minor_version;
@@ -316,6 +318,89 @@ struct SaveLoadCompat {
SaveLoadVersion version_to; ///< Save/load the variable before this savegame version.
};
/**
* Get the NumberType of a setting. This describes the integer type
* as it is represented in memory
* @param type VarType holding information about the variable-type
* @return the SLE_VAR_* part of a variable-type description
*/
static inline constexpr VarType GetVarMemType(VarType type)
{
return type & 0xF0; // GB(type, 4, 4) << 4;
}
/**
* Get the FileType of a setting. This describes the integer type
* as it is represented in a savegame/file
* @param type VarType holding information about the file-type
* @return the SLE_FILE_* part of a variable-type description
*/
static inline VarType GetVarFileType(VarType type)
{
return type & 0xF; // GB(type, 0, 4);
}
/**
* Check if the given saveload type is a numeric type.
* @param conv the type to check
* @return True if it's a numeric type.
*/
static inline constexpr bool IsNumericType(VarType conv)
{
return GetVarMemType(conv) <= SLE_VAR_U64;
}
/**
* Return expect size in bytes of a VarType
* @param type VarType to get size of.
* @return size of type in bytes.
*/
static inline constexpr size_t SlVarSize(VarType type)
{
switch (GetVarMemType(type)) {
case SLE_VAR_BL: return sizeof(bool);
case SLE_VAR_I8: return sizeof(int8_t);
case SLE_VAR_U8: return sizeof(uint8_t);
case SLE_VAR_I16: return sizeof(int16_t);
case SLE_VAR_U16: return sizeof(uint16_t);
case SLE_VAR_I32: return sizeof(int32_t);
case SLE_VAR_U32: return sizeof(uint32_t);
case SLE_VAR_I64: return sizeof(int64_t);
case SLE_VAR_U64: return sizeof(uint64_t);
case SLE_VAR_NULL: return sizeof(void *);
case SLE_VAR_STR: return sizeof(std::string);
case SLE_VAR_STRQ: return sizeof(std::string);
case SLE_VAR_NAME: return sizeof(std::string);
default: NOT_REACHED();
}
}
/**
* Check if a saveload cmd/type/length entry matches the size of the variable.
* @param cmd SaveLoadType of entry.
* @param type VarType of entry.
* @param length Array length of entry.
* @param size Actual size of variable.
* @return true iff the sizes match.
*/
static inline constexpr bool SlCheckVarSize(SaveLoadType cmd, VarType type, size_t length, size_t size)
{
switch (cmd) {
case SL_VAR: return SlVarSize(type) == size;
case SL_REF: return sizeof(void *) == size;
case SL_STR: return sizeof(void *) == size;
case SL_STDSTR: return SlVarSize(type) == size;
case SL_ARR: return SlVarSize(type) * length <= size; // Partial load of array is permitted.
case SL_RING: return sizeof(ring_buffer<void *>) == size;
case SL_VECTOR: return sizeof(std::vector<void *>) == size;
case SL_REFLIST: return sizeof(std::list<void *>) == size;
case SL_REFRING: return sizeof(ring_buffer<void *>) == size;
case SL_REFVEC: return sizeof(std::vector<void *>) == size;
case SL_SAVEBYTE: return true;
default: NOT_REACHED();
}
}
/**
* Storage of simple variables, references (pointers), and arrays.
* @param cmd Load/save type. @see SaveLoadType
@@ -323,12 +408,18 @@ struct SaveLoadCompat {
* @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 length Number of elements in the array.
* @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_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}
#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 * { \
static_assert(SlCheckVarSize(cmd, type, length, sizeof(static_cast<base *>(b)->variable))); \
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.
@@ -336,6 +427,7 @@ struct SaveLoadCompat {
* @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 length Number of elements in the array.
* @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.
@@ -545,7 +637,10 @@ struct SaveLoadCompat {
* @param extra Extra data to pass to the address callback function.
* @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 * { return static_cast<void *>(std::addressof(variable)); }, extra, nullptr}
#define SLEG_GENERAL(name, cmd, variable, type, length, from, to, extra) \
SaveLoad {name, cmd, type, length, from, to, sizeof(variable), [] (void *, size_t) -> void * { \
static_assert(SlCheckVarSize(cmd, type, length, sizeof(variable))); \
return static_cast<void *>(std::addressof(variable)); }, extra, nullptr}
/**
* Storage of a global variable in some savegame versions.
@@ -775,38 +870,6 @@ static inline bool IsSavegameVersionBeforeOrAt(SaveLoadVersion major)
return _sl_version <= major;
}
/**
* Get the NumberType of a setting. This describes the integer type
* as it is represented in memory
* @param type VarType holding information about the variable-type
* @return the SLE_VAR_* part of a variable-type description
*/
static inline VarType GetVarMemType(VarType type)
{
return type & 0xF0; // GB(type, 4, 4) << 4;
}
/**
* Get the FileType of a setting. This describes the integer type
* as it is represented in a savegame/file
* @param type VarType holding information about the file-type
* @return the SLE_FILE_* part of a variable-type description
*/
static inline VarType GetVarFileType(VarType type)
{
return type & 0xF; // GB(type, 0, 4);
}
/**
* Check if the given saveload type is a numeric type.
* @param conv the type to check
* @return True if it's a numeric type.
*/
static inline bool IsNumericType(VarType conv)
{
return GetVarMemType(conv) <= SLE_VAR_U64;
}
/**
* Get the address of the variable. Null-variables don't have an address,
* everything else has a callback function that returns the address based