GRF: Extend EntityIDMapping/OverrideManagerBase to 16 bit entity IDs
This commit is contained in:
@@ -59,7 +59,7 @@ OverrideManagerBase::OverrideManagerBase(uint16 offset, uint16 maximum, uint16 i
|
|||||||
* @param grfid ID of the grf file
|
* @param grfid ID of the grf file
|
||||||
* @param entity_type original entity type
|
* @param entity_type original entity type
|
||||||
*/
|
*/
|
||||||
void OverrideManagerBase::Add(uint8 local_id, uint32 grfid, uint entity_type)
|
void OverrideManagerBase::Add(uint16 local_id, uint32 grfid, uint entity_type)
|
||||||
{
|
{
|
||||||
assert(entity_type < this->max_offset);
|
assert(entity_type < this->max_offset);
|
||||||
/* An override can be set only once */
|
/* An override can be set only once */
|
||||||
@@ -87,7 +87,7 @@ void OverrideManagerBase::ResetOverride()
|
|||||||
* @param grfid ID of the grf file
|
* @param grfid ID of the grf file
|
||||||
* @return the ID of the candidate, of the Invalid flag item ID
|
* @return the ID of the candidate, of the Invalid flag item ID
|
||||||
*/
|
*/
|
||||||
uint16 OverrideManagerBase::GetID(uint8 grf_local_id, uint32 grfid) const
|
uint16 OverrideManagerBase::GetID(uint16 grf_local_id, uint32 grfid) const
|
||||||
{
|
{
|
||||||
for (uint16 id = 0; id < this->max_entities; id++) {
|
for (uint16 id = 0; id < this->max_entities; id++) {
|
||||||
const EntityIDMapping *map = &this->mappings[id];
|
const EntityIDMapping *map = &this->mappings[id];
|
||||||
@@ -106,7 +106,7 @@ uint16 OverrideManagerBase::GetID(uint8 grf_local_id, uint32 grfid) const
|
|||||||
* @param substitute_id is the original entity from which data is copied for the new one
|
* @param substitute_id is the original entity from which data is copied for the new one
|
||||||
* @return the proper usable slot id, or invalid marker if none is found
|
* @return the proper usable slot id, or invalid marker if none is found
|
||||||
*/
|
*/
|
||||||
uint16 OverrideManagerBase::AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id)
|
uint16 OverrideManagerBase::AddEntityID(uint16 grf_local_id, uint32 grfid, uint16 substitute_id)
|
||||||
{
|
{
|
||||||
uint16 id = this->GetID(grf_local_id, grfid);
|
uint16 id = this->GetID(grf_local_id, grfid);
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ void HouseOverrideManager::SetEntitySpec(const HouseSpec *hs)
|
|||||||
* @param grfid ID of the grf file
|
* @param grfid ID of the grf file
|
||||||
* @return the ID of the candidate, of the Invalid flag item ID
|
* @return the ID of the candidate, of the Invalid flag item ID
|
||||||
*/
|
*/
|
||||||
uint16 IndustryOverrideManager::GetID(uint8 grf_local_id, uint32 grfid) const
|
uint16 IndustryOverrideManager::GetID(uint16 grf_local_id, uint32 grfid) const
|
||||||
{
|
{
|
||||||
uint16 id = OverrideManagerBase::GetID(grf_local_id, grfid);
|
uint16 id = OverrideManagerBase::GetID(grf_local_id, grfid);
|
||||||
if (id != this->invalid_id) return id;
|
if (id != this->invalid_id) return id;
|
||||||
@@ -205,7 +205,7 @@ uint16 IndustryOverrideManager::GetID(uint8 grf_local_id, uint32 grfid) const
|
|||||||
* @param substitute_id industry from which data has been copied
|
* @param substitute_id industry from which data has been copied
|
||||||
* @return a free entity id (slotid) if ever one has been found, or Invalid_ID marker otherwise
|
* @return a free entity id (slotid) if ever one has been found, or Invalid_ID marker otherwise
|
||||||
*/
|
*/
|
||||||
uint16 IndustryOverrideManager::AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id)
|
uint16 IndustryOverrideManager::AddEntityID(uint16 grf_local_id, uint32 grfid, uint16 substitute_id)
|
||||||
{
|
{
|
||||||
/* This entity hasn't been defined before, so give it an ID now. */
|
/* This entity hasn't been defined before, so give it an ID now. */
|
||||||
for (uint16 id = 0; id < this->max_entities; id++) {
|
for (uint16 id = 0; id < this->max_entities; id++) {
|
||||||
|
@@ -185,8 +185,8 @@ private:
|
|||||||
*/
|
*/
|
||||||
struct EntityIDMapping {
|
struct EntityIDMapping {
|
||||||
uint32 grfid; ///< The GRF ID of the file the entity belongs to
|
uint32 grfid; ///< The GRF ID of the file the entity belongs to
|
||||||
uint8 entity_id; ///< The entity ID within the GRF file
|
uint16 entity_id; ///< The entity ID within the GRF file
|
||||||
uint8 substitute_id; ///< The (original) entity ID to use if this GRF is not available
|
uint16 substitute_id; ///< The (original) entity ID to use if this GRF is not available
|
||||||
};
|
};
|
||||||
|
|
||||||
class OverrideManagerBase {
|
class OverrideManagerBase {
|
||||||
@@ -209,12 +209,12 @@ public:
|
|||||||
void ResetOverride();
|
void ResetOverride();
|
||||||
void ResetMapping();
|
void ResetMapping();
|
||||||
|
|
||||||
void Add(uint8 local_id, uint32 grfid, uint entity_type);
|
void Add(uint16 local_id, uint32 grfid, uint entity_type);
|
||||||
virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
|
virtual uint16 AddEntityID(uint16 grf_local_id, uint32 grfid, uint16 substitute_id);
|
||||||
|
|
||||||
uint32 GetGRFID(uint16 entity_id) const;
|
uint32 GetGRFID(uint16 entity_id) const;
|
||||||
uint16 GetSubstituteID(uint16 entity_id) const;
|
uint16 GetSubstituteID(uint16 entity_id) const;
|
||||||
virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const;
|
virtual uint16 GetID(uint16 grf_local_id, uint32 grfid) const;
|
||||||
|
|
||||||
inline uint16 GetMaxMapping() const { return this->max_entities; }
|
inline uint16 GetMaxMapping() const { return this->max_entities; }
|
||||||
inline uint16 GetMaxOffset() const { return this->max_offset; }
|
inline uint16 GetMaxOffset() const { return this->max_offset; }
|
||||||
@@ -237,8 +237,8 @@ public:
|
|||||||
IndustryOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
|
IndustryOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
|
||||||
OverrideManagerBase(offset, maximum, invalid) {}
|
OverrideManagerBase(offset, maximum, invalid) {}
|
||||||
|
|
||||||
uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id) override;
|
uint16 AddEntityID(uint16 grf_local_id, uint32 grfid, uint16 substitute_id) override;
|
||||||
uint16 GetID(uint8 grf_local_id, uint32 grfid) const override;
|
uint16 GetID(uint16 grf_local_id, uint32 grfid) const override;
|
||||||
|
|
||||||
void SetEntitySpec(IndustrySpec *inds);
|
void SetEntitySpec(IndustrySpec *inds);
|
||||||
};
|
};
|
||||||
|
@@ -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_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 },
|
||||||
{ XSLFI_AUX_TILE_LOOP, XSCF_NULL, 1, 1, "aux_tile_loop", 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_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_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 },
|
{ 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_TOWN_SETTING_OVERRIDE, ///< Town setting overrides
|
||||||
XSLFI_LINKGRAPH_SPARSE_EDGES, ///< Link graph edge matrix is stored in sparse format, and saved in order
|
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_AUX_TILE_LOOP, ///< Auxiliary tile loop
|
||||||
|
XSLFI_NEWGRF_ENTITY_EXTRA, ///< NewGRF entity mappings are 16 bit
|
||||||
|
|
||||||
XSLFI_SCRIPT_INT64, ///< See: SLV_SCRIPT_INT64
|
XSLFI_SCRIPT_INT64, ///< See: SLV_SCRIPT_INT64
|
||||||
XSLFI_U64_TICK_COUNTER, ///< See: SLV_U64_TICK_COUNTER
|
XSLFI_U64_TICK_COUNTER, ///< See: SLV_U64_TICK_COUNTER
|
||||||
|
@@ -17,10 +17,15 @@
|
|||||||
#include "../safeguards.h"
|
#include "../safeguards.h"
|
||||||
|
|
||||||
/** Save and load the mapping between a spec and the NewGRF it came from. */
|
/** 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, grfid, SLE_UINT32),
|
||||||
SLE_VAR(EntityIDMapping, entity_id, SLE_UINT8),
|
SLE_VAR(EntityIDMapping, entity_id, SLE_FILE_U8 | SLE_VAR_U16),
|
||||||
SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
|
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 &&
|
if (mapping.mappings[i].grfid == 0 &&
|
||||||
mapping.mappings[i].entity_id == 0) continue;
|
mapping.mappings[i].entity_id == 0) continue;
|
||||||
SlSetArrayIndex(i);
|
SlSetArrayIndex(i);
|
||||||
SlSetLength(4 + 1 + 1);
|
SlSetLength(4 + 2 + 2);
|
||||||
SlObjectSaveFiltered(const_cast<EntityIDMapping *>(&mapping.mappings[i]), _newgrf_mapping_desc); // _newgrf_mapping_desc has no conditionals
|
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();
|
uint max_id = mapping.GetMaxMapping();
|
||||||
|
|
||||||
|
SaveLoadTable slt = SlXvIsFeaturePresent(XSLFI_NEWGRF_ENTITY_EXTRA) ? SaveLoadTable(_newgrf_mapping_desc_new) : SaveLoadTable(_newgrf_mapping_desc_old);
|
||||||
|
|
||||||
int index;
|
int index;
|
||||||
while ((index = SlIterateArray()) != -1) {
|
while ((index = SlIterateArray()) != -1) {
|
||||||
if (unlikely((uint)index >= max_id)) SlErrorCorrupt("Too many NewGRF entity mappings");
|
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. */
|
/** 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[] = {
|
||||||
SLE_VAR(EntityIDMapping, grfid, SLE_UINT32),
|
SLE_VAR(EntityIDMapping, grfid, SLE_UINT32),
|
||||||
SLE_VAR(EntityIDMapping, entity_id, SLE_UINT8),
|
SLE_VAR(EntityIDMapping, entity_id, SLE_FILE_U8 | SLE_VAR_U16),
|
||||||
SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8),
|
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
|
void NewGRFMappingChunkHandler::Save() const
|
||||||
{
|
{
|
||||||
SlTableHeader(_newgrf_mapping_desc);
|
// removed
|
||||||
|
NOT_REACHED();
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user