From 60c0f1d0988fc93e7b06da1863590d59250f04f1 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Fri, 7 Mar 2014 20:17:12 +0100 Subject: [PATCH] Added OnComponentCreated event for systems --- Escape-the-Dawn/System.h | 4 ++++ Escape-the-Dawn/World.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Escape-the-Dawn/System.h b/Escape-the-Dawn/System.h index f747476..3ad42db 100644 --- a/Escape-the-Dawn/System.h +++ b/Escape-the-Dawn/System.h @@ -2,6 +2,7 @@ #define System_h__ #include "Entity.h" +#include "Component.h" class World; @@ -16,6 +17,9 @@ public: // Called once for every entity in the world every tick virtual void Update(double dt, EntityID entity, EntityID parent) { } + // Called when a component is created + virtual void OnComponentCreated(std::string type, std:: shared_ptr component); + protected: World* m_World; }; diff --git a/Escape-the-Dawn/World.h b/Escape-the-Dawn/World.h index 874cee4..6d6b2a5 100644 --- a/Escape-the-Dawn/World.h +++ b/Escape-the-Dawn/World.h @@ -44,8 +44,12 @@ public: return nullptr; } + component->Entity = entity; m_ComponentsOfType[componentType].push_back(component); m_EntityComponents[entity][componentType] = component; + for (auto system : m_Systems) { + system->OnComponentCreated(componentType, component); + } return component; }