Codechange: Store objectspecs in std::vector instead of flat array.
(cherry picked from commit 1ae263c5467105820e4d770b3d57d25ba01e22b1)
This commit is contained in:

committed by
Jonathan G Rennison

parent
d34e1bbbc1
commit
74e4556a85
@@ -31,7 +31,12 @@ ObjectOverrideManager _object_mngr(NEW_OBJECT_OFFSET, NUM_OBJECTS, INVALID_OBJEC
|
||||
|
||||
extern const ObjectSpec _original_objects[NEW_OBJECT_OFFSET];
|
||||
/** All the object specifications. */
|
||||
ObjectSpec _object_specs[NUM_OBJECTS];
|
||||
std::vector<ObjectSpec> _object_specs;
|
||||
|
||||
size_t ObjectSpec::Count()
|
||||
{
|
||||
return _object_specs.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the specification associated with a specific ObjectType.
|
||||
@@ -40,7 +45,11 @@ ObjectSpec _object_specs[NUM_OBJECTS];
|
||||
*/
|
||||
/* static */ const ObjectSpec *ObjectSpec::Get(ObjectType index)
|
||||
{
|
||||
/* Empty object if index is out of range -- this might happen if NewGRFs are changed. */
|
||||
static ObjectSpec empty = {};
|
||||
|
||||
assert(index < NUM_OBJECTS);
|
||||
if (index >= _object_specs.size()) return ∅
|
||||
return &_object_specs[index];
|
||||
}
|
||||
|
||||
@@ -90,7 +99,7 @@ bool ObjectSpec::IsAvailable() const
|
||||
*/
|
||||
uint ObjectSpec::Index() const
|
||||
{
|
||||
return this - _object_specs;
|
||||
return this - _object_specs.data();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,14 +118,13 @@ uint ObjectSpec::Index() const
|
||||
void ResetObjects()
|
||||
{
|
||||
/* Clean the pool. */
|
||||
for (uint16 i = 0; i < NUM_OBJECTS; i++) {
|
||||
_object_specs[i] = {};
|
||||
}
|
||||
_object_specs.clear();
|
||||
|
||||
/* And add our originals. */
|
||||
MemCpyT(_object_specs, _original_objects, lengthof(_original_objects));
|
||||
_object_specs.resize(lengthof(_original_objects));
|
||||
|
||||
for (uint16 i = 0; i < lengthof(_original_objects); i++) {
|
||||
_object_specs[i] = _original_objects[i];
|
||||
_object_specs[i].grf_prop.local_id = i;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user