Barebones entity component commit events
This commit is contained in:
@@ -20,6 +20,7 @@ void GameWorld::Initialize()
|
||||
cameraComp->FarClip = 2000.f;
|
||||
AddComponent(camera, "Input");
|
||||
auto freeSteering = AddComponent<Components::FreeSteering>(camera, "FreeSteering");
|
||||
CommitEntity(camera);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +39,7 @@ void GameWorld::Initialize()
|
||||
|
||||
auto physics = AddComponent<Components::Physics>(ground, "Physics");
|
||||
physics->Mass = 10;
|
||||
CommitEntity(ground);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -47,6 +49,7 @@ void GameWorld::Initialize()
|
||||
|
||||
auto model = AddComponent<Components::Model>(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<Components::Model>(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<Components::Physics>(ball, "Physics");
|
||||
physics->Mass = 1;
|
||||
CommitEntity(ball);
|
||||
}
|
||||
|
||||
/*{
|
||||
|
||||
@@ -28,6 +28,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;
|
||||
|
||||
@@ -148,6 +148,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));
|
||||
|
||||
@@ -63,6 +63,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