← API Reference Class

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.

Warning

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.

Warning

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.

Template Parameters
Ts

Component types an entity must have to appear in this view.

Public Types

#using value_type = std::tuple< Entity, std::reference_wrapper< Ts >... >

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 > > >private
#using Tuple_t = std::tuple< Pool< Ts > *... >private
#using Variant_t = std::variant< Pool< Ts > *... >private

Static Private Attributes

#static constexpr bool kSkipDisabled = !( std::is_same_v<std::remove_const_t<Ts>, markers::Disable> || ... )private

Private Attributes

#std::function< bool(Entity)> m_IsDisabledprivate
#Tuple_t m_Poolsprivate
#bool m_Validprivate
#IComponentPool const * m_SmallestPoolprivate
#bool m_IncludeDisabled {false}private

Friends

#friend Iteratorprivate

Private Member Functions

#IComponentPool const * GetSmallestPool() const noexceptprivate

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 begin()

Start of the view; matches end() immediately if any pool is missing.

#Iterator end()

One-past-the-last element of the view.

#View IncludeDisabled() &&noexcept

Opts this view back into entities carrying markers::Disable.

Returns

*this, moved chain directly off Registry::View(), e.g. for (auto ... : registry.View<T>().IncludeDisabled()).

#std::size_t Size() const noexcept