Barebones entity component commit events

Conflicts:
	src/GameWorld.cpp
This commit is contained in:
ViktorLjung
2014-04-22 17:18:54 +02:00
parent 4481c95681
commit f0b2f2a659
4 changed files with 23 additions and 0 deletions
+10
View File
@@ -16,6 +16,7 @@ void GameWorld::Initialize()
cameraComp->FarClip = 2000.f; cameraComp->FarClip = 2000.f;
AddComponent(camera, "Input"); AddComponent(camera, "Input");
auto freeSteering = AddComponent<Components::FreeSteering>(camera, "FreeSteering"); auto freeSteering = AddComponent<Components::FreeSteering>(camera, "FreeSteering");
CommitEntity(camera);
} }
@@ -35,6 +36,8 @@ void GameWorld::Initialize()
auto physics = AddComponent<Components::Physics>(ground, "Physics"); auto physics = AddComponent<Components::Physics>(ground, "Physics");
physics->Mass = 10; physics->Mass = 10;
physics->Static = true; physics->Static = true;
CommitEntity(ground);
} }
@@ -66,6 +69,7 @@ void GameWorld::Initialize()
Wheel->Mass = 10; Wheel->Mass = 10;
Wheel->Radius = 0.6f; Wheel->Radius = 0.6f;
Wheel->Steering = true; Wheel->Steering = true;
CommitEntity(ent);
} }
{ {
// Front Left Wheel // Front Left Wheel
@@ -78,6 +82,7 @@ void GameWorld::Initialize()
Wheel->Mass = 10; Wheel->Mass = 10;
Wheel->Radius = 0.6f; Wheel->Radius = 0.6f;
Wheel->Steering = true; Wheel->Steering = true;
CommitEntity(ent);
} }
{ {
// Back Right Wheel // Back Right Wheel
@@ -90,6 +95,7 @@ void GameWorld::Initialize()
Wheel->Mass = 10; Wheel->Mass = 10;
Wheel->Radius = 0.6f; Wheel->Radius = 0.6f;
Wheel->Steering = false; Wheel->Steering = false;
CommitEntity(ent);
} }
{ {
// Back Left Wheel // Back Left Wheel
@@ -102,8 +108,10 @@ void GameWorld::Initialize()
Wheel->Mass = 10; Wheel->Mass = 10;
Wheel->Radius = 0.6f; Wheel->Radius = 0.6f;
Wheel->Steering = false; Wheel->Steering = false;
CommitEntity(ent);
} }
CommitEntity(car);
} }
@@ -123,6 +131,7 @@ void GameWorld::Initialize()
box->Width = 5.f; box->Width = 5.f;
box->Height = 5.f; box->Height = 5.f;
box->Depth = 5.f; box->Depth = 5.f;
CommitEntity(ball);
} }
{ {
@@ -132,6 +141,7 @@ void GameWorld::Initialize()
emitter->Path = "Sounds/korvring.wav"; emitter->Path = "Sounds/korvring.wav";
emitter->Loop = true; emitter->Loop = true;
GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(emitter); GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(emitter);
CommitEntity(entity);
} }
} }
+2
View File
@@ -24,6 +24,8 @@ public:
virtual void OnComponentCreated(std::string type, std::shared_ptr<Component> component) { } virtual void OnComponentCreated(std::string type, std::shared_ptr<Component> component) { }
// Called when a component is removed // Called when a component is removed
virtual void OnComponentRemoved(std::string type, Component* component) { } virtual void OnComponentRemoved(std::string type, Component* component) { }
// Called when components are committed to an entity
virtual void OnEntityCommit(EntityID entity) { }
protected: protected:
World* m_World; World* m_World;
+9
View File
@@ -147,6 +147,15 @@ std::shared_ptr<Component> World::AddComponent(EntityID entity, std::string comp
return AddComponent<Component>(entity, componentType); return AddComponent<Component>(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) void World::AddSystem(std::string systemType)
{ {
m_Systems[systemType] = std::shared_ptr<System>(m_SystemFactory.Create(systemType)); m_Systems[systemType] = std::shared_ptr<System>(m_SystemFactory.Create(systemType));
+2
View File
@@ -64,6 +64,8 @@ public:
std::shared_ptr<Component> AddComponent(EntityID entity, std::string componentType); std::shared_ptr<Component> AddComponent(EntityID entity, std::string componentType);
template <class T> template <class T>
T* GetComponent(EntityID entity, std::string componentType); T* GetComponent(EntityID entity, std::string componentType);
// Triggers commit events in systems
void CommitEntity(EntityID entity);
/*std::vector<EntityID> GetEntityChildren(EntityID entity);*/ /*std::vector<EntityID> GetEntityChildren(EntityID entity);*/