mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Bind objectspecs to classes once all finalised.
parent
02961fd7af
commit
93197f58b7
|
@ -9518,6 +9518,8 @@ static void FinaliseObjectsArray()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ObjectSpec::BindToClasses();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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. */
|
||||||
|
|
Loading…
Reference in New Issue