template<typename ... Ts> asge::ecs::View
Lazy, non-owning iterator over entities that have every component in Ts.
#include <View.hpp>Built from one ComponentPool<T>* per T in Ts (typically via Registry::View<Ts...>()); iterating yields (Entity, Ts&...) for every entity present in all of them. Iteration walks the smallest contributing pool's dense storage and filters each entity against the rest, so its order follows that pool's storage order and can change after a Remove() on any contributing pool.
If a requested component type has never been used in the Registry the view was built from, its pool pointer is null and the view is permanently empty — even if that type is added to an entity afterwards.
Holds raw pointers into the pools it was built from; must not outlive the Registry (or ComponentPool instances) that produced them including indirectly, through the IsDisabled predicate below.
An entity is skipped during iteration by default if the IsDisabled predicate passed in at construction says so (Registry::View() binds this to Registry::IsDisabled(), i.e. the entity carries markers::Disable itself, or any ancestor in its Hierarchy chain does) call IncludeDisabled() to see it anyway. This skip does not apply if Disable itself is one of Ts, since the caller is then explicitly asking to see disabled entities.
Ts may be const-qualified (e.g. View<Sprite const>, what Registry::View<Ts...>() const returns) to get (Entity, Ts const&...) instead — the same pools, just read-only, for a Registry the caller only holds a const reference to.
Ts | Component types an entity must have to appear in this view. |
Public Types
Private Types
using Pool = std::conditional_t< std::is_const_v< T >, ComponentPool< std::remove_const_t< T >, component_cap_v< std::remove_const_t< T > > > const, ComponentPool< T, component_cap_v< T > > >privateStatic Private Attributes
static constexpr bool kSkipDisabled = !( std::is_same_v<std::remove_const_t<Ts>, markers::Disable> || ... )privatePrivate Attributes
Friends
Private Member Functions
Returns the smallest pool based on entity density.
Public Member Functions
View(std::function< bool(Entity)> inIsDisabled, Pool< Ts > *&&... inPools)Builds a view over the given per-type component pools.
inPools[i] should be the pool for the i-th type in Ts (nullptr if that type has never been used), typically Registry::FindPool<T>()'s result — Registry::View<Ts...>() is the intended way to construct this. inIsDisabled need not be set (an empty std::function skips the check below entirely, same as every entity passing it).
Iterator end()One-past-the-last element of the view.
Opts this view back into entities carrying markers::Disable.
*this, moved chain directly off Registry::View(), e.g. for (auto ... : registry.View<T>().IncludeDisabled()).
std::size_t Size() const noexcept