1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-24 12:44:10 +01:00

Codechange: Add NewGRFSpecsBase class to hold class/index information.

Standardises how the class index is stored in the spec, instead of relying ot the Spec structs having the same members.

This allows retrieving class_index and index without searching or using pointer arithmetic.

'cls_id' is renamed to 'class_index' to make it clearer that it is an index rather than the multichar label of the class.
This commit is contained in:
Peter Nelson
2024-05-07 12:13:46 +01:00
committed by Peter Nelson
parent 733284cc16
commit d5671030b1
13 changed files with 83 additions and 78 deletions

View File

@@ -111,7 +111,7 @@ uint ObjectSpec::Index() const
/* static */ void ObjectSpec::BindToClasses()
{
for (auto &spec : _object_specs) {
if (spec.IsEnabled() && spec.cls_id != INVALID_OBJECT_CLASS) {
if (spec.IsEnabled() && spec.class_index != INVALID_OBJECT_CLASS) {
ObjectClass::Assign(&spec);
}
}
@@ -132,8 +132,8 @@ void ResetObjects()
}
/* Set class for originals. */
_object_specs[OBJECT_LIGHTHOUSE].cls_id = ObjectClass::Allocate('LTHS');
_object_specs[OBJECT_TRANSMITTER].cls_id = ObjectClass::Allocate('TRNS');
_object_specs[OBJECT_LIGHTHOUSE].class_index = ObjectClass::Allocate('LTHS');
_object_specs[OBJECT_TRANSMITTER].class_index = ObjectClass::Allocate('TRNS');
}
template <>