From 072e4d4dbb901d7a3f1966d8f9a5003e02ed800b Mon Sep 17 00:00:00 2001 From: Stiffly Date: Sun, 25 May 2014 04:01:40 +0200 Subject: [PATCH] OnComponentCreated nu eventbaserat --- src/Events/ComponentCreated.h | 19 +++++++++++++++++++ src/System.h | 2 -- src/Systems/PhysicsSystem.cpp | 5 ----- src/Systems/PhysicsSystem.h | 1 - src/World.cpp | 10 +++++----- src/World.h | 1 + vs11/Returngeance/Returngeance.vcxproj | 1 + .../Returngeance/Returngeance.vcxproj.filters | 6 ++++++ 8 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 src/Events/ComponentCreated.h diff --git a/src/Events/ComponentCreated.h b/src/Events/ComponentCreated.h new file mode 100644 index 0000000..a6848b6 --- /dev/null +++ b/src/Events/ComponentCreated.h @@ -0,0 +1,19 @@ +#ifndef Event_ComponentCreated_h__ +#define Event_ComponentCreated_h__ + +#include "EventBroker.h" +#include "Entity.h" +#include "Component.h" + +namespace Events +{ + +struct ComponentCreated : Event +{ + EntityID Entity; + std::shared_ptr<::Component> Component; +}; + +} + +#endif // Event_ComponentCreated_h__ diff --git a/src/System.h b/src/System.h index b40bdef..0e74150 100755 --- a/src/System.h +++ b/src/System.h @@ -27,8 +27,6 @@ public: // Called once for every entity in the world every tick virtual void UpdateEntity(double dt, EntityID entity, EntityID parent) { } - // Called when a component is created - virtual void OnComponentCreated(std::string type, std::shared_ptr component) { } // Called when a component is removed virtual void OnComponentRemoved(std::string type, Component* component) { } // Called when components are committed to an entity diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index 3c3c1f6..5280899 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -493,11 +493,6 @@ void Systems::PhysicsSystem::TearDownPhysicsState(EntityID entity, EntityID pare } -void Systems::PhysicsSystem::OnComponentCreated(std::string type, std::shared_ptr component) -{ - -} - void Systems::PhysicsSystem::OnComponentRemoved(std::string type, Component* component) { diff --git a/src/Systems/PhysicsSystem.h b/src/Systems/PhysicsSystem.h index 029dd8e..552c34d 100644 --- a/src/Systems/PhysicsSystem.h +++ b/src/Systems/PhysicsSystem.h @@ -104,7 +104,6 @@ public: void Update(double dt) override; void UpdateEntity(double dt, EntityID entity, EntityID parent) override; - void OnComponentCreated(std::string type, std::shared_ptr component) override; void OnComponentRemoved(std::string type, Component* component) override; void OnEntityCommit(EntityID entity) override; diff --git a/src/World.cpp b/src/World.cpp index fe1f760..e65a73d 100755 --- a/src/World.cpp +++ b/src/World.cpp @@ -148,11 +148,11 @@ void World::AddComponent(EntityID entity, std::string componentType, std::shared component->Entity = entity; m_ComponentsOfType[componentType].push_back(component); m_EntityComponents[entity][componentType] = component; - for (auto pair : m_Systems) - { - auto system = pair.second; - system->OnComponentCreated(componentType, component); - } + + Events::ComponentCreated e; + e.Entity = entity; + e.Component = component; + m_EventBroker->Publish(e); } EntityID World::CloneEntity(EntityID entity, EntityID parent /* = 0 */) diff --git a/src/World.h b/src/World.h index 87bfecf..67c3aae 100755 --- a/src/World.h +++ b/src/World.h @@ -16,6 +16,7 @@ #include "Components/Template.h" #include "System.h" #include "EventBroker.h" +#include "Events/ComponentCreated.h" #include "ResourceManager.h" class World diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index 233d7a3..01f9cb0 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -164,6 +164,7 @@ + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index d5029a1..fca9767 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -158,6 +158,9 @@ {cb06b441-90b8-46ed-b347-4190dac7185b} + + {3cbe68d9-2446-45ee-8637-ffb805997dcd} + @@ -400,6 +403,9 @@ Audio\Components + + Base\Events +