Changeset - r27035:b10b476e56e4
[Not reviewed]
master
0 4 0
Peter Nelson - 17 months ago 2023-01-16 23:31:31
peter1138@openttd.org
Codechange: Bind objectspecs to classes once all finalised.
4 files changed with 22 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/newgrf.cpp
Show inline comments
 
@@ -9518,6 +9518,8 @@ static void FinaliseObjectsArray()
 
			}
 
		}
 
	}
 

	
 
	ObjectSpec::BindToClasses();
 
}
 

	
 
/**
src/newgrf_commons.cpp
Show inline comments
 
@@ -316,7 +316,6 @@ void ObjectOverrideManager::SetEntitySpe
 

	
 
	/* Now that we know we can use the given id, copy the spec to its final destination. */
 
	memcpy(&_object_specs[type], spec, sizeof(*spec));
 
	ObjectClass::Assign(&_object_specs[type]);
 
}
 

	
 
/**
src/newgrf_object.cpp
Show inline comments
 
@@ -90,6 +90,18 @@ uint ObjectSpec::Index() const
 
	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. */
 
void ResetObjects()
 
{
 
@@ -104,20 +116,17 @@ void ResetObjects()
 
	for (uint16 i = 0; i < lengthof(_original_objects); 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>
 
/* static */ void NewGRFClass<Tspec, Tid, Tmax>::InsertDefaults()
 
{
 
	ObjectClassID cls = ObjectClass::Allocate('LTHS');
 
	ObjectClass::Get(cls)->name = STR_OBJECT_CLASS_LTHS;
 
	_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]);
 
	ObjectClass::Get(ObjectClass::Allocate('LTHS'))->name = STR_OBJECT_CLASS_LTHS;
 
	ObjectClass::Get(ObjectClass::Allocate('TRNS'))->name = STR_OBJECT_CLASS_TRNS;
 
}
 

	
 
template <typename Tspec, typename Tid, Tid Tmax>
src/newgrf_object.h
Show inline comments
 
@@ -101,6 +101,8 @@ struct ObjectSpec {
 

	
 
	static const ObjectSpec *Get(ObjectType index);
 
	static const ObjectSpec *GetByTile(TileIndex tile);
 

	
 
	static void BindToClasses();
 
};
 

	
 
/** Object scope resolver. */
0 comments (0 inline, 0 general)