OnComponentCreated nu eventbaserat
This commit is contained in:
@@ -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__
|
||||
@@ -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> component) { }
|
||||
// Called when a component is removed
|
||||
virtual void OnComponentRemoved(std::string type, Component* component) { }
|
||||
// Called when components are committed to an entity
|
||||
|
||||
@@ -493,11 +493,6 @@ void Systems::PhysicsSystem::TearDownPhysicsState(EntityID entity, EntityID pare
|
||||
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::OnComponentCreated(std::string type, std::shared_ptr<Component> component)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Systems::PhysicsSystem::OnComponentRemoved(std::string type, Component* component)
|
||||
{
|
||||
|
||||
|
||||
@@ -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> component) override;
|
||||
void OnComponentRemoved(std::string type, Component* component) override;
|
||||
void OnEntityCommit(EntityID entity) override;
|
||||
|
||||
|
||||
+5
-5
@@ -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 */)
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "Components/Template.h"
|
||||
#include "System.h"
|
||||
#include "EventBroker.h"
|
||||
#include "Events/ComponentCreated.h"
|
||||
#include "ResourceManager.h"
|
||||
|
||||
class World
|
||||
|
||||
@@ -164,6 +164,7 @@
|
||||
<ClInclude Include="..\..\src\Events\BindGamepadButton.h" />
|
||||
<ClInclude Include="..\..\src\Events\BindKey.h" />
|
||||
<ClInclude Include="..\..\src\Events\BindMouseButton.h" />
|
||||
<ClInclude Include="..\..\src\Events\ComponentCreated.h" />
|
||||
<ClInclude Include="..\..\src\Events\GamepadAxis.h" />
|
||||
<ClInclude Include="..\..\src\Events\GamepadButton.h" />
|
||||
<ClInclude Include="..\..\src\Events\InputCommand.h" />
|
||||
|
||||
@@ -158,6 +158,9 @@
|
||||
<Filter Include="Gameplay\Components">
|
||||
<UniqueIdentifier>{cb06b441-90b8-46ed-b347-4190dac7185b}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Base\Events">
|
||||
<UniqueIdentifier>{3cbe68d9-2446-45ee-8637-ffb805997dcd}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\World.h" />
|
||||
@@ -400,6 +403,9 @@
|
||||
<ClInclude Include="..\..\src\Components\Listener.h">
|
||||
<Filter>Audio\Components</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Events\ComponentCreated.h">
|
||||
<Filter>Base\Events</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\src\Shaders\Fragment2.glsl">
|
||||
|
||||
Reference in New Issue
Block a user