Copperfield Engine 0.1
C++ Game Engine
Loading...
Searching...
No Matches
ComponentIterator< T, Types > Class Template Reference

Helper to iterate several component lists simultaneously. More...

#include <lists_iterator.hpp>

Public Member Functions

 ComponentIterator (T &main, Types &... list)
 Constructor. More...
 
bool next ()
 Iterates all lists until an entity containing all components is found. More...
 
auto get ()
 Retrieve the components of the last entity found using next. More...
 
Entity getEntity ()
 retrieves the entity being currently iterated More...
 
void reset ()
 Resets the internal state, so that you can iterate the lists again.
 

Detailed Description

template<typename T, typename... Types>
class ComponentIterator< T, Types >

Helper to iterate several component lists simultaneously.

Template Parameters
TMain list to iterate; it should be a list that contains fewer components.
TypesRest of the lists.

Constructor & Destructor Documentation

◆ ComponentIterator()

template<typename T , typename... Types>
ComponentIterator< T, Types >::ComponentIterator ( T &  main,
Types &...  list 
)
inline

Constructor.

Parameters
mainShould be a list that contains fewer components.
...listRest of the lists.

Member Function Documentation

◆ get()

template<typename T , typename... Types>
auto ComponentIterator< T, Types >::get ( )
inline

Retrieve the components of the last entity found using next.

Returns
Tuple containing references to all the requested components on the entity.

◆ getEntity()

template<typename T , typename... Types>
Entity ComponentIterator< T, Types >::getEntity ( )
inline

retrieves the entity being currently iterated

make sure you don't delete an entity during iteration it will break the internal iterator and probably crash the program

you can store the entities you want to delete in an array and delete them after the loop has finished

Returns
Entity being currently iterated

◆ next()

template<typename T , typename... Types>
bool ComponentIterator< T, Types >::next ( )
inline

Iterates all lists until an entity containing all components is found.

Returns
True if an entity was found, false if no new entity was found before reaching the end of a list.