Leviathan  0.8.0.0
Leviathan game engine
Leviathan::SystemCachedComponentCollectionStorage< UsedCachedComponentCollectionT > Class Template Reference

#include <System.h>

Public Types

using HolderType = CachedComponentCollectionHolder< UsedCachedComponentCollectionT >
 

Public Member Functions

void Clear ()
 
auto GetCachedComponentCollectionCount () const
 

Static Public Member Functions

template<class FirstType , class SecondType >
static void TupleCachedComponentCollectionHelper (ObjectPool< std::tuple< FirstType &, SecondType &>, ObjectID > &CachedComponentCollections, const std::vector< std::tuple< FirstType *, ObjectID >> &firstdata, const std::vector< std::tuple< SecondType *, ObjectID >> &seconddata, const ComponentHolder< FirstType > &firstholder, const ComponentHolder< SecondType > &secondholder)
 Helper function for creating nodes based on std::tuple. More...
 
template<class FirstType , class SecondType , class ThirdType >
static void TupleCachedComponentCollectionHelper (ObjectPool< std::tuple< FirstType &, SecondType &, ThirdType &>, ObjectID > &CachedComponentCollections, const std::vector< std::tuple< FirstType *, ObjectID >> &firstdata, const std::vector< std::tuple< SecondType *, ObjectID >> &seconddata, const std::vector< std::tuple< ThirdType *, ObjectID >> &thirddata, const ComponentHolder< FirstType > &firstholder, const ComponentHolder< SecondType > &secondholder, const ComponentHolder< ThirdType > &thirdholder)
 Tree part component TupleCachedComponentCollectionHelper. More...
 

Public Attributes

HolderType CachedComponents
 

Static Protected Member Functions

template<class T >
static T * _TupleHelperGetIfComponentExists (ObjectID id, const std::vector< std::tuple< T *, ObjectID >> &addedlist, const ComponentHolder< T > &holder)
 

Detailed Description

template<class UsedCachedComponentCollectionT>
class Leviathan::SystemCachedComponentCollectionStorage< UsedCachedComponentCollectionT >

This is split from System to allow easily creation of systems that have multiple CachedComponentCollection types

Definition at line 26 of file System.h.

Member Typedef Documentation

◆ HolderType

template<class UsedCachedComponentCollectionT>
using Leviathan::SystemCachedComponentCollectionStorage< UsedCachedComponentCollectionT >::HolderType = CachedComponentCollectionHolder<UsedCachedComponentCollectionT>

Definition at line 29 of file System.h.

Member Function Documentation

◆ _TupleHelperGetIfComponentExists()

template<class UsedCachedComponentCollectionT>
template<class T >
static T* Leviathan::SystemCachedComponentCollectionStorage< UsedCachedComponentCollectionT >::_TupleHelperGetIfComponentExists ( ObjectID  id,
const std::vector< std::tuple< T *, ObjectID >> &  addedlist,
const ComponentHolder< T > &  holder 
)
inlinestaticprotected

Definition at line 142 of file System.h.

145  {
146  // First search added //
147  for(auto iter = addedlist.begin(); iter != addedlist.end(); ++iter){
148 
149  if(std::get<1>(*iter) == id){
150 
151  return std::get<0>(*iter);
152  }
153  }
154 
155  // This full search returns a nullptr if not found //
156  return holder.Find(id);
157  }

◆ Clear()

template<class UsedCachedComponentCollectionT>
void Leviathan::SystemCachedComponentCollectionStorage< UsedCachedComponentCollectionT >::Clear ( )
inline

Definition at line 31 of file System.h.

31  {
32 
34  }
void Clear()
Clears the index and replaces the pool with a new one.
Definition: ObjectPool.h:206

◆ GetCachedComponentCollectionCount()

template<class UsedCachedComponentCollectionT>
auto Leviathan::SystemCachedComponentCollectionStorage< UsedCachedComponentCollectionT >::GetCachedComponentCollectionCount ( ) const
inline

Definition at line 36 of file System.h.

36  {
38  }
auto GetObjectCount() const
Definition: ObjectPool.h:218

◆ TupleCachedComponentCollectionHelper() [1/2]

template<class UsedCachedComponentCollectionT>
template<class FirstType , class SecondType >
static void Leviathan::SystemCachedComponentCollectionStorage< UsedCachedComponentCollectionT >::TupleCachedComponentCollectionHelper ( ObjectPool< std::tuple< FirstType &, SecondType &>, ObjectID > &  CachedComponentCollections,
const std::vector< std::tuple< FirstType *, ObjectID >> &  firstdata,
const std::vector< std::tuple< SecondType *, ObjectID >> &  seconddata,
const ComponentHolder< FirstType > &  firstholder,
const ComponentHolder< SecondType > &  secondholder 
)
inlinestatic

Helper function for creating nodes based on std::tuple.

Todo:
Also figure out if "CachedComponentCollections.Find(id) != nullptr" should be before _TupleHelperGetIfComponentExists

Definition at line 47 of file System.h.

53  {
54  // First way around //
55  for(auto iter = firstdata.begin(); iter != firstdata.end(); ++iter){
56 
57  const auto id = std::get<1>(*iter);
58  SecondType* other = _TupleHelperGetIfComponentExists(id, seconddata, secondholder);
59 
60  // Create node if required components where found and it doesn't exist already //
61  if(!other || CachedComponentCollections.Find(id) != nullptr)
62  continue;
63 
64  CachedComponentCollections.ConstructNew(id, *std::get<0>(*iter), *other);
65  }
66 
67  // And the other way around //
68  for(auto iter = seconddata.begin(); iter != seconddata.end(); ++iter){
69 
70  const auto id = std::get<1>(*iter);
71  FirstType* other = _TupleHelperGetIfComponentExists(id, firstdata, firstholder);
72 
73  // Create node if required components where found and it doesn't exist already //
74  if(!other || CachedComponentCollections.Find(id) != nullptr)
75  continue;
76 
77  CachedComponentCollections.ConstructNew(id, *other, *std::get<0>(*iter));
78  }
79  }
static T * _TupleHelperGetIfComponentExists(ObjectID id, const std::vector< std::tuple< T *, ObjectID >> &addedlist, const ComponentHolder< T > &holder)
Definition: System.h:142

◆ TupleCachedComponentCollectionHelper() [2/2]

template<class UsedCachedComponentCollectionT>
template<class FirstType , class SecondType , class ThirdType >
static void Leviathan::SystemCachedComponentCollectionStorage< UsedCachedComponentCollectionT >::TupleCachedComponentCollectionHelper ( ObjectPool< std::tuple< FirstType &, SecondType &, ThirdType &>, ObjectID > &  CachedComponentCollections,
const std::vector< std::tuple< FirstType *, ObjectID >> &  firstdata,
const std::vector< std::tuple< SecondType *, ObjectID >> &  seconddata,
const std::vector< std::tuple< ThirdType *, ObjectID >> &  thirddata,
const ComponentHolder< FirstType > &  firstholder,
const ComponentHolder< SecondType > &  secondholder,
const ComponentHolder< ThirdType > &  thirdholder 
)
inlinestatic

Tree part component TupleCachedComponentCollectionHelper.

Definition at line 83 of file System.h.

92  {
93  // First way around //
94  for(auto iter = firstdata.begin(); iter != firstdata.end(); ++iter){
95 
96  const auto id = std::get<1>(*iter);
97  SecondType* other2 = _TupleHelperGetIfComponentExists(id, seconddata,
98  secondholder);
99  ThirdType* other3 = _TupleHelperGetIfComponentExists(id, thirddata, thirdholder);
100 
101  // Create node if required components where found and it doesn't exist already //
102  if(!other2 || !other3 || CachedComponentCollections.Find(id) != nullptr)
103  continue;
104 
105  CachedComponentCollections.ConstructNew(id, *std::get<0>(*iter), *other2, *other3);
106  }
107 
108  // And the other way around //
109  for(auto iter = seconddata.begin(); iter != seconddata.end(); ++iter){
110 
111  const auto id = std::get<1>(*iter);
112  FirstType* other1 = _TupleHelperGetIfComponentExists(id, firstdata, firstholder);
113  ThirdType* other3 = _TupleHelperGetIfComponentExists(id, thirddata, thirdholder);
114 
115  // Create node if required components where found and it doesn't exist already //
116  if(!other1 || !other3 || CachedComponentCollections.Find(id) != nullptr)
117  continue;
118 
119  CachedComponentCollections.ConstructNew(id, *other1, *std::get<0>(*iter), *other3);
120  }
121 
122  // Third way around //
123  for(auto iter = thirddata.begin(); iter != thirddata.end(); ++iter){
124 
125  const auto id = std::get<1>(*iter);
126  FirstType* other1 = _TupleHelperGetIfComponentExists(id, firstdata, firstholder);
127  SecondType* other2 = _TupleHelperGetIfComponentExists(id, seconddata,
128  secondholder);
129 
130  // Create node if required components where found and it doesn't exist already //
131  if(!other1 || !other2 || CachedComponentCollections.Find(id) != nullptr)
132  continue;
133 
134  CachedComponentCollections.ConstructNew(id, *other1, *other2, *std::get<0>(*iter));
135  }
136  }
static T * _TupleHelperGetIfComponentExists(ObjectID id, const std::vector< std::tuple< T *, ObjectID >> &addedlist, const ComponentHolder< T > &holder)
Definition: System.h:142

Member Data Documentation

◆ CachedComponents

template<class UsedCachedComponentCollectionT>
HolderType Leviathan::SystemCachedComponentCollectionStorage< UsedCachedComponentCollectionT >::CachedComponents

Definition at line 161 of file System.h.


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