Saveload: Use table format for tunnel chunk

This commit is contained in:
Jonathan G Rennison 2024-07-08 18:48:37 +01:00
parent 3035b91b5c
commit 2bf05321bb
2 changed files with 14 additions and 11 deletions

View File

@ -116,7 +116,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_EXTENDED_GAMELOG, XSCF_NULL, 2, 2, "extended_gamelog", nullptr, nullptr, nullptr }, { XSLFI_EXTENDED_GAMELOG, XSCF_NULL, 2, 2, "extended_gamelog", nullptr, nullptr, nullptr },
{ XSLFI_STATION_CATCHMENT_INC, XSCF_NULL, 1, 1, "station_catchment_inc", nullptr, nullptr, nullptr }, { XSLFI_STATION_CATCHMENT_INC, XSCF_NULL, 1, 1, "station_catchment_inc", nullptr, nullptr, nullptr },
{ XSLFI_CUSTOM_BRIDGE_HEADS, XSCF_NULL, 4, 4, "custom_bridge_heads", nullptr, nullptr, nullptr }, { XSLFI_CUSTOM_BRIDGE_HEADS, XSCF_NULL, 4, 4, "custom_bridge_heads", nullptr, nullptr, nullptr },
{ XSLFI_CHUNNEL, XSCF_NULL, 2, 2, "chunnel", nullptr, nullptr, "TUNN" }, { XSLFI_CHUNNEL, XSCF_NULL, 3, 3, "chunnel", nullptr, nullptr, "TUNN" },
{ XSLFI_SCHEDULED_DISPATCH, XSCF_NULL, 8, 8, "scheduled_dispatch", nullptr, nullptr, nullptr }, { XSLFI_SCHEDULED_DISPATCH, XSCF_NULL, 8, 8, "scheduled_dispatch", nullptr, nullptr, nullptr },
{ XSLFI_MORE_TOWN_GROWTH_RATES, XSCF_NULL, 1, 1, "more_town_growth_rates", nullptr, nullptr, nullptr }, { XSLFI_MORE_TOWN_GROWTH_RATES, XSCF_NULL, 1, 1, "more_town_growth_rates", nullptr, nullptr, nullptr },
{ XSLFI_MULTIPLE_DOCKS, XSCF_NULL, 2, 2, "multiple_docks", nullptr, nullptr, nullptr }, { XSLFI_MULTIPLE_DOCKS, XSCF_NULL, 2, 2, "multiple_docks", nullptr, nullptr, nullptr },

View File

@ -15,36 +15,39 @@
#include "../safeguards.h" #include "../safeguards.h"
static const SaveLoad _tunnel_desc[] = { static const NamedSaveLoad _tunnel_desc[] = {
SLE_CONDVAR(Tunnel, tile_n, SLE_UINT32, SL_MIN_VERSION, SL_MAX_VERSION), NSL("tile_n", SLE_VAR(Tunnel, tile_n, SLE_UINT32)),
SLE_CONDVAR(Tunnel, tile_s, SLE_UINT32, SL_MIN_VERSION, SL_MAX_VERSION), NSL("tile_s", SLE_VAR(Tunnel, tile_s, SLE_UINT32)),
SLE_CONDVAR(Tunnel, height, SLE_UINT8, SL_MIN_VERSION, SL_MAX_VERSION), NSL("height", SLE_VAR(Tunnel, height, SLE_UINT8)),
SLE_CONDVAR(Tunnel, is_chunnel, SLE_BOOL, SL_MIN_VERSION, SL_MAX_VERSION), NSL("is_chunnel", SLE_VAR(Tunnel, is_chunnel, SLE_BOOL)),
SLE_CONDVAR_X(Tunnel, style, SLE_UINT8, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_NEW_SIGNAL_STYLES)), NSL("style", SLE_CONDVAR_X(Tunnel, style, SLE_UINT8, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_NEW_SIGNAL_STYLES))),
}; };
static void Save_TUNN() static void Save_TUNN()
{ {
std::vector<SaveLoad> slt = SlTableHeader(_tunnel_desc);
for (Tunnel *tunnel : Tunnel::Iterate()) { for (Tunnel *tunnel : Tunnel::Iterate()) {
SlSetArrayIndex(tunnel->index); SlSetArrayIndex(tunnel->index);
SlObject(tunnel, _tunnel_desc); SlObjectSaveFiltered(tunnel, slt);
} }
} }
static void Load_TUNN() static void Load_TUNN()
{ {
int index; std::vector<SaveLoad> slt = SlTableHeaderOrRiff(_tunnel_desc);
int index;
while ((index = SlIterateArray()) != -1) { while ((index = SlIterateArray()) != -1) {
Tunnel *tunnel = new (index) Tunnel(); Tunnel *tunnel = new (index) Tunnel();
SlObject(tunnel, _tunnel_desc); SlObjectLoadFiltered(tunnel, slt);
tunnel->UpdateIndexes(); tunnel->UpdateIndexes();
} }
} }
extern const ChunkHandler tunnel_chunk_handlers[] = { extern const ChunkHandler tunnel_chunk_handlers[] = {
{ 'TUNN', Save_TUNN, Load_TUNN, nullptr, nullptr, CH_ARRAY }, { 'TUNN', Save_TUNN, Load_TUNN, nullptr, nullptr, CH_TABLE },
}; };
extern const ChunkHandlerTable _tunnel_chunk_handlers(tunnel_chunk_handlers); extern const ChunkHandlerTable _tunnel_chunk_handlers(tunnel_chunk_handlers);