Saveload: Use table format for station/waypoint chunk

This commit is contained in:
Jonathan G Rennison 2024-07-29 17:12:13 +01:00
parent a192485ce9
commit f724853985
8 changed files with 588 additions and 259 deletions

View File

@ -582,7 +582,7 @@ public:
/** The super class ought to know what it's doing. */ /** The super class ought to know what it's doing. */
friend class CargoList<StationCargoList, StationCargoPacketMap>; friend class CargoList<StationCargoList, StationCargoPacketMap>;
/** The stations, via GoodsEntry, have a CargoList. */ /** The stations, via GoodsEntry, have a CargoList. */
friend SaveLoadTable GetGoodsDesc(); friend NamedSaveLoadTable GetGoodsDesc();
friend upstream_sl::SlStationGoods; friend upstream_sl::SlStationGoods;
friend class CargoLoad; friend class CargoLoad;

View File

@ -219,6 +219,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_TABLE_SCRIPT_SL, XSCF_NULL, 1, 1, "table_script_sl", nullptr, nullptr, nullptr }, { XSLFI_TABLE_SCRIPT_SL, XSCF_NULL, 1, 1, "table_script_sl", nullptr, nullptr, nullptr },
{ XSLFI_TABLE_NEWGRF_SL, XSCF_NULL, 2, 2, "table_newgrf_sl", nullptr, nullptr, nullptr }, { XSLFI_TABLE_NEWGRF_SL, XSCF_NULL, 2, 2, "table_newgrf_sl", nullptr, nullptr, nullptr },
{ XSLFI_TABLE_INDUSTRY_SL, XSCF_NULL, 2, 2, "table_industry_sl", nullptr, nullptr, nullptr }, { XSLFI_TABLE_INDUSTRY_SL, XSCF_NULL, 2, 2, "table_industry_sl", nullptr, nullptr, nullptr },
{ XSLFI_TABLE_STATION_SL, XSCF_NULL, 1, 1, "table_station_sl", nullptr, nullptr, nullptr },
{ XSLFI_NULL, XSCF_NULL, 0, 0, nullptr, nullptr, nullptr, nullptr }, // This is the end marker { XSLFI_NULL, XSCF_NULL, 0, 0, nullptr, nullptr, nullptr, nullptr }, // This is the end marker
}; };

View File

@ -174,6 +174,8 @@ enum SlXvFeatureIndex {
XSLFI_TABLE_INDUSTRY_SL, ///< Use table format for industry chunks: XSLFI_TABLE_INDUSTRY_SL, ///< Use table format for industry chunks:
///< v1: IBLD, ITBL ///< v1: IBLD, ITBL
///< v2: INDY ///< v2: INDY
XSLFI_TABLE_STATION_SL, ///< Use table format for station chunks:
///< v1: STNN
XSLFI_RIFF_HEADER_60_BIT, ///< Size field in RIFF chunk header is 60 bit XSLFI_RIFF_HEADER_60_BIT, ///< Size field in RIFF chunk header is 60 bit
XSLFI_HEIGHT_8_BIT, ///< Map tile height is 8 bit instead of 4 bit, but savegame version may be before this became true in trunk XSLFI_HEIGHT_8_BIT, ///< Map tile height is 8 bit instead of 4 bit, but savegame version may be before this became true in trunk

View File

@ -1898,7 +1898,6 @@ size_t SlCalcObjMemberLength(const void *object, const SaveLoad &sld)
break; break;
case SL_WRITEBYTE: return 1; // a uint8_t is logically of size 1 case SL_WRITEBYTE: return 1; // a uint8_t is logically of size 1
case SL_VEH_INCLUDE: return SlCalcObjLength(object, GetVehicleDescription(VEH_END)); case SL_VEH_INCLUDE: return SlCalcObjLength(object, GetVehicleDescription(VEH_END));
case SL_ST_INCLUDE: return SlCalcObjLength(object, GetBaseStationDescription());
case SL_STRUCT: case SL_STRUCT:
case SL_STRUCTLIST: case SL_STRUCTLIST:
@ -1968,8 +1967,8 @@ static void SlFilterObjectMember(const SaveLoad &sld, std::vector<SaveLoad> &sav
SlFilterObject(GetVehicleDescription(VEH_END), save); SlFilterObject(GetVehicleDescription(VEH_END), save);
break; break;
case SL_ST_INCLUDE: case SL_INCLUDE:
SlFilterObject(GetBaseStationDescription(), save); sld.include_functor(save);
break; break;
default: NOT_REACHED(); default: NOT_REACHED();
@ -2133,10 +2132,6 @@ bool SlObjectMemberGeneric(void *object, const SaveLoad &sld)
SlObject(ptr, GetVehicleDescription(VEH_END)); SlObject(ptr, GetVehicleDescription(VEH_END));
break; break;
case SL_ST_INCLUDE:
SlObject(ptr, GetBaseStationDescription());
break;
default: NOT_REACHED(); default: NOT_REACHED();
} }
return true; return true;

View File

@ -719,7 +719,9 @@ inline constexpr void *SlVarWrapper(void* ptr)
#define SLE_WRITEBYTE(base, variable) SLE_GENERAL(SL_WRITEBYTE, base, variable, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION) #define SLE_WRITEBYTE(base, variable) SLE_GENERAL(SL_WRITEBYTE, base, variable, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION)
#define SLE_VEH_INCLUDE() SaveLoad { false, SL_VEH_INCLUDE, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, SLTAG_DEFAULT, { nullptr }, 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()}
/** SaveLoad include, for non-table use with SlFilterObject/SlFilterNamedSaveLoadTable. */
#define SLE_INCLUDE(inc_functor) SaveLoad { false, SL_INCLUDE, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, SLTAG_DEFAULT, { .include_functor = inc_functor }, SlXvFeatureTest()}
/** /**
* Storage of global simple variables, references (pointers), and arrays. * Storage of global simple variables, references (pointers), and arrays.
@ -987,6 +989,7 @@ size_t SlCalcObjLength(const void *object, const SaveLoadTable &slt);
uint SlReadSimpleGamma(); uint SlReadSimpleGamma();
void SlWriteSimpleGamma(size_t i); void SlWriteSimpleGamma(size_t i);
uint SlGetGammaLength(size_t i); uint SlGetGammaLength(size_t i);
constexpr uint SlGetMaxGammaLength() { return 5; }
/** /**
* Run proc, automatically prepending the written length * Run proc, automatically prepending the written length
@ -1084,6 +1087,7 @@ void SlObject(void *object, const SaveLoadTable &slt);
bool SlObjectMember(void *object, const SaveLoad &sld); bool SlObjectMember(void *object, const SaveLoad &sld);
std::vector<SaveLoad> SlFilterObject(const SaveLoadTable &slt); std::vector<SaveLoad> SlFilterObject(const SaveLoadTable &slt);
void SlFilterNamedSaveLoadTable(const NamedSaveLoadTable &nslt, std::vector<SaveLoad> &save);
std::vector<SaveLoad> SlFilterNamedSaveLoadTable(const NamedSaveLoadTable &nslt); std::vector<SaveLoad> SlFilterNamedSaveLoadTable(const NamedSaveLoadTable &nslt);
void SlObjectSaveFiltered(void *object, const SaveLoadTable &slt); void SlObjectSaveFiltered(void *object, const SaveLoadTable &slt);
void SlObjectLoadFiltered(void *object, const SaveLoadTable &slt); void SlObjectLoadFiltered(void *object, const SaveLoadTable &slt);

View File

@ -23,7 +23,6 @@ void ResetOldNames();
void ResetOldWaypoints(); void ResetOldWaypoints();
void MoveBuoysToWaypoints(); void MoveBuoysToWaypoints();
void MoveWaypointsToBaseStations(); void MoveWaypointsToBaseStations();
SaveLoadTable GetBaseStationDescription();
void AfterLoadVehiclesPhase1(bool part_of_load); void AfterLoadVehiclesPhase1(bool part_of_load);
void AfterLoadVehiclesPhase2(bool part_of_load); void AfterLoadVehiclesPhase2(bool part_of_load);

View File

@ -120,12 +120,13 @@ enum SaveLoadTypes {
/* non-normal save-load types */ /* non-normal save-load types */
SL_WRITEBYTE, SL_WRITEBYTE,
SL_VEH_INCLUDE, SL_VEH_INCLUDE,
SL_ST_INCLUDE, SL_INCLUDE,
}; };
typedef uint8_t SaveLoadType; ///< Save/load type. @see SaveLoadTypes typedef uint8_t SaveLoadType; ///< Save/load type. @see SaveLoadTypes
using SaveLoadStructHandlerFactory = std::unique_ptr<class SaveLoadStructHandler> (*)(); using SaveLoadStructHandlerFactory = std::unique_ptr<class SaveLoadStructHandler> (*)();
using SaveLoadIncludeFunctor = void (*)(std::vector<struct SaveLoad> &);
/** SaveLoad type struct. Do NOT use this directly but use the SLE_ macros defined just below! */ /** SaveLoad type struct. Do NOT use this directly but use the SLE_ macros defined just below! */
struct SaveLoad { struct SaveLoad {
@ -144,6 +145,7 @@ struct SaveLoad {
* that is called to save it. address: global=true, offset: global=false */ * 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) void *address; ///< address of variable OR offset of variable in the struct (max offset is 65536)
SaveLoadStructHandlerFactory struct_handler_factory; ///< factory function pointer for SaveLoadStructHandler SaveLoadStructHandlerFactory struct_handler_factory; ///< factory function pointer for SaveLoadStructHandler
SaveLoadIncludeFunctor include_functor; ///< include functor for SL_INCLUDE
}; };
SlXvFeatureTest ext_feature_test; ///< extended feature test SlXvFeatureTest ext_feature_test; ///< extended feature test
@ -162,6 +164,7 @@ enum SaveLoadTags {
SLTAG_CUSTOM_START, SLTAG_CUSTOM_START,
SLTAG_CUSTOM_0 = SLTAG_CUSTOM_START, SLTAG_CUSTOM_0 = SLTAG_CUSTOM_START,
SLTAG_CUSTOM_1, SLTAG_CUSTOM_1,
SLTAG_CUSTOM_2,
}; };
enum NamedSaveLoadFlags : uint8_t { enum NamedSaveLoadFlags : uint8_t {
@ -215,6 +218,12 @@ inline constexpr NamedSaveLoad NSLT_STRUCTLIST(const char *name, SaveLoadVersion
return NSLT_STRUCTLIST(name, factory, from, to, extver); return NSLT_STRUCTLIST(name, factory, from, to, extver);
} }
inline constexpr NamedSaveLoad NSLTAG(uint16_t label_tag, NamedSaveLoad nsl)
{
nsl.save_load.label_tag = label_tag;
return nsl;
}
struct SaveLoadTableData : public std::vector<SaveLoad> { struct SaveLoadTableData : public std::vector<SaveLoad> {
std::vector<std::unique_ptr<class SaveLoadStructHandler>> struct_handlers; std::vector<std::unique_ptr<class SaveLoadStructHandler>> struct_handlers;
}; };

File diff suppressed because it is too large Load Diff