21 #ifndef HX3D_ECS_ENGINE 22 #define HX3D_ECS_ENGINE 24 #include "hx3d/ecs/system.hpp" 25 #include "hx3d/ecs/entity.hpp" 26 #include "hx3d/ecs/component.hpp" 28 #include "hx3d/utils/log.hpp" 29 #include "hx3d/utils/ptr.hpp" 98 template <
class T,
class... Args>
116 template <
class T,
class... Args>
167 void update(
const float delta);
176 std::map<unsigned int, Ptr<Entity>> _entities;
178 std::map<unsigned int, std::map<std::type_index, Ptr<Component>>> _components;
180 std::map<unsigned int, Bitset> _bits;
183 std::map<std::type_index, Ptr<System>> _systems;
185 std::map<std::type_index, std::function<void(Ptr<Component>,
Ptr<Entity>)>> _onComponentAdded;
187 std::map<std::type_index, std::function<void(Ptr<Component>,
Ptr<Entity>)>> _onComponentRemoved;
190 std::vector<unsigned int> _toRemove;
195 void cleanEntities();
202 unsigned int lastEntityAvailable();
211 void addInternalComponent(
const unsigned int entityId,
const Ptr<Component>& component);
218 void removeComponents(
const unsigned int entityId);
224 #include "hx3d/ecs/_inline/engine.inl.hpp" Manages entity in a world.
void createSystem(Args...args)
Create a system into the engine.
void registerComponentAdded(std::function< void(const Ptr< Component > &, const Ptr< Entity > &)> callback)
Register a callback for a certain component type when it's added.
void clear()
Remove everything from the engine.
void addComponent(const Ptr< Entity > &entity, const Ptr< Component > &component)
Add a component for an entity.
void update(const float delta)
Update the engine.
void createComponent(const Ptr< Entity > &entity, Args...args)
Create a component for an entity with variable args.
Ptr< Entity > createEntity()
Create a new entity with the last entity id available.
void removeEntity(const Ptr< Entity > &entity)
Mark the entity for deletion from the engine.
unsigned int getComponentSize(const Ptr< Entity > &entity)
Get the number of components for an entity.
unsigned int getEntityCount()
Get the number of entities.
void registerComponentRemoved(std::function< void(const Ptr< Component > &, const Ptr< Entity > &)> callback)
Register a callback for a certain component type when it's removed.
unsigned int getBits(const Ptr< Entity > &entity)
Get the bits corresponding to the entity components.
std::shared_ptr< T > Ptr
Quick-typing shared ptr.
void registerEntity(const Ptr< Entity > &entity)
Affect an ID to a uninitialized entity.
Ptr< T > getComponent(const Ptr< Entity > &entity)
Get the component for an entity.
void addSystem(const Ptr< System > &sys)
Add a system to the engine.