Saveload: Use table format for CAPA chunk

This commit is contained in:
Jonathan G Rennison 2024-07-13 12:03:58 +01:00
parent acfe8909b4
commit f739710ad3
4 changed files with 25 additions and 22 deletions

View File

@ -35,7 +35,7 @@ struct GoodsEntry; // forward-declare for Stage() and RerouteStalePackets()
template <class Tinst, class Tcont> class CargoList;
class StationCargoList; // forward-declare, so we can use it in VehicleCargoList.
extern SaveLoadTable GetCargoPacketDesc();
extern NamedSaveLoadTable GetCargoPacketDesc();
namespace upstream_sl {
extern upstream_sl::SaveLoadTable GetCargoPacketDesc();
@ -79,7 +79,7 @@ private:
friend class VehicleCargoList;
friend class StationCargoList;
/** We want this to be saved, right? */
friend SaveLoadTable GetCargoPacketDesc();
friend NamedSaveLoadTable GetCargoPacketDesc();
friend upstream_sl::SaveLoadTable upstream_sl::GetCargoPacketDesc();
friend void Load_CPDP();
public:

View File

@ -155,23 +155,23 @@ extern btree::btree_map<uint64_t, Money> _cargo_packet_deferred_payments;
* some of the variables itself are private.
* @return the saveload description for CargoPackets.
*/
SaveLoadTable GetCargoPacketDesc()
NamedSaveLoadTable GetCargoPacketDesc()
{
static const SaveLoad _cargopacket_desc[] = {
SLE_VAR(CargoPacket, first_station, SLE_UINT16),
SLE_VAR(CargoPacket, source_xy, SLE_UINT32),
SLE_VAR(CargoPacket, next_hop, SLE_FILE_U32 | SLE_VAR_U16),
SLE_VAR(CargoPacket, count, SLE_UINT16),
SLE_CONDVAR_X(CargoPacket, periods_in_transit, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_MORE_CARGO_AGE, 0, 0)),
SLE_CONDVAR_X(CargoPacket, periods_in_transit, SLE_UINT16, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_MORE_CARGO_AGE)),
SLE_VAR(CargoPacket, feeder_share, SLE_INT64),
SLE_CONDVAR(CargoPacket, source_type, SLE_UINT8, SLV_125, SL_MAX_VERSION),
SLE_CONDVAR(CargoPacket, source_id, SLE_UINT16, SLV_125, SL_MAX_VERSION),
SLE_CONDVAR_X(CargoPacket, travelled.x, SLE_INT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_CARGO_TRAVELLED)),
SLE_CONDVAR_X(CargoPacket, travelled.y, SLE_INT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_CARGO_TRAVELLED)),
static const NamedSaveLoad _cargopacket_desc[] = {
NSL("source", SLE_VAR(CargoPacket, first_station, SLE_UINT16)),
NSL("source_xy", SLE_VAR(CargoPacket, source_xy, SLE_UINT32)),
NSL("loaded_at_xy", SLE_VAR(CargoPacket, next_hop, SLE_FILE_U32 | SLE_VAR_U16)),
NSL("count", SLE_VAR(CargoPacket, count, SLE_UINT16)),
NSL("periods_in_transit", SLE_CONDVAR_X(CargoPacket, periods_in_transit, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_MORE_CARGO_AGE, 0, 0))),
NSL("periods_in_transit", SLE_CONDVAR_X(CargoPacket, periods_in_transit, SLE_UINT16, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_MORE_CARGO_AGE))),
NSL("feeder_share", SLE_VAR(CargoPacket, feeder_share, SLE_INT64)),
NSL("source_type", SLE_CONDVAR(CargoPacket, source_type, SLE_UINT8, SLV_125, SL_MAX_VERSION)),
NSL("source_id", SLE_CONDVAR(CargoPacket, source_id, SLE_UINT16, SLV_125, SL_MAX_VERSION)),
NSL("travelled.x", SLE_CONDVAR_X(CargoPacket, travelled.x, SLE_INT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_CARGO_TRAVELLED))),
NSL("travelled.y", SLE_CONDVAR_X(CargoPacket, travelled.y, SLE_INT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_CARGO_TRAVELLED))),
/* Used to be paid_for, but that got changed. */
SLE_CONDNULL(1, SL_MIN_VERSION, SLV_121),
NSL("", SLE_CONDNULL(1, SL_MIN_VERSION, SLV_121)),
};
return _cargopacket_desc;
}
@ -181,10 +181,11 @@ SaveLoadTable GetCargoPacketDesc()
*/
static void Save_CAPA()
{
std::vector<SaveLoad> filtered_packet_desc = SlFilterObject(GetCargoPacketDesc());
std::vector<SaveLoad> slt = SlTableHeader(GetCargoPacketDesc());
for (CargoPacket *cp : CargoPacket::Iterate()) {
SlSetArrayIndex(cp->index);
SlObjectSaveFiltered(cp, filtered_packet_desc);
SlObjectSaveFiltered(cp, slt);
}
}
@ -193,11 +194,12 @@ static void Save_CAPA()
*/
static void Load_CAPA()
{
std::vector<SaveLoad> filtered_packet_desc = SlFilterObject(GetCargoPacketDesc());
std::vector<SaveLoad> slt = SlTableHeaderOrRiff(GetCargoPacketDesc());
int index;
while ((index = SlIterateArray()) != -1) {
CargoPacket *cp = new (index) CargoPacket();
SlObjectLoadFiltered(cp, filtered_packet_desc);
SlObjectLoadFiltered(cp, slt);
}
}
@ -237,7 +239,7 @@ void Load_CPDP()
/** Chunk handlers related to cargo packets. */
static const ChunkHandler cargopacket_chunk_handlers[] = {
{ 'CAPA', Save_CAPA, Load_CAPA, nullptr, nullptr, CH_ARRAY },
{ 'CAPA', Save_CAPA, Load_CAPA, nullptr, nullptr, CH_TABLE },
{ 'CPDP', Save_CPDP, Load_CPDP, nullptr, nullptr, CH_RIFF },
};

View File

@ -214,7 +214,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_VEHICLE_ECONOMY_AGE, XSCF_NULL, 1, 1, "slv_vehicle_economy_age", nullptr, nullptr, nullptr },
{ XSLFI_TABLE_PATS, XSCF_NULL, 1, 1, "table_pats", nullptr, nullptr, nullptr },
{ XSLFI_TABLE_MISC_SL, XSCF_NULL, 2, 2, "table_misc_sl", nullptr, nullptr, nullptr },
{ XSLFI_TABLE_MISC_SL, XSCF_NULL, 3, 3, "table_misc_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_INDUSTRY_SL, XSCF_NULL, 1, 1, "table_industry_sl", nullptr, nullptr, nullptr },

View File

@ -166,6 +166,7 @@ enum SlXvFeatureIndex {
XSLFI_TABLE_MISC_SL, ///< Use upstream table format for miscellaneous chunks:
///< v1: DATE, VIEW, MAPS
///< v2: SUBS, CMDL, CMPU, ERNW, DEPT, CAPY, ECMY, EIDS, ENGN, GOAL, GRPS, RAIL, OBJS, SIGN, PSAC, STPE, STPA
///< v3: CAPA
XSLFI_TABLE_SCRIPT_SL, ///< Use upstream table format for script chunks
XSLFI_TABLE_NEWGRF_SL, ///< Use upstream table format for NewGRF/ID mapping chunks
///< In v1, NGRF chunks were saved incorrectly: see SLBF_TABLE_ARRAY_LENGTH_PREFIX_MISSING