Skip to main content

PartialView Class Template

Declaration

template <typename TEntityManager, typename... TRequired, typename... TOptional> class helios::ecs::PartialView<TEntityManager, std::tuple< TRequired... >, 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 filterEnabledOnly)

Public Member Functions Index

template <typename... TNewOptional>
auto withOptional () -> PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TNewOptional... > >

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

template <typename T>
PartialView &exclude ()

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

template < ... >
boolempty ()
template < ... >
PartialView &whereEnabled ()

Filters to only include entities with enabled components. 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_
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 < ... >
boolfilterEnabledOnly_ = false

Flag to filter only enabled components. More...

Definition at line 67 of file View.ixx.

Public Constructors

PartialView()

template <typename TEntityManager, typename... TRequired, typename... TOptional>
helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, 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 100 of file View.ixx.

100 explicit PartialView(TEntityManager* em) : em_(em) {
101 // Retrieve pointers to the specific component sets immediately.
102 includeSets_ = std::make_tuple(em_->template getSparseSet<TRequired>()...);
103 optionalSets_ = std::make_tuple(em_->template getSparseSet<TOptional>()...);
104 };

PartialView()

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

Definition at line 106 of file View.ixx.

106 explicit PartialView(
107 TEntityManager* em,
108 std::tuple<SparseSet<TRequired>*...> includeSets,
109 std::vector<std::function<bool(EntityId)>> excludeChecks,
110 const bool filterEnabledOnly
111 ) : em_(em), includeSets_(includeSets), excludeChecks_(std::move(excludeChecks)), filterEnabledOnly_(filterEnabledOnly) {
112 static_assert(sizeof...(TOptional) == 0, "withOptional() should provide all optional components types in a single call.");
113 optionalSets_ = std::make_tuple(em_->template getSparseSet<TOptional>()...);
114 }

Public Member Functions

begin()

template <typename TEntityManager, typename... TRequired, typename... TOptional>
Iterator helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, 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 403 of file View.ixx.

403 [[nodiscard]] Iterator begin() {
404 auto* leadSet = std::get<0>(includeSets_);
405
406 if (!leadSet) {
407 return Iterator{};
408 }
409
410 Iterator it{leadSet->begin(), leadSet->end(), this};
411
412 if (!it.isValid()) {
413 it.advance();
414 }
415
416 return it;
417 }

empty()

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

Definition at line 176 of file View.ixx.

176 [[nodiscard]] bool empty() {
177 auto* leadSet = std::get<0>(includeSets_);
178 if (!leadSet) {
179 return true;
180 }
181 return begin() == end();
182 }

end()

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

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

Returns

End iterator for comparison.

Definition at line 424 of file View.ixx.

424 [[nodiscard]] Iterator end() {
425 auto* leadSet = std::get<0>(includeSets_);
426
427 if (!leadSet) {
428 return Iterator{};
429 }
430
431 return Iterator{leadSet->end(), leadSet->end(), this};
432 }

exclude()

template <typename T>
PartialView & helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, 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 165 of file View.ixx.

166 auto* set = em_->template getSparseSet<T>();
167
168 if (set) {
169 excludeChecks_.emplace_back([set](EntityId entityId) {
170 return set->contains(entityId);
171 });
172 }
173 return *this;
174 }

whereEnabled()

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

Filters to only include entities with enabled components.

Components must implement isEnabled() returning bool. Components without this method are assumed to be enabled.

Returns

Reference to this View for method chaining.

Definition at line 192 of file View.ixx.

193 filterEnabledOnly_ = true;
194 return *this;
195 }

withOptional()

template <typename... TNewOptional>
PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TNewOptional... > > helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, 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 139 of file View.ixx.

139 PartialView<TEntityManager, std::tuple<TRequired...>, std::tuple<TNewOptional...>> withOptional() {
140 return PartialView<TEntityManager, std::tuple<TRequired...>, std::tuple<TNewOptional...>>(
141 em_, includeSets_, excludeChecks_, filterEnabledOnly_
142 );
143 }

Private Member Attributes

em_

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

Definition at line 70 of file View.ixx.

70 TEntityManager* em_;

excludeChecks_

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

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

filterEnabledOnly_

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

Flag to filter only enabled components.

Definition at line 90 of file View.ixx.

90 bool filterEnabledOnly_ = false;

includeSets_

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

Pointers to the SparseSets of the included components.

Definition at line 75 of file View.ixx.

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

optionalSets_

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

Definition at line 78 of file View.ixx.

78 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.