Barebones entity component commit events
Conflicts: src/GameWorld.cpp
This commit is contained in:
@@ -16,6 +16,7 @@ void GameWorld::Initialize()
|
||||
cameraComp->FarClip = 2000.f;
|
||||
AddComponent(camera, "Input");
|
||||
auto freeSteering = AddComponent<Components::FreeSteering>(camera, "FreeSteering");
|
||||
CommitEntity(camera);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +36,8 @@ void GameWorld::Initialize()
|
||||
auto physics = AddComponent<Components::Physics>(ground, "Physics");
|
||||
physics->Mass = 10;
|
||||
physics->Static = true;
|
||||
|
||||
CommitEntity(ground);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,6 +69,7 @@ void GameWorld::Initialize()
|
||||
Wheel->Mass = 10;
|
||||
Wheel->Radius = 0.6f;
|
||||
Wheel->Steering = true;
|
||||
CommitEntity(ent);
|
||||
}
|
||||
{
|
||||
// Front Left Wheel
|
||||
@@ -78,6 +82,7 @@ void GameWorld::Initialize()
|
||||
Wheel->Mass = 10;
|
||||
Wheel->Radius = 0.6f;
|
||||
Wheel->Steering = true;
|
||||
CommitEntity(ent);
|
||||
}
|
||||
{
|
||||
// Back Right Wheel
|
||||
@@ -90,6 +95,7 @@ void GameWorld::Initialize()
|
||||
Wheel->Mass = 10;
|
||||
Wheel->Radius = 0.6f;
|
||||
Wheel->Steering = false;
|
||||
CommitEntity(ent);
|
||||
}
|
||||
{
|
||||
// Back Left Wheel
|
||||
@@ -102,8 +108,10 @@ void GameWorld::Initialize()
|
||||
Wheel->Mass = 10;
|
||||
Wheel->Radius = 0.6f;
|
||||
Wheel->Steering = false;
|
||||
CommitEntity(ent);
|
||||
}
|
||||
|
||||
CommitEntity(car);
|
||||
}
|
||||
|
||||
|
||||
@@ -123,6 +131,7 @@ void GameWorld::Initialize()
|
||||
box->Width = 5.f;
|
||||
box->Height = 5.f;
|
||||
box->Depth = 5.f;
|
||||
CommitEntity(ball);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -132,6 +141,7 @@ void GameWorld::Initialize()
|
||||
emitter->Path = "Sounds/korvring.wav";
|
||||
emitter->Loop = true;
|
||||
GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(emitter);
|
||||
CommitEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ public:
|
||||
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
|
||||
virtual void OnEntityCommit(EntityID entity) { }
|
||||
|
||||
protected:
|
||||
World* m_World;
|
||||
|
||||
@@ -147,6 +147,15 @@ std::shared_ptr<Component> World::AddComponent(EntityID entity, std::string comp
|
||||
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)
|
||||
{
|
||||
m_Systems[systemType] = std::shared_ptr<System>(m_SystemFactory.Create(systemType));
|
||||
|
||||
@@ -64,6 +64,8 @@ public:
|
||||
std::shared_ptr<Component> AddComponent(EntityID entity, std::string componentType);
|
||||
template <class T>
|
||||
T* GetComponent(EntityID entity, std::string componentType);
|
||||
// Triggers commit events in systems
|
||||
void CommitEntity(EntityID entity);
|
||||
|
||||
/*std::vector<EntityID> GetEntityChildren(EntityID entity);*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user