Saveload: Use table format for new signal style mapping chunk
This commit is contained in:
@@ -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, 2, 2, "new_signal_styles", nullptr, nullptr, "XBST,NSID" },
|
||||
{ XSLFI_NEW_SIGNAL_STYLES, XSCF_NULL, 3, 3, "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 },
|
||||
|
@@ -14,13 +14,19 @@
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
static const NamedSaveLoad _new_signal_style_mapping_desc[] = {
|
||||
NSLT("grfid", SLE_VAR(NewSignalStyleMapping, grfid, SLE_UINT32)),
|
||||
NSLT("grf_local_id", SLE_VAR(NewSignalStyleMapping, grf_local_id, SLE_UINT8)),
|
||||
};
|
||||
|
||||
static void Save_NSID()
|
||||
{
|
||||
SlSetLength(4 + (_new_signal_style_mapping.size() * 5));
|
||||
SlWriteUint32((uint)_new_signal_style_mapping.size());
|
||||
for (const NewSignalStyleMapping &mapping : _new_signal_style_mapping) {
|
||||
SlWriteUint32(mapping.grfid);
|
||||
SlWriteByte(mapping.grf_local_id);
|
||||
std::vector<SaveLoad> slt = SlTableHeader(_new_signal_style_mapping_desc);
|
||||
|
||||
int index = 0;
|
||||
for (NewSignalStyleMapping &it : _new_signal_style_mapping) {
|
||||
SlSetArrayIndex(index++);
|
||||
SlObjectSaveFiltered(&it, slt);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,17 +34,28 @@ static void Load_NSID()
|
||||
{
|
||||
_new_signal_style_mapping.fill({});
|
||||
|
||||
uint count = SlReadUint32();
|
||||
for (uint i = 0; i < count; i++) {
|
||||
NewSignalStyleMapping mapping;
|
||||
mapping.grfid = SlReadUint32();
|
||||
mapping.grf_local_id = SlReadByte();
|
||||
if (i < _new_signal_style_mapping.size()) _new_signal_style_mapping[i] = mapping;
|
||||
if (SlIsTableChunk()) {
|
||||
std::vector<SaveLoad> slt = SlTableHeader(_new_signal_style_mapping_desc);
|
||||
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
NewSignalStyleMapping mapping;
|
||||
SlObjectLoadFiltered(&mapping, slt);
|
||||
if (static_cast<size_t>(index) < _new_signal_style_mapping.size()) _new_signal_style_mapping[index] = mapping;
|
||||
}
|
||||
} else {
|
||||
uint count = SlReadUint32();
|
||||
for (uint i = 0; i < count; i++) {
|
||||
NewSignalStyleMapping mapping;
|
||||
mapping.grfid = SlReadUint32();
|
||||
mapping.grf_local_id = SlReadByte();
|
||||
if (i < _new_signal_style_mapping.size()) _new_signal_style_mapping[i] = mapping;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const ChunkHandler new_signal_chunk_handlers[] = {
|
||||
{ 'NSID', Save_NSID, Load_NSID, nullptr, nullptr, CH_RIFF },
|
||||
{ 'NSID', Save_NSID, Load_NSID, nullptr, nullptr, CH_TABLE },
|
||||
};
|
||||
|
||||
extern const ChunkHandlerTable _new_signal_chunk_handlers(new_signal_chunk_handlers);
|
||||
|
Reference in New Issue
Block a user