mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use vector for NewGRF spec overrides.
This replaces C-style memory management.pull/10415/head
parent
07940726d3
commit
eedb786872
|
@ -44,21 +44,10 @@ OverrideManagerBase::OverrideManagerBase(uint16 offset, uint16 maximum, uint16 i
|
||||||
max_new_entities = maximum;
|
max_new_entities = maximum;
|
||||||
invalid_ID = invalid;
|
invalid_ID = invalid;
|
||||||
|
|
||||||
mapping_ID = CallocT<EntityIDMapping>(max_new_entities);
|
this->mapping_ID.resize(this->max_new_entities);
|
||||||
entity_overrides = MallocT<uint16>(max_offset);
|
this->entity_overrides.resize(this->max_offset);
|
||||||
for (size_t i = 0; i < max_offset; i++) entity_overrides[i] = invalid;
|
std::fill(this->entity_overrides.begin(), this->entity_overrides.end(), this->invalid_ID);
|
||||||
grfid_overrides = CallocT<uint32>(max_offset);
|
this->grfid_overrides.resize(this->max_offset);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Destructor of the generic class.
|
|
||||||
* Frees allocated memory of constructor
|
|
||||||
*/
|
|
||||||
OverrideManagerBase::~OverrideManagerBase()
|
|
||||||
{
|
|
||||||
free(mapping_ID);
|
|
||||||
free(entity_overrides);
|
|
||||||
free(grfid_overrides);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,16 +70,14 @@ void OverrideManagerBase::Add(uint8 local_id, uint32 grfid, uint entity_type)
|
||||||
/** Resets the mapping, which is used while initializing game */
|
/** Resets the mapping, which is used while initializing game */
|
||||||
void OverrideManagerBase::ResetMapping()
|
void OverrideManagerBase::ResetMapping()
|
||||||
{
|
{
|
||||||
memset(mapping_ID, 0, (max_new_entities - 1) * sizeof(EntityIDMapping));
|
std::fill(this->mapping_ID.begin(), this->mapping_ID.end(), EntityIDMapping{});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resets the override, which is used while initializing game */
|
/** Resets the override, which is used while initializing game */
|
||||||
void OverrideManagerBase::ResetOverride()
|
void OverrideManagerBase::ResetOverride()
|
||||||
{
|
{
|
||||||
for (uint16 i = 0; i < max_offset; i++) {
|
std::fill(this->entity_overrides.begin(), this->entity_overrides.end(), this->invalid_ID);
|
||||||
entity_overrides[i] = invalid_ID;
|
std::fill(this->grfid_overrides.begin(), this->grfid_overrides.end(), uint32());
|
||||||
grfid_overrides[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -191,8 +191,8 @@ struct EntityIDMapping {
|
||||||
|
|
||||||
class OverrideManagerBase {
|
class OverrideManagerBase {
|
||||||
protected:
|
protected:
|
||||||
uint16 *entity_overrides;
|
std::vector<uint16> entity_overrides;
|
||||||
uint32 *grfid_overrides;
|
std::vector<uint32> grfid_overrides;
|
||||||
|
|
||||||
uint16 max_offset; ///< what is the length of the original entity's array of specs
|
uint16 max_offset; ///< what is the length of the original entity's array of specs
|
||||||
uint16 max_new_entities; ///< what is the amount of entities, old and new summed
|
uint16 max_new_entities; ///< what is the amount of entities, old and new summed
|
||||||
|
@ -201,10 +201,10 @@ protected:
|
||||||
virtual bool CheckValidNewID(uint16 testid) { return true; }
|
virtual bool CheckValidNewID(uint16 testid) { return true; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EntityIDMapping *mapping_ID; ///< mapping of ids from grf files. Public out of convenience
|
std::vector<EntityIDMapping> mapping_ID; ///< mapping of ids from grf files. Public out of convenience
|
||||||
|
|
||||||
OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid);
|
OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid);
|
||||||
virtual ~OverrideManagerBase();
|
virtual ~OverrideManagerBase() {}
|
||||||
|
|
||||||
void ResetOverride();
|
void ResetOverride();
|
||||||
void ResetMapping();
|
void ResetMapping();
|
||||||
|
@ -267,7 +267,7 @@ public:
|
||||||
struct AirportTileSpec;
|
struct AirportTileSpec;
|
||||||
class AirportTileOverrideManager : public OverrideManagerBase {
|
class AirportTileOverrideManager : public OverrideManagerBase {
|
||||||
protected:
|
protected:
|
||||||
virtual bool CheckValidNewID(uint16 testid) { return testid != 0xFF; }
|
virtual bool CheckValidNewID(uint16 testid) override { return testid != 0xFF; }
|
||||||
public:
|
public:
|
||||||
AirportTileOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
|
AirportTileOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
|
||||||
OverrideManagerBase(offset, maximum, invalid) {}
|
OverrideManagerBase(offset, maximum, invalid) {}
|
||||||
|
@ -278,7 +278,7 @@ public:
|
||||||
struct ObjectSpec;
|
struct ObjectSpec;
|
||||||
class ObjectOverrideManager : public OverrideManagerBase {
|
class ObjectOverrideManager : public OverrideManagerBase {
|
||||||
protected:
|
protected:
|
||||||
virtual bool CheckValidNewID(uint16 testid) { return testid != 0xFF; }
|
virtual bool CheckValidNewID(uint16 testid) override { return testid != 0xFF; }
|
||||||
public:
|
public:
|
||||||
ObjectOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
|
ObjectOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
|
||||||
OverrideManagerBase(offset, maximum, invalid) {}
|
OverrideManagerBase(offset, maximum, invalid) {}
|
||||||
|
|
Loading…
Reference in New Issue