Forward iterator for View traversal. More...
Declaration
struct helios::ecs::PartialView::Iterator<TEntityManager, std::tuple< TRequired... >, std::tuple< TOptional... > >::Iterator { ... }
Public Member Typedefs Index
Public Constructors Index
| Iterator ()=default |
|
Default constructor creating an invalid iterator. More...
|
|
| Iterator (LeadIterator current, LeadIterator end, const PartialView *view) |
|
Constructs an iterator with the given range and view. More...
|
|
Public Operators Index
Public Member Functions Index
| bool | isValid () const |
|
Validates if the current entity matches all filter criteria. More...
|
|
| void | advance () |
|
Advances to the next valid entity. More...
|
|
Public Member Attributes Index
Description
Forward iterator for View traversal.
Uses the first component type as the "lead" iterator and validates each entity against all include/exclude/enabled criteria before yielding.
Definition at line 204 of file View.ixx.
Public Member Typedefs
Entity_type
| using helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TOptional... > >::Iterator::Entity_type = Entity<TEntityManager> |
|
LeadComponent
| using helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TOptional... > >::Iterator::LeadComponent = std::tuple_element_t<0, std::tuple<TRequired...> > |
|
The first component type determines iteration order.
Definition at line 211 of file View.ixx.
LeadIterator
| using helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TOptional... > >::Iterator::LeadIterator = typename SparseSet<LeadComponent>::Iterator |
|
Public Constructors
Iterator()
| helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TOptional... > >::Iterator::Iterator () |
|
default
|
Default constructor creating an invalid iterator.
Definition at line 225 of file View.ixx.
Iterator()
| helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TOptional... > >::Iterator::Iterator (LeadIterator current, LeadIterator end, const PartialView * view) |
|
inline
|
Constructs an iterator with the given range and view.
- Parameters
-
| current | Iterator to the current position. |
| end | Iterator to the end position. |
| view | Pointer to the owning View for filter access. |
Definition at line 234 of file View.ixx.
235 : current_(current), end_(end), view_(view) {}
Public Operators
operator!=()
| bool helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TOptional... > >::Iterator::operator!= (const Iterator & other) |
|
inline
noexcept
|
Inequality comparison.
- Parameters
-
| other | The iterator to compare against. |
- Returns
True if iterators point to different positions.
Definition at line 337 of file View.ixx.
338 return current_ != other.current_;
339 }
operator*()
| auto helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TOptional... > >::Iterator::operator* () |
|
inline
|
Dereference operator.
- Returns
A tuple containing: 1) Entity_type, 2) pointers to all required components, 3) pointers to all optional components.
Optional component pointers may be nullptr when the current entity does not own the respective component (or it is filtered by whereEnabled() when isEnabled() is available).
Returns by value to support C++17 structured binding.
Definition at line 355 of file View.ixx.
356 EntityId entityId = current_.entityId();
357 auto handle = view_->em_->handle(entityId);
358
359
360 return std::tuple_cat(
362 std::apply([entityId](auto*... sets) {
363 return std::make_tuple(sets->get(entityId)...);
364 }, view_->includeSets_),
365
366 std::apply([entityId, filterEnabledOnly = view_->filterEnabledOnly_](auto*... sets) {
367 return std::make_tuple(
368 ([filterEnabledOnly, entityId, &sets]() {
369 if (!sets || !sets->contains(entityId)) {
370 return nullptr;
371 }
372
373 auto* component = sets->get(entityId);
374
375 if constexpr (requires {component->isEnabled(); }) {
376 if (filterEnabledOnly && !component->isEnabled()) {
377 return nullptr;
378 }
379 }
380
381 return component;
382 }())...
383
384 );
385 }, view_->optionalSets_)
386
387 );
388 }
operator++()
| Iterator & helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TOptional... > >::Iterator::operator++ () |
|
inline
noexcept
|
Pre-increment operator.
- Returns
Reference to this iterator after advancing.
Definition at line 325 of file View.ixx.
326 advance();
327 return *this;
328 }
operator==()
| bool helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TOptional... > >::Iterator::operator== (const Iterator & other) |
|
inline
noexcept
|
Definition at line 390 of file View.ixx.
390 [[nodiscard]] bool operator==(const Iterator& other) const noexcept {
391 return current_ == other.current_;
392 }
Public Member Functions
advance()
| void helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TOptional... > >::Iterator::advance () |
|
inline
|
Advances to the next valid entity.
Increments the underlying iterator and skips invalid entities until a valid one is found or end is reached.
Definition at line 314 of file View.ixx.
315 do {
316 ++current_;
317 } while (current_ != end_ && !isValid());
318 }
isValid()
| bool helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TOptional... > >::Iterator::isValid () |
|
inline
|
Validates if the current entity matches all filter criteria.
Performs the following checks in order:
- Entity validity in the registry
- Include check - entity has all required components
- Exclude check - entity has none of the excluded components
- Enabled check - all components pass isEnabled() (if filtered)
- Returns
True if the entity passes all checks, false otherwise.
Definition at line 248 of file View.ixx.
249 if (current_ == end_) {
250 return true;
251 }
252
253
254 EntityId entityId = current_.entityId();
255
256 if (!view_->em_->isValid(entityId)) {
257 return false;
258 }
259
260
261
262 const bool hasAllIncludes = std::apply([entityId](auto*... sets) {
263 return ((sets && sets->contains(entityId)) && ...);
264 }, view_->includeSets_);
265
266 if (!hasAllIncludes) {
267 return false;
268 }
269
270
271 for (const auto& excludeCheck : view_->excludeChecks_) {
272 if (excludeCheck(entityId)) {
273 return false;
274 }
275 }
276
277
278 if (view_->filterEnabledOnly_) {
279
280
281 auto isComponentEnabled = [](const auto& comp) -> bool {
282 if constexpr (requires { comp.isEnabled(); }) {
283 return comp.isEnabled();
284 } else {
285 return true;
286 }
287 };
288
289
290 if (!isComponentEnabled(*current_)) {
291 return false;
292 }
293
294
295 const bool allEnabled = std::apply([&](auto*... sets) {
296
297 return (isComponentEnabled(*sets->get(entityId)) && ...);
298 }, view_->includeSets_);
299
300 if (!allEnabled) {
301 return false;
302 }
303 }
304
305 return true;
306 }
Public Member Attributes
current_
| LeadIterator helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TOptional... > >::Iterator::current_ |
|
end_
| LeadIterator helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TOptional... > >::Iterator::end_ |
|
view_
| const PartialView* helios::ecs::PartialView< TEntityManager, std::tuple< TRequired... >, std::tuple< TOptional... > >::Iterator::view_ |
|
The documentation for this struct was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.