OpenLexocad  27.1
entt::basic_registry< Entity > Class Template Reference

Fast and reliable entity-component system. More...

#include <entt.hpp>

Public Types

using entity_type = Entity
 Underlying entity identifier. More...
 
using version_type = typename traits_type::version_type
 Underlying version type. More...
 
using size_type = std::size_t
 Unsigned integer type. More...
 

Public Member Functions

 basic_registry () ENTT_NOEXCEPT=default
 Default constructor. More...
 
 basic_registry (basic_registry &&)=default
 Default move constructor. More...
 
basic_registryoperator= (basic_registry &&)=default
 Default move assignment operator. More...
 
template<typename... Component>
void prepare ()
 Prepares pools for the given types if required. More...
 
template<typename Component >
size_type size () const ENTT_NOEXCEPT
 Returns the number of existing components of the given type. More...
 
size_type size () const ENTT_NOEXCEPT
 Returns the number of entities created so far. More...
 
size_type alive () const ENTT_NOEXCEPT
 Returns the number of entities still in use. More...
 
template<typename... Component>
void reserve (const size_type cap)
 Increases the capacity of the registry or of the pools for the given components. More...
 
template<typename Component >
size_type capacity () const ENTT_NOEXCEPT
 Returns the capacity of the pool for the given component. More...
 
size_type capacity () const ENTT_NOEXCEPT
 Returns the number of entities that a registry has currently allocated space for. More...
 
template<typename... Component>
void shrink_to_fit ()
 Requests the removal of unused capacity for the given components. More...
 
template<typename... Component>
bool empty () const ENTT_NOEXCEPT
 Checks whether the registry or the pools of the given components are empty. More...
 
template<typename Component >
const Component * raw () const ENTT_NOEXCEPT
 Direct access to the list of components of a given pool. More...
 
template<typename Component >
Component * raw () ENTT_NOEXCEPT
 Direct access to the list of components of a given pool. More...
 
template<typename Component >
const entity_typedata () const ENTT_NOEXCEPT
 Direct access to the list of entities of a given pool. More...
 
bool valid (const entity_type entity) const ENTT_NOEXCEPT
 Checks if an entity identifier refers to a valid entity. More...
 
version_type current (const entity_type entity) const ENTT_NOEXCEPT
 Returns the actual version for an entity identifier. More...
 
template<typename... Component>
auto create ()
 Creates a new entity and returns it. More...
 
template<typename... Component, typename It >
auto create (It first, It last)
 Assigns each element in a range an entity. More...
 
template<typename... Component, typename... Exclude>
entity_type create (entity_type src, const basic_registry &other, exclude_t< Exclude... >={})
 Creates a new entity from a prototype entity. More...
 
template<typename... Component, typename It , typename... Exclude>
void create (It first, It last, entity_type src, const basic_registry &other, exclude_t< Exclude... >={})
 Assigns each element in a range an entity from a prototype entity. More...
 
void destroy (const entity_type entity)
 Destroys an entity and lets the registry recycle the identifier. More...
 
template<typename It >
void destroy (It first, It last)
 Destroys all the entities in a range. More...
 
template<typename Component , typename... Args>
decltype(auto) assign (const entity_type entity, [[maybe_unused]] Args &&... args)
 Assigns the given component to an entity. More...
 
template<typename Component >
void remove (const entity_type entity)
 Removes the given component from an entity. More...
 
template<typename... Component>
bool has (const entity_type entity) const ENTT_NOEXCEPT
 Checks if an entity has all the given components. More...
 
template<typename... Component>
decltype(auto) get ([[maybe_unused]] const entity_type entity) const
 Returns references to the given components for an entity. More...
 
template<typename... Component>
decltype(auto) get ([[maybe_unused]] const entity_type entity) ENTT_NOEXCEPT
 Returns references to the given components for an entity. More...
 
template<typename Component , typename... Args>
decltype(auto) get_or_assign (const entity_type entity, Args &&... args) ENTT_NOEXCEPT
 Returns a reference to the given component for an entity. More...
 
template<typename... Component>
auto try_get ([[maybe_unused]] const entity_type entity) const ENTT_NOEXCEPT
 Returns pointers to the given components for an entity. More...
 
template<typename... Component>
auto try_get ([[maybe_unused]] const entity_type entity) ENTT_NOEXCEPT
 Returns pointers to the given components for an entity. More...
 
template<typename Component , typename... Args>
decltype(auto) replace (const entity_type entity, Args &&... args)
 Replaces the given component for an entity. More...
 
template<typename Component , typename... Args>
decltype(auto) assign_or_replace (const entity_type entity, Args &&... args)
 Assigns or replaces the given component for an entity. More...
 
template<typename Component >
auto on_construct () ENTT_NOEXCEPT
 Returns a sink object for the given component. More...
 
template<typename Component >
auto on_replace () ENTT_NOEXCEPT
 Returns a sink object for the given component. More...
 
template<typename Component >
auto on_destroy () ENTT_NOEXCEPT
 Returns a sink object for the given component. More...
 
template<typename Component , typename Compare , typename Sort = std_sort, typename... Args>
void sort (Compare compare, Sort algo=Sort{}, Args &&... args)
 Sorts the pool of entities for the given component. More...
 
template<typename To , typename From >
void sort ()
 Sorts two pools of components in the same way. More...
 
template<typename Component >
void reset (const entity_type entity)
 Resets the given component for an entity. More...
 
template<typename Component >
void reset ()
 Resets the pool of the given component. More...
 
void reset ()
 Resets a whole registry. More...
 
template<typename Func >
void each (Func func) const
 Iterates all the entities that are still in use. More...
 
bool orphan (const entity_type entity) const
 Checks if an entity has components assigned. More...
 
template<typename Func >
void orphans (Func func) const
 Iterates orphans and applies them the given function object. More...
 
template<typename... Component, typename... Exclude>
entt::basic_view< Entity, exclude_t< Exclude... >, Component... > view (exclude_t< Exclude... >={})
 Returns a view for the given components. More...
 
template<typename... Component, typename... Exclude>
entt::basic_view< Entity, exclude_t< Exclude... >, Component... > view (exclude_t< Exclude... >={}) const
 Returns a view for the given components. More...
 
template<typename... Component>
bool sortable () const ENTT_NOEXCEPT
 Checks whether the given components belong to any group. More...
 
template<typename... Owned, typename... Get, typename... Exclude>
entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... > group (get_t< Get... >, exclude_t< Exclude... >={})
 Returns a group for the given components. More...
 
template<typename... Owned, typename... Get, typename... Exclude>
entt::basic_group< Entity, exclude_t< Exclude... >, get_t< Get... >, Owned... > group (get_t< Get... >, exclude_t< Exclude... >={}) const
 Returns a group for the given components. More...
 
template<typename... Owned, typename... Exclude>
entt::basic_group< Entity, exclude_t< Exclude... >, get_t<>, Owned... > group (exclude_t< Exclude... >={})
 Returns a group for the given components. More...
 
template<typename... Owned, typename... Exclude>
entt::basic_group< Entity, exclude_t< Exclude... >, get_t<>, Owned... > group (exclude_t< Exclude... >={}) const
 Returns a group for the given components. More...
 
template<typename It >
entt::basic_runtime_view< Entity > runtime_view (It first, It last) const
 Returns a runtime view for the given components. More...
 
template<typename... Component, typename... Exclude>
basic_registry clone (exclude_t< Exclude... >={}) const
 Returns a full or partial copy of a registry. More...
 
template<typename... Component, typename... Exclude>
void stomp (const entity_type dst, const entity_type src, const basic_registry &other, exclude_t< Exclude... >={})
 Stomps an entity and its components. More...
 
template<typename... Component, typename It , typename... Exclude>
void stomp (It first, It last, const entity_type src, const basic_registry &other, exclude_t< Exclude... >={})
 Stomps the entities in a range and their components. More...
 
entt::basic_snapshot< Entity > snapshot () const ENTT_NOEXCEPT
 Returns a temporary object to use to create snapshots. More...
 
basic_snapshot_loader< Entity > loader () ENTT_NOEXCEPT
 Returns a temporary object to use to load snapshots. More...
 
template<typename Type , typename... Args>
Type & set (Args &&... args)
 Binds an object to the context of the registry. More...
 
template<typename Type >
void unset ()
 Unsets a context variable if it exists. More...
 
template<typename Type , typename... Args>
Type & ctx_or_set (Args &&... args)
 Binds an object to the context of the registry. More...
 
template<typename Type >
const Type * try_ctx () const ENTT_NOEXCEPT
 Returns a pointer to an object in the context of the registry. More...
 
template<typename Type >
Type * try_ctx () ENTT_NOEXCEPT
 Returns a pointer to an object in the context of the registry. More...
 
template<typename Type >
const Type & ctx () const ENTT_NOEXCEPT
 Returns a reference to an object in the context of the registry. More...
 
template<typename Type >
Type & ctx () ENTT_NOEXCEPT
 Returns a reference to an object in the context of the registry. More...
 

Static Public Member Functions

template<typename Component >
static component type () ENTT_NOEXCEPT
 Returns the opaque identifier of a component. More...
 
static entity_type entity (const entity_type entity) ENTT_NOEXCEPT
 Returns the entity identifier without the version. More...
 
static version_type version (const entity_type entity) ENTT_NOEXCEPT
 Returns the version stored along with an entity identifier. More...
 

Detailed Description

template<typename Entity>
class entt::basic_registry< Entity >

Fast and reliable entity-component system.

The registry is the core class of the entity-component framework.
It stores entities and arranges pools of components on a per request basis. By means of a registry, users can manage entities and components and thus create views or groups to iterate them.

Template Parameters
EntityA valid entity type (see entt_traits for more details).

Member Typedef Documentation

◆ entity_type

template<typename Entity>
using entt::basic_registry< Entity >::entity_type = Entity

Underlying entity identifier.

◆ size_type

template<typename Entity>
using entt::basic_registry< Entity >::size_type = std::size_t

Unsigned integer type.

◆ version_type

template<typename Entity>
using entt::basic_registry< Entity >::version_type = typename traits_type::version_type

Underlying version type.

Constructor & Destructor Documentation

◆ basic_registry() [1/2]

template<typename Entity>
entt::basic_registry< Entity >::basic_registry ( )
default

Default constructor.

◆ basic_registry() [2/2]

template<typename Entity>
entt::basic_registry< Entity >::basic_registry ( basic_registry< Entity > &&  )
default

Default move constructor.

Member Function Documentation

◆ alive()

template<typename Entity>
size_type entt::basic_registry< Entity >::alive ( ) const
inline

Returns the number of entities still in use.

Returns
Number of entities still in use.

◆ assign()

template<typename Entity>
template<typename Component , typename... Args>
decltype(auto) entt::basic_registry< Entity >::assign ( const entity_type  entity,
[[maybe_unused] ] Args &&...  args 
)
inline

Assigns the given component to an entity.

A new instance of the given component is created and initialized with the arguments provided (the component must have a proper constructor or be of aggregate type). Then the component is assigned to the given entity.

Warning
Attempting to use an invalid entity or to assign a component to an entity that already owns it results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case of invalid entity or if the entity already owns an instance of the given component.
Template Parameters
ComponentType of component to create.
ArgsTypes of arguments to use to construct the component.
Parameters
entityA valid entity identifier.
argsParameters to use to initialize the component.
Returns
A reference to the newly created component.

◆ assign_or_replace()

template<typename Entity>
template<typename Component , typename... Args>
decltype(auto) entt::basic_registry< Entity >::assign_or_replace ( const entity_type  entity,
Args &&...  args 
)
inline

Assigns or replaces the given component for an entity.

Equivalent to the following snippet (pseudocode):

auto &component = registry.has<Component>(entity) ? registry.replace<Component>(entity, args...) : registry.assign<Component>(entity, args...);

Prefer this function anyway because it has slightly better performance.

Warning
Attempting to use an invalid entity results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case of invalid entity.
Template Parameters
ComponentType of component to assign or replace.
ArgsTypes of arguments to use to construct the component.
Parameters
entityA valid entity identifier.
argsParameters to use to initialize the component.
Returns
A reference to the newly created component.

◆ capacity() [1/2]

template<typename Entity>
template<typename Component >
size_type entt::basic_registry< Entity >::capacity ( ) const
inline

Returns the capacity of the pool for the given component.

Template Parameters
ComponentType of component in which one is interested.
Returns
Capacity of the pool of the given component.

◆ capacity() [2/2]

template<typename Entity>
size_type entt::basic_registry< Entity >::capacity ( ) const
inline

Returns the number of entities that a registry has currently allocated space for.

Returns
Capacity of the registry.

◆ clone()

template<typename Entity>
template<typename... Component, typename... Exclude>
basic_registry entt::basic_registry< Entity >::clone ( exclude_t< Exclude... >  = {}) const
inline

Returns a full or partial copy of a registry.

The components must be copyable for obvious reasons. The entities maintain their versions once copied.
If no components are provided, the registry will try to clone all the existing pools. The ones for non-copyable types won't be cloned.

This feature supports exclusion lists. The excluded types have higher priority than those indicated for cloning. An excluded type will never be cloned.

Note
There isn't an efficient way to know if all the entities are assigned at least one component once copied. Therefore, there may be orphans. It is up to the caller to clean up the registry if necessary.
Listeners and groups aren't copied. It is up to the caller to connect the listeners of interest to the new registry and to set up groups.
Warning
Attempting to clone components that aren't copyable results in unexpected behaviors.
A static assertion will abort the compilation when the components provided aren't copy constructible. Otherwise, an assertion will abort the execution at runtime in debug mode in case one or more pools cannot be cloned.
Template Parameters
ComponentTypes of components to clone.
ExcludeTypes of components not to be cloned.
Returns
A fresh copy of the registry.

◆ create() [1/4]

template<typename Entity>
template<typename... Component>
auto entt::basic_registry< Entity >::create ( void  )
inline

Creates a new entity and returns it.

There are two kinds of entity identifiers:

  • Newly created ones in case no entities have been previously destroyed.
  • Recycled ones with updated versions.

Users should not care about the type of the returned entity identifier. In case entity identifers are stored around, the valid member function can be used to know if they are still valid or the entity has been destroyed and potentially recycled.
The returned entity has assigned the given components, if any.

The components must be at least default constructible. A compilation error will occur otherwhise.

Template Parameters
ComponentTypes of components to assign to the entity.
Returns
A valid entity identifier if the component list is empty, a tuple containing the entity identifier and the references to the components just created otherwise.

◆ create() [2/4]

template<typename Entity>
template<typename... Component, typename It >
auto entt::basic_registry< Entity >::create ( It  first,
It  last 
)
inline

Assigns each element in a range an entity.

See also
create

The components must be at least move and default insertable. A compilation error will occur otherwhise.

Template Parameters
ComponentTypes of components to assign to the entity.
ItType of forward iterator.
Parameters
firstAn iterator to the first element of the range to generate.
lastAn iterator past the last element of the range to generate.
Returns
No return value if the component list is empty, a tuple containing the iterators to the lists of components just created and sorted the same of the entities otherwise.

◆ create() [3/4]

template<typename Entity>
template<typename... Component, typename... Exclude>
entity_type entt::basic_registry< Entity >::create ( entity_type  src,
const basic_registry< Entity > &  other,
exclude_t< Exclude... >  = {} 
)
inline

Creates a new entity from a prototype entity.

See also
create

The components must be copyable for obvious reasons. The source entity must be a valid one.
If no components are provided, the registry will try to copy all the existing types. The non-copyable ones will be ignored.

Note
Specifying the list of components is ways faster than an opaque copy.
Template Parameters
ComponentTypes of components to copy.
ExcludeTypes of components not to be copied.
Parameters
srcA valid entity identifier to be copied.
otherThe registry that owns the source entity.
Returns
A valid entity identifier.

◆ create() [4/4]

template<typename Entity>
template<typename... Component, typename It , typename... Exclude>
void entt::basic_registry< Entity >::create ( It  first,
It  last,
entity_type  src,
const basic_registry< Entity > &  other,
exclude_t< Exclude... >  = {} 
)
inline

Assigns each element in a range an entity from a prototype entity.

See also
create

The components must be copyable for obvious reasons. The entities must be all valid.
If no components are provided, the registry will try to copy all the existing types. The non-copyable ones will be ignored.

Note
Specifying the list of components is ways faster than an opaque copy and uses the batch creation under the hood.
Template Parameters
ComponentTypes of components to copy.
ItType of input iterator.
ExcludeTypes of components not to be copied.
Parameters
firstAn iterator to the first element of the range to generate.
lastAn iterator past the last element of the range to generate.
srcA valid entity identifier to be copied.
otherThe registry that owns the source entity.

◆ ctx() [1/2]

template<typename Entity>
template<typename Type >
const Type& entt::basic_registry< Entity >::ctx ( ) const
inline

Returns a reference to an object in the context of the registry.

Warning
Attempting to get a context variable that doesn't exist results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case of invalid requests.
Template Parameters
TypeType of object to get.
Returns
A valid reference to the object in the context of the registry.

◆ ctx() [2/2]

template<typename Entity>
template<typename Type >
Type& entt::basic_registry< Entity >::ctx ( )
inline

Returns a reference to an object in the context of the registry.

Warning
Attempting to get a context variable that doesn't exist results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case of invalid requests.
Template Parameters
TypeType of object to get.
Returns
A valid reference to the object in the context of the registry.

◆ ctx_or_set()

template<typename Entity>
template<typename Type , typename... Args>
Type& entt::basic_registry< Entity >::ctx_or_set ( Args &&...  args)
inline

Binds an object to the context of the registry.

In case the context doesn't contain the given object, the parameters provided are used to construct it.

Template Parameters
TypeType of object to set.
ArgsTypes of arguments to use to construct the object.
Parameters
argsParameters to use to initialize the object.
Returns
Reference to the object.

◆ current()

template<typename Entity>
version_type entt::basic_registry< Entity >::current ( const entity_type  entity) const
inline

Returns the actual version for an entity identifier.

Warning
Attempting to use an entity that doesn't belong to the registry results in undefined behavior. An entity belongs to the registry even if it has been previously destroyed and/or recycled.
An assertion will abort the execution at runtime in debug mode if the registry doesn't own the given entity.
Parameters
entityA valid entity identifier.
Returns
Actual version for the given entity identifier.

◆ data()

template<typename Entity>
template<typename Component >
const entity_type* entt::basic_registry< Entity >::data ( ) const
inline

Direct access to the list of entities of a given pool.

The returned pointer is such that range [data<Component>(), data<Component>() + size<Component>()] is always a valid range, even if the container is empty.

There are no guarantees on the order of the entities. Use a view if you want to iterate entities and components in the expected order.

Template Parameters
ComponentType of component in which one is interested.
Returns
A pointer to the array of entities.

◆ destroy() [1/2]

template<typename Entity>
void entt::basic_registry< Entity >::destroy ( const entity_type  entity)
inline

Destroys an entity and lets the registry recycle the identifier.

When an entity is destroyed, its version is updated and the identifier can be recycled at any time. In case entity identifers are stored around, the valid member function can be used to know if they are still valid or the entity has been destroyed and potentially recycled.

Warning
In case there are listeners that observe the destruction of components and assign other components to the entity in their bodies, the result of invoking this function may not be as expected. In the worst case, it could lead to undefined behavior. An assertion will abort the execution at runtime in debug mode if a violation is detected.
Attempting to use an invalid entity results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case of invalid entity.
Parameters
entityA valid entity identifier.

◆ destroy() [2/2]

template<typename Entity>
template<typename It >
void entt::basic_registry< Entity >::destroy ( It  first,
It  last 
)
inline

Destroys all the entities in a range.

See also
destroy
Template Parameters
ItType of input iterator.
Parameters
firstAn iterator to the first element of the range to destroy.
lastAn iterator past the last element of the range to destroy.

◆ each()

template<typename Entity>
template<typename Func >
void entt::basic_registry< Entity >::each ( Func  func) const
inline

Iterates all the entities that are still in use.

The function object is invoked for each entity that is still in use.
The signature of the function should be equivalent to the following:

void(const Entity);

This function is fairly slow and should not be used frequently. However, it's useful for iterating all the entities still in use, regardless of their components.

Template Parameters
FuncType of the function object to invoke.
Parameters
funcA valid function object.

◆ empty()

template<typename Entity>
template<typename... Component>
bool entt::basic_registry< Entity >::empty ( ) const
inline

Checks whether the registry or the pools of the given components are empty.

A registry is considered empty when it doesn't contain entities that are still in use.

Template Parameters
ComponentTypes of components in which one is interested.
Returns
True if the registry or the pools of the given components are empty, false otherwise.

◆ entity()

template<typename Entity>
static entity_type entt::basic_registry< Entity >::entity ( const entity_type  entity)
inlinestatic

Returns the entity identifier without the version.

Parameters
entityAn entity identifier, either valid or not.
Returns
The entity identifier without the version.

◆ get() [1/2]

template<typename Entity>
template<typename... Component>
decltype(auto) entt::basic_registry< Entity >::get ( [[maybe_unused] ] const entity_type  entity) const
inline

Returns references to the given components for an entity.

Warning
Attempting to use an invalid entity or to get a component from an entity that doesn't own it results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case of invalid entity or if the entity doesn't own an instance of the given component.
Template Parameters
ComponentTypes of components to get.
Parameters
entityA valid entity identifier.
Returns
References to the components owned by the entity.

◆ get() [2/2]

template<typename Entity>
template<typename... Component>
decltype(auto) entt::basic_registry< Entity >::get ( [[maybe_unused] ] const entity_type  entity)
inline

Returns references to the given components for an entity.

Warning
Attempting to use an invalid entity or to get a component from an entity that doesn't own it results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case of invalid entity or if the entity doesn't own an instance of the given component.
Template Parameters
ComponentTypes of components to get.
Parameters
entityA valid entity identifier.
Returns
References to the components owned by the entity.

◆ get_or_assign()

template<typename Entity>
template<typename Component , typename... Args>
decltype(auto) entt::basic_registry< Entity >::get_or_assign ( const entity_type  entity,
Args &&...  args 
)
inline

Returns a reference to the given component for an entity.

In case the entity doesn't own the component, the parameters provided are used to construct it.
Equivalent to the following snippet (pseudocode):

auto &component = registry.has<Component>(entity) ? registry.get<Component>(entity) : registry.assign<Component>(entity, args...);

Prefer this function anyway because it has slightly better performance.

Warning
Attempting to use an invalid entity results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case of invalid entity.
Template Parameters
ComponentType of component to get.
ArgsTypes of arguments to use to construct the component.
Parameters
entityA valid entity identifier.
argsParameters to use to initialize the component.
Returns
Reference to the component owned by the entity.

◆ group() [1/4]

template<typename Entity>
template<typename... Owned, typename... Get, typename... Exclude>
entt::basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...> entt::basic_registry< Entity >::group ( get_t< Get... >  ,
exclude_t< Exclude... >  = {} 
)
inline

Returns a group for the given components.

This kind of objects are created on the fly and share with the registry its internal data structures.
Feel free to discard a group after the use. Creating and destroying a group is an incredibly cheap operation because they do not require any type of initialization, but for the first time they are requested.
As a rule of thumb, storing a group should never be an option.

Groups support exclusion lists and can own types of components. The more types are owned by a group, the faster it is to iterate entities and components.
However, groups also affect some features of the registry such as the creation and destruction of components, which will consequently be slightly slower (nothing that can be noticed in most cases).

Note
Pools of components that are owned by a group cannot be sorted anymore. The group takes the ownership of the pools and arrange components so as to iterate them as fast as possible.
Template Parameters
OwnedTypes of components owned by the group.
GetTypes of components observed by the group.
ExcludeTypes of components used to filter the group.
Returns
A newly created group.

◆ group() [2/4]

template<typename Entity>
template<typename... Owned, typename... Get, typename... Exclude>
entt::basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...> entt::basic_registry< Entity >::group ( get_t< Get... >  ,
exclude_t< Exclude... >  = {} 
) const
inline

Returns a group for the given components.

See also
group
Template Parameters
OwnedTypes of components owned by the group.
GetTypes of components observed by the group.
ExcludeTypes of components used to filter the group.
Returns
A newly created group.

◆ group() [3/4]

template<typename Entity>
template<typename... Owned, typename... Exclude>
entt::basic_group<Entity, exclude_t<Exclude...>, get_t<>, Owned...> entt::basic_registry< Entity >::group ( exclude_t< Exclude... >  = {})
inline

Returns a group for the given components.

See also
group
Template Parameters
OwnedTypes of components owned by the group.
ExcludeTypes of components used to filter the group.
Returns
A newly created group.

◆ group() [4/4]

template<typename Entity>
template<typename... Owned, typename... Exclude>
entt::basic_group<Entity, exclude_t<Exclude...>, get_t<>, Owned...> entt::basic_registry< Entity >::group ( exclude_t< Exclude... >  = {}) const
inline

Returns a group for the given components.

See also
group
Template Parameters
OwnedTypes of components owned by the group.
ExcludeTypes of components used to filter the group.
Returns
A newly created group.

◆ has()

template<typename Entity>
template<typename... Component>
bool entt::basic_registry< Entity >::has ( const entity_type  entity) const
inline

Checks if an entity has all the given components.

Warning
Attempting to use an invalid entity results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case of invalid entity.
Template Parameters
ComponentComponents for which to perform the check.
Parameters
entityA valid entity identifier.
Returns
True if the entity has all the components, false otherwise.

◆ loader()

template<typename Entity>
basic_snapshot_loader<Entity> entt::basic_registry< Entity >::loader ( )
inline

Returns a temporary object to use to load snapshots.

A snapshot is either a full or a partial dump of a registry.
It can be used to save and restore its internal state or to keep two or more instances of this class in sync, as an example in a client-server architecture.

Note
The loader returned by this function requires that the registry be empty. In case it isn't, all the data will be automatically deleted before to return.
Returns
A temporary object to use to load snasphosts.

◆ on_construct()

template<typename Entity>
template<typename Component >
auto entt::basic_registry< Entity >::on_construct ( )
inline

Returns a sink object for the given component.

A sink is an opaque object used to connect listeners to components.
The sink returned by this function can be used to receive notifications whenever a new instance of the given component is created and assigned to an entity.

The function type for a listener is equivalent to:

void(Entity, registry<Entity> &, Component &);

Listeners are invoked after the component has been assigned to the entity. The order of invocation of the listeners isn't guaranteed.

Note
Empty types aren't explicitly instantiated. Therefore, temporary objects are returned through signals. They can be caught only by copy or with const references.
See also
sink
Template Parameters
ComponentType of component of which to get the sink.
Returns
A temporary sink object.

◆ on_destroy()

template<typename Entity>
template<typename Component >
auto entt::basic_registry< Entity >::on_destroy ( )
inline

Returns a sink object for the given component.

A sink is an opaque object used to connect listeners to components.
The sink returned by this function can be used to receive notifications whenever an instance of the given component is removed from an entity and thus destroyed.

The function type for a listener is equivalent to:

void(Entity, registry<Entity> &);

Listeners are invoked before the component has been removed from the entity. The order of invocation of the listeners isn't guaranteed.

Note
Empty types aren't explicitly instantiated. Therefore, temporary objects are returned through signals. They can be caught only by copy or with const references.
See also
sink
Template Parameters
ComponentType of component of which to get the sink.
Returns
A temporary sink object.

◆ on_replace()

template<typename Entity>
template<typename Component >
auto entt::basic_registry< Entity >::on_replace ( )
inline

Returns a sink object for the given component.

A sink is an opaque object used to connect listeners to components.
The sink returned by this function can be used to receive notifications whenever an instance of the given component is explicitly replaced.

The function type for a listener is equivalent to:

void(Entity, registry<Entity> &, Component &);

Listeners are invoked before the component has been replaced. The order of invocation of the listeners isn't guaranteed.

Note
Empty types aren't explicitly instantiated. Therefore, temporary objects are returned through signals. They can be caught only by copy or with const references.
See also
sink
Template Parameters
ComponentType of component of which to get the sink.
Returns
A temporary sink object.

◆ operator=()

template<typename Entity>
basic_registry& entt::basic_registry< Entity >::operator= ( basic_registry< Entity > &&  )
default

Default move assignment operator.

Returns
This registry.

◆ orphan()

template<typename Entity>
bool entt::basic_registry< Entity >::orphan ( const entity_type  entity) const
inline

Checks if an entity has components assigned.

Parameters
entityA valid entity identifier.
Returns
True if the entity has no components assigned, false otherwise.

◆ orphans()

template<typename Entity>
template<typename Func >
void entt::basic_registry< Entity >::orphans ( Func  func) const
inline

Iterates orphans and applies them the given function object.

The function object is invoked for each entity that is still in use and has no components assigned.
The signature of the function should be equivalent to the following:

void(const Entity);

This function can be very slow and should not be used frequently.

Template Parameters
FuncType of the function object to invoke.
Parameters
funcA valid function object.

◆ prepare()

template<typename Entity>
template<typename... Component>
void entt::basic_registry< Entity >::prepare ( )
inline

Prepares pools for the given types if required.

Template Parameters
ComponentTypes of components for which to prepare pools.

◆ raw() [1/2]

template<typename Entity>
template<typename Component >
const Component* entt::basic_registry< Entity >::raw ( ) const
inline

Direct access to the list of components of a given pool.

The returned pointer is such that range [raw<Component>(), raw<Component>() + size<Component>()] is always a valid range, even if the container is empty.

There are no guarantees on the order of the components. Use a view if you want to iterate entities and components in the expected order.

Note
Empty components aren't explicitly instantiated. Therefore, this function isn't available for them. A compilation error will occur if invoked.
Template Parameters
ComponentType of component in which one is interested.
Returns
A pointer to the array of components of the given type.

◆ raw() [2/2]

template<typename Entity>
template<typename Component >
Component* entt::basic_registry< Entity >::raw ( )
inline

Direct access to the list of components of a given pool.

The returned pointer is such that range [raw<Component>(), raw<Component>() + size<Component>()] is always a valid range, even if the container is empty.

There are no guarantees on the order of the components. Use a view if you want to iterate entities and components in the expected order.

Note
Empty components aren't explicitly instantiated. Therefore, this function isn't available for them. A compilation error will occur if invoked.
Template Parameters
ComponentType of component in which one is interested.
Returns
A pointer to the array of components of the given type.

◆ remove()

template<typename Entity>
template<typename Component >
void entt::basic_registry< Entity >::remove ( const entity_type  entity)
inline

Removes the given component from an entity.

Warning
Attempting to use an invalid entity or to remove a component from an entity that doesn't own it results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case of invalid entity or if the entity doesn't own an instance of the given component.
Template Parameters
ComponentType of component to remove.
Parameters
entityA valid entity identifier.

◆ replace()

template<typename Entity>
template<typename Component , typename... Args>
decltype(auto) entt::basic_registry< Entity >::replace ( const entity_type  entity,
Args &&...  args 
)
inline

Replaces the given component for an entity.

A new instance of the given component is created and initialized with the arguments provided (the component must have a proper constructor or be of aggregate type). Then the component is assigned to the given entity.

Warning
Attempting to use an invalid entity or to replace a component of an entity that doesn't own it results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case of invalid entity or if the entity doesn't own an instance of the given component.
Template Parameters
ComponentType of component to replace.
ArgsTypes of arguments to use to construct the component.
Parameters
entityA valid entity identifier.
argsParameters to use to initialize the component.
Returns
A reference to the newly created component.

◆ reserve()

template<typename Entity>
template<typename... Component>
void entt::basic_registry< Entity >::reserve ( const size_type  cap)
inline

Increases the capacity of the registry or of the pools for the given components.

If no components are specified, the capacity of the registry is increased, that is the number of entities it contains. Otherwise the capacity of the pools for the given components is increased.
In both cases, if the new capacity is greater than the current capacity, new storage is allocated, otherwise the method does nothing.

Template Parameters
ComponentTypes of components for which to reserve storage.
Parameters
capDesired capacity.

◆ reset() [1/3]

template<typename Entity>
template<typename Component >
void entt::basic_registry< Entity >::reset ( const entity_type  entity)
inline

Resets the given component for an entity.

If the entity has an instance of the component, this function removes the component from the entity. Otherwise it does nothing.

Warning
Attempting to use an invalid entity results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case of invalid entity.
Template Parameters
ComponentType of component to reset.
Parameters
entityA valid entity identifier.

◆ reset() [2/3]

template<typename Entity>
template<typename Component >
void entt::basic_registry< Entity >::reset ( )
inline

Resets the pool of the given component.

For each entity that has an instance of the given component, the component itself is removed and thus destroyed.

Template Parameters
ComponentType of component whose pool must be reset.

◆ reset() [3/3]

template<typename Entity>
void entt::basic_registry< Entity >::reset ( )
inline

Resets a whole registry.

Destroys all the entities. After a call to reset, all the entities still in use are recycled with a new version number. In case entity identifers are stored around, the valid member function can be used to know if they are still valid.

◆ runtime_view()

template<typename Entity>
template<typename It >
entt::basic_runtime_view<Entity> entt::basic_registry< Entity >::runtime_view ( It  first,
It  last 
) const
inline

Returns a runtime view for the given components.

This kind of objects are created on the fly and share with the registry its internal data structures.
Users should throw away the view after use. Fortunately, creating and destroying a runtime view is an incredibly cheap operation because they do not require any type of initialization.
As a rule of thumb, storing a view should never be an option.

Runtime views are to be used when users want to construct a view from some external inputs and don't know at compile-time what are the required components.
This is particularly well suited to plugin systems and mods in general.

Template Parameters
ItType of input iterator.
Parameters
firstAn iterator to the first element of the range of components.
lastAn iterator past the last element of the range of components.
Returns
A newly created runtime view.

◆ set()

template<typename Entity>
template<typename Type , typename... Args>
Type& entt::basic_registry< Entity >::set ( Args &&...  args)
inline

Binds an object to the context of the registry.

If the value already exists it is overwritten, otherwise a new instance of the given type is created and initialized with the arguments provided.

Template Parameters
TypeType of object to set.
ArgsTypes of arguments to use to construct the object.
Parameters
argsParameters to use to initialize the value.
Returns
A reference to the newly created object.

◆ shrink_to_fit()

template<typename Entity>
template<typename... Component>
void entt::basic_registry< Entity >::shrink_to_fit ( )
inline

Requests the removal of unused capacity for the given components.

Template Parameters
ComponentTypes of components for which to reclaim unused capacity.

◆ size() [1/2]

template<typename Entity>
template<typename Component >
size_type entt::basic_registry< Entity >::size ( ) const
inline

Returns the number of existing components of the given type.

Template Parameters
ComponentType of component of which to return the size.
Returns
Number of existing components of the given type.

◆ size() [2/2]

template<typename Entity>
size_type entt::basic_registry< Entity >::size ( ) const
inline

Returns the number of entities created so far.

Returns
Number of entities created so far.

◆ snapshot()

template<typename Entity>
entt::basic_snapshot<Entity> entt::basic_registry< Entity >::snapshot ( ) const
inline

Returns a temporary object to use to create snapshots.

A snapshot is either a full or a partial dump of a registry.
It can be used to save and restore its internal state or to keep two or more instances of this class in sync, as an example in a client-server architecture.

Returns
A temporary object to use to take snasphosts.

◆ sort() [1/2]

template<typename Entity>
template<typename Component , typename Compare , typename Sort = std_sort, typename... Args>
void entt::basic_registry< Entity >::sort ( Compare  compare,
Sort  algo = Sort{},
Args &&...  args 
)
inline

Sorts the pool of entities for the given component.

The order of the elements in a pool is highly affected by assignments of components to entities and deletions. Components are arranged to maximize the performance during iterations and users should not make any assumption on the order.
This function can be used to impose an order to the elements in the pool of the given component. The order is kept valid until a component of the given type is assigned or removed from an entity.

The comparison function object must return true if the first element is less than the second one, false otherwise. The signature of the comparison function should be equivalent to one of the following:

bool(const Entity, const Entity);
bool(const Component &, const Component &);

Moreover, the comparison function object shall induce a strict weak ordering on the values.

The sort function oject must offer a member function template operator() that accepts three arguments:

  • An iterator to the first element of the range to sort.
  • An iterator past the last element of the range to sort.
  • A comparison function to use to compare the elements.

The comparison funtion object received by the sort function object hasn't necessarily the type of the one passed along with the other parameters to this member function.

Warning
Pools of components owned by a group cannot be sorted.
An assertion will abort the execution at runtime in debug mode in case the pool is owned by a group.
Template Parameters
ComponentType of components to sort.
CompareType of comparison function object.
SortType of sort function object.
ArgsTypes of arguments to forward to the sort function object.
Parameters
compareA valid comparison function object.
algoA valid sort function object.
argsArguments to forward to the sort function object, if any.

◆ sort() [2/2]

template<typename Entity>
template<typename To , typename From >
void entt::basic_registry< Entity >::sort ( )
inline

Sorts two pools of components in the same way.

The order of the elements in a pool is highly affected by assignments of components to entities and deletions. Components are arranged to maximize the performance during iterations and users should not make any assumption on the order.

It happens that different pools of components must be sorted the same way because of runtime and/or performance constraints. This function can be used to order a pool of components according to the order between the entities in another pool of components.

How it works

Being A and B the two sets where B is the master (the one the order of which rules) and A is the slave (the one to sort), after a call to this function an iterator for A will return the entities according to the following rules:

  • All the entities in A that are also in B are returned first according to the order they have in B.
  • All the entities in A that are not in B are returned in no particular order after all the other entities.

Any subsequent change to B won't affect the order in A.

Warning
Pools of components owned by a group cannot be sorted.
An assertion will abort the execution at runtime in debug mode in case the pool is owned by a group.
Template Parameters
ToType of components to sort.
FromType of components to use to sort.

◆ sortable()

template<typename Entity>
template<typename... Component>
bool entt::basic_registry< Entity >::sortable ( ) const
inline

Checks whether the given components belong to any group.

Template Parameters
ComponentTypes of components in which one is interested.
Returns
True if the pools of the given components are sortable, false otherwise.

◆ stomp() [1/2]

template<typename Entity>
template<typename... Component, typename... Exclude>
void entt::basic_registry< Entity >::stomp ( const entity_type  dst,
const entity_type  src,
const basic_registry< Entity > &  other,
exclude_t< Exclude... >  = {} 
)
inline

Stomps an entity and its components.

The components must be copyable for obvious reasons. The entities must be both valid.
If no components are provided, the registry will try to copy all the existing types. The non-copyable ones will be ignored.

This feature supports exclusion lists as an alternative to component lists. An excluded type will never be copied.

Warning
Attempting to copy components that aren't copyable results in unexpected behaviors.
A static assertion will abort the compilation when the components provided aren't copy constructible. Otherwise, an assertion will abort the execution at runtime in debug mode in case one or more types cannot be copied.
Attempting to use invalid entities results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case of invalid entities.
Template Parameters
ComponentTypes of components to copy.
ExcludeTypes of components not to be copied.
Parameters
dstA valid entity identifier to copy to.
srcA valid entity identifier to be copied.
otherThe registry that owns the source entity.

◆ stomp() [2/2]

template<typename Entity>
template<typename... Component, typename It , typename... Exclude>
void entt::basic_registry< Entity >::stomp ( It  first,
It  last,
const entity_type  src,
const basic_registry< Entity > &  other,
exclude_t< Exclude... >  = {} 
)
inline

Stomps the entities in a range and their components.

See also
stomp
Template Parameters
ComponentTypes of components to copy.
ItType of input iterator.
ExcludeTypes of components not to be copied.
Parameters
firstAn iterator to the first element of the range to stomp.
lastAn iterator past the last element of the range to stomp.
srcA valid entity identifier to be copied.
otherThe registry that owns the source entity.

◆ try_ctx() [1/2]

template<typename Entity>
template<typename Type >
const Type* entt::basic_registry< Entity >::try_ctx ( ) const
inline

Returns a pointer to an object in the context of the registry.

Template Parameters
TypeType of object to get.
Returns
A pointer to the object if it exists in the context of the registry, a null pointer otherwise.

◆ try_ctx() [2/2]

template<typename Entity>
template<typename Type >
Type* entt::basic_registry< Entity >::try_ctx ( )
inline

Returns a pointer to an object in the context of the registry.

Template Parameters
TypeType of object to get.
Returns
A pointer to the object if it exists in the context of the registry, a null pointer otherwise.

◆ try_get() [1/2]

template<typename Entity>
template<typename... Component>
auto entt::basic_registry< Entity >::try_get ( [[maybe_unused] ] const entity_type  entity) const
inline

Returns pointers to the given components for an entity.

Warning
Attempting to use an invalid entity results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case of invalid entity.
Template Parameters
ComponentTypes of components to get.
Parameters
entityA valid entity identifier.
Returns
Pointers to the components owned by the entity.

◆ try_get() [2/2]

template<typename Entity>
template<typename... Component>
auto entt::basic_registry< Entity >::try_get ( [[maybe_unused] ] const entity_type  entity)
inline

Returns pointers to the given components for an entity.

Warning
Attempting to use an invalid entity results in undefined behavior.
An assertion will abort the execution at runtime in debug mode in case of invalid entity.
Template Parameters
ComponentTypes of components to get.
Parameters
entityA valid entity identifier.
Returns
Pointers to the components owned by the entity.

◆ type()

template<typename Entity>
template<typename Component >
static component entt::basic_registry< Entity >::type ( )
inlinestatic

Returns the opaque identifier of a component.

The given component doesn't need to be necessarily in use.
Identifiers aren't guaranteed to be stable between different runs.

Template Parameters
ComponentType of component to query.
Returns
The opaque identifier of the given type of component.

◆ unset()

template<typename Entity>
template<typename Type >
void entt::basic_registry< Entity >::unset ( )
inline

Unsets a context variable if it exists.

Template Parameters
TypeType of object to set.

◆ valid()

template<typename Entity>
bool entt::basic_registry< Entity >::valid ( const entity_type  entity) const
inline

Checks if an entity identifier refers to a valid entity.

Parameters
entityAn entity identifier, either valid or not.
Returns
True if the identifier is valid, false otherwise.

◆ version()

template<typename Entity>
static version_type entt::basic_registry< Entity >::version ( const entity_type  entity)
inlinestatic

Returns the version stored along with an entity identifier.

Parameters
entityAn entity identifier, either valid or not.
Returns
The version stored along with the given entity identifier.

◆ view() [1/2]

template<typename Entity>
template<typename... Component, typename... Exclude>
entt::basic_view<Entity, exclude_t<Exclude...>, Component...> entt::basic_registry< Entity >::view ( exclude_t< Exclude... >  = {})
inline

Returns a view for the given components.

This kind of objects are created on the fly and share with the registry its internal data structures.
Feel free to discard a view after the use. Creating and destroying a view is an incredibly cheap operation because they do not require any type of initialization.
As a rule of thumb, storing a view should never be an option.

Views do their best to iterate the smallest set of candidate entities. In particular:

  • Single component views are incredibly fast and iterate a packed array of entities, all of which has the given component.
  • Multi component views look at the number of entities available for each component and pick up a reference to the smallest set of candidates to test for the given components.

Views in no way affect the functionalities of the registry nor those of the underlying pools.

Note
Multi component views are pretty fast. However their performance tend to degenerate when the number of components to iterate grows up and the most of the entities have all the given components.
To get a performance boost, consider using a group instead.
Template Parameters
ComponentType of components used to construct the view.
ExcludeTypes of components used to filter the view.
Returns
A newly created view.

◆ view() [2/2]

template<typename Entity>
template<typename... Component, typename... Exclude>
entt::basic_view<Entity, exclude_t<Exclude...>, Component...> entt::basic_registry< Entity >::view ( exclude_t< Exclude... >  = {}) const
inline

Returns a view for the given components.

This kind of objects are created on the fly and share with the registry its internal data structures.
Feel free to discard a view after the use. Creating and destroying a view is an incredibly cheap operation because they do not require any type of initialization.
As a rule of thumb, storing a view should never be an option.

Views do their best to iterate the smallest set of candidate entities. In particular:

  • Single component views are incredibly fast and iterate a packed array of entities, all of which has the given component.
  • Multi component views look at the number of entities available for each component and pick up a reference to the smallest set of candidates to test for the given components.

Views in no way affect the functionalities of the registry nor those of the underlying pools.

Note
Multi component views are pretty fast. However their performance tend to degenerate when the number of components to iterate grows up and the most of the entities have all the given components.
To get a performance boost, consider using a group instead.
Template Parameters
ComponentType of components used to construct the view.
ExcludeTypes of components used to filter the view.
Returns
A newly created view.

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