Skip to main content

PartialView Class Template

Declaration

template <typename TEntityManager, typename... TRequired, typename... TDirty, typename... TOptional> class helios::ecs::PartialView<TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... >> { ... }

Public Constructors Index

template < ... >
PartialView (TEntityManager *em)

Constructs the view and retrieves the necessary component sets. More...

template < ... >
PartialView (TEntityManager *em, std::tuple< SparseSet< TRequired > *... > includeSets, std::vector< std::function< bool(EntityId)> > excludeChecks, const bool filterActiveOnly, SparseSet< Active< typename TEntityManager::Handle_type > > *activeSet)

Constructs the view with the specified component sets and filters. More...

Public Member Functions Index

template <typename... TNewOptional>
autowithOptional ()

Adds optional component types to the current view. More...

template <typename... TNewDirty>
autowhereAnyDirty ()

Filters to only include entities with changed components. More...

template <typename T>
PartialView &exclude ()

Excludes entities that have a specific component. More...

template < ... >
boolempty ()

Returns true if the view has no entities to iterate over. More...

template < ... >
PartialView &withActive ()

Filters to only include entities with an active component. More...

template < ... >
Iteratorbegin ()

Returns an iterator to the first valid entity. More...

template < ... >
Iteratorend ()

Returns an iterator to the end (past the last entity). More...

Private Member Attributes Index

template < ... >
TEntityManager *em_
template < ... >
std::tuple< SparseSet< TRequired > *... >includeSets_

Pointers to the SparseSets of the included components. More...

template < ... >
std::tuple< SparseSet< TOptional > *... >optionalSets_

Optional components, might return nullptr. Are not considered by whereAnyChanged(). More...

template < ... >
std::tuple< SparseSet< DirtyComponentSpec< TDirty > > *... >anyDirtySets_

Pointers to the SparseSets of the dirty component sets. More...

template < ... >
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 < ... >
SparseSet< Active< typename TEntityManager::Handle_type > > *activeSet_ = nullptr

SparseSet for Active component, required with filterActiveOnly_. More...

template < ... >
boolfilterActiveOnly_ = false

Flag to filter only entities with Active component. More...

Definition at line 72 of file View.ixx.

Public Constructors

PartialView()

template <typename TEntityManager, typename... TRequired, typename... TDirty, typename... TOptional>
helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::PartialView (TEntityManager * em)
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 116 of file View.ixx.

116 explicit PartialView(TEntityManager* em)
117 requires (sizeof...(TOptional) == 0 && sizeof...(TDirty) == 0)
118 : em_(em) {
119 // Retrieve pointers to the specific component sets immediately.
120 includeSets_ = std::make_tuple(em_->template sparseSet<TRequired>()...);
121 };

PartialView()

template <typename TEntityManager, typename... TRequired, typename... TDirty, typename... TOptional>
helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::PartialView (TEntityManager * em, std::tuple< SparseSet< TRequired > *... > includeSets, std::vector< std::function< bool(EntityId)> > excludeChecks, const bool filterActiveOnly, SparseSet< Active< typename TEntityManager::Handle_type > > * activeSet)
inline explicit

Constructs the view with the specified component sets and filters.

Parameters
em

Pointer to the EntityManager to retrieve sets and construct Entities.

includeSets

Tuple of pointers to the SparseSets of the required components.

excludeChecks

Vector of functions to determine if an entity should be excluded.

filterActiveOnly

Flag to filter only entities with Active component.

activeSet

Pointer to the SparseSet of Active components.

Definition at line 133 of file View.ixx.

133 explicit PartialView(
134 TEntityManager* em,
135 std::tuple<SparseSet<TRequired>*...> includeSets,
136 std::vector<std::function<bool(EntityId)>> excludeChecks,
137 const bool filterActiveOnly,
139 ) : em_(em),
140 includeSets_(std::move(includeSets)),
141 excludeChecks_(std::move(excludeChecks)),
142 filterActiveOnly_(filterActiveOnly),
143 activeSet_(activeSet),
144
145 optionalSets_(std::make_tuple(em_->template sparseSet<TOptional>()...)),
146 anyDirtySets_(std::make_tuple(em_->template sparseSet<DirtyComponentSpec<TDirty>>()...))
147 {}

Public Member Functions

begin()

template <typename TEntityManager, typename... TRequired, typename... TDirty, typename... TOptional>
Iterator helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::begin ()
inline

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.

Returns

Iterator to the first valid entity, or end() if none found.

Definition at line 453 of file View.ixx.

453 [[nodiscard]] Iterator begin() {
454 auto* leadSet = std::get<0>(includeSets_);
455
456 if (!leadSet) {
457 return Iterator{};
458 }
459
460 Iterator it{leadSet->begin(), leadSet->end(), this};
461
462 if (!it.isValid()) {
463 it.advance();
464 }
465
466 return it;
467 }

empty()

template <typename TEntityManager, typename... TRequired, typename... TDirty, typename... TOptional>
bool helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::empty ()
inline

Returns true if the view has no entities to iterate over.

Returns

boolean

Definition at line 248 of file View.ixx.

248 [[nodiscard]] bool empty() {
249 auto* leadSet = std::get<0>(includeSets_);
250 if (!leadSet) {
251 return true;
252 }
253 return begin() == end();
254 }

end()

template <typename TEntityManager, typename... TRequired, typename... TDirty, typename... TOptional>
Iterator helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::end ()
inline

Returns an iterator to the end (past the last entity).

Returns

End iterator for comparison.

Definition at line 474 of file View.ixx.

474 [[nodiscard]] Iterator end() {
475 auto* leadSet = std::get<0>(includeSets_);
476
477 if (!leadSet) {
478 return Iterator{};
479 }
480
481 return Iterator{leadSet->end(), leadSet->end(), this};
482 }

exclude()

template <typename T>
PartialView & helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::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.

 // 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 232 of file View.ixx.

233 auto* set = em_->template sparseSet<T>();
234
235 if (set) {
236 excludeChecks_.emplace_back([set](EntityId entityId) {
237 return set->contains(entityId);
238 });
239 }
240 return *this;
241 }

whereAnyDirty()

template <typename... TNewDirty>
auto helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::whereAnyDirty ()
inline

Filters to only include entities with changed components.

Returns

Reference to this View for method chaining.

Definition at line 195 of file View.ixx.

195 auto whereAnyDirty() requires (sizeof...(TOptional) == 0 && sizeof...(TDirty) == 0) {
196
197 return PartialView<
198 TEntityManager,
199 std::tuple<TRequired...>,
200 std::tuple<TNewDirty...>,
201 std::tuple<>
202 >(
203 em_,
204 includeSets_,
205 excludeChecks_,
206 filterActiveOnly_,
207 activeSet_
208 );
209
210 }

withActive()

template <typename TEntityManager, typename... TRequired, typename... TDirty, typename... TOptional>
PartialView & helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::withActive ()
inline

Filters to only include entities with an active component.

Returns

Reference to this View for method chaining.

Definition at line 261 of file View.ixx.

262 activeSet_ = em_->template sparseSet<Active<typename TEntityManager::Handle_type>>();
263 filterActiveOnly_ = true;
264 return *this;
265 }

withOptional()

template <typename... TNewOptional>
auto helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::withOptional ()
inline

Adds optional component types to the current view.

Optional components do not participate in entity filtering. For each optional type, iteration yields either a component pointer or nullptr if the entity does not own that component.

This method is intended to be called once with all optional types:

 for (auto [e, transform, velocity, maybeHealth, maybeShield] : world
  .view<EntityManager, TransformComponent, VelocityComponent>()
  .withOptional<HealthComponent, ShieldComponent>()) {
  // maybeHealth / maybeShield may be nullptr
 }
Template Parameters
TNewOptional

Optional component types to expose in iteration.

Returns

A new PartialView with unchanged required components and the provided optional component types.

Definition at line 172 of file View.ixx.

173 requires (sizeof...(TOptional) == 0)
174 {
175 return PartialView<
176 TEntityManager,
177 std::tuple<TRequired...>,
178 std::tuple<TDirty...>,
179 std::tuple<TNewOptional...>>(
180 em_,
181 includeSets_,
182 excludeChecks_,
183 filterActiveOnly_,
184 activeSet_,
185 anyDirtySets_
186 );
187 }

Private Member Attributes

activeSet_

template <typename TEntityManager, typename... TRequired, typename... TDirty, typename... TOptional>
SparseSet<Active<typename TEntityManager::Handle_type> >* helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::activeSet_ = nullptr

SparseSet for Active component, required with filterActiveOnly_.

Definition at line 103 of file View.ixx.

anyDirtySets_

template <typename TEntityManager, typename... TRequired, typename... TDirty, typename... TOptional>
std::tuple<SparseSet<DirtyComponentSpec<TDirty> >*... > helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::anyDirtySets_

Pointers to the SparseSets of the dirty component sets.

Definition at line 90 of file View.ixx.

90 std::tuple<SparseSet<DirtyComponentSpec<TDirty>>*... > anyDirtySets_;

em_

template <typename TEntityManager, typename... TRequired, typename... TDirty, typename... TOptional>
TEntityManager* helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::em_

Definition at line 75 of file View.ixx.

75 TEntityManager* em_;

excludeChecks_

template <typename TEntityManager, typename... TRequired, typename... TDirty, typename... TOptional>
std::vector<std::function<bool(EntityId)> > helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::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.

Definition at line 98 of file View.ixx.

98 std::vector<std::function<bool(EntityId)>> excludeChecks_;

filterActiveOnly_

template <typename TEntityManager, typename... TRequired, typename... TDirty, typename... TOptional>
bool helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::filterActiveOnly_ = false

Flag to filter only entities with Active component.

Definition at line 108 of file View.ixx.

108 bool filterActiveOnly_ = false;

includeSets_

template <typename TEntityManager, typename... TRequired, typename... TDirty, typename... TOptional>
std::tuple<SparseSet<TRequired>*... > helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::includeSets_

Pointers to the SparseSets of the included components.

Definition at line 80 of file View.ixx.

80 std::tuple<SparseSet<TRequired>*... > includeSets_;

optionalSets_

template <typename TEntityManager, typename... TRequired, typename... TDirty, typename... TOptional>
std::tuple<SparseSet<TOptional>*... > helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TDirty... >, std::tuple< TOptional... > >::optionalSets_

Optional components, might return nullptr. Are not considered by whereAnyChanged().

Definition at line 85 of file View.ixx.

85 std::tuple<SparseSet<TOptional>*... > optionalSets_;

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.