Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
esengine::ecs::View< T > Class Template Reference

Optimized view for single-component queries. More...

#include <View.hpp>

Public Types

using Iterator = typename std::vector<Entity>::const_iterator
 Iterator type (directly iterates pool).
using PoolsTuple
 Tuple type for pool pointers.

Public Member Functions

 View (SparseSet< T > *pool)
 Constructs a single-component view.
Iterator begin () const
 Returns iterator to the first entity.
Iterator end () const
 Returns iterator past the last entity.
T & get (Entity entity)
 Gets the component for an entity.
const T & get (Entity entity) const
 Gets the component for an entity.
std::tuple< T & > getAll (Entity entity)
 Gets all components for an entity as a tuple.
bool empty () const
 Checks if the view is empty.
usize size () const
 Gets the exact number of entities in the view.
usize sizeHint () const
 Upper bound on matching entities — exact here, since nothing filters.
template<typename Func>
void each (Func &&func)
 Executes a function for each entity.
template<typename Func>
void eachLive (Func &&func)
 Like each(), but iterates the live dense array with no defensive copy.

Detailed Description

template<typename T>
class esengine::ecs::View< T >

Optimized view for single-component queries.

Template Parameters
TThe single component type

When querying for only one component type, no filtering is needed. This specialization directly iterates the component pool for maximum efficiency.

// Iterate all entities with Position
for (Entity e : registry.view<Position>()) {
auto& pos = registry.get<Position>(e);
}
// Direct component iteration (most efficient)
registry.view<Position>().each([](Entity e, Position& p) {
p.x += 1.0f;
});
void each(Func &&func)
Executes a function for each entity.
Definition View.hpp:467
Entity identifier with packed index + generation.
Definition Types.hpp:135

Definition at line 397 of file View.hpp.

Member Typedef Documentation

◆ Iterator

template<typename T>
using esengine::ecs::View< T >::Iterator = typename std::vector<Entity>::const_iterator

Iterator type (directly iterates pool).

Definition at line 400 of file View.hpp.

◆ PoolsTuple

using esengine::ecs::View< Components >::PoolsTuple

Tuple type for pool pointers.

Definition at line 189 of file View.hpp.

Constructor & Destructor Documentation

◆ View()

template<typename T>
esengine::ecs::View< T >::View ( SparseSet< T > * pool)
inlineexplicit

Constructs a single-component view.

Parameters
poolPointer to the component pool

Definition at line 406 of file View.hpp.

Member Function Documentation

◆ begin()

template<typename T>
Iterator esengine::ecs::View< T >::begin ( ) const
inline

Returns iterator to the first entity.

Returns
Begin iterator

Definition at line 412 of file View.hpp.

◆ each()

template<typename T>
template<typename Func>
void esengine::ecs::View< T >::each ( Func && func)
inline

Executes a function for each entity.

Template Parameters
FuncCallback type
Parameters
funcThe callback to invoke

Optimized direct iteration without any filtering. Callback signatures:

  • void(Entity, T&) - entity and component
  • void(T&) - component only
  • void(Entity) - entity only

Definition at line 467 of file View.hpp.

◆ eachLive()

template<typename T>
template<typename Func>
void esengine::ecs::View< T >::eachLive ( Func && func)
inline

Like each(), but iterates the live dense array with no defensive copy.

Warning
The callback MUST NOT emplace/remove T during iteration — that would invalidate the dense array. Use for read-only per-frame system passes (the common hot path); use each() when the callback may mutate the pool.

Definition at line 494 of file View.hpp.

◆ empty()

template<typename T>
bool esengine::ecs::View< T >::empty ( ) const
inline

Checks if the view is empty.

Returns
True if no entities have this component

Definition at line 441 of file View.hpp.

◆ end()

template<typename T>
Iterator esengine::ecs::View< T >::end ( ) const
inline

Returns iterator past the last entity.

Returns
End iterator

Definition at line 418 of file View.hpp.

◆ get() [1/2]

template<typename T>
T & esengine::ecs::View< T >::get ( Entity entity)
inline

Gets the component for an entity.

Parameters
entityThe entity
Returns
Reference to the component

Definition at line 425 of file View.hpp.

◆ get() [2/2]

template<typename T>
const T & esengine::ecs::View< T >::get ( Entity entity) const
inline

Gets the component for an entity.

Parameters
entityThe entity
Returns
Reference to the component

Definition at line 428 of file View.hpp.

◆ getAll()

template<typename T>
std::tuple< T & > esengine::ecs::View< T >::getAll ( Entity entity)
inline

Gets all components for an entity as a tuple.

Parameters
entityThe entity
Returns
Tuple of component references

Definition at line 435 of file View.hpp.

◆ size()

template<typename T>
usize esengine::ecs::View< T >::size ( ) const
inline

Gets the exact number of entities in the view.

Returns
Entity count

Definition at line 447 of file View.hpp.

Referenced by sizeHint().

◆ sizeHint()

template<typename T>
usize esengine::ecs::View< T >::sizeHint ( ) const
inline

Upper bound on matching entities — exact here, since nothing filters.

Returns
Entity count

Definition at line 453 of file View.hpp.

References size().


The documentation for this class was generated from the following file:
  • /home/runner/work/estella/estella/src/esengine/ecs/View.hpp