فهرست منبع

Refactor scene a bit

Panagiotis Christopoulos Charitos 8 سال پیش
والد
کامیت
cbeac82df6

+ 3 - 8
src/anki/scene/BodyNode.cpp

@@ -49,8 +49,6 @@ BodyNode::~BodyNode()
 
 Error BodyNode::init(const CString& resourceFname)
 {
-	SceneComponent* comp;
-
 	// Load resource
 	ANKI_CHECK(getResourceManager().loadResource(resourceFname, m_rsrc));
 
@@ -61,16 +59,13 @@ Error BodyNode::init(const CString& resourceFname)
 	m_body = getSceneGraph().getPhysicsWorld().newInstance<PhysicsBody>(init);
 
 	// Body component
-	comp = getSceneAllocator().newInstance<BodyComponent>(this, m_body);
-	addComponent(comp, true);
+	newComponent<BodyComponent>(this, m_body);
 
 	// Feedback component
-	comp = getSceneAllocator().newInstance<BodyFeedbackComponent>(this);
-	addComponent(comp, true);
+	newComponent<BodyFeedbackComponent>(this);
 
 	// Move component
-	comp = getSceneAllocator().newInstance<MoveComponent>(this);
-	addComponent(comp, true);
+	newComponent<MoveComponent>(this);
 
 	return ErrorCode::NONE;
 }

+ 5 - 12
src/anki/scene/Camera.cpp

@@ -64,18 +64,14 @@ Camera::Camera(SceneGraph* scene, Type type, CString name)
 
 Error Camera::init(Frustum* frustum)
 {
-	SceneComponent* comp;
-
 	// Move component
-	comp = getSceneAllocator().newInstance<MoveComponent>(this);
-	addComponent(comp, true);
+	newComponent<MoveComponent>(this);
 
 	// Feedback component
-	comp = getSceneAllocator().newInstance<CameraMoveFeedbackComponent>(this);
-	addComponent(comp, true);
+	newComponent<CameraMoveFeedbackComponent>(this);
 
 	// Frustum component
-	FrustumComponent* frc = getSceneAllocator().newInstance<FrustumComponent>(this, frustum);
+	FrustumComponent* frc = newComponent<FrustumComponent>(this, frustum);
 	frc->setEnabledVisibilityTests(FrustumComponentVisibilityTestFlag::RENDER_COMPONENTS
 		| FrustumComponentVisibilityTestFlag::LIGHT_COMPONENTS
 		| FrustumComponentVisibilityTestFlag::LENS_FLARE_COMPONENTS
@@ -83,15 +79,12 @@ Error Camera::init(Frustum* frustum)
 		| FrustumComponentVisibilityTestFlag::REFLECTION_PROXIES
 		| FrustumComponentVisibilityTestFlag::OCCLUDERS
 		| FrustumComponentVisibilityTestFlag::DECALS);
-	addComponent(frc, true);
 
 	// Feedback component #2
-	comp = getSceneAllocator().newInstance<CameraFrustumFeedbackComponent>(this);
-	addComponent(comp, true);
+	newComponent<CameraFrustumFeedbackComponent>(this);
 
 	// Spatial component
-	comp = getSceneAllocator().newInstance<SpatialComponent>(this, frustum);
-	addComponent(comp, true);
+	newComponent<SpatialComponent>(this, frustum);
 
 	return ErrorCode::NONE;
 }

+ 5 - 16
src/anki/scene/DecalNode.cpp

@@ -65,22 +65,11 @@ DecalNode::~DecalNode()
 
 Error DecalNode::init()
 {
-	SceneComponent* comp;
-
-	comp = getSceneAllocator().newInstance<MoveComponent>(this);
-	addComponent(comp, true);
-
-	comp = getSceneAllocator().newInstance<DecalMoveFeedbackComponent>(this);
-	addComponent(comp, true);
-
-	comp = getSceneAllocator().newInstance<DecalComponent>(this);
-	addComponent(comp, true);
-
-	comp = getSceneAllocator().newInstance<DecalShapeFeedbackComponent>(this);
-	addComponent(comp, true);
-
-	comp = getSceneAllocator().newInstance<SpatialComponent>(this, &m_obbW);
-	addComponent(comp, true);
+	newComponent<MoveComponent>(this);
+	newComponent<DecalMoveFeedbackComponent>(this);
+	newComponent<DecalComponent>(this);
+	newComponent<DecalShapeFeedbackComponent>(this);
+	newComponent<SpatialComponent>(this, &m_obbW);
 
 	return ErrorCode::NONE;
 }

+ 7 - 20
src/anki/scene/Light.cpp

@@ -55,23 +55,17 @@ Light::~Light()
 
 Error Light::init(LightComponentType type, CollisionShape* shape)
 {
-	SceneComponent* comp;
-
 	// Move component
-	comp = getSceneAllocator().newInstance<MoveComponent>(this);
-	addComponent(comp, true);
+	newComponent<MoveComponent>(this);
 
 	// Light component
-	comp = getSceneAllocator().newInstance<LightComponent>(this, type);
-	addComponent(comp, true);
+	newComponent<LightComponent>(this, type);
 
 	// Feedback component
-	comp = getSceneAllocator().newInstance<LightFeedbackComponent>(this);
-	addComponent(comp, true);
+	newComponent<LightFeedbackComponent>(this);
 
 	// Spatial component
-	comp = getSceneAllocator().newInstance<SpatialComponent>(this, shape);
-	addComponent(comp, true);
+	newComponent<SpatialComponent>(this, shape);
 
 	return ErrorCode::NONE;
 }
@@ -131,7 +125,7 @@ Error Light::loadLensFlare(const CString& filename)
 {
 	ANKI_ASSERT(tryGetComponent<LensFlareComponent>() == nullptr);
 
-	LensFlareComponent* flareComp = getSceneAllocator().newInstance<LensFlareComponent>(this);
+	LensFlareComponent* flareComp = newComponent<LensFlareComponent>(this);
 
 	Error err = flareComp->init(filename);
 	if(err)
@@ -140,8 +134,6 @@ Error Light::loadLensFlare(const CString& filename)
 		return err;
 	}
 
-	addComponent(flareComp, true);
-
 	return ErrorCode::NONE;
 }
 
@@ -228,10 +220,7 @@ Error PointLight::frameUpdate(F32 prevUpdateTime, F32 crntTime)
 			trf.setOrigin(origin);
 			m_shadowData[i].m_frustum.resetTransform(trf);
 
-			FrustumComponent* comp =
-				getSceneAllocator().newInstance<FrustumComponent>(this, &m_shadowData[i].m_frustum);
-
-			addComponent(comp, true);
+			newComponent<FrustumComponent>(this, &m_shadowData[i].m_frustum);
 		}
 	}
 
@@ -249,11 +238,9 @@ Error SpotLight::init()
 {
 	ANKI_CHECK(Light::init(LightComponentType::SPOT, &m_frustum));
 
-	FrustumComponent* fr = getSceneAllocator().newInstance<FrustumComponent>(this, &m_frustum);
+	FrustumComponent* fr = newComponent<FrustumComponent>(this, &m_frustum);
 	fr->setEnabledVisibilityTests(FrustumComponentVisibilityTestFlag::NONE);
 
-	addComponent(fr, true);
-
 	return ErrorCode::NONE;
 }
 

+ 4 - 13
src/anki/scene/ModelNode.cpp

@@ -51,15 +51,10 @@ Error ModelPatchNode::init(const ModelPatch* modelPatch)
 	m_modelPatch = modelPatch;
 
 	// Spatial component
-	SceneComponent* comp = getSceneAllocator().newInstance<SpatialComponent>(this, &m_obb);
-
-	addComponent(comp, true);
+	newComponent<SpatialComponent>(this, &m_obb);
 
 	// Render component
-	RenderComponent* rcomp = getSceneAllocator().newInstance<ModelPatchRenderComponent>(this);
-	comp = rcomp;
-
-	addComponent(comp, true);
+	RenderComponent* rcomp = newComponent<ModelPatchRenderComponent>(this);
 	ANKI_CHECK(rcomp->init());
 
 	return ErrorCode::NONE;
@@ -138,8 +133,6 @@ ModelNode::~ModelNode()
 
 Error ModelNode::init(const CString& modelFname)
 {
-	SceneComponent* comp;
-
 	ANKI_CHECK(getResourceManager().loadResource(modelFname, m_model));
 
 	m_modelPatches.create(getSceneAllocator(), m_model->getModelPatches().getSize(), nullptr);
@@ -158,12 +151,10 @@ Error ModelNode::init(const CString& modelFname)
 	}
 
 	// Move component
-	comp = getSceneAllocator().newInstance<MoveComponent>(this);
-	addComponent(comp, true);
+	newComponent<MoveComponent>(this);
 
 	// Feedback component
-	comp = getSceneAllocator().newInstance<ModelMoveFeedbackComponent>(this);
-	addComponent(comp, true);
+	newComponent<ModelMoveFeedbackComponent>(this);
 
 	return ErrorCode::NONE;
 }

+ 3 - 8
src/anki/scene/OccluderNode.cpp

@@ -63,14 +63,9 @@ Error OccluderNode::init(const CString& meshFname)
 	}
 
 	// Create the components
-	SceneComponent* comp = getSceneAllocator().newInstance<MoveComponent>(this);
-	addComponent(comp, true);
-
-	comp = getSceneAllocator().newInstance<OccluderMoveFeedbackComponent>(this);
-	addComponent(comp, true);
-
-	comp = getSceneAllocator().newInstance<OccluderComponent>(this);
-	addComponent(comp, true);
+	newComponent<MoveComponent>(this);
+	newComponent<OccluderMoveFeedbackComponent>(this);
+	newComponent<OccluderComponent>(this);
 
 	return ErrorCode::NONE;
 }

+ 4 - 12
src/anki/scene/ParticleEmitter.cpp

@@ -224,29 +224,21 @@ ParticleEmitter::~ParticleEmitter()
 
 Error ParticleEmitter::init(const CString& filename)
 {
-	SceneComponent* comp;
-
 	// Load resource
 	ANKI_CHECK(getResourceManager().loadResource(filename, m_particleEmitterResource));
 
 	// Move component
-	comp = getSceneAllocator().newInstance<MoveComponent>(this);
-	addComponent(comp, true);
+	newComponent<MoveComponent>(this);
 
 	// Move component feedback
-	comp = getSceneAllocator().newInstance<MoveFeedbackComponent>(this);
-	addComponent(comp, true);
+	newComponent<MoveFeedbackComponent>(this);
 
 	// Spatial component
-	comp = getSceneAllocator().newInstance<SpatialComponent>(this, &m_obb);
-	addComponent(comp, true);
+	newComponent<SpatialComponent>(this, &m_obb);
 
 	// Render component
-	ParticleEmitterRenderComponent* rcomp = getSceneAllocator().newInstance<ParticleEmitterRenderComponent>(this);
-
+	ParticleEmitterRenderComponent* rcomp = newComponent<ParticleEmitterRenderComponent>(this);
 	ANKI_CHECK(rcomp->init());
-	comp = rcomp;
-	addComponent(comp, true);
 
 	// Other
 	m_obb.setCenter(Vec4(0.0));

+ 4 - 10
src/anki/scene/PlayerNode.cpp

@@ -126,23 +126,17 @@ Error PlayerNode::init(const Vec4& position)
 	init.m_position = position;
 	m_player = getSceneGraph().getPhysicsWorld().newInstance<PhysicsPlayerController>(init);
 
-	SceneComponent* comp;
-
 	// Player controller component
-	comp = getSceneAllocator().newInstance<PlayerControllerComponent>(this, m_player);
-	addComponent(comp, true);
+	newComponent<PlayerControllerComponent>(this, m_player);
 
 	// Feedback component
-	comp = getSceneAllocator().newInstance<PlayerNodeFeedbackComponent>(this);
-	addComponent(comp, true);
+	newComponent<PlayerNodeFeedbackComponent>(this);
 
 	// Move component
-	comp = getSceneAllocator().newInstance<MoveComponent>(this);
-	addComponent(comp, true);
+	newComponent<MoveComponent>(this);
 
 	// Feedback component #2
-	comp = getSceneAllocator().newInstance<PlayerNodeFeedbackComponent2>(this);
-	addComponent(comp, true);
+	newComponent<PlayerNodeFeedbackComponent2>(this);
 
 	return ErrorCode::NONE;
 }

+ 5 - 13
src/anki/scene/ReflectionProbe.cpp

@@ -48,15 +48,11 @@ ReflectionProbe::~ReflectionProbe()
 
 Error ReflectionProbe::init(F32 radius)
 {
-	SceneComponent* comp;
-
 	// Move component first
-	comp = getSceneAllocator().newInstance<MoveComponent>(this);
-	addComponent(comp, true);
+	newComponent<MoveComponent>(this);
 
 	// Feedback component
-	comp = getSceneAllocator().newInstance<ReflectionProbeMoveFeedbackComponent>(this);
-	addComponent(comp, true);
+	newComponent<ReflectionProbeMoveFeedbackComponent>(this);
 
 	// The frustum components
 	const F32 ang = toRad(90.0);
@@ -85,23 +81,19 @@ Error ReflectionProbe::init(F32 radius)
 		m_cubeSides[i].m_frustum.setAll(ang, ang, zNear, EFFECTIVE_DISTANCE);
 		m_cubeSides[i].m_frustum.resetTransform(m_cubeSides[i].m_localTrf);
 
-		FrustumComponent* frc = getSceneAllocator().newInstance<FrustumComponent>(this, &m_cubeSides[i].m_frustum);
+		FrustumComponent* frc = newComponent<FrustumComponent>(this, &m_cubeSides[i].m_frustum);
 
 		frc->setEnabledVisibilityTests(FrustumComponentVisibilityTestFlag::NONE);
-
-		addComponent(frc, true);
 	}
 
 	// Spatial component
 	m_spatialSphere.setCenter(Vec4(0.0));
 	m_spatialSphere.setRadius(radius);
-	comp = getSceneAllocator().newInstance<SpatialComponent>(this, &m_spatialSphere);
-	addComponent(comp, true);
+	newComponent<SpatialComponent>(this, &m_spatialSphere);
 
 	// Reflection probe comp
-	ReflectionProbeComponent* reflc = getSceneAllocator().newInstance<ReflectionProbeComponent>(this);
+	ReflectionProbeComponent* reflc = newComponent<ReflectionProbeComponent>(this);
 	reflc->setRadius(radius);
-	addComponent(reflc, true);
 
 	return ErrorCode::NONE;
 }

+ 4 - 8
src/anki/scene/ReflectionProxy.cpp

@@ -40,12 +40,10 @@ public:
 Error ReflectionProxy::init(const CString& proxyMesh)
 {
 	// Move component first
-	SceneComponent* comp = getSceneAllocator().newInstance<MoveComponent>(this);
-	addComponent(comp, true);
+	newComponent<MoveComponent>(this);
 
 	// Feedback component
-	comp = getSceneAllocator().newInstance<ReflectionProxyMoveFeedbackComponent>(this);
-	addComponent(comp, true);
+	newComponent<ReflectionProxyMoveFeedbackComponent>(this);
 
 	// Load vertices
 	MeshLoader loader(&getResourceManager());
@@ -81,8 +79,7 @@ Error ReflectionProxy::init(const CString& proxyMesh)
 	}
 
 	// Proxy component
-	comp = getSceneAllocator().newInstance<ReflectionProxyComponent>(this, quadCount);
-	addComponent(comp, true);
+	newComponent<ReflectionProxyComponent>(this, quadCount);
 
 	// Spatial component
 	m_boxLSpace.setFromPointCloud(loader.getVertexData(),
@@ -92,8 +89,7 @@ Error ReflectionProxy::init(const CString& proxyMesh)
 
 	m_boxWSpace = m_boxLSpace;
 
-	comp = getSceneAllocator().newInstance<SpatialComponent>(this, &m_boxWSpace);
-	addComponent(comp, true);
+	newComponent<SpatialComponent>(this, &m_boxWSpace);
 
 	return ErrorCode::NONE;
 }

+ 10 - 26
src/anki/scene/SceneComponent.cpp

@@ -14,12 +14,18 @@ SceneComponent::SceneComponent(SceneComponentType type, SceneNode* node)
 	: m_node(node)
 	, m_type(type)
 {
-	m_node->getSceneGraph().getSceneComponentLists().insertNew(this);
+	if(m_type != SceneComponentType::NONE)
+	{
+		m_node->getSceneGraph().getSceneComponentLists().insertNew(this);
+	}
 }
 
 SceneComponent::~SceneComponent()
 {
-	m_node->getSceneGraph().getSceneComponentLists().remove(this);
+	if(m_type != SceneComponentType::NONE)
+	{
+		m_node->getSceneGraph().getSceneComponentLists().remove(this);
+	}
 }
 
 Timestamp SceneComponent::getGlobalTimestamp() const
@@ -61,37 +67,15 @@ SceneAllocator<U8> SceneComponent::getAllocator() const
 void SceneComponentLists::insertNew(SceneComponent* comp)
 {
 	ANKI_ASSERT(comp);
-	ANKI_ASSERT(find(comp) == m_lists[comp->getType()].getEnd());
 
-	m_lists[comp->getType()].pushBack(m_alloc, comp);
+	m_lists[comp->getType()].pushBack(comp);
 }
 
 void SceneComponentLists::remove(SceneComponent* comp)
 {
 	ANKI_ASSERT(comp);
 
-	auto it = find(comp);
-	ANKI_ASSERT(it != m_lists[comp->getType()].getEnd());
-	m_lists[comp->getType()].erase(m_alloc, it);
-}
-
-List<SceneComponent*>::Iterator SceneComponentLists::find(SceneComponent* comp)
-{
-	ANKI_ASSERT(comp);
-
-	List<SceneComponent*>& list = m_lists[comp->getType()];
-	auto it = list.getBegin();
-	auto end = list.getEnd();
-	while(it != end)
-	{
-		if(*it == comp)
-		{
-			break;
-		}
-		++it;
-	}
-
-	return it;
+	m_lists[comp->getType()].erase(comp);
 }
 
 } // end namespace anki

+ 3 - 27
src/anki/scene/SceneComponent.h

@@ -41,7 +41,7 @@ enum class SceneComponentType : U16
 };
 
 /// Scene node component
-class SceneComponent
+class SceneComponent : public IntrusiveListEnabled<SceneComponent>
 {
 public:
 	/// Construct the scene component.
@@ -81,16 +81,6 @@ public:
 	/// Called only by the SceneGraph
 	ANKI_USE_RESULT Error updateReal(SceneNode& node, F32 prevTime, F32 crntTime, Bool& updated);
 
-	void setAutomaticCleanup(Bool enable)
-	{
-		m_flags.set(AUTOMATIC_CLEANUP, enable);
-	}
-
-	Bool getAutomaticCleanup() const
-	{
-		return m_flags.get(AUTOMATIC_CLEANUP);
-	}
-
 	SceneNode& getSceneNode()
 	{
 		return *m_node;
@@ -111,13 +101,7 @@ protected:
 	Timestamp m_timestamp; ///< Indicates when an update happened
 
 private:
-	enum Flags
-	{
-		AUTOMATIC_CLEANUP = 1 << 0
-	};
-
 	SceneComponentType m_type;
-	BitMask<U8> m_flags;
 };
 
 /// Multiple lists of all types of components.
@@ -132,11 +116,6 @@ anki_internal:
 	{
 	}
 
-	void init(SceneAllocator<U8> alloc)
-	{
-		m_alloc = alloc;
-	}
-
 	void insertNew(SceneComponent* comp);
 
 	void remove(SceneComponent* comp);
@@ -149,16 +128,13 @@ anki_internal:
 
 		while(it != end)
 		{
-			func(*static_cast<TSceneComponentType*>(*it));
+			func(static_cast<TSceneComponentType&>(*it));
 			++it;
 		}
 	}
 
 private:
-	SceneAllocator<U8> m_alloc;
-	Array<List<SceneComponent*>, U(SceneComponentType::COUNT)> m_lists;
-
-	List<SceneComponent*>::Iterator find(SceneComponent* comp);
+	Array<IntrusiveList<SceneComponent>, U(SceneComponentType::COUNT)> m_lists;
 };
 /// @}
 

+ 0 - 2
src/anki/scene/SceneGraph.cpp

@@ -90,8 +90,6 @@ Error SceneGraph::init(AllocAlignedCallback allocCb,
 
 	m_maxReflectionProxyDistance = config.getNumber("imageReflectionMaxDistance");
 
-	m_componentLists.init(m_alloc);
-
 	// Init the default main camera
 	ANKI_CHECK(newSceneNode<PerspectiveCamera>("mainCamera", m_defaultMainCam));
 	m_defaultMainCam->setAll(toRad(60.0), toRad(60.0), 0.1, 1000.0);

+ 1 - 32
src/anki/scene/SceneNode.cpp

@@ -28,10 +28,7 @@ SceneNode::~SceneNode()
 	for(; it != end; ++it)
 	{
 		SceneComponent* comp = *it;
-		if(comp->getAutomaticCleanup())
-		{
-			alloc.deleteInstance(comp);
-		}
+		alloc.deleteInstance(comp);
 	}
 
 	Base::destroy(alloc);
@@ -87,34 +84,6 @@ U32 SceneNode::getLastUpdateFrame() const
 	return max;
 }
 
-void SceneNode::addComponent(SceneComponent* comp, Bool transferOwnership)
-{
-	ANKI_ASSERT(comp);
-
-#if ANKI_EXTRA_CHECKS
-	Error err = iterateComponents([&](const SceneComponent& bcomp) -> Error {
-		ANKI_ASSERT(comp != &bcomp);
-		return ErrorCode::NONE;
-	});
-	(void)err;
-#endif
-
-	if(m_components.getSize() < m_componentsCount + 1u)
-	{
-		// Not enough room
-		const U extra = 2;
-		m_components.resize(getSceneAllocator(), m_componentsCount + 1 + extra);
-	}
-
-	m_components[m_componentsCount++] = comp;
-	comp->setAutomaticCleanup(transferOwnership);
-}
-
-void SceneNode::removeComponent(SceneComponent* comp)
-{
-	ANKI_ASSERT(0 && "TODO");
-}
-
 ResourceManager& SceneNode::getResourceManager()
 {
 	return m_scene->getResourceManager();

+ 15 - 4
src/anki/scene/SceneNode.h

@@ -194,11 +194,22 @@ public:
 	}
 
 protected:
-	/// Append a component to the components container. The SceneNode will not take ownership.
-	void addComponent(SceneComponent* comp, Bool transferOwnership = false);
+	/// Create and append a component to the components container. The SceneNode will not take ownership.
+	template<typename TComponent, typename... TArgs>
+	TComponent* newComponent(TArgs&&... args)
+	{
+		TComponent* comp = getSceneAllocator().newInstance<TComponent>(std::forward<TArgs>(args)...);
 
-	/// Remove a component from the container
-	void removeComponent(SceneComponent* comp);
+		if(m_components.getSize() <= m_componentsCount)
+		{
+			// Not enough room
+			const U extra = 2;
+			m_components.resize(getSceneAllocator(), max<PtrSize>(m_components.getSize() + extra, 1));
+		}
+
+		m_components[m_componentsCount++] = comp;
+		return comp;
+	}
 
 	ResourceManager& getResourceManager();
 

+ 3 - 5
src/anki/scene/Sector.cpp

@@ -58,19 +58,17 @@ PortalSectorBase::~PortalSectorBase()
 Error PortalSectorBase::init(const CString& meshFname, Bool isSector)
 {
 	// Create move component
-	SceneComponent* comp = getSceneAllocator().newInstance<MoveComponent>(this);
-	addComponent(comp, true);
+	newComponent<MoveComponent>(this);
 
 	// Create portal or sector component
 	if(isSector)
 	{
-		comp = getSceneAllocator().newInstance<SectorComponent>(this);
+		newComponent<SectorComponent>(this);
 	}
 	else
 	{
-		comp = getSceneAllocator().newInstance<PortalComponent>(this);
+		newComponent<PortalComponent>(this);
 	}
-	addComponent(comp, true);
 
 	// Load mesh
 	MeshLoader loader(&getSceneGraph().getResourceManager());

+ 2 - 7
src/anki/scene/StaticGeometryNode.cpp

@@ -47,18 +47,13 @@ Error StaticGeometryPatchNode::init(const ModelPatch* modelPatch)
 	// Create spatial components
 	for(U i = 1; i < m_modelPatch->getSubMeshesCount(); i++)
 	{
-		SpatialComponent* spatial =
-			getSceneAllocator().newInstance<SpatialComponent>(this, &m_modelPatch->getBoundingShapeSub(i));
-
-		addComponent(spatial, true);
+		SpatialComponent* spatial = newComponent<SpatialComponent>(this, &m_modelPatch->getBoundingShapeSub(i));
 
 		spatial->setSpatialOrigin(m_modelPatch->getBoundingShapeSub(i).getCenter());
-		spatial->setAutomaticCleanup(true);
 	}
 
 	// Create render component
-	RenderComponent* rcomp = getSceneAllocator().newInstance<StaticGeometryRenderComponent>(this);
-	addComponent(rcomp, true);
+	newComponent<StaticGeometryRenderComponent>(this);
 
 	return ErrorCode::NONE;
 }