Browse Source

Minor work on components

Panagiotis Christopoulos Charitos 2 years ago
parent
commit
14fbcaefc5
2 changed files with 15 additions and 1 deletions
  1. 7 1
      AnKi/Scene/Components/SceneComponent.h
  2. 8 0
      AnKi/Scene/SceneNode.h

+ 7 - 1
AnKi/Scene/Components/SceneComponent.h

@@ -149,6 +149,12 @@ public:
 		return g_sceneComponentCallbacks.m_update[m_classId](*this, info, updated);
 	}
 
+	ANKI_INTERNAL void onOtherComponentRemovedOrAddedReal(SceneComponent* other, Bool added)
+	{
+		ANKI_ASSERT(other);
+		g_sceneComponentCallbacks.m_onOtherComponentRemovedOrAdded[m_classId](*this, other, added);
+	}
+
 	/// Don't call it directly.
 	ANKI_INTERNAL void setTimestamp(Timestamp timestamp)
 	{
@@ -175,7 +181,7 @@ protected:
 		return Error::kNone;
 	}
 
-	/// Called when a component is added or removed in the SceneNode.
+	/// Pseudo-virtual. Called when a component is added or removed in the SceneNode.
 	/// @param other The component that was inserted.
 	/// @param added Was it inserted or removed?
 	void onOtherComponentRemovedOrAdded([[maybe_unused]] SceneComponent* other, [[maybe_unused]] Bool added)

+ 8 - 0
AnKi/Scene/SceneNode.h

@@ -267,8 +267,16 @@ protected:
 	TComponent* newComponent()
 	{
 		TComponent* comp = newInstance<TComponent>(getMemoryPool(), this);
+
+		// Inform all other components that some component was added
+		for(SceneComponent* comp : m_components)
+		{
+			comp->onOtherComponentRemovedOrAddedReal(comp, true);
+		}
+
 		m_components.emplaceBack(getMemoryPool(), comp);
 		m_componentInfos.emplaceBack(getMemoryPool(), *comp);
+
 		return comp;
 	}