A view lets you get a range over components of Args out of a registry.
More...
#include <view.hpp>
|
| | view (registry_type registry) noexcept |
| | Constructs a new view object.
|
| |
| auto | single () -> std::optional< std::tuple< Args... > > requires(!is_const) |
| | Returns a single tuple of components matching Args, if available in the view.
|
| |
| auto | single () const -> std::optional< std::tuple< Args... > > requires(is_const) |
| | Returns a single tuple of components matching Args, if available in the view (const version).
|
| |
| auto | each () -> decltype(auto) requires(!is_const) |
| | Returns an iterator that yields a std::tuple<Args...>.
|
| |
| auto | each () const -> decltype(auto) requires(is_const) |
| | Returns an iterator that yields a std::tuple<Args...> (const version).
|
| |
| void | each (auto &&func) |
| | Runs a function on every entity that matches the Args requirement.
|
| |
| void | each (auto &&func) const |
| | Runs a function on every entity that matches the Args requirement (const version).
|
| |
| void | par_each (auto &&func) |
| | Runs a function on every entity that matches the Args requirement in parallel.
|
| |
| void | par_each (auto &&func) const |
| | Runs a function on every entity that matches the Args requirement in parallel (const version).
|
| |
| auto | chunks () -> decltype(auto) |
| | Gets the chunks range.
|
| |
| auto | chunks () const -> decltype(auto) |
| | Gets the const chunks range.
|
| |
template<component_reference... Args>
class co_ecs::view< Args >
A view lets you get a range over components of Args out of a registry.
Views represent a slice of a registry restricting the access to a particular components.
pos.x += vel.x;
pos.y += vel.y;
}
view.
each([](
auto& pos,
const auto& vel) {
pos.x += vel.x;
pos.y += vel.y;
});
Registry is a container for all our entities and components. Components are stored in continuously in...
Definition registry.hpp:13
constexpr void each(F &&func)
Executes a given function on each entity that matches the specified component requirements.
Definition registry.hpp:147
A view lets you get a range over components of Args out of a registry.
Definition view.hpp:36
auto each() -> decltype(auto) requires(!is_const)
Returns an iterator that yields a std::tuple<Args...>.
Definition view.hpp:90
view(registry_type registry) noexcept
Constructs a new view object.
Definition view.hpp:50
- Note
- A view isn't invalidated when there are changes made to the registry, which allows creating one and re-using it over time.
- Template Parameters
-
| Args | Component reference types |
◆ view()
template<component_reference... Args>
Constructs a new view object.
- Parameters
-
| registry | Reference to the registry. |
◆ chunks() [1/2]
template<component_reference... Args>
Gets the chunks range.
- Returns
- Chunks.
◆ chunks() [2/2]
template<component_reference... Args>
| auto co_ecs::view< Args >::chunks |
( |
| ) |
const -> decltype(auto) |
|
inline |
Gets the const chunks range.
- Returns
- Chunks.
◆ each() [1/4]
template<component_reference... Args>
| auto co_ecs::view< Args >::each |
( |
| ) |
-> decltype(auto)
requires(!is_const)
|
|
inline |
Returns an iterator that yields a std::tuple<Args...>.
- Returns
- decltype(auto) Iterator.
◆ each() [2/4]
template<component_reference... Args>
| auto co_ecs::view< Args >::each |
( |
| ) |
const -> decltype(auto)
requires(is_const)
|
|
inline |
Returns an iterator that yields a std::tuple<Args...> (const version).
- Returns
- decltype(auto) Iterator.
◆ each() [3/4]
template<component_reference... Args>
Runs a function on every entity that matches the Args requirement.
- Parameters
-
| func | A callable to run on entity components. |
◆ each() [4/4]
template<component_reference... Args>
Runs a function on every entity that matches the Args requirement (const version).
- Parameters
-
| func | A callable to run on entity components. |
- Note
- This method is similar to the non-const each() but is available in const views.
◆ par_each() [1/2]
template<component_reference... Args>
Runs a function on every entity that matches the Args requirement in parallel.
- Parameters
-
| func | A callable to run on entity components. |
◆ par_each() [2/2]
template<component_reference... Args>
Runs a function on every entity that matches the Args requirement in parallel (const version).
- Parameters
-
| func | A callable to run on entity components. |
- Note
- This method is similar to the non-const par_each() but is available in const views.
◆ single() [1/2]
template<component_reference... Args>
| auto co_ecs::view< Args >::single |
( |
| ) |
-> std::optional<std::tuple<Args...>>
requires(!is_const)
|
|
inline |
Returns a single tuple of components matching Args, if available in the view.
This method is available in const views and allows accessing a single tuple of components matching Args. It returns an optional tuple, which is empty if no entities in the view match the component requirements.
auto single() -> std::optional< std::tuple< Args... > > requires(!is_const)
Returns a single tuple of components matching Args, if available in the view.
Definition view.hpp:64
- Returns
- Optional tuple of components if found, otherwise empty optional.
◆ single() [2/2]
template<component_reference... Args>
| auto co_ecs::view< Args >::single |
( |
| ) |
const -> std::optional<std::tuple<Args...>>
requires(is_const)
|
|
inline |
Returns a single tuple of components matching Args, if available in the view (const version).
- Returns
- Optional tuple of components if found, otherwise empty optional.
The documentation for this class was generated from the following file: