#ifndef World_h__ #define World_h__ #include #include #include #include #include "Entity.h" #include "Component.h" #include "ComponentFactory.h" #include "System.h" #include "Systems/CollisionSystem.h" class World { public: World(); ~World(); EntityID CreateEntity(EntityID parent = 0); void RemoveEntity(EntityID entity); bool ValidEntity(EntityID entity); EntityID GetEntityParent(EntityID entity); template std::shared_ptr AddComponent(EntityID entity, std::string componentType) { std::shared_ptr component = std::static_pointer_cast(ComponentFactory::Instance()->Create(componentType)); m_ComponentsOfType[componentType].push_back(component); m_EntityComponents[entity][componentType] = component; return component; } template std::shared_ptr GetComponent(EntityID entity, std::string componentType) { return std::static_pointer_cast(m_EntityComponents[entity][componentType]); } /*std::vector GetEntityChildren(EntityID entity);*/ void AddSystem(System* system); // Recursively update through the scene graph void Update(double dt); void RecursiveUpdate(std::shared_ptr system, double dt, EntityID parentEntity); private: EntityID m_LastEntityID; std::stack m_RecycledEntityIDs; // A bottom to top tree. A map of child entities to parent entities. std::unordered_map m_EntityParents; std::unordered_map>> m_ComponentsOfType; std::unordered_map>> m_EntityComponents; std::vector> m_Systems; EntityID GenerateEntityID(); void RecycleEntityID(EntityID id); }; #endif // World_h__