GRF: Extend EntityIDMapping/OverrideManagerBase to 16 bit entity IDs
This commit is contained in:
@@ -178,6 +178,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
|
||||
{ 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_AUX_TILE_LOOP, XSCF_NULL, 1, 1, "aux_tile_loop", nullptr, nullptr, nullptr },
|
||||
{ XSLFI_NEWGRF_ENTITY_EXTRA, XSCF_NULL, 1, 1, "newgrf_entity_extra", nullptr, nullptr, nullptr },
|
||||
{ XSLFI_SCRIPT_INT64, XSCF_NULL, 1, 1, "script_int64", nullptr, nullptr, nullptr },
|
||||
{ XSLFI_U64_TICK_COUNTER, XSCF_NULL, 1, 1, "u64_tick_counter", nullptr, nullptr, nullptr },
|
||||
{ XSLFI_LINKGRAPH_TRAVEL_TIME, XSCF_NULL, 1, 1, "linkgraph_travel_time", nullptr, nullptr, nullptr },
|
||||
|
||||
@@ -131,6 +131,7 @@ enum SlXvFeatureIndex {
|
||||
XSLFI_TOWN_SETTING_OVERRIDE, ///< Town setting overrides
|
||||
XSLFI_LINKGRAPH_SPARSE_EDGES, ///< Link graph edge matrix is stored in sparse format, and saved in order
|
||||
XSLFI_AUX_TILE_LOOP, ///< Auxiliary tile loop
|
||||
XSLFI_NEWGRF_ENTITY_EXTRA, ///< NewGRF entity mappings are 16 bit
|
||||
|
||||
XSLFI_SCRIPT_INT64, ///< See: SLV_SCRIPT_INT64
|
||||
XSLFI_U64_TICK_COUNTER, ///< See: SLV_U64_TICK_COUNTER
|
||||
|
||||
@@ -17,10 +17,15 @@
|
||||
#include "../safeguards.h"
|
||||
|
||||
/** Save and load the mapping between a spec and the NewGRF it came from. */
|
||||
static const SaveLoad _newgrf_mapping_desc[] = {
|
||||
static const SaveLoad _newgrf_mapping_desc_old[] = {
|
||||
SLE_VAR(EntityIDMapping, grfid, SLE_UINT32),
|
||||
SLE_VAR(EntityIDMapping, entity_id, SLE_UINT8),
|
||||
SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
|
||||
SLE_VAR(EntityIDMapping, entity_id, SLE_FILE_U8 | SLE_VAR_U16),
|
||||
SLE_VAR(EntityIDMapping, substitute_id, SLE_FILE_U8 | SLE_VAR_U16),
|
||||
};
|
||||
static const SaveLoad _newgrf_mapping_desc_new[] = {
|
||||
SLE_VAR(EntityIDMapping, grfid, SLE_UINT32),
|
||||
SLE_VAR(EntityIDMapping, entity_id, SLE_UINT16),
|
||||
SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT16),
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -33,8 +38,8 @@ void Save_NewGRFMapping(const OverrideManagerBase &mapping)
|
||||
if (mapping.mappings[i].grfid == 0 &&
|
||||
mapping.mappings[i].entity_id == 0) continue;
|
||||
SlSetArrayIndex(i);
|
||||
SlSetLength(4 + 1 + 1);
|
||||
SlObjectSaveFiltered(const_cast<EntityIDMapping *>(&mapping.mappings[i]), _newgrf_mapping_desc); // _newgrf_mapping_desc has no conditionals
|
||||
SlSetLength(4 + 2 + 2);
|
||||
SlObjectSaveFiltered(const_cast<EntityIDMapping *>(&mapping.mappings[i]), _newgrf_mapping_desc_new); // _newgrf_mapping_desc_new has no conditionals
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,10 +55,12 @@ void Load_NewGRFMapping(OverrideManagerBase &mapping)
|
||||
|
||||
uint max_id = mapping.GetMaxMapping();
|
||||
|
||||
SaveLoadTable slt = SlXvIsFeaturePresent(XSLFI_NEWGRF_ENTITY_EXTRA) ? SaveLoadTable(_newgrf_mapping_desc_new) : SaveLoadTable(_newgrf_mapping_desc_old);
|
||||
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
if (unlikely((uint)index >= max_id)) SlErrorCorrupt("Too many NewGRF entity mappings");
|
||||
SlObjectLoadFiltered(&mapping.mappings[index], _newgrf_mapping_desc); // _newgrf_mapping_desc has no conditionals
|
||||
SlObjectLoadFiltered(&mapping.mappings[index], slt); // _newgrf_mapping_desc_old/_newgrf_mapping_desc_new has no conditionals
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ namespace upstream_sl {
|
||||
/** Save and load the mapping between a spec and the NewGRF it came from. */
|
||||
static const SaveLoad _newgrf_mapping_desc[] = {
|
||||
SLE_VAR(EntityIDMapping, grfid, SLE_UINT32),
|
||||
SLE_VAR(EntityIDMapping, entity_id, SLE_UINT8),
|
||||
SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
|
||||
SLE_VAR(EntityIDMapping, entity_id, SLE_FILE_U8 | SLE_VAR_U16),
|
||||
SLE_VAR(EntityIDMapping, substitute_id, SLE_FILE_U8 | SLE_VAR_U16),
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -31,14 +31,8 @@ static const SaveLoad _newgrf_mapping_desc[] = {
|
||||
*/
|
||||
void NewGRFMappingChunkHandler::Save() const
|
||||
{
|
||||
SlTableHeader(_newgrf_mapping_desc);
|
||||
|
||||
for (uint i = 0; i < this->mapping.GetMaxMapping(); i++) {
|
||||
if (this->mapping.mappings[i].grfid == 0 &&
|
||||
this->mapping.mappings[i].entity_id == 0) continue;
|
||||
SlSetArrayIndex(i);
|
||||
SlObject(&this->mapping.mappings[i], _newgrf_mapping_desc);
|
||||
}
|
||||
// removed
|
||||
NOT_REACHED();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user