29#include "engine_logger.hpp"
30#include "engine_time.hpp"
34using namespace Brenta::ECS;
35using namespace Brenta::Utils;
37SetPtr<Entity> World::entities;
38UMapPtr<std::type_index, Resource> World::resources;
39UMapVecPtr<std::type_index, Component> World::components;
41template <>
void World::QueryComponentsRec<None>(std::vector<Entity> *entities)
47 using namespace Types;
48 World::entities = std::make_unique<std::set<Entity>>();
49 World::resources = std::make_unique<UMap<std::type_index, Resource>>();
50 World::components = std::make_unique<UMapVec<std::type_index, Component>>();
52 INFO(
"World initialized");
57 World::entities.reset();
58 World::components.reset();
59 World::resources.reset();
61 INFO(
"World deleted");
73 ERROR(
"Cannot create entity: world not initialized");
77 if (World::entities->empty())
79 World::entities->insert(1);
83 Entity new_entity = *(World::entities->rbegin()) + 1;
84 World::entities->insert(new_entity);
86 INFO(
"New entity created: ", new_entity);
95 ERROR(
"Cannot get entities: world not initialized");
98 return World::entities.get();
103 if (!World::resources)
105 ERROR(
"Cannot get resources: world not initialized");
108 return World::resources.get();
113 if (!World::components)
115 ERROR(
"Cannot get components: world not initialized");
118 return World::components.get();
123 if (!World::entities)
125 ERROR(
"Cannot remove entity: world not initialized");
129 World::entities->erase(entity);
131 for (
auto iter = World::components->begin();
132 iter != World::components->end(); iter++)
135 std::remove_if(iter->second.begin(), iter->second.end(),
136 [&entity](
const std::shared_ptr<Component> &elem)
137 { return elem->entity == entity; }),
141 INFO(
"Entity removed: ", entity);
static UMap< std::type_index, Resource > * getResources()
Get the resources container.
static void RemoveEntity(Entity entity)
Remove an entity.
static void Tick()
Tick the world.
static UMapVec< std::type_index, Component > * getComponents()
Get the components container.
static std::set< Entity > * getEntities()
Get the entities container.
static void Init()
Initialize the world.
static void RunSystems()
Run all systems.
static Entity NewEntity()
Create a new entity.
static void Delete()
Delete the world.