diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 62e3980..d3b9aad 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -20,6 +20,7 @@ void GameWorld::Initialize() cameraComp->FarClip = 2000.f; AddComponent(camera, "Input"); auto freeSteering = AddComponent(camera, "FreeSteering"); + CommitEntity(camera); } @@ -38,6 +39,7 @@ void GameWorld::Initialize() auto physics = AddComponent(ground, "Physics"); physics->Mass = 10; + CommitEntity(ground); } { @@ -47,6 +49,7 @@ void GameWorld::Initialize() auto model = AddComponent(TankTest, "Model"); model->ModelFile = "Models/Placeholders/tank/Chassi.obj"; + CommitEntity(TankTest); } for(int i = 0; i < 83; i++) @@ -65,6 +68,7 @@ void GameWorld::Initialize() auto model = AddComponent(light, "Model"); model->ModelFile = "Models/Placeholders/PhysicsTest/PointLight.obj"; + CommitEntity(light); } for(int i = 0; i < 500; i++) @@ -80,6 +84,7 @@ void GameWorld::Initialize() sphere->Radius = 0.5; auto physics = AddComponent(ball, "Physics"); physics->Mass = 1; + CommitEntity(ball); } /*{ diff --git a/src/System.h b/src/System.h index 0cd3cc7..ff76450 100755 --- a/src/System.h +++ b/src/System.h @@ -28,6 +28,8 @@ public: 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 + virtual void OnEntityCommit(EntityID entity) { } protected: World* m_World; diff --git a/src/World.cpp b/src/World.cpp index 78b297d..0b6a245 100755 --- a/src/World.cpp +++ b/src/World.cpp @@ -148,6 +148,15 @@ std::shared_ptr World::AddComponent(EntityID entity, std::string comp return AddComponent(entity, componentType); } +void World::CommitEntity(EntityID entity) +{ + for (auto pair : m_Systems) + { + auto system = pair.second; + system->OnEntityCommit(entity); + } +} + void World::AddSystem(std::string systemType) { m_Systems[systemType] = std::shared_ptr(m_SystemFactory.Create(systemType)); diff --git a/src/World.h b/src/World.h index 9deeab9..255ef1b 100755 --- a/src/World.h +++ b/src/World.h @@ -63,6 +63,8 @@ public: std::shared_ptr AddComponent(EntityID entity, std::string componentType); template T* GetComponent(EntityID entity, std::string componentType); + // Triggers commit events in systems + void CommitEntity(EntityID entity); /*std::vector GetEntityChildren(EntityID entity);*/