1
0
Fork 0

Codechange: Bind objectspecs to classes once all finalised.

pull/10594/head
Peter Nelson 2023-01-16 23:31:31 +00:00 committed by PeterN
parent 02961fd7af
commit 93197f58b7
4 changed files with 22 additions and 10 deletions

View File

@ -9518,6 +9518,8 @@ static void FinaliseObjectsArray()
} }
} }
} }
ObjectSpec::BindToClasses();
} }
/** /**

View File

@ -316,7 +316,6 @@ void ObjectOverrideManager::SetEntitySpec(ObjectSpec *spec)
/* Now that we know we can use the given id, copy the spec to its final destination. */ /* Now that we know we can use the given id, copy the spec to its final destination. */
memcpy(&_object_specs[type], spec, sizeof(*spec)); memcpy(&_object_specs[type], spec, sizeof(*spec));
ObjectClass::Assign(&_object_specs[type]);
} }
/** /**

View File

@ -90,6 +90,18 @@ uint ObjectSpec::Index() const
return this - _object_specs; return this - _object_specs;
} }
/**
* Tie all ObjectSpecs to their class.
*/
/* static */ void ObjectSpec::BindToClasses()
{
for (auto &spec : _object_specs) {
if (spec.IsEnabled() && spec.cls_id != INVALID_OBJECT_CLASS) {
ObjectClass::Assign(&spec);
}
}
}
/** This function initialize the spec arrays of objects. */ /** This function initialize the spec arrays of objects. */
void ResetObjects() void ResetObjects()
{ {
@ -104,20 +116,17 @@ void ResetObjects()
for (uint16 i = 0; i < lengthof(_original_objects); i++) { for (uint16 i = 0; i < lengthof(_original_objects); i++) {
_object_specs[i].grf_prop.local_id = i; _object_specs[i].grf_prop.local_id = i;
} }
/* Set class for originals. */
_object_specs[OBJECT_LIGHTHOUSE].cls_id = ObjectClass::Allocate('LTHS');
_object_specs[OBJECT_TRANSMITTER].cls_id = ObjectClass::Allocate('TRNS');
} }
template <typename Tspec, typename Tid, Tid Tmax> template <typename Tspec, typename Tid, Tid Tmax>
/* static */ void NewGRFClass<Tspec, Tid, Tmax>::InsertDefaults() /* static */ void NewGRFClass<Tspec, Tid, Tmax>::InsertDefaults()
{ {
ObjectClassID cls = ObjectClass::Allocate('LTHS'); ObjectClass::Get(ObjectClass::Allocate('LTHS'))->name = STR_OBJECT_CLASS_LTHS;
ObjectClass::Get(cls)->name = STR_OBJECT_CLASS_LTHS; ObjectClass::Get(ObjectClass::Allocate('TRNS'))->name = STR_OBJECT_CLASS_TRNS;
_object_specs[OBJECT_LIGHTHOUSE].cls_id = cls;
ObjectClass::Assign(&_object_specs[OBJECT_LIGHTHOUSE]);
cls = ObjectClass::Allocate('TRNS');
ObjectClass::Get(cls)->name = STR_OBJECT_CLASS_TRNS;
_object_specs[OBJECT_TRANSMITTER].cls_id = cls;
ObjectClass::Assign(&_object_specs[OBJECT_TRANSMITTER]);
} }
template <typename Tspec, typename Tid, Tid Tmax> template <typename Tspec, typename Tid, Tid Tmax>

View File

@ -101,6 +101,8 @@ struct ObjectSpec {
static const ObjectSpec *Get(ObjectType index); static const ObjectSpec *Get(ObjectType index);
static const ObjectSpec *GetByTile(TileIndex tile); static const ObjectSpec *GetByTile(TileIndex tile);
static void BindToClasses();
}; };
/** Object scope resolver. */ /** Object scope resolver. */