4 ECS::ECS(
const ComponentRegistry& registry) : m_registry(registry) {
5 for (
auto it = m_registry.cbegin(); it != m_registry.cend(); ++it) {
6 it->second.create_list(m_components);
14 for (std::size_t i = 0; i < num; i++) ids[i] =
gen_entity();
45 if (maybe_info.is_none()) {
46 assert(
false &&
"This should never happen");
52 return rec.delete_component(
m_components, cmpn, info.owner);
63 if (maybe_info.is_none())
return utils::make_none<Component&>();
64 auto info = maybe_info.unwrap();
67 }, utils::make_none<Component&>());
std::size_t num_components() const
Returns the number of components of the given type.
Base class for components.
utils::SlotMap< ComponentInfo > m_component_info
bool delete_entity(Entity id)
Info directly attached to a ComponentID.
const ComponentID get_id() const
Returns this Component's id.
utils::IDFactory< ComponentID > m_cmpn_gen
Responsible for creating unique IDs for the Components.
const ComponentRegistry m_registry
bool does_entity_exist(Entity entity) const
Returns true if the given Entity exists.
utils::Option< T & > get_component(Entity entity) const
Returns the Component of the given type associated to the given Entity.
Entity gen_entity()
Generates a new Entity, returning its ID.
utils::TypeMap m_components
bool delete_component(ComponentID cmpn)
void clear()
Removes all entities and components from this system.
void gen_entities(std::size_t num, Entity *ids)
Generates several entities, storing their IDs in ids.
utils::Option< Entity > get_owner(ComponentID cmpn) const
Returns the Entity associated to this Component.
utils::IDFactory< Entity > m_entity_gen
Responsible for creating unique IDs for the Entities.