Class EcsRegistry¶
Defined in File ecsregistry.hpp
Class Documentation¶
-
class
legion::core::ecs
::
EcsRegistry
¶ Manager and owner of all ECS related objects.
Public Functions
-
EcsRegistry
(events::EventBus *eventBus)¶ Constructor initializes everything for the ECS and creates world entity.
-
template<typename
component_type
>
inline voidreportComponentType
(std::optional<std::string> name = std::nullopt)¶ Reports component type to the registry so that it can be stored managed and recognized as a component.
- Note
For a struct to fully work as a component to all supported features of this ECS the struct needs the following requirements:
It needs to be default constructible.
It needs to be trivially copyable.
The + operator needs to be defined.
The * operator needs to be defined.
- Template Parameters
component_type
: Type of struct you with to add as a component.
-
template<typename
component_type
>
inline component_pool<component_type> *getFamily
()¶ Get component storage of a certain type.
- Return
component_pool<component_type>* Pointer to the component container that contains all components of the requested type.
- Template Parameters
component_type
: Type of the component you wish to fetch.
- Exceptions
legion_unknown_component_error
: When component type is unknown.
-
inline async::rw_spinlock &
getEntityLock
() const¶
-
component_pool_base *
getFamily
(id_type componentTypeId)¶ Get component storage of a certain type.
- Return
component_pool_base* Pointer to the component container that contains all components of the requested type. (needs to be cast to original type to use)
- Parameters
componentTypeId
: Type id of the component you wish to fetch.
- Exceptions
legion_unknown_component_error
: When component type is unknown.
-
bool
hasComponent
(id_type entityId, id_type componentTypeId)¶ Check if an entity has a certain component.
- Parameters
entityId
: Id of the entity.componentTypeId
: Type id of component to check for.
- Exceptions
legion_entity_not_found_error
: If the entity id does not belong to a valid entity.
-
template<typename
component_type
>
inline boolhasComponent
(id_type entityId)¶ Check if an entity has a certain component.
- Template Parameters
component_type
: Type of the component to check for.
- Parameters
entityId
: Id of the entity.
- Exceptions
legion_entity_not_found_error
: If the entity id does not belong to a valid entity.
-
template<typename
component_type
, typename ...component_types
>
inline boolhasComponents
(id_type entityId)¶ Check if an entity has a certain component combination.
- Template Parameters
component_type
: Type of the first component to check for.component_types
: Types of the other components to check for.
- Parameters
entityId
: Id of the entity.
- Exceptions
legion_entity_not_found_error
: If the entity id does not belong to a valid entity.
-
template<typename
archetype_type
>
inline boolhasComponents
(id_type entityId)¶ Check if an entity has a certain component combination using an archetype.
- Template Parameters
archetype_type
: Type of the archetype to check for.
- Parameters
entityId
: Id of the entity.
- Exceptions
legion_entity_not_found_error
: If the entity id does not belong to a valid entity.
-
component_handle_base
getComponent
(id_type entityId, id_type componentTypeId)¶ Get component handle of a certain type attached to a certain entity.
- Return
component_handle_base Component handle to the requested component. (may be invalid if the entity does not have this component type)
- Note
Handle needs to force_cast to component_handle<T> in order to use correctly.
- Parameters
entityId
: Id of entity to get the component from.componentTypeId
: Type id of component to get handle of.
- Exceptions
legion_entity_not_found_error
: If the entity id does not belong to a valid entity.
-
template<typename
component_type
>
inline component_handle<component_type>getComponent
(id_type entityId)¶ Get component handle of a certain type attached to a certain entity.
- Return
component_handle<component_type> Component handle to the requested component. (may be invalid if the entity does not have this component type)
- Template Parameters
component_type
: Type of component to get handle of.
- Parameters
entityId
: Id of entity to get the component from.
- Exceptions
legion_entity_not_found_error
: If the entity id does not belong to a valid entity.
-
template<typename
component_type
, typename ...component_types
>
inline std::tuple<component_handle<component_type>, component_handle<component_types>...>getComponents
(id_type entityId)¶ Get component handles of a certain types attached to a certain entity.
- Return
component_handle<component_type> Component handle to the requested component. (may be invalid if the entity does not have this component type)
- Template Parameters
component_type
: Type of the first component to get handle of.component_types
: Types of the other components to get the handles of.
- Parameters
entityId
: Id of entity to get the component from.
- Exceptions
legion_entity_not_found_error
: If the entity id does not belong to a valid entity.
-
template<typename
archetype_type
, typename ...component_types
>
inline autogetComponents
(id_type entityId)¶
-
template<typename
component_type
>
inline component_handle<component_type>createComponent
(id_type entityId)¶ Create component of a certain type attached to a certain entity.
- Return
component_handle<component_type> Component handle to the created component.
- Template Parameters
component_type
: Type of component you wish to create.
- Parameters
entityId
: Id of the entity you wish to attach the component to.
- Exceptions
legion_entity_not_found_error
: If the entity id does not belong to a valid entity.
-
template<typename
component_type
>
inline component_handle<std::remove_reference_t<component_type>>createComponent
(id_type entityId, component_type &&component)¶
-
template<typename
component_type
>
inline component_handle<std::remove_reference_t<component_type>>createComponent
(id_type entityId, component_type &component)¶
-
template<typename
archetype_type
, typename ...component_types
>
inline autocreateComponents
(id_type entityId, component_types&&... defaultValues)¶
-
template<typename
component_type
, typename ...component_types
>
inline std::tuple<component_handle<component_type>, component_handle<component_types>...>createComponents
(id_type entityId)¶
-
template<typename
component_type
, typename ...component_types
>
inline std::tuple<component_handle<std::remove_reference_t<component_type>>, component_handle<std::remove_reference_t<component_types>>...>createComponents
(id_type entityId, component_type &&defaultValue, component_types&&... defaultValues)¶
-
component_handle_base
createComponent
(id_type entityId, id_type componentTypeId)¶ Create component of a certain type attached to a certain entity.
- Return
component_handle_base Component handle to the created component.
- Note
Handle needs to force_cast to component_handle<T> in order to use correctly.
- Parameters
entityId
: Id of the entity you wish to attach the component to.componentTypeId
: Type id of component you wish to create.
- Exceptions
legion_entity_not_found_error
: If the entity id does not belong to a valid entity.
-
component_handle_base
createComponent
(id_type entityId, id_type componentTypeId, void *value)¶ Create component of a certain type attached to a certain entity.
- Return
component_handle_base Component handle to the created component.
- Note
Handle needs to force_cast to component_handle<T> in order to use correctly.
- Parameters
entityId
: Id of the entity you wish to attach the component to.componentTypeId
: Type id of component you wish to create.value
: Pointer to component_type that has the starting value you require.
- Exceptions
legion_entity_not_found_error
: If the entity id does not belong to a valid entity.
-
component_handle_base
copyComponent
(id_type destinationEntity, id_type sourceEntity, id_type componentTypeId)¶ Copies a component from entity to another.
- Return
component_handle_base Component handle to the copied component.
- Parameters
destinationEntity
: The entity you want to copy the component onto.sourceEntity
: The entity you want to copy the component from.componentTypeId
: The component you want to copy
-
void
destroyComponent
(id_type entityId, id_type componentTypeId)¶ Destroy component of a certain type attached to a certain entity.
- Parameters
entityId
: Id of the entity you wish to remove the component from.componentTypeId
: Type id of component you wish to destroy.
- Exceptions
legion_entity_not_found_error
: If the entity id does not belong to a valid entity.
-
template<typename
component_type
>
inline voiddestroyComponent
(id_type entityId)¶ Destroy component of a certain type attached to a certain entity.
- Template Parameters
component_type
: Type of component you wish to destroy.
- Parameters
entityId
: Id of the entity you wish to remove the component from.
- Exceptions
legion_entity_not_found_error
: If the entity id does not belong to a valid entity.
-
template<typename
component_type
, typename ...component_types
>
inline voiddestroyComponents
(id_type entityId)¶
-
bool
validateEntity
(id_type entityId)¶ Check if entity exists.
- Return
bool True if entity exists, false if it doesn’t or if the id is invalid_id.
- Parameters
entityId
: Id of entity you wish to check if it exists.
-
entity_handle
createEntity
(bool worldChild = true, id_type entityId = invalid_id)¶ Create new entity.
- Return
entity_handle Entity handle pointing to the newly created entity.
-
entity_handle
createEntity
(id_type entityId, bool worldChild = true)¶
-
void
destroyEntity
(id_type entityId, bool recurse = true)¶ Destroys entity and all of its components.
- Parameters
entityId
: Id of entity you wish to destroy.recurse
: Do you wish to destroy all children and children of children etc as well? True by default.
-
entity_handle
getEntity
(id_type entityId)¶ Get entity handle for a certain entity id.
- Return
entity_handle Handle to the requested entity. (may be invalid if the entity doesn’t exist)
- Note
You could always use the entity_handle constructor… you have the registry reference already anyways.
- Parameters
entityId
: Id of entity you want a handle to.
-
entity_data
getEntityData
(id_type entityId)¶ Get entity data for a certain entity id.
- Return
entity_data& Hierarchy and composition data of the entity requested.
- Parameters
entityId
: Id of entity you want the data from.
-
void
setEntityData
(id_type entityId, const entity_data &data)¶
-
entity_handle
getEntityParent
(id_type entityId)¶
-
std::pair<entity_set&, async::rw_spinlock&>
getEntities
()¶ Get a container with ALL entities.
- Return
sparse_map<id_type, entity_handle>& Container that keeps both the id’s and corresponding entity handles for easy use.
-
template<typename ...
component_types
>
inline EntityQuerycreateQuery
()¶ Get a query for your component combination.
- Return
EntityQuery Query that will query the entities with the requested components.
- Note
This function is quite slow and thus it’s advised to create a query once and reuse it.
- Template Parameters
component_types
: Variadic parameter types of all component types you wish to query for.
-
inline EntityQuery
createQuery
(const hashed_sparse_set<id_type> &componentTypes)¶ Get a query for your component combination.
- Return
EntityQuery Query that will query the entities with the requested components.
- Note
This function is quite slow and thus it’s advised to create a query once and reuse it.
- Parameters
componentTypes
: Container with type ids of all component types you wish to query for.
Public Static Attributes
-
static entity_handle
world
= entity_handle(world_entity_id)¶
-