View Class Template
A view class to iterate over entities having specific components. More...
Declaration
Public Constructors Index
template <typename... Components> | |
| View (EntityManager *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... Components> | |
| View & | whereEnabled () |
|
Filters to only include entities with enabled components. More... | |
template <typename... Components> | |
| Iterator | begin () |
|
Returns an iterator to the first valid entity. More... | |
template <typename... Components> | |
| Iterator | end () |
|
Returns an iterator to the end (past the last entity). More... | |
Private Member Attributes Index
template <typename... Components> | |
| EntityManager * | em_ |
template <typename... Components> | |
| std::tuple< SparseSet< Components > *... > | includeSets_ |
|
Pointers to the SparseSets of the included components. More... | |
template <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... Components> | |
| bool | filterEnabledOnly_ = false |
|
Flag to filter only enabled components. More... | |
template <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] : gameWorld->view< TransformComponent, VelocityComponent, Active >().whereEnabled()) { // Process entity } ```
- Template Parameters
-
Components The component types to query for.
- See Also
- See Also
Definition at line 48 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 GameObjects.
Definition at line 78 of file View.ixx.
Referenced by helios::engine::ecs::View< Components >::exclude, helios::engine::ecs::View< Components >::Iterator::Iterator and helios::engine::ecs::View< 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 298 of file View.ixx.
References helios::engine::ecs::View< Components >::Iterator::advance and helios::engine::ecs::View< Components >::Iterator::isValid.
end()
| inline nodiscard |
Returns an iterator to the end (past the last entity).
- Returns
End iterator for comparison.
Definition at line 319 of file View.ixx.
Referenced by helios::engine::ecs::View< 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 103 of file View.ixx.
whereEnabled()
| inline |
Private Member Attributes
em_
|
Definition at line 51 of file View.ixx.
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.