Saveload: Use table format for bridge signal style map

This commit is contained in:
Jonathan G Rennison 2024-07-16 22:00:12 +01:00
parent 5aa1c2ee04
commit d67a2ea167
2 changed files with 26 additions and 6 deletions

View File

@ -16,6 +16,14 @@ static const NamedSaveLoad _long_bridge_signal_storage_desc[] = {
NSL("signal_red_bits", SLE_VARVEC(LongBridgeSignalStorage, signal_red_bits, SLE_UINT64)), NSL("signal_red_bits", SLE_VARVEC(LongBridgeSignalStorage, signal_red_bits, SLE_UINT64)),
}; };
struct BridgeSignalStyleMapStub {
std::vector<uint32_t> 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() static void Load_XBSS()
{ {
SaveLoadTableData slt = SlTableHeaderOrRiff(_long_bridge_signal_storage_desc); SaveLoadTableData slt = SlTableHeaderOrRiff(_long_bridge_signal_storage_desc);
@ -40,15 +48,27 @@ static void Save_XBSS()
static void Load_XBST() static void Load_XBST()
{ {
size_t count = SlGetFieldLength() / sizeof(uint32_t); if (SlIsTableChunk()) {
for (size_t i = 0; i < count; i++) { SaveLoadTableData slt = SlTableHeader(_bridge_signal_style_map_desc);
_bridge_signal_style_map.insert(SlReadUint32()); 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() 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) { for (uint32_t val : _bridge_signal_style_map) {
SlWriteUint32(val); SlWriteUint32(val);
} }
@ -56,7 +76,7 @@ static void Save_XBST()
extern const ChunkHandler bridge_signal_chunk_handlers[] = { extern const ChunkHandler bridge_signal_chunk_handlers[] = {
{ 'XBSS', Save_XBSS, Load_XBSS, nullptr, nullptr, CH_SPARSE_TABLE }, { '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); extern const ChunkHandlerTable _bridge_signal_chunk_handlers(bridge_signal_chunk_handlers);

View File

@ -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_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_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_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_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_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 }, { XSLFI_LINKGRAPH_SPARSE_EDGES, XSCF_NULL, 1, 1, "linkgraph_sparse_edges", nullptr, nullptr, nullptr },