View Class Template
A view class to iterate over entities having specific components. More...
Declaration
Public Constructors Index
template <typename TEntityManager, typename... Components> | |
| View (TEntityManager *em) | |
|
Constructs the view and retrieves the necessary component sets. More... | |
Public Member Functions Index
template <typename T> | |
| View & | exclude () |
|
Excludes entities that have a specific component. More... | |
template <typename TEntityManager, typename... Components> | |
| bool | empty () |
template <typename TEntityManager, typename... Components> | |
| View & | whereEnabled () |
|
Filters to only include entities with enabled components. More... | |
template <typename TEntityManager, typename... Components> | |
| Iterator | begin () |
|
Returns an iterator to the first valid entity. More... | |
template <typename TEntityManager, typename... Components> | |
| Iterator | end () |
|
Returns an iterator to the end (past the last entity). More... | |
Private Member Attributes Index
template <typename TEntityManager, typename... Components> | |
| TEntityManager * | em_ |
template <typename TEntityManager, typename... Components> | |
| std::tuple< SparseSet< Components > *... > | includeSets_ |
|
Pointers to the SparseSets of the included components. More... | |
template <typename TEntityManager, typename... Components> | |
| std::vector< std::function< bool(EntityId)> > | excludeChecks_ |
|
List of exclusion predicates. Stores functions that return true if an entity should be EXCLUDED. Operates on EntityId (index) because the SparseSet uses it internally. More... | |
template <typename TEntityManager, typename... Components> | |
| bool | filterEnabledOnly_ = false |
|
Flag to filter only enabled components. More... | |
template <typename TEntityManager, typename... Components> | |
| bool | filterActiveOnly_ = false |
Description
A view class to iterate over entities having specific components.
The View acts as a lightweight iterator over the SparseSets of the requested components. It uses the first component type (Lead) as the primary iterator and cross-references existence in other sets.
## Usage
```cpp for (auto [entity, transform, velocity, active] : world.view< GameHandle, TransformComponent, VelocityComponent, Active >().whereEnabled()) { // Process entity } ```
- Template Parameters
-
TEntityManager The concrete `EntityManager` specialisation to iterate over. Determines the handle type and component storage used.
Components The component types to query for.
- See Also
- See Also
- See Also
Definition at line 52 of file View.ixx.
Public Constructors
View()
| inline explicit |
Constructs the view and retrieves the necessary component sets.
- Parameters
-
em Pointer to the EntityManager to retrieve sets and construct Entities.
Definition at line 82 of file View.ixx.
Referenced by helios::ecs::View< TEntityManager, Components >::exclude, helios::ecs::View< TEntityManager, Components >::Iterator::Iterator and helios::ecs::View< TEntityManager, Components >::whereEnabled.
Public Member Functions
begin()
| inline nodiscard |
Returns an iterator to the first valid entity.
Uses the first component type's SparseSet as the lead. If the first entity is invalid, advances to the next valid one.
Definition at line 317 of file View.ixx.
References helios::ecs::View< TEntityManager, Components >::Iterator::advance and helios::ecs::View< TEntityManager, Components >::Iterator::isValid.
Referenced by helios::ecs::View< TEntityManager, Components >::empty.
empty()
| inline nodiscard |
Definition at line 118 of file View.ixx.
References helios::ecs::View< TEntityManager, Components >::begin and helios::ecs::View< TEntityManager, Components >::end.
end()
| inline nodiscard |
Returns an iterator to the end (past the last entity).
- Returns
End iterator for comparison.
Definition at line 338 of file View.ixx.
Referenced by helios::ecs::View< TEntityManager, Components >::empty and helios::ecs::View< TEntityManager, Components >::Iterator::Iterator.
exclude()
| inline |
Excludes entities that have a specific component.
Entities possessing the specified component type will be skipped during iteration. Multiple exclusions can be chained.
```cpp // Skip entities with Shield or Invincible for (auto [e, health] : world->view<HealthComponent>() .exclude<ShieldComponent>() .exclude<InvincibleComponent>()) { // Only vulnerable entities } ```
- Template Parameters
-
T The component type to exclude.
- Returns
Reference to this View for method chaining.
Definition at line 107 of file View.ixx.
Reference helios::ecs::View< TEntityManager, Components >::View.
whereEnabled()
| inline |
Filters to only include entities with enabled components.
Components must implement `isEnabled()` returning bool. Components without this method are assumed to be enabled.
- Returns
Reference to this View for method chaining.
Definition at line 134 of file View.ixx.
Reference helios::ecs::View< TEntityManager, Components >::View.
Private Member Attributes
em_
|
excludeChecks_
|
filterActiveOnly_
|
filterEnabledOnly_
|
includeSets_
|
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.