Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
rtp::ecs::ZipView< Containers > Class Template Reference

A view that iterates over entities possessing all specified components. More...

#include <ZipView.hpp>

Collaboration diagram for rtp::ecs::ZipView< Containers >:

Classes

class  Iterator
 The actual iterator performing the intersection logic. More...
 

Public Types

using tuple_arrays_t = std::tuple< Containers... >
 Tuple type holding references to all SparseArrays.
 

Public Member Functions

 ZipView (Containers... arrays)
 Constructor for ZipView.
 
Iterator begin ()
 Get iterator to the beginning of the zipped view.
 
Iterator end ()
 Get iterator to the end of the zipped view.
 

Private Member Functions

template<size_t I>
void findSmallest (size_t &min_size)
 Find the index of the SparseArray with the smallest size.
 
std::span< const EntitygetEntitiesFromSmallest (size_t index)
 Get the entity list from the SparseArray at the specified index.
 

Private Attributes

tuple_arrays_t _arrays
 Tuple of references to SparseArrays.
 
size_t _smallest_idx = 0
 Index of the SparseArray with the fewest entities.
 

Detailed Description

template<class... Containers>
class rtp::ecs::ZipView< Containers >

A view that iterates over entities possessing all specified components.

Template Parameters
ContainersThe types of the SparseArrays (e.g., SparseArray<Pos>&, SparseArray<Vel>&)

Definition at line 26 of file ZipView.hpp.

Member Typedef Documentation

◆ tuple_arrays_t

template<class... Containers>
using rtp::ecs::ZipView< Containers >::tuple_arrays_t = std::tuple<Containers...>

Tuple type holding references to all SparseArrays.

Definition at line 31 of file ZipView.hpp.

Constructor & Destructor Documentation

◆ ZipView()

template<class... Containers>
rtp::ecs::ZipView< Containers >::ZipView ( Containers...  arrays)
inline

Constructor for ZipView.

Parameters
arraysReferences to the SparseArrays to zip

Definition at line 110 of file ZipView.hpp.

References rtp::ecs::ZipView< Containers >::_arrays, and rtp::ecs::ZipView< Containers >::_smallest_idx.

Member Function Documentation

◆ begin()

template<class... Containers>
Iterator rtp::ecs::ZipView< Containers >::begin ( )
inline

Get iterator to the beginning of the zipped view.

Returns
Iterator to the first valid entity with all components

Definition at line 120 of file ZipView.hpp.

References rtp::ecs::ZipView< Containers >::_arrays, rtp::ecs::ZipView< Containers >::_smallest_idx, and rtp::ecs::ZipView< Containers >::getEntitiesFromSmallest().

◆ end()

template<class... Containers>
Iterator rtp::ecs::ZipView< Containers >::end ( )
inline

Get iterator to the end of the zipped view.

Returns
Iterator past the last entity

Definition at line 129 of file ZipView.hpp.

References rtp::ecs::ZipView< Containers >::_arrays, rtp::ecs::ZipView< Containers >::_smallest_idx, and rtp::ecs::ZipView< Containers >::getEntitiesFromSmallest().

◆ findSmallest()

template<class... Containers>
template<size_t I>
void rtp::ecs::ZipView< Containers >::findSmallest ( size_t &  min_size)
inlineprivate

Find the index of the SparseArray with the smallest size.

Template Parameters
ICurrent index in the tuple
Parameters
min_sizeReference to the current minimum size found

Definition at line 144 of file ZipView.hpp.

References rtp::ecs::ZipView< Containers >::_arrays, and rtp::ecs::ZipView< Containers >::_smallest_idx.

◆ getEntitiesFromSmallest()

template<class... Containers>
std::span< const Entity > rtp::ecs::ZipView< Containers >::getEntitiesFromSmallest ( size_t  index)
inlineprivate

Get the entity list from the SparseArray at the specified index.

Parameters
indexIndex of the SparseArray in the tuple
Returns
Reference to the vector of entities

Definition at line 160 of file ZipView.hpp.

References rtp::ecs::ZipView< Containers >::_arrays.

Referenced by rtp::ecs::ZipView< Containers >::begin(), and rtp::ecs::ZipView< Containers >::end().

Member Data Documentation

◆ _arrays

◆ _smallest_idx

template<class... Containers>
size_t rtp::ecs::ZipView< Containers >::_smallest_idx = 0
private

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