GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::execution::EntityRegistry< KnownComponents > Class Template Reference

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.

Detailed Description

template<typename... KnownComponents>
class grem::execution::EntityRegistry< KnownComponents >

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.

Template Parameters
KnownComponentscompile-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.
See also
EntityTable

Member Typedef Documentation

◆ value_type

template<typename... KnownComponents>
using grem::execution::EntityRegistry< KnownComponents >::value_type = EntityID

◆ reference

template<typename... KnownComponents>
using grem::execution::EntityRegistry< KnownComponents >::reference = EntityID&

◆ const_reference

template<typename... KnownComponents>
using grem::execution::EntityRegistry< KnownComponents >::const_reference = const EntityID&

◆ pointer

template<typename... KnownComponents>
using grem::execution::EntityRegistry< KnownComponents >::pointer = EntityID*

◆ const_pointer

template<typename... KnownComponents>
using grem::execution::EntityRegistry< KnownComponents >::const_pointer = const EntityID*

◆ size_type

template<typename... KnownComponents>
using grem::execution::EntityRegistry< KnownComponents >::size_type = size_t

◆ difference_type

template<typename... KnownComponents>
using grem::execution::EntityRegistry< KnownComponents >::difference_type = ptrdiff_t

◆ iterator

template<typename... KnownComponents>
using grem::execution::EntityRegistry< KnownComponents >::iterator = typename Buffer<EntityID>::iterator

◆ const_iterator

template<typename... KnownComponents>
using grem::execution::EntityRegistry< KnownComponents >::const_iterator = typename Buffer<EntityID>::const_iterator

Constructor & Destructor Documentation

◆ EntityRegistry() [1/3]

template<typename... KnownComponents>
grem::execution::EntityRegistry< KnownComponents >::EntityRegistry ( )
defaultnoexcept

Construct an empty entity registry.

◆ ~EntityRegistry()

template<typename... KnownComponents>
grem::execution::EntityRegistry< KnownComponents >::~EntityRegistry ( )
inline

Destructor.

◆ EntityRegistry() [2/3]

template<typename... KnownComponents>
grem::execution::EntityRegistry< KnownComponents >::EntityRegistry ( const EntityRegistry< KnownComponents > & other)
inline

Copy constructor.

◆ EntityRegistry() [3/3]

template<typename... KnownComponents>
grem::execution::EntityRegistry< KnownComponents >::EntityRegistry ( EntityRegistry< KnownComponents > && other)
inlinenoexcept

Move constructor.

Member Function Documentation

◆ operator=() [1/2]

template<typename... KnownComponents>
EntityRegistry & grem::execution::EntityRegistry< KnownComponents >::operator= ( const EntityRegistry< KnownComponents > & other)
inline

Copy assignment.

◆ operator=() [2/2]

template<typename... KnownComponents>
EntityRegistry & grem::execution::EntityRegistry< KnownComponents >::operator= ( EntityRegistry< KnownComponents > && other)
inlinenoexcept

Move assignment.

◆ clear()

template<typename... KnownComponents>
void grem::execution::EntityRegistry< KnownComponents >::clear ( )
inlinenoexcept

Destroy all entities and erase all of their associated components from the registry.

◆ createEntity()

template<typename... KnownComponents>
EntityBuilder< EntityRegistry > grem::execution::EntityRegistry< KnownComponents >::createEntity ( EntityID::Flags flags = {})
inlinenodiscard

Create a new entity.

Parameters
flagsflags to embed in the entity handle of the new entity.
Returns
an entity builder for building the new entity. To finish creating the entity, call EntityBuilder::build().
Exceptions
std::logic_errorif an entity with the given handle already exists in the registry.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.

◆ createEntityAtID()

template<typename... KnownComponents>
EntityBuilder< EntityRegistry > grem::execution::EntityRegistry< KnownComponents >::createEntityAtID ( EntityID id)
inlinenodiscard

Create a new entity with a specific entity handle.

Parameters
identity handle containing the slot index, generation counter and flags of the new entity.
Returns
an entity builder for building the new entity. To finish creating the entity, call EntityBuilder::build().
Exceptions
std::invalid_argumentif 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_errorif an entity with the given handle already exists in the registry.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.

◆ setEntityFlags()

template<typename... KnownComponents>
EntityID grem::execution::EntityRegistry< KnownComponents >::setEntityFlags ( EntityID id,
EntityID::Flags newFlags )
inline

Update the flags embedded in an entity's handle.

Parameters
identity handle of the entity to update the flags of.
newFlagsnew flags to set.
Returns
the new entity handle with the updated flags, or an invalid default-constructed handle if the given entity handle does not correspond to a valid entity.

◆ destroyEntity()

template<typename... KnownComponents>
GREM_ALWAYS_INLINE bool grem::execution::EntityRegistry< KnownComponents >::destroyEntity ( EntityID id)
inlinenoexcept

Destroy an entity and all of its associated components.

Parameters
identity handle of the entity to destroy.
Returns
true if the entity handle corresponded to a valid entity that was successfully destroyed, false otherwise.

◆ destroyEntityAtIndex()

template<typename... KnownComponents>
bool grem::execution::EntityRegistry< KnownComponents >::destroyEntityAtIndex ( EntityID::Index slotIndex)
inlinenoexcept

Destroy the entity in a specific slot and all of its associated components.

Parameters
slotIndexindex of the entity slot containing the entity to destroy.
Returns
true if the slot corresponded to a valid entity that was successfully destroyed, false otherwise.

◆ begin() [1/2]

template<typename... KnownComponents>
GREM_ALWAYS_INLINE iterator grem::execution::EntityRegistry< KnownComponents >::begin ( )
inlinenodiscardnoexcept

◆ begin() [2/2]

template<typename... KnownComponents>
GREM_ALWAYS_INLINE const_iterator grem::execution::EntityRegistry< KnownComponents >::begin ( ) const
inlinenodiscardnoexcept

◆ cbegin()

template<typename... KnownComponents>
GREM_ALWAYS_INLINE const_iterator grem::execution::EntityRegistry< KnownComponents >::cbegin ( ) const
inlinenodiscardnoexcept

◆ end() [1/2]

template<typename... KnownComponents>
GREM_ALWAYS_INLINE iterator grem::execution::EntityRegistry< KnownComponents >::end ( )
inlinenodiscardnoexcept

◆ end() [2/2]

template<typename... KnownComponents>
GREM_ALWAYS_INLINE const_iterator grem::execution::EntityRegistry< KnownComponents >::end ( ) const
inlinenodiscardnoexcept

◆ cend()

template<typename... KnownComponents>
GREM_ALWAYS_INLINE const_iterator grem::execution::EntityRegistry< KnownComponents >::cend ( ) const
inlinenodiscardnoexcept

◆ containsEntity()

template<typename... KnownComponents>
GREM_ALWAYS_INLINE bool grem::execution::EntityRegistry< KnownComponents >::containsEntity ( EntityID id) const
inlinenodiscardnoexcept

Check if the registry contains a specific entity.

Parameters
identity handle to check.
Returns
true if the given handle corresponds to a valid entity in this registry, false otherwise.

◆ containsEntityAtIndex()

template<typename... KnownComponents>
GREM_ALWAYS_INLINE bool grem::execution::EntityRegistry< KnownComponents >::containsEntityAtIndex ( EntityID::Index slotIndex) const
inlinenodiscard

Check if the registry contains an entity in a specific slot.

Parameters
slotIndexindex of the entity slot to check.
Returns
true if the given slot contains a valid entity in this registry, false otherwise.

◆ size()

template<typename... KnownComponents>
GREM_ALWAYS_INLINE size_type grem::execution::EntityRegistry< KnownComponents >::size ( ) const
inlinenodiscardnoexcept

Get the number of valid entity handles currently in the registry.

Returns
the number of entities.

◆ empty()

template<typename... KnownComponents>
GREM_ALWAYS_INLINE bool grem::execution::EntityRegistry< KnownComponents >::empty ( ) const
inlinenodiscardnoexcept

Check if the registry is empty.

Returns
true if the registry does not contain any valid entity handles, false otherwise.

◆ max_size()

template<typename... KnownComponents>
GREM_ALWAYS_INLINE size_type grem::execution::EntityRegistry< KnownComponents >::max_size ( ) const
inlinenodiscardnoexcept

Get the maximum number of simultaneous valid entity handles that the registry can contain.

Returns
the maximum entity count.

◆ addComponent()

template<typename... KnownComponents>
template<component T, typename... Args>
GREM_ALWAYS_INLINE T & grem::execution::EntityRegistry< KnownComponents >::addComponent ( EntityID id,
Args &&... args )
inline

Add a component to an entity.

Template Parameters
Tcomponent type to add.
Parameters
identity handle of the entity to add the component to.
argsarguments to forward to the component constructor.
Returns
a reference to the newly created component.
Exceptions
std::logic_errorif the given entity already has the specified component.
std::out_of_rangeif the given handle does not correspond to a valid entity.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the component constructor.
Note
The component pool for the specified component type will be created if it doesn't already exist.

◆ addComponentIfMissing()

template<typename... KnownComponents>
template<component T, typename... Args>
GREM_ALWAYS_INLINE T * grem::execution::EntityRegistry< KnownComponents >::addComponentIfMissing ( EntityID id,
Args &&... args )
inline

Add a component to an entity if it doesn't already have it.

Template Parameters
Tcomponent type to add.
Parameters
identity handle of the entity to add the component to.
argsarguments to forward to the component constructor.
Returns
a pointer to the newly created component, or nullptr if the entity already has the specified component.
Exceptions
std::out_of_rangeif the given handle does not correspond to a valid entity.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the component constructor.
Note
The component pool for the specified component type will be created if it doesn't already exist.

◆ addOrAssignComponent() [1/2]

template<typename... KnownComponents>
template<component T>
GREM_ALWAYS_INLINE T & grem::execution::EntityRegistry< KnownComponents >::addOrAssignComponent ( EntityID id,
T && value )
inline

Add a component to an entity, or assign to it if it already has one.

Template Parameters
Tcomponent type to add or assign.
Parameters
identity handle of the entity to add or assign the component to.
valuecomponent value to add or assign.
Returns
a reference to the newly created component, or to the existing component if the entity already had one.
Exceptions
std::out_of_rangeif the given handle does not correspond to a valid entity.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the move constructor or move assignment operator of the component type.
Note
The component pool for the specified component type will be created if it doesn't already exist.

◆ addOrAssignComponent() [2/2]

template<typename... KnownComponents>
template<component T>
GREM_ALWAYS_INLINE T & grem::execution::EntityRegistry< KnownComponents >::addOrAssignComponent ( EntityID id,
const T & value )
inline

Add a component to an entity, or assign to it if it already has one.

Template Parameters
Tcomponent type to add or assign.
Parameters
identity handle of the entity to add or assign the component to.
valuecomponent value to add or assign.
Returns
a reference to the newly created component, or to the existing component if the entity already had one.
Exceptions
std::out_of_rangeif the given handle does not correspond to a valid entity.
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
anyexception thrown by the copy constructor or copy assignment operator of the component type.
Note
The component pool for the specified component type will be created if it doesn't already exist.

◆ removeComponent()

template<typename... KnownComponents>
template<component T>
GREM_ALWAYS_INLINE bool grem::execution::EntityRegistry< KnownComponents >::removeComponent ( EntityID id)
inlinenoexcept

Erase a component from an entity.

Template Parameters
Tcomponent type to remove.
Parameters
identity handle of the entity to remove the component from.
Returns
true if the given handle corresponded to a valid entity with the specified component that was successfully removed, false otherwise.
Note
If the specified entity does not exist, this function has no effect, and will NOT create any missing component pools.

◆ removeAllComponents()

template<typename... KnownComponents>
GREM_ALWAYS_INLINE bool grem::execution::EntityRegistry< KnownComponents >::removeAllComponents ( EntityID id)
inlinenoexcept

Erase all components from an entity.

Parameters
identity handle of the entity to remove all components from.
Returns
true if the given handle corresponded to a valid entity, false otherwise.
Note
If the specified entity does not exist, this function has no effect, and will NOT create any missing component pools.

◆ removeComponentFromAllEntities()

template<typename... KnownComponents>
template<component T>
size_type GREM_ALWAYS_INLINE grem::execution::EntityRegistry< KnownComponents >::removeComponentFromAllEntities ( )
inlinenoexcept

Erase a specific component from all entities.

Template Parameters
Tcomponent type to remove.
Returns
the number of entities that had the specified component before it was removed.
Note
If no entities have the specified component, this function has no effect, and will NOT create any missing component pools.

◆ hasComponent()

template<typename... KnownComponents>
template<component T>
GREM_ALWAYS_INLINE bool grem::execution::EntityRegistry< KnownComponents >::hasComponent ( EntityID id) const
inlinenodiscardnoexcept

Check if an entity has a specific component.

Template Parameters
Tcomponent type to check for.
Parameters
identity handle to check.
Returns
true if the given handle corresponds to a valid entity with the specified component, false otherwise.

◆ getComponent() [1/2]

template<typename... KnownComponents>
template<component T>
GREM_ALWAYS_INLINE T & grem::execution::EntityRegistry< KnownComponents >::getComponent ( EntityID id)
inlinenodiscard

Get a specific component of an entity.

Template Parameters
Tcomponent type to get.
Parameters
identity handle of the entity to get the component from.
Returns
a reference to the specified component.
Exceptions
std::out_of_rangeif the given handle does not correspond to a valid entity with the specified component.

◆ getComponent() [2/2]

template<typename... KnownComponents>
template<component T>
GREM_ALWAYS_INLINE const T & grem::execution::EntityRegistry< KnownComponents >::getComponent ( EntityID id) const
inlinenodiscard

Get a specific component of an entity.

Template Parameters
Tcomponent type to get.
Parameters
identity handle of the entity to get the component from.
Returns
a read-only reference to the specified component.
Exceptions
std::out_of_rangeif the given handle does not correspond to a valid entity with the specified component.

◆ getComponentOr()

template<typename... KnownComponents>
template<component T, typename U>
GREM_ALWAYS_INLINE T grem::execution::EntityRegistry< KnownComponents >::getComponentOr ( EntityID id,
U && defaultValue ) const
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.

Template Parameters
Tcomponent type to get.
Parameters
identity handle of the entity to get the component from.
defaultValuedefault value to return in case the given handle does not correspond to a valid entity with the specified component.
Returns
a copy of the specified component, or the specified default value if the given handle does not correspond to a valid entity with the specified component.

◆ findComponent() [1/2]

template<typename... KnownComponents>
template<component T>
GREM_ALWAYS_INLINE T * grem::execution::EntityRegistry< KnownComponents >::findComponent ( EntityID id)
inlinenodiscardnoexcept

Try to get a specific component of an entity.

Template Parameters
Tcomponent type to get.
Parameters
identity handle of the entity to get the component from.
Returns
a pointer to the specified component, or nullptr if the given handle does not correspond to a valid entity with the specified component.

◆ findComponent() [2/2]

template<typename... KnownComponents>
template<component T>
GREM_ALWAYS_INLINE const T * grem::execution::EntityRegistry< KnownComponents >::findComponent ( EntityID id) const
inlinenodiscardnoexcept

Try to get a specific component of an entity.

Template Parameters
Tcomponent type to get.
Parameters
identity handle of the entity to get the component from.
Returns
a read-only pointer to the specified component, or nullptr if the given handle does not correspond to a valid entity with the specified component.

◆ getEntityIDAtEntityIndexUnsafe()

template<typename... KnownComponents>
GREM_ALWAYS_INLINE EntityID grem::execution::EntityRegistry< KnownComponents >::getEntityIDAtEntityIndexUnsafe ( EntityID::Index slotIndex) const
inlinenodiscard

Get the entity handle of the entity in a specific slot.

Parameters
slotIndexindex 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.
Returns
the entity handle of the entity in the specified slot.

◆ getComponentAtEntityIndexUnsafe() [1/2]

template<typename... KnownComponents>
template<component T>
GREM_ALWAYS_INLINE T & grem::execution::EntityRegistry< KnownComponents >::getComponentAtEntityIndexUnsafe ( EntityID::Index slotIndex)
inlinenodiscard

Get a specific component of the entity in a specific slot.

Template Parameters
Tcomponent type to get.
Parameters
slotIndexindex 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.
Returns
a reference to the specified component of the entity in the specified slot.

◆ getComponentAtEntityIndexUnsafe() [2/2]

template<typename... KnownComponents>
template<component T>
GREM_ALWAYS_INLINE const T & grem::execution::EntityRegistry< KnownComponents >::getComponentAtEntityIndexUnsafe ( EntityID::Index slotIndex) const
inlinenodiscard

Get a specific component of the entity in a specific slot.

Template Parameters
Tcomponent type to get.
Parameters
slotIndexindex 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.
Returns
a read-only reference to the specified component of the entity in the specified slot.

◆ getEntities() [1/2]

template<typename... KnownComponents>
template<typename... ComponentsAndExclusions>
requires (!meta::type_list_empty_v<typename Entities<ComponentsAndExclusions...>::MutableComponents>)
GREM_ALWAYS_INLINE Entities< ComponentsAndExclusions... > grem::execution::EntityRegistry< KnownComponents >::getEntities ( )
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.

Template Parameters
ComponentsAndExclusionscomponent and component exclusion types (e.g. Exclude<Component>) that specify which entities are part of the range.
Returns
the specified entity range, whose reference type can be destructured into a structured binding containing a read-only reference to the entity handle followed by potentially read-only references to all required components.
Remarks
Example usage: cpp for (auto&& [entityID, a, b] : registry.getEntities<A, const B, Exclude<C>>()) { // ... }

◆ getEntities() [2/2]

template<typename... KnownComponents>
template<typename... ComponentsAndExclusions>
requires (meta::type_list_empty_v<typename Entities<ComponentsAndExclusions...>::MutableComponents>)
GREM_ALWAYS_INLINE Entities< ComponentsAndExclusions... > grem::execution::EntityRegistry< KnownComponents >::getEntities ( ) const
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.

Template Parameters
ComponentsAndExclusionscomponent and component exclusion types (e.g. Exclude<Component>) that specify which entities are part of the range.
Returns
the specified entity range, whose reference type can be destructured into a structured binding containing a read-only reference to the entity handle followed by read-only references to all required components.
Remarks
Example usage: cpp for (auto&& [entityID, a, b] : registry.getEntities<const A, const B, Exclude<C>>()) { // ... }

◆ operator Entities< ComponentsAndExclusions... >() [1/2]

template<typename... KnownComponents>
template<typename... ComponentsAndExclusions>
requires (!meta::type_list_empty_v<typename Entities<ComponentsAndExclusions...>::MutableComponents>)
GREM_ALWAYS_INLINE grem::execution::EntityRegistry< KnownComponents >::operator Entities< ComponentsAndExclusions... > ( )
inlinenodiscardnoexcept

Implicitly convert the registry to an entity range.

Returns
the entity range.
See also
getEntities()

◆ operator Entities< ComponentsAndExclusions... >() [2/2]

template<typename... KnownComponents>
template<typename... ComponentsAndExclusions>
requires (meta::type_list_empty_v<typename Entities<ComponentsAndExclusions...>::MutableComponents>)
GREM_ALWAYS_INLINE grem::execution::EntityRegistry< KnownComponents >::operator Entities< ComponentsAndExclusions... > ( ) const
inlinenodiscardnoexcept

Implicitly convert the registry to an entity range.

Returns
the entity range.
See also
getEntities()

◆ getEntitiesChunk() [1/2]

template<typename... KnownComponents>
template<typename... ComponentsAndExclusions>
requires (!meta::type_list_empty_v<typename Entities<ComponentsAndExclusions...>::MutableComponents>)
GREM_ALWAYS_INLINE Entities< ComponentsAndExclusions... > grem::execution::EntityRegistry< KnownComponents >::getEntitiesChunk ( size_t chunkIndex,
size_t chunkCount )
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.

Template Parameters
ComponentsAndExclusionscomponent and component exclusion types (e.g. Exclude<Component>) that specify which entities are part of the range.
Parameters
chunkIndexindex of the specific chunk to get. Must be less than chunkCount.
chunkCountnumber of chunks that the entity range is divided into. Must be positive, and greater than chunkIndex.
Returns
the specified entity range chunk, whose reference type can be destructured into a structured binding containing a read-only reference to the entity handle followed by potentially read-only references to all required components.
Remarks
Example usage: cpp myParallelFor(chunkCount, [&](size_t chunkIndex) { for (auto&& [entityID, a, b] : registry.getEntitiesChunk<A, const B, Exclude<C>>(chunkIndex, chunkCount)) { // ... } });

◆ getEntitiesChunk() [2/2]

template<typename... KnownComponents>
template<typename... ComponentsAndExclusions>
requires (meta::type_list_empty_v<typename Entities<ComponentsAndExclusions...>::MutableComponents>)
GREM_ALWAYS_INLINE Entities< ComponentsAndExclusions... > grem::execution::EntityRegistry< KnownComponents >::getEntitiesChunk ( size_t chunkIndex,
size_t chunkCount ) const
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.

Template Parameters
ComponentsAndExclusionscomponent and component exclusion types (e.g. Exclude<Component>) that specify which entities are part of the range.
Parameters
chunkIndexindex of the specific chunk to get. Must be less than chunkCount.
chunkCountnumber of chunks that the entity range is divided into. Must be positive, and greater than chunkIndex.
Returns
the specified entity range chunk, whose reference type can be destructured into a structured binding containing a read-only reference to the entity handle followed by read-only references to all required components.
Remarks
Example usage: cpp myParallelFor(chunkCount, [&](size_t chunkIndex) { for (auto&& [entityID, a, b] : registry.getEntitiesChunk<const A, const B, Exclude<C>>(chunkIndex, chunkCount)) { // ... } });

◆ createComponentPool()

template<typename... KnownComponents>
template<component T>
GREM_ALWAYS_INLINE ComponentPool< T > grem::execution::EntityRegistry< KnownComponents >::createComponentPool ( )
inline

Ensure that the component pool for a specific component type has been created, and get a reference to it.

Template Parameters
Tcomponent type of the pool to create.
Returns
a valid reference to the specified component pool, which is created if it didn't already exist.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
See also
getComponentPool()

◆ getComponentPool() [1/2]

template<typename... KnownComponents>
template<component T>
GREM_ALWAYS_INLINE ComponentPool< T > grem::execution::EntityRegistry< KnownComponents >::getComponentPool ( )
inlinenodiscardnoexcept

Get a reference to a specific component pool if it exists.

Template Parameters
Tcomponent type of the pool to get.
Returns
a reference to the specified component pool, or an invalid component pool reference if the component pool hasn't been created yet.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
See also
createComponentPool()

◆ getComponentPool() [2/2]

template<typename... KnownComponents>
template<component T>
GREM_ALWAYS_INLINE ComponentPool< const T > grem::execution::EntityRegistry< KnownComponents >::getComponentPool ( ) const
inlinenodiscardnoexcept

Get a reference to a specific component pool if it exists.

Template Parameters
Tcomponent type of the pool to get.
Returns
a reference to the specified component pool, or an invalid component pool reference if the component pool hasn't been created yet.
Exceptions
std::length_errorif an internal size limit was exceeded.
std::bad_array_new_lengthif an internal size limit was exceeded.
std::bad_allocon allocation failure.
See also
createComponentPool()

◆ destroyEntities()

template<typename... KnownComponents>
template<typename... ComponentsAndExclusions>
size_type grem::execution::EntityRegistry< KnownComponents >::destroyEntities ( )
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.

Template Parameters
ComponentsAndExclusionscomponent and component exclusion types (e.g. Exclude<Component>) that specify which entities to destroy.

◆ erase_if

template<typename... KnownComponents>
template<typename Predicate>
size_type erase_if ( EntityRegistry< KnownComponents > & c,
Predicate predicate )
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.

Parameters
centity registry to erase from.
predicatecondition to check.
Returns
the number of entities that matched the predicate and were subsequently erased.
Exceptions
anyexception thrown by the predicate function.

The documentation for this class was generated from the following file: