|
| | PersistentView (view_type &view, pool_type< Component > &... pools) noexcept |
| | Constructs a persistent view around a dedicated pool of entities. More...
|
| |
| size_type | size () const noexcept |
| | Returns the number of entities that have the given components. More...
|
| |
| const entity_type * | data () const noexcept |
| | Direct access to the list of entities. More...
|
| |
| iterator_type | begin () const noexcept |
| | Returns an iterator to the first entity that has the given components. More...
|
| |
| iterator_type | end () const noexcept |
| | Returns an iterator that is past the last entity that has the given components. More...
|
| |
| template<typename Comp > |
| const Comp & | get (entity_type entity) const noexcept |
| | Returns the component assigned to the given entity. More...
|
| |
| template<typename Comp > |
| Comp & | get (entity_type entity) noexcept |
| | Returns the component assigned to the given entity. More...
|
| |
| template<typename Comp > |
| void | sort () |
| | Sort the shared pool of entities according to the given component. More...
|
| |
template<typename Entity, typename... Component>
class entt::PersistentView< Entity, Component >
Persistent view.
A persistent view returns all the entities and only the entities that have at least the given components. Moreover, it's guaranteed that the entity list is thightly packed in memory for fast iterations.
In general, persistent views don't stay true to the order of any set of components unless users explicitly sort them.
Important
Iterators aren't invalidated if:
- New instances of the given components are created and assigned to entities.
- The entity currently pointed is modified (as an example, if one of the given components is removed from the entity to which the iterator points).
In all the other cases, modify the pools of the given components somehow invalidates all the iterators and using them results in undefined behavior.
- Note
- Views share references to the underlying data structures with the Registry that generated them. Therefore any change to the entities and to the components made by means of the registry are immediately reflected by views.
Moreover, sorting a persistent view affects all the other views of the same type (it means that users don't have to call sort on each view to sort all of them because they share the set of entities).
- Warning
- Lifetime of a view must overcome the one of the registry that generated it. In any other case, attempting to use a view results in undefined behavior.
- See also
- View
-
View<Entity, Component>
- Template Parameters
-
| Entity | A valid entity type (see entt_traits for more details). |
| Component | The types of the components iterated by the view. |
Definition at line 52 of file view.hpp.
template<typename Entity , typename... Component>
Returns an iterator to the first entity that has the given components.
The returned iterator points to the first entity that has the given components. If the view is empty, the returned iterator will be equal to end().
- Note
- Input iterators stay true to the order imposed to the underlying data structures.
- Returns
- An iterator to the first entity that has the given components.
Definition at line 121 of file view.hpp.
template<typename Entity , typename... Component>
Direct access to the list of entities.
The returned pointer is such that range [data(), data() + size()] is always a valid range, even if the container is empty.
- Note
- There are no guarantees on the order of the entities. Use
begin and end if you want to iterate the view in the expected order.
- Returns
- A pointer to the array of entities.
Definition at line 103 of file view.hpp.
template<typename Entity , typename... Component>
Returns an iterator that is past the last entity that has the given components.
The returned iterator points to the entity following the last entity that has the given components. Attempting to dereference the returned iterator results in undefined behavior.
- Note
- Input iterators stay true to the order imposed to the underlying data structures.
- Returns
- An iterator to the entity following the last entity that has the given components.
Definition at line 140 of file view.hpp.
template<typename Entity , typename... Component>
template<typename Comp >
Returns the component assigned to the given entity.
Prefer this function instead of Registry::get during iterations. It has far better performance than its companion function.
- Warning
- Attempting to use an invalid component type results in a compilation error. Attempting to use an entity that doesn't belong to the view results in undefined behavior.
An assertion will abort the execution at runtime in debug mode if the view doesn't contain the given entity.
- Template Parameters
-
| Comp | The type of the component to get. |
- Parameters
-
| entity | A valid entity identifier. |
- Returns
- The component assigned to the entity.
Definition at line 162 of file view.hpp.
template<typename Entity , typename... Component>
template<typename Comp >
Returns the component assigned to the given entity.
Prefer this function instead of Registry::get during iterations. It has far better performance than its companion function.
- Warning
- Attempting to use an invalid component type results in a compilation error. Attempting to use an entity that doesn't belong to the view results in undefined behavior.
An assertion will abort the execution at runtime in debug mode if the view doesn't contain the given entity.
- Template Parameters
-
| Comp | The type of the component to get. |
- Parameters
-
| entity | A valid entity identifier. |
- Returns
- The component assigned to the entity.
Definition at line 184 of file view.hpp.
template<typename Entity , typename... Component>
template<typename Comp >
Sort the shared pool of entities according to the given component.
Persistent views of the same type share with the Registry a pool of entities with its own order that doesn't depend on the order of any pool of components. Users can order the underlying data structure so that it respects the order of the pool of the given component.
- Note
- The shared pool of entities and thus its order is affected by the changes to each and every pool of components that it tracks. Therefore changes to the pools of components can quickly ruin the order imposed to the pool of entities shared between the persistent views.
- Template Parameters
-
| Comp | The type of the component to use to impose the order. |
Definition at line 205 of file view.hpp.