SystemFactory for dynamic creation and fetching of systems in a world.

This commit is contained in:
2014-03-09 03:37:39 +01:00
parent f767cdbc9c
commit c952953787
15 changed files with 218 additions and 100 deletions
+21 -16
View File
@@ -23,7 +23,7 @@ void World::RecursiveUpdate(std::shared_ptr<System> system, double dt, EntityID
EntityID parent = pair.second;
if (parent == parentEntity) {
system->Update(dt, child, parent);
system->UpdateEntity(dt, child, parent);
RecursiveUpdate(system, dt, child);
}
}
@@ -31,17 +31,13 @@ void World::RecursiveUpdate(std::shared_ptr<System> system, double dt, EntityID
void World::Update(double dt)
{
for (auto system : m_Systems) {
for (auto pair : m_Systems) {
auto system = pair.second;
system->Update(dt);
RecursiveUpdate(system, dt, 0);
}
}
void World::AddSystem(System* system)
{
}
//std::vector<EntityID> GetEntityChildren(EntityID entity);
//{
// std::vector<EntityID> children;
@@ -83,21 +79,30 @@ World::~World()
World::World()
{
m_LastEntityID = 0;
m_Systems.push_back(std::make_shared<Systems::Collision>(this));
RegisterComponents();
RegisterSystems();
}
void World::RegisterComponents()
void World::Initialize()
{
m_ComponentFactory.Register("Transform", []() { return new Components::Transform(); });
m_ComponentFactory.Register("Input", []() { return new Components::Input(); });
m_ComponentFactory.Register("DirectionalLight", []() { return new Components::DirectionalLight(); });
RegisterSystems();
RegisterComponents();
}
void World::RegisterSystems()
{
}
void World::RegisterComponents()
{
}
std::shared_ptr<Component> World::AddComponent(EntityID entity, std::string componentType)
{
return AddComponent<Component>(entity, componentType);
}
void World::AddSystem(std::string systemType)
{
m_Systems[systemType] = std::shared_ptr<System>(m_SystemFactory.Create(systemType));
}