|
GREM 3.12.0
Game/Rendering Engine Modules for C++
|
Dynamic container of entities with stable EntityID handles and associated component instances, available to tasks defined through a Scheduler. More...
#include <GREM/execution/EntityRegistry.hpp>
Public Types | |
| using | value_type = EntityID |
| using | reference = EntityID& |
| using | const_reference = const EntityID& |
| using | pointer = EntityID* |
| using | const_pointer = const EntityID* |
| using | size_type = size_t |
| using | difference_type = ptrdiff_t |
| using | iterator = typename Buffer<EntityID>::iterator |
| using | const_iterator = typename Buffer<EntityID>::const_iterator |
Public Member Functions | |
| EntityRegistry () noexcept=default | |
| Construct an empty entity registry. | |
| ~EntityRegistry () | |
| Destructor. | |
| EntityRegistry (const EntityRegistry &other) | |
| Copy constructor. | |
| EntityRegistry (EntityRegistry &&other) noexcept | |
| Move constructor. | |
| EntityRegistry & | operator= (const EntityRegistry &other) |
| Copy assignment. | |
| EntityRegistry & | operator= (EntityRegistry &&other) noexcept |
| Move assignment. | |
| void | clear () noexcept |
| Destroy all entities and erase all of their associated components from the registry. | |
| EntityBuilder< EntityRegistry > | createEntity (EntityID::Flags flags={}) |
| Create a new entity. | |
| EntityBuilder< EntityRegistry > | createEntityAtID (EntityID id) |
| Create a new entity with a specific entity handle. | |
| EntityID | setEntityFlags (EntityID id, EntityID::Flags newFlags) |
| Update the flags embedded in an entity's handle. | |
| GREM_ALWAYS_INLINE bool | destroyEntity (EntityID id) noexcept |
| Destroy an entity and all of its associated components. | |
| bool | destroyEntityAtIndex (EntityID::Index slotIndex) noexcept |
| Destroy the entity in a specific slot and all of its associated components. | |
| GREM_ALWAYS_INLINE iterator | begin () noexcept |
| GREM_ALWAYS_INLINE const_iterator | begin () const noexcept |
| GREM_ALWAYS_INLINE const_iterator | cbegin () const noexcept |
| GREM_ALWAYS_INLINE iterator | end () noexcept |
| GREM_ALWAYS_INLINE const_iterator | end () const noexcept |
| GREM_ALWAYS_INLINE const_iterator | cend () const noexcept |
| GREM_ALWAYS_INLINE bool | containsEntity (EntityID id) const noexcept |
| Check if the registry contains a specific entity. | |
| GREM_ALWAYS_INLINE bool | containsEntityAtIndex (EntityID::Index slotIndex) const |
| Check if the registry contains an entity in a specific slot. | |
| GREM_ALWAYS_INLINE size_type | size () const noexcept |
| Get the number of valid entity handles currently in the registry. | |
| GREM_ALWAYS_INLINE bool | empty () const noexcept |
| Check if the registry is empty. | |
| GREM_ALWAYS_INLINE size_type | max_size () const noexcept |
| Get the maximum number of simultaneous valid entity handles that the registry can contain. | |
| template<component T, typename... Args> | |
| GREM_ALWAYS_INLINE T & | addComponent (EntityID id, Args &&... args) |
| Add a component to an entity. | |
| template<component T, typename... Args> | |
| GREM_ALWAYS_INLINE T * | addComponentIfMissing (EntityID id, Args &&... args) |
| Add a component to an entity if it doesn't already have it. | |
| template<component T> | |
| GREM_ALWAYS_INLINE T & | addOrAssignComponent (EntityID id, T &&value) |
| Add a component to an entity, or assign to it if it already has one. | |
| template<component T> | |
| GREM_ALWAYS_INLINE T & | addOrAssignComponent (EntityID id, const T &value) |
| Add a component to an entity, or assign to it if it already has one. | |
| template<component T> | |
| GREM_ALWAYS_INLINE bool | removeComponent (EntityID id) noexcept |
| Erase a component from an entity. | |
| GREM_ALWAYS_INLINE bool | removeAllComponents (EntityID id) noexcept |
| Erase all components from an entity. | |
| template<component T> | |
| size_type GREM_ALWAYS_INLINE | removeComponentFromAllEntities () noexcept |
| Erase a specific component from all entities. | |
| template<component T> | |
| GREM_ALWAYS_INLINE bool | hasComponent (EntityID id) const noexcept |
| Check if an entity has a specific component. | |
| template<component T> | |
| GREM_ALWAYS_INLINE T & | getComponent (EntityID id) |
| Get a specific component of an entity. | |
| template<component T> | |
| GREM_ALWAYS_INLINE const T & | getComponent (EntityID id) const |
| Get a specific component of an entity. | |
| template<component T, typename U> | |
| GREM_ALWAYS_INLINE T | getComponentOr (EntityID id, U &&defaultValue) const |
| Get a specific component of an entity, or a default value in case the entity doesn't exist or doesn't have the specified component. | |
| template<component T> | |
| GREM_ALWAYS_INLINE T * | findComponent (EntityID id) noexcept |
| Try to get a specific component of an entity. | |
| template<component T> | |
| GREM_ALWAYS_INLINE const T * | findComponent (EntityID id) const noexcept |
| Try to get a specific component of an entity. | |
| GREM_ALWAYS_INLINE EntityID | getEntityIDAtEntityIndexUnsafe (EntityID::Index slotIndex) const |
| Get the entity handle of the entity in a specific slot. | |
| template<component T> | |
| GREM_ALWAYS_INLINE T & | getComponentAtEntityIndexUnsafe (EntityID::Index slotIndex) |
| Get a specific component of the entity in a specific slot. | |
| template<component T> | |
| GREM_ALWAYS_INLINE const T & | getComponentAtEntityIndexUnsafe (EntityID::Index slotIndex) const |
| Get a specific component of the entity in a specific slot. | |
| template<typename... ComponentsAndExclusions> requires (!meta::type_list_empty_v<typename Entities<ComponentsAndExclusions...>::MutableComponents>) | |
| GREM_ALWAYS_INLINE Entities< ComponentsAndExclusions... > | getEntities () noexcept |
| Get a view of all entites in the registry that have all of the required components and none of the excluded components specified in a list of types. | |
| template<typename... ComponentsAndExclusions> requires (meta::type_list_empty_v<typename Entities<ComponentsAndExclusions...>::MutableComponents>) | |
| GREM_ALWAYS_INLINE Entities< ComponentsAndExclusions... > | getEntities () const noexcept |
| Get a view of all entites in the registry that have all of the required components and none of the excluded components specified in a list of types. | |
| template<typename... ComponentsAndExclusions> requires (!meta::type_list_empty_v<typename Entities<ComponentsAndExclusions...>::MutableComponents>) | |
| GREM_ALWAYS_INLINE | operator Entities< ComponentsAndExclusions... > () noexcept |
| Implicitly convert the registry to an entity range. | |
| template<typename... ComponentsAndExclusions> requires (meta::type_list_empty_v<typename Entities<ComponentsAndExclusions...>::MutableComponents>) | |
| GREM_ALWAYS_INLINE | operator Entities< ComponentsAndExclusions... > () const noexcept |
| Implicitly convert the registry to an entity range. | |
| template<typename... ComponentsAndExclusions> requires (!meta::type_list_empty_v<typename Entities<ComponentsAndExclusions...>::MutableComponents>) | |
| GREM_ALWAYS_INLINE Entities< ComponentsAndExclusions... > | getEntitiesChunk (size_t chunkIndex, size_t chunkCount) noexcept |
| Get a specific chunk of the entites in the registry that have all of the required components and none of the excluded components specified in a list of types. | |
| template<typename... ComponentsAndExclusions> requires (meta::type_list_empty_v<typename Entities<ComponentsAndExclusions...>::MutableComponents>) | |
| GREM_ALWAYS_INLINE Entities< ComponentsAndExclusions... > | getEntitiesChunk (size_t chunkIndex, size_t chunkCount) const noexcept |
| Get a specific chunk of the entites in the registry that have all of the required components and none of the excluded components specified in a list of types. | |
| template<component T> | |
| GREM_ALWAYS_INLINE ComponentPool< T > | createComponentPool () |
| Ensure that the component pool for a specific component type has been created, and get a reference to it. | |
| template<component T> | |
| GREM_ALWAYS_INLINE ComponentPool< T > | getComponentPool () noexcept |
| Get a reference to a specific component pool if it exists. | |
| template<component T> | |
| GREM_ALWAYS_INLINE ComponentPool< const T > | getComponentPool () const noexcept |
| Get a reference to a specific component pool if it exists. | |
| template<typename... ComponentsAndExclusions> | |
| size_type | destroyEntities () noexcept |
| Destroy all entities that have all of the required components and none of the excluded components, and erase all of those entities' associated components from the registry. | |
Friends | |
| template<typename Predicate> | |
| size_type | erase_if (EntityRegistry &c, Predicate predicate) |
| Destroy all entities in an entity registry whose entity handles match a predicate, and erase all of those entities' associated components from the registry. | |
Dynamic container of entities with stable EntityID handles and associated component instances, available to tasks defined through a Scheduler.
This container supports extending the set of possible component types dynamically at runtime.
| KnownComponents | compile-time-known set of possible component types, which are given dedicated storage slots in the entity registry to speed up access to them. Any unknown component types that are not in this list will be stored in a dynamic associative container keyed by the component's typeid, which is looked up at runtime, incurring some performance overhead. |
| using grem::execution::EntityRegistry< KnownComponents >::value_type = EntityID |
| using grem::execution::EntityRegistry< KnownComponents >::reference = EntityID& |
| using grem::execution::EntityRegistry< KnownComponents >::const_reference = const EntityID& |
| using grem::execution::EntityRegistry< KnownComponents >::pointer = EntityID* |
| using grem::execution::EntityRegistry< KnownComponents >::const_pointer = const EntityID* |
| using grem::execution::EntityRegistry< KnownComponents >::size_type = size_t |
| using grem::execution::EntityRegistry< KnownComponents >::difference_type = ptrdiff_t |
| using grem::execution::EntityRegistry< KnownComponents >::iterator = typename Buffer<EntityID>::iterator |
| using grem::execution::EntityRegistry< KnownComponents >::const_iterator = typename Buffer<EntityID>::const_iterator |
|
defaultnoexcept |
Construct an empty entity registry.
|
inline |
Destructor.
|
inline |
Copy constructor.
|
inlinenoexcept |
Move constructor.
|
inline |
Copy assignment.
|
inlinenoexcept |
Move assignment.
|
inlinenoexcept |
Destroy all entities and erase all of their associated components from the registry.
|
inlinenodiscard |
Create a new entity.
| flags | flags to embed in the entity handle of the new entity. |
| std::logic_error | if an entity with the given handle already exists in the registry. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
inlinenodiscard |
Create a new entity with a specific entity handle.
| id | entity handle containing the slot index, generation counter and flags of the new entity. |
| std::invalid_argument | if the given entity handle cannot be used to represent a valid entity because its slot index is EntityID::INVALID_INDEX or its generation counter value is even. |
| std::logic_error | if an entity with the given handle already exists in the registry. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
inline |
Update the flags embedded in an entity's handle.
| id | entity handle of the entity to update the flags of. |
| newFlags | new flags to set. |
|
inlinenoexcept |
Destroy an entity and all of its associated components.
| id | entity handle of the entity to destroy. |
|
inlinenoexcept |
Destroy the entity in a specific slot and all of its associated components.
| slotIndex | index of the entity slot containing the entity to destroy. |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
Check if the registry contains a specific entity.
| id | entity handle to check. |
|
inlinenodiscard |
Check if the registry contains an entity in a specific slot.
| slotIndex | index of the entity slot to check. |
|
inlinenodiscardnoexcept |
Get the number of valid entity handles currently in the registry.
|
inlinenodiscardnoexcept |
Check if the registry is empty.
|
inlinenodiscardnoexcept |
Get the maximum number of simultaneous valid entity handles that the registry can contain.
|
inline |
Add a component to an entity.
| T | component type to add. |
| id | entity handle of the entity to add the component to. |
| args | arguments to forward to the component constructor. |
| std::logic_error | if the given entity already has the specified component. |
| std::out_of_range | if the given handle does not correspond to a valid entity. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
| any | exception thrown by the component constructor. |
|
inline |
Add a component to an entity if it doesn't already have it.
| T | component type to add. |
| id | entity handle of the entity to add the component to. |
| args | arguments to forward to the component constructor. |
| std::out_of_range | if the given handle does not correspond to a valid entity. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
| any | exception thrown by the component constructor. |
|
inline |
Add a component to an entity, or assign to it if it already has one.
| T | component type to add or assign. |
| id | entity handle of the entity to add or assign the component to. |
| value | component value to add or assign. |
| std::out_of_range | if the given handle does not correspond to a valid entity. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
| any | exception thrown by the move constructor or move assignment operator of the component type. |
|
inline |
Add a component to an entity, or assign to it if it already has one.
| T | component type to add or assign. |
| id | entity handle of the entity to add or assign the component to. |
| value | component value to add or assign. |
| std::out_of_range | if the given handle does not correspond to a valid entity. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
| any | exception thrown by the copy constructor or copy assignment operator of the component type. |
|
inlinenoexcept |
Erase a component from an entity.
| T | component type to remove. |
| id | entity handle of the entity to remove the component from. |
|
inlinenoexcept |
Erase all components from an entity.
| id | entity handle of the entity to remove all components from. |
|
inlinenoexcept |
Erase a specific component from all entities.
| T | component type to remove. |
|
inlinenodiscardnoexcept |
Check if an entity has a specific component.
| T | component type to check for. |
| id | entity handle to check. |
|
inlinenodiscard |
Get a specific component of an entity.
| T | component type to get. |
| id | entity handle of the entity to get the component from. |
| std::out_of_range | if the given handle does not correspond to a valid entity with the specified component. |
|
inlinenodiscard |
Get a specific component of an entity.
| T | component type to get. |
| id | entity handle of the entity to get the component from. |
| std::out_of_range | if the given handle does not correspond to a valid entity with the specified component. |
|
inlinenodiscard |
Get a specific component of an entity, or a default value in case the entity doesn't exist or doesn't have the specified component.
| T | component type to get. |
| id | entity handle of the entity to get the component from. |
| defaultValue | default value to return in case the given handle does not correspond to a valid entity with the specified component. |
|
inlinenodiscardnoexcept |
Try to get a specific component of an entity.
| T | component type to get. |
| id | entity handle of the entity to get the component from. |
|
inlinenodiscardnoexcept |
Try to get a specific component of an entity.
| T | component type to get. |
| id | entity handle of the entity to get the component from. |
|
inlinenodiscard |
Get the entity handle of the entity in a specific slot.
| slotIndex | index of the entity slot to get the entity handle of. Must be a valid slot index corresponding to an entity that is currently valid, e.g. the result of a previous call to id.getIndex() on a valid entity handle id that has not since been invalidated. |
|
inlinenodiscard |
Get a specific component of the entity in a specific slot.
| T | component type to get. |
| slotIndex | index of the entity slot to get the entity handle of. Must be a valid slot index corresponding to an entity that is currently valid and has the specified component, e.g. the result of a previous call to id.getIndex() on a valid entity handle id that is known to have the specified component, and has not since been invalidated. |
|
inlinenodiscard |
Get a specific component of the entity in a specific slot.
| T | component type to get. |
| slotIndex | index of the entity slot to get the entity handle of. Must be a valid slot index corresponding to an entity that is currently valid and has the specified component, e.g. the result of a previous call to id.getIndex() on a valid entity handle id that is known to have the specified component, and has not since been invalidated. |
|
inlinenodiscardnoexcept |
Get a view of all entites in the registry that have all of the required components and none of the excluded components specified in a list of types.
| ComponentsAndExclusions | component and component exclusion types (e.g. Exclude<Component>) that specify which entities are part of the range. |
|
inlinenodiscardnoexcept |
Get a view of all entites in the registry that have all of the required components and none of the excluded components specified in a list of types.
| ComponentsAndExclusions | component and component exclusion types (e.g. Exclude<Component>) that specify which entities are part of the range. |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
|
inlinenodiscardnoexcept |
Get a specific chunk of the entites in the registry that have all of the required components and none of the excluded components specified in a list of types.
| ComponentsAndExclusions | component and component exclusion types (e.g. Exclude<Component>) that specify which entities are part of the range. |
| chunkIndex | index of the specific chunk to get. Must be less than chunkCount. |
| chunkCount | number of chunks that the entity range is divided into. Must be positive, and greater than chunkIndex. |
|
inlinenodiscardnoexcept |
Get a specific chunk of the entites in the registry that have all of the required components and none of the excluded components specified in a list of types.
| ComponentsAndExclusions | component and component exclusion types (e.g. Exclude<Component>) that specify which entities are part of the range. |
| chunkIndex | index of the specific chunk to get. Must be less than chunkCount. |
| chunkCount | number of chunks that the entity range is divided into. Must be positive, and greater than chunkIndex. |
|
inline |
Ensure that the component pool for a specific component type has been created, and get a reference to it.
| T | component type of the pool to create. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
inlinenodiscardnoexcept |
Get a reference to a specific component pool if it exists.
| T | component type of the pool to get. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
inlinenodiscardnoexcept |
Get a reference to a specific component pool if it exists.
| T | component type of the pool to get. |
| std::length_error | if an internal size limit was exceeded. |
| std::bad_array_new_length | if an internal size limit was exceeded. |
| std::bad_alloc | on allocation failure. |
|
inlinenoexcept |
Destroy all entities that have all of the required components and none of the excluded components, and erase all of those entities' associated components from the registry.
| ComponentsAndExclusions | component and component exclusion types (e.g. Exclude<Component>) that specify which entities to destroy. |
|
friend |
Destroy all entities in an entity registry whose entity handles match a predicate, and erase all of those entities' associated components from the registry.
| c | entity registry to erase from. |
| predicate | condition to check. |
| any | exception thrown by the predicate function. |