From d67a2ea16771b424aa0c0eb591b4db57df5c7256 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Tue, 16 Jul 2024 22:00:12 +0100 Subject: [PATCH] Saveload: Use table format for bridge signal style map --- src/sl/bridge_signal_sl.cpp | 30 +++++++++++++++++++++++++----- src/sl/extended_ver_sl.cpp | 2 +- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/sl/bridge_signal_sl.cpp b/src/sl/bridge_signal_sl.cpp index fab8e93da4..6da69d8154 100644 --- a/src/sl/bridge_signal_sl.cpp +++ b/src/sl/bridge_signal_sl.cpp @@ -16,6 +16,14 @@ static const NamedSaveLoad _long_bridge_signal_storage_desc[] = { NSL("signal_red_bits", SLE_VARVEC(LongBridgeSignalStorage, signal_red_bits, SLE_UINT64)), }; +struct BridgeSignalStyleMapStub { + std::vector signal_style_map; +}; + +static const NamedSaveLoad _bridge_signal_style_map_desc[] = { + NSL("signal_style_map", SLE_VARVEC(BridgeSignalStyleMapStub, signal_style_map, SLE_UINT32)), +}; + static void Load_XBSS() { SaveLoadTableData slt = SlTableHeaderOrRiff(_long_bridge_signal_storage_desc); @@ -40,15 +48,27 @@ static void Save_XBSS() static void Load_XBST() { - size_t count = SlGetFieldLength() / sizeof(uint32_t); - for (size_t i = 0; i < count; i++) { - _bridge_signal_style_map.insert(SlReadUint32()); + if (SlIsTableChunk()) { + SaveLoadTableData slt = SlTableHeader(_bridge_signal_style_map_desc); + BridgeSignalStyleMapStub stub{}; + SlLoadTableObjectChunk(slt, &stub); + _bridge_signal_style_map.insert(stub.signal_style_map.begin(), stub.signal_style_map.end()); + } else { + size_t count = SlGetFieldLength() / sizeof(uint32_t); + for (size_t i = 0; i < count; i++) { + _bridge_signal_style_map.insert(SlReadUint32()); + } } } static void Save_XBST() { - SlSetLength(_bridge_signal_style_map.size() * sizeof(uint32_t)); + SaveLoadTableData slt = SlTableHeader(_bridge_signal_style_map_desc); + + SlSetArrayIndex(0); + const size_t count = _bridge_signal_style_map.size(); + SlSetLength(SlGetGammaLength(count) + (count * 4)); + SlWriteSimpleGamma(count); for (uint32_t val : _bridge_signal_style_map) { SlWriteUint32(val); } @@ -56,7 +76,7 @@ static void Save_XBST() extern const ChunkHandler bridge_signal_chunk_handlers[] = { { 'XBSS', Save_XBSS, Load_XBSS, nullptr, nullptr, CH_SPARSE_TABLE }, - { 'XBST', Save_XBST, Load_XBST, nullptr, nullptr, CH_RIFF }, + { 'XBST', Save_XBST, Load_XBST, nullptr, nullptr, CH_TABLE }, }; extern const ChunkHandlerTable _bridge_signal_chunk_handlers(bridge_signal_chunk_handlers); diff --git a/src/sl/extended_ver_sl.cpp b/src/sl/extended_ver_sl.cpp index 1f35c9fcbc..d6c557ac57 100644 --- a/src/sl/extended_ver_sl.cpp +++ b/src/sl/extended_ver_sl.cpp @@ -180,7 +180,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = { { XSLFI_RV_ORDER_EXTRA_FLAGS, XSCF_IGNORABLE_UNKNOWN, 1, 1, "rv_order_extra_flags", nullptr, nullptr, nullptr }, { XSLFI_GRF_ROADSTOPS, XSCF_NULL, 3, 3, "grf_road_stops", nullptr, nullptr, nullptr }, { XSLFI_INDUSTRY_ANIM_MASK, XSCF_IGNORABLE_ALL, 1, 1, "industry_anim_mask", nullptr, nullptr, nullptr }, - { XSLFI_NEW_SIGNAL_STYLES, XSCF_NULL, 3, 3, "new_signal_styles", nullptr, nullptr, "XBST,NSID" }, + { XSLFI_NEW_SIGNAL_STYLES, XSCF_NULL, 4, 4, "new_signal_styles", nullptr, nullptr, "XBST,NSID" }, { XSLFI_NO_TREE_COUNTER, XSCF_IGNORABLE_ALL, 1, 1, "no_tree_counter", nullptr, nullptr, nullptr }, { XSLFI_TOWN_SETTING_OVERRIDE, XSCF_NULL, 1, 1, "town_setting_override", nullptr, nullptr, nullptr }, { XSLFI_LINKGRAPH_SPARSE_EDGES, XSCF_NULL, 1, 1, "linkgraph_sparse_edges", nullptr, nullptr, nullptr },