EnTT 3.13.0
|
Fast and reliable entity-component system. More...
#include <registry.hpp>
Public Types | |
using | traits_type = typename base_type::traits_type |
Entity traits. | |
using | allocator_type = Allocator |
Allocator type. | |
using | entity_type = typename traits_type::value_type |
Underlying entity identifier. | |
using | version_type = typename traits_type::version_type |
Underlying version type. | |
using | size_type = std::size_t |
Unsigned integer type. | |
using | common_type = base_type |
Common type among all storage types. | |
using | context = internal::registry_context< allocator_type > |
Context type. | |
using | iterable = iterable_adaptor< internal::registry_storage_iterator< typename pool_container_type::iterator > > |
Iterable registry type. | |
using | const_iterable = iterable_adaptor< internal::registry_storage_iterator< typename pool_container_type::const_iterator > > |
Constant iterable registry type. | |
template<typename Type > | |
using | storage_for_type = typename storage_for< Type, Entity, typename alloc_traits::template rebind_alloc< std::remove_const_t< Type > > >::type |
Public Member Functions | |
basic_registry () | |
Default constructor. | |
basic_registry (const allocator_type &allocator) | |
Constructs an empty registry with a given allocator. | |
basic_registry (const size_type count, const allocator_type &allocator=allocator_type{}) | |
Allocates enough memory upon construction to store count pools. | |
basic_registry (basic_registry &&other) noexcept | |
Move constructor. | |
basic_registry & | operator= (basic_registry &&other) noexcept |
Move assignment operator. | |
void | swap (basic_registry &other) |
Exchanges the contents with those of a given registry. | |
constexpr allocator_type | get_allocator () const noexcept |
Returns the associated allocator. | |
iterable | storage () noexcept |
Returns an iterable object to use to visit a registry. | |
const_iterable | storage () const noexcept |
Returns an iterable object to use to visit a registry. | |
common_type * | storage (const id_type id) |
Finds the storage associated with a given name, if any. | |
const common_type * | storage (const id_type id) const |
Finds the storage associated with a given name, if any. | |
template<typename Type > | |
storage_for_type< Type > & | storage (const id_type id=type_hash< Type >::value()) |
Returns the storage for a given component type. | |
template<typename Type > | |
const storage_for_type< Type > * | storage (const id_type id=type_hash< Type >::value()) const |
Returns the storage for a given component type, if any. | |
bool | valid (const entity_type entt) const |
Checks if an identifier refers to a valid entity. | |
version_type | current (const entity_type entt) const |
Returns the actual version for an identifier. | |
entity_type | create () |
Creates a new entity or recycles a destroyed one. | |
entity_type | create (const entity_type hint) |
Creates a new entity or recycles a destroyed one. | |
template<typename It > | |
void | create (It first, It last) |
Assigns each element in a range an identifier. | |
version_type | destroy (const entity_type entt) |
Destroys an entity and releases its identifier. | |
version_type | destroy (const entity_type entt, const version_type version) |
Destroys an entity and releases its identifier. | |
template<typename It > | |
void | destroy (It first, It last) |
Destroys all entities in a range and releases their identifiers. | |
template<typename Type , typename... Args> | |
decltype(auto) | emplace (const entity_type entt, Args &&...args) |
Assigns the given component to an entity. | |
template<typename Type , typename It > | |
void | insert (It first, It last, const Type &value={}) |
Assigns each entity in a range the given component. | |
template<typename Type , typename EIt , typename CIt , typename = std::enable_if_t<std::is_same_v<typename std::iterator_traits<CIt>::value_type, Type>>> | |
void | insert (EIt first, EIt last, CIt from) |
Assigns each entity in a range the given components. | |
template<typename Type , typename... Args> | |
decltype(auto) | emplace_or_replace (const entity_type entt, Args &&...args) |
Assigns or replaces the given component for an entity. | |
template<typename Type , typename... Func> | |
decltype(auto) | patch (const entity_type entt, Func &&...func) |
Patches the given component for an entity. | |
template<typename Type , typename... Args> | |
decltype(auto) | replace (const entity_type entt, Args &&...args) |
Replaces the given component for an entity. | |
template<typename Type , typename... Other> | |
size_type | remove (const entity_type entt) |
Removes the given components from an entity. | |
template<typename Type , typename... Other, typename It > | |
size_type | remove (It first, It last) |
Removes the given components from all the entities in a range. | |
template<typename Type , typename... Other> | |
void | erase (const entity_type entt) |
Erases the given components from an entity. | |
template<typename Type , typename... Other, typename It > | |
void | erase (It first, It last) |
Erases the given components from all the entities in a range. | |
template<typename Func > | |
void | erase_if (const entity_type entt, Func func) |
Erases components satisfying specific criteria from an entity. | |
template<typename... Type> | |
void | compact () |
Removes all tombstones from a registry or only the pools for the given components. | |
template<typename... Type> | |
bool | all_of (const entity_type entt) const |
Check if an entity is part of all the given storage. | |
template<typename... Type> | |
bool | any_of (const entity_type entt) const |
Check if an entity is part of at least one given storage. | |
template<typename... Type> | |
decltype(auto) | get (const entity_type entt) const |
Returns references to the given components for an entity. | |
template<typename... Type> | |
decltype(auto) | get (const entity_type entt) |
Returns references to the given components for an entity. | |
template<typename Type , typename... Args> | |
decltype(auto) | get_or_emplace (const entity_type entt, Args &&...args) |
Returns a reference to the given component for an entity. | |
template<typename... Type> | |
auto | try_get (const entity_type entt) const |
Returns pointers to the given components for an entity. | |
template<typename... Type> | |
auto | try_get (const entity_type entt) |
Returns pointers to the given components for an entity. | |
template<typename... Type> | |
void | clear () |
Clears a whole registry or the pools for the given components. | |
bool | orphan (const entity_type entt) const |
Checks if an entity has components assigned. | |
template<typename Type > | |
auto | on_construct (const id_type id=type_hash< Type >::value()) |
Returns a sink object for the given component. | |
template<typename Type > | |
auto | on_update (const id_type id=type_hash< Type >::value()) |
Returns a sink object for the given component. | |
template<typename Type > | |
auto | on_destroy (const id_type id=type_hash< Type >::value()) |
Returns a sink object for the given component. | |
template<typename Type , typename... Other, typename... Exclude> | |
basic_view< get_t< storage_for_type< const Type >, storage_for_type< const Other >... >, exclude_t< storage_for_type< const Exclude >... > > | view (exclude_t< Exclude... >=exclude_t{}) const |
Returns a view for the given components. | |
template<typename Type , typename... Other, typename... Exclude> | |
basic_view< get_t< storage_for_type< Type >, storage_for_type< Other >... >, exclude_t< storage_for_type< Exclude >... > > | view (exclude_t< Exclude... >=exclude_t{}) |
Returns a view for the given components. | |
template<typename... Owned, typename... Get, typename... Exclude> | |
basic_group< owned_t< storage_for_type< Owned >... >, get_t< storage_for_type< Get >... >, exclude_t< storage_for_type< Exclude >... > > | group (get_t< Get... >=get_t{}, exclude_t< Exclude... >=exclude_t{}) |
Returns a group for the given components. | |
template<typename... Owned, typename... Get, typename... Exclude> | |
basic_group< owned_t< storage_for_type< const Owned >... >, get_t< storage_for_type< const Get >... >, exclude_t< storage_for_type< const Exclude >... > > | group_if_exists (get_t< Get... >=get_t{}, exclude_t< Exclude... >=exclude_t{}) const |
Returns a group for the given components. | |
template<typename Type , typename... Other> | |
bool | owned () const |
Checks whether the given components belong to any group. | |
template<typename Type , typename Compare , typename Sort = std_sort, typename... Args> | |
void | sort (Compare compare, Sort algo=Sort{}, Args &&...args) |
Sorts the elements of a given component. | |
template<typename To , typename From > | |
void | sort () |
Sorts two pools of components in the same way. | |
context & | ctx () noexcept |
Returns the context object, that is, a general purpose container. | |
const context & | ctx () const noexcept |
Returns the context object, that is, a general purpose container. | |
Fast and reliable entity-component system.
Entity | A valid entity type. |
Allocator | Type of allocator used to manage memory and elements. |
Definition at line 233 of file registry.hpp.
using entt::basic_registry< Entity, Allocator >::allocator_type = Allocator |
Allocator type.
Definition at line 299 of file registry.hpp.
using entt::basic_registry< Entity, Allocator >::common_type = base_type |
Common type among all storage types.
Definition at line 307 of file registry.hpp.
using entt::basic_registry< Entity, Allocator >::const_iterable = iterable_adaptor<internal::registry_storage_iterator<typename pool_container_type::const_iterator> > |
Constant iterable registry type.
Definition at line 313 of file registry.hpp.
using entt::basic_registry< Entity, Allocator >::context = internal::registry_context<allocator_type> |
Context type.
Definition at line 309 of file registry.hpp.
using entt::basic_registry< Entity, Allocator >::entity_type = typename traits_type::value_type |
Underlying entity identifier.
Definition at line 301 of file registry.hpp.
using entt::basic_registry< Entity, Allocator >::iterable = iterable_adaptor<internal::registry_storage_iterator<typename pool_container_type::iterator> > |
Iterable registry type.
Definition at line 311 of file registry.hpp.
using entt::basic_registry< Entity, Allocator >::size_type = std::size_t |
Unsigned integer type.
Definition at line 305 of file registry.hpp.
using entt::basic_registry< Entity, Allocator >::storage_for_type = typename storage_for<Type, Entity, typename alloc_traits::template rebind_alloc<std::remove_const_t<Type> >>::type |
Type | Storage value type, eventually const. |
Definition at line 320 of file registry.hpp.
using entt::basic_registry< Entity, Allocator >::traits_type = typename base_type::traits_type |
Entity traits.
Definition at line 297 of file registry.hpp.
using entt::basic_registry< Entity, Allocator >::version_type = typename traits_type::version_type |
Underlying version type.
Definition at line 303 of file registry.hpp.
|
inline |
Default constructor.
Definition at line 323 of file registry.hpp.
|
inlineexplicit |
Constructs an empty registry with a given allocator.
allocator | The allocator to use. |
Definition at line 330 of file registry.hpp.
|
inline |
Allocates enough memory upon construction to store count
pools.
count | The number of pools to allocate memory for. |
allocator | The allocator to use. |
Definition at line 338 of file registry.hpp.
|
inlinenoexcept |
Move constructor.
other | The instance to move from. |
Definition at line 351 of file registry.hpp.
|
inline |
Check if an entity is part of all the given storage.
Type | Type of storage to check for. |
entt | A valid identifier. |
Definition at line 833 of file registry.hpp.
|
inline |
Check if an entity is part of at least one given storage.
Type | Type of storage to check for. |
entt | A valid identifier. |
Definition at line 850 of file registry.hpp.
|
inline |
Clears a whole registry or the pools for the given components.
Type | Types of components to remove from their entities. |
Definition at line 943 of file registry.hpp.
|
inline |
Removes all tombstones from a registry or only the pools for the given components.
Type | Types of components for which to clear all tombstones. |
Definition at line 816 of file registry.hpp.
|
inline |
Creates a new entity or recycles a destroyed one.
Definition at line 480 of file registry.hpp.
|
inline |
Creates a new entity or recycles a destroyed one.
If the requested entity isn't in use, the suggested identifier is used. Otherwise, a new identifier is generated.
hint | Required identifier. |
Definition at line 493 of file registry.hpp.
|
inline |
Assigns each element in a range an identifier.
It | Type of forward iterator. |
first | An iterator to the first element of the range to generate. |
last | An iterator past the last element of the range to generate. |
Definition at line 507 of file registry.hpp.
|
inlinenoexcept |
Returns the context object, that is, a general purpose container.
Definition at line 1191 of file registry.hpp.
|
inlinenoexcept |
Returns the context object, that is, a general purpose container.
Definition at line 1186 of file registry.hpp.
|
inline |
Returns the actual version for an identifier.
entt | A valid identifier. |
Definition at line 472 of file registry.hpp.
|
inline |
Destroys an entity and releases its identifier.
entt | A valid identifier. |
Definition at line 521 of file registry.hpp.
|
inline |
Destroys an entity and releases its identifier.
The suggested version or the valid version closest to the suggested one is used instead of the implicitly generated version.
entt | A valid identifier. |
version | A desired version upon destruction. |
Definition at line 542 of file registry.hpp.
|
inline |
Destroys all entities in a range and releases their identifiers.
It | Type of input iterator. |
first | An iterator to the first element of the range of entities. |
last | An iterator past the last element of the range of entities. |
Definition at line 558 of file registry.hpp.
|
inline |
Assigns the given component to an entity.
The component must have a proper constructor or be of aggregate type.
Type | Type of component to create. |
Args | Types of arguments to use to construct the component. |
entt | A valid identifier. |
args | Parameters to use to initialize the component. |
Definition at line 587 of file registry.hpp.
|
inline |
Assigns or replaces the given component for an entity.
Type | Type of component to assign or replace. |
Args | Types of arguments to use to construct the component. |
entt | A valid identifier. |
args | Parameters to use to initialize the component. |
Definition at line 637 of file registry.hpp.
|
inline |
Erases the given components from an entity.
Type | Types of components to erase. |
Other | Other types of components to erase. |
entt | A valid identifier. |
Definition at line 750 of file registry.hpp.
|
inline |
Erases the given components from all the entities in a range.
Type | Types of components to erase. |
Other | Other types of components to erase. |
It | Type of input iterator. |
first | An iterator to the first element of the range of entities. |
last | An iterator past the last element of the range of entities. |
Definition at line 766 of file registry.hpp.
|
inline |
Erases components satisfying specific criteria from an entity.
The function type is equivalent to:
Only storage where the entity exists are passed to the function.
Func | Type of the function object to invoke. |
entt | A valid identifier. |
func | A valid function object. |
Definition at line 802 of file registry.hpp.
|
inline |
Returns references to the given components for an entity.
Type | Types of components to get. |
entt | A valid identifier. |
Definition at line 876 of file registry.hpp.
|
inline |
Returns references to the given components for an entity.
Type | Types of components to get. |
entt | A valid identifier. |
Definition at line 866 of file registry.hpp.
|
inlineconstexprnoexcept |
Returns the associated allocator.
Definition at line 395 of file registry.hpp.
|
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.
Type | Type of component to get. |
Args | Types of arguments to use to construct the component. |
entt | A valid identifier. |
args | Parameters to use to initialize the component. |
Definition at line 900 of file registry.hpp.
|
inline |
Returns a group for the given components.
Owned | Types of storage owned by the group. |
Get | Types of storage observed by the group, if any. |
Exclude | Types of storage used to filter the group, if any. |
Definition at line 1069 of file registry.hpp.
|
inline |
Returns a group for the given components.
Owned | Types of storage owned by the group. |
Get | Types of storage observed by the group, if any. |
Exclude | Types of storage used to filter the group, if any. |
Definition at line 1093 of file registry.hpp.
|
inline |
Assigns each entity in a range the given components.
Type | Type of component to create. |
EIt | Type of input iterator. |
CIt | Type of input iterator. |
first | An iterator to the first element of the range of entities. |
last | An iterator past the last element of the range of entities. |
from | An iterator to the first element of the range of components. |
Definition at line 620 of file registry.hpp.
|
inline |
Assigns each entity in a range the given component.
Type | Type of component to create. |
It | Type of input iterator. |
first | An iterator to the first element of the range of entities. |
last | An iterator past the last element of the range of entities. |
value | An instance of the component to assign. |
Definition at line 603 of file registry.hpp.
|
inline |
Returns a sink object for the given component.
Use this function 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:
Listeners are invoked after assigning the component to the entity.
Type | Type of component of which to get the sink. |
id | Optional name used to map the storage within the registry. |
Definition at line 985 of file registry.hpp.
|
inline |
Returns a sink object for the given component.
Use this function 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:
Listeners are invoked before removing the component from the entity.
Type | Type of component of which to get the sink. |
id | Optional name used to map the storage within the registry. |
Definition at line 1033 of file registry.hpp.
|
inline |
Returns a sink object for the given component.
Use this function to receive notifications whenever an instance of the given component is explicitly updated.
The function type for a listener is equivalent to:
Listeners are invoked after updating the component.
Type | Type of component of which to get the sink. |
id | Optional name used to map the storage within the registry. |
Definition at line 1009 of file registry.hpp.
|
inlinenoexcept |
Move assignment operator.
other | The instance to move from. |
Definition at line 364 of file registry.hpp.
|
inline |
Checks if an entity has components assigned.
entt | A valid identifier. |
Definition at line 961 of file registry.hpp.
|
inline |
Checks whether the given components belong to any group.
Type | Type of component in which one is interested. |
Other | Other types of components in which one is interested. |
Definition at line 1111 of file registry.hpp.
|
inline |
Patches the given component for an entity.
The signature of the function should be equivalent to the following:
Type | Type of component to patch. |
Func | Types of the function objects to invoke. |
entt | A valid identifier. |
func | Valid function objects. |
Definition at line 665 of file registry.hpp.
|
inline |
Removes the given components from an entity.
Type | Type of component to remove. |
Other | Other types of components to remove. |
entt | A valid identifier. |
Definition at line 697 of file registry.hpp.
|
inline |
Removes the given components from all the entities in a range.
Type | Type of component to remove. |
Other | Other types of components to remove. |
It | Type of input iterator. |
first | An iterator to the first element of the range of entities. |
last | An iterator past the last element of the range of entities. |
Definition at line 714 of file registry.hpp.
|
inline |
Replaces the given component for an entity.
The component must have a proper constructor or be of aggregate type.
Type | Type of component to replace. |
Args | Types of arguments to use to construct the component. |
entt | A valid identifier. |
args | Parameters to use to initialize the component. |
Definition at line 685 of file registry.hpp.
|
inline |
Sorts two pools of components in the same way.
Entities and components in To
which are part of both storage are sorted internally with the order they have in From
. The others follow in no particular order.
To | Type of components to sort. |
From | Type of components to use to sort. |
Definition at line 1176 of file registry.hpp.
|
inline |
Sorts the elements of a given component.
The comparison function object returns true
if the first element is less than the second one, false
otherwise. Its signature is also equivalent to one of the following:
Moreover, it shall induce a strict weak ordering on the values.
The sort function object offers an operator()
that accepts:
The comparison function object hasn't necessarily the type of the one passed along with the other parameters to this member function.
Type | Type of components to sort. |
Compare | Type of comparison function object. |
Sort | Type of sort function object. |
Args | Types of arguments to forward to the sort function object. |
compare | A valid comparison function object. |
algo | A valid sort function object. |
args | Arguments to forward to the sort function object, if any. |
Definition at line 1150 of file registry.hpp.
|
inlinenoexcept |
Returns an iterable object to use to visit a registry.
The iterable object returns a pair that contains the name and a reference to the current storage.
Definition at line 412 of file registry.hpp.
|
inlinenoexcept |
Returns an iterable object to use to visit a registry.
The iterable object returns a pair that contains the name and a reference to the current storage.
Definition at line 407 of file registry.hpp.
|
inline |
Finds the storage associated with a given name, if any.
id | Name used to map the storage within the registry. |
Definition at line 421 of file registry.hpp.
|
inline |
Finds the storage associated with a given name, if any.
id | Name used to map the storage within the registry. |
Definition at line 430 of file registry.hpp.
|
inline |
Returns the storage for a given component type.
Type | Type of component of which to return the storage. |
id | Optional name used to map the storage within the registry. |
Definition at line 442 of file registry.hpp.
|
inline |
Returns the storage for a given component type, if any.
Type | Type of component of which to return the storage. |
id | Optional name used to map the storage within the registry. |
Definition at line 453 of file registry.hpp.
|
inline |
Exchanges the contents with those of a given registry.
other | Registry to exchange the content with. |
Definition at line 379 of file registry.hpp.
|
inline |
Returns pointers to the given components for an entity.
Type | Types of components to get. |
entt | A valid identifier. |
Definition at line 930 of file registry.hpp.
|
inline |
Returns pointers to the given components for an entity.
Type | Types of components to get. |
entt | A valid identifier. |
Definition at line 919 of file registry.hpp.
|
inline |
Checks if an identifier refers to a valid entity.
entt | An identifier, either valid or not. |
Definition at line 462 of file registry.hpp.
|
inline |
Returns a view for the given components.
Type | Type of component used to construct the view. |
Other | Other types of components used to construct the view. |
Exclude | Types of components used to filter the view. |
Definition at line 1056 of file registry.hpp.
|
inline |
Returns a view for the given components.
Type | Type of component used to construct the view. |
Other | Other types of components used to construct the view. |
Exclude | Types of components used to filter the view. |
Definition at line 1046 of file registry.hpp.