Saveload: Use table format for template vehicle chunks

This commit is contained in:
Jonathan G Rennison 2024-07-15 18:24:21 +01:00
parent 7bf1cf0865
commit 9099caa059
4 changed files with 54 additions and 46 deletions

View File

@ -110,7 +110,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_REVERSE_AT_WAYPOINT, XSCF_NULL, 1, 1, "reverse_at_waypoint", nullptr, nullptr, nullptr },
{ XSLFI_VEH_LIFETIME_PROFIT, XSCF_NULL, 1, 1, "veh_lifetime_profit", nullptr, nullptr, nullptr },
{ XSLFI_LINKGRAPH_DAY_SCALE, XSCF_NULL, 6, 6, "linkgraph_day_scale", nullptr, nullptr, nullptr },
{ XSLFI_TEMPLATE_REPLACEMENT, XSCF_NULL, 9, 9, "template_replacement", nullptr, nullptr, "TRPL,TMPL" },
{ XSLFI_TEMPLATE_REPLACEMENT, XSCF_NULL, 10, 10, "template_replacement", nullptr, nullptr, "TRPL,TMPL" },
{ XSLFI_MORE_RAIL_TYPES, XSCF_NULL, 0, 1, "more_rail_types", nullptr, nullptr, nullptr },
{ XSLFI_CARGO_TYPE_ORDERS, XSCF_NULL, 3, 3, "cargo_type_orders", nullptr, nullptr, "ORDX,VEOX" },
{ XSLFI_EXTENDED_GAMELOG, XSCF_NULL, 2, 2, "extended_gamelog", nullptr, nullptr, nullptr },

View File

@ -4,32 +4,35 @@
#include "saveload.h"
static const SaveLoad _template_replacement_desc[] = {
SLE_VAR(TemplateReplacement, sel_template, SLE_UINT16),
SLE_VAR(TemplateReplacement, group, SLE_UINT16),
static const NamedSaveLoad _template_replacement_desc[] = {
NSL("sel_template", SLE_VAR(TemplateReplacement, sel_template, SLE_UINT16)),
NSL("group", SLE_VAR(TemplateReplacement, group, SLE_UINT16)),
};
static void Save_TMPL_RPLS()
{
SaveLoadTableData slt = SlTableHeader(_template_replacement_desc);
for (TemplateReplacement *tr : TemplateReplacement::Iterate()) {
SlSetArrayIndex(tr->index);
SlObject(tr, _template_replacement_desc);
SlObjectSaveFiltered(tr, slt);
}
}
static void Load_TMPL_RPLS()
{
int index;
SaveLoadTableData slt = SlTableHeaderOrRiff(_template_replacement_desc);
int index;
while ((index = SlIterateArray()) != -1) {
TemplateReplacement *tr = new (index) TemplateReplacement();
SlObject(tr, _template_replacement_desc);
SlObjectLoadFiltered(tr, slt);
}
ReindexTemplateReplacements();
}
extern const ChunkHandler template_replacement_chunk_handlers[] = {
{ 'TRPL', Save_TMPL_RPLS, Load_TMPL_RPLS, nullptr, nullptr, CH_ARRAY },
{ 'TRPL', Save_TMPL_RPLS, Load_TMPL_RPLS, nullptr, nullptr, CH_TABLE },
};
extern const ChunkHandlerTable _template_replacement_chunk_handlers(template_replacement_chunk_handlers);

View File

@ -9,74 +9,79 @@
#include "saveload.h"
const SaveLoadTable GTD() {
static const SaveLoad _template_veh_desc[] = {
SLE_REF(TemplateVehicle, next, REF_TEMPLATE_VEHICLE),
NamedSaveLoadTable GetTemplateVehicleDesc() {
static const NamedSaveLoad _template_veh_desc[] = {
NSL("next", SLE_REF(TemplateVehicle, next, REF_TEMPLATE_VEHICLE)),
SLE_VAR(TemplateVehicle, reuse_depot_vehicles, SLE_UINT8),
SLE_VAR(TemplateVehicle, keep_remaining_vehicles, SLE_UINT8),
SLE_VAR(TemplateVehicle, refit_as_template, SLE_UINT8),
SLE_CONDVAR_X(TemplateVehicle, replace_old_only, SLE_UINT8, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 5)),
NSL("reuse_depot_vehicles", SLE_VAR(TemplateVehicle, reuse_depot_vehicles, SLE_UINT8)),
NSL("keep_remaining_vehicles", SLE_VAR(TemplateVehicle, keep_remaining_vehicles, SLE_UINT8)),
NSL("refit_as_template", SLE_VAR(TemplateVehicle, refit_as_template, SLE_UINT8)),
NSL("replace_old_only", SLE_CONDVAR_X(TemplateVehicle, replace_old_only, SLE_UINT8, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 5))),
SLE_CONDVAR_X(TemplateVehicle, owner, SLE_VAR_U8 | SLE_FILE_U32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 0, 3)),
SLE_CONDVAR_X(TemplateVehicle, owner, SLE_UINT8, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 4)),
SLE_CONDNULL_X(1, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 0, 3)),
NSL("owner", SLE_CONDVAR_X(TemplateVehicle, owner, SLE_VAR_U8 | SLE_FILE_U32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 0, 3))),
NSL("owner", SLE_CONDVAR_X(TemplateVehicle, owner, SLE_UINT8, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 4))),
NSL("", SLE_CONDNULL_X(1, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 0, 3))),
SLE_VAR(TemplateVehicle, engine_type, SLE_UINT16),
SLE_VAR(TemplateVehicle, cargo_type, SLE_UINT8),
SLE_VAR(TemplateVehicle, cargo_cap, SLE_UINT16),
SLE_VAR(TemplateVehicle, cargo_subtype, SLE_UINT8),
NSL("engine_type", SLE_VAR(TemplateVehicle, engine_type, SLE_UINT16)),
NSL("cargo_type", SLE_VAR(TemplateVehicle, cargo_type, SLE_UINT8)),
NSL("cargo_capacity", SLE_VAR(TemplateVehicle, cargo_cap, SLE_UINT16)),
NSL("cargo_subtype", SLE_VAR(TemplateVehicle, cargo_subtype, SLE_UINT8)),
SLE_VAR(TemplateVehicle, subtype, SLE_UINT8),
SLE_VAR(TemplateVehicle, railtype, SLE_UINT8),
NSL("subtype", SLE_VAR(TemplateVehicle, subtype, SLE_UINT8)),
NSL("railtype", SLE_VAR(TemplateVehicle, railtype, SLE_UINT8)),
SLE_VAR(TemplateVehicle, index, SLE_UINT32),
NSL("", SLE_VAR(TemplateVehicle, index, SLE_UINT32)),
SLE_VAR(TemplateVehicle, real_consist_length, SLE_UINT16),
NSL("real_consist_length", SLE_VAR(TemplateVehicle, real_consist_length, SLE_UINT16)),
SLE_VAR(TemplateVehicle, max_speed, SLE_UINT16),
SLE_VAR(TemplateVehicle, power, SLE_UINT32),
SLE_VAR(TemplateVehicle, empty_weight, SLE_UINT32),
SLE_CONDVAR_X(TemplateVehicle, full_weight, SLE_UINT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 6)),
SLE_VAR(TemplateVehicle, max_te, SLE_UINT32),
SLE_CONDVAR_X(TemplateVehicle, air_drag, SLE_UINT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 8)),
NSL("max_speed", SLE_VAR(TemplateVehicle, max_speed, SLE_UINT16)),
NSL("power", SLE_VAR(TemplateVehicle, power, SLE_UINT32)),
NSL("empty_weight", SLE_VAR(TemplateVehicle, empty_weight, SLE_UINT32)),
NSL("full_weight", SLE_CONDVAR_X(TemplateVehicle, full_weight, SLE_UINT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 6))),
NSL("max_te", SLE_VAR(TemplateVehicle, max_te, SLE_UINT32)),
NSL("air_drag", SLE_CONDVAR_X(TemplateVehicle, air_drag, SLE_UINT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 8))),
SLE_CONDVAR_X(TemplateVehicle, ctrl_flags, SLE_UINT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 7)),
SLE_CONDSSTR_X(TemplateVehicle, name, SLE_STR | SLF_ALLOW_CONTROL, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 9)),
NSL("ctrl_flags", SLE_CONDVAR_X(TemplateVehicle, ctrl_flags, SLE_UINT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 7))),
NSL("name", SLE_CONDSSTR_X(TemplateVehicle, name, SLE_STR | SLF_ALLOW_CONTROL, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 9))),
SLE_CONDNULL_X(1, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 0, 3)),
SLE_CONDNULL_X(4, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 0, 1)),
SLE_CONDNULL_X(36, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 2, 3)),
SLE_CONDNULL_X(36, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_JOKERPP)),
SLE_CONDNULL_X(4, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 0, 3)),
NSL("", SLE_CONDNULL_X(1, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 0, 3))),
NSL("", SLE_CONDNULL_X(4, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 0, 1))),
NSL("", SLE_CONDNULL_X(36, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 2, 3))),
NSL("", SLE_CONDNULL_X(36, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_JOKERPP))),
NSL("", SLE_CONDNULL_X(4, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TEMPLATE_REPLACEMENT, 0, 3))),
};
return _template_veh_desc;
}
};
static void Save_TMPLS()
{
SaveLoadTableData slt = SlTableHeader(GetTemplateVehicleDesc());
for (TemplateVehicle *tv : TemplateVehicle::Iterate()) {
SlSetArrayIndex(tv->index);
SlObject(tv, GTD());
SlObjectSaveFiltered(tv, slt);
}
}
static void Load_TMPLS()
{
int index;
SaveLoadTableData slt = SlTableHeaderOrRiff(GetTemplateVehicleDesc());
int index;
while ((index = SlIterateArray()) != -1) {
TemplateVehicle *tv = new (index) TemplateVehicle();
SlObject(tv, GTD());
SlObjectLoadFiltered(tv, slt);
}
}
static void Ptrs_TMPLS()
{
SaveLoadTableData slt = SlPrepareNamedSaveLoadTableForPtrOrNull(GetTemplateVehicleDesc());
for (TemplateVehicle *tv : TemplateVehicle::Iterate()) {
SlObject(tv, GTD());
SlObjectPtrOrNullFiltered(tv, slt);
}
}
@ -153,7 +158,7 @@ void AfterLoadTemplateVehiclesUpdateProperties()
}
extern const ChunkHandler template_vehicle_chunk_handlers[] = {
{ 'TMPL', Save_TMPLS, Load_TMPLS, Ptrs_TMPLS, nullptr, CH_ARRAY },
{ 'TMPL', Save_TMPLS, Load_TMPLS, Ptrs_TMPLS, nullptr, CH_TABLE },
};
extern const ChunkHandlerTable _template_vehicle_chunk_handlers(template_vehicle_chunk_handlers);

View File

@ -88,7 +88,7 @@ private:
TemplateVehicle *first; ///< NOSAVE: pointer to the first vehicle in the chain
public:
friend const SaveLoadTable GTD();
friend NamedSaveLoadTable GetTemplateVehicleDesc();
friend void AfterLoadTemplateVehicles();
// Template usage configuration