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 25 of file System.h.

Member Typedef Documentation

◆ HolderType

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

Definition at line 27 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 140 of file System.h.

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

◆ Clear()

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

Definition at line 29 of file System.h.

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

◆ GetCachedComponentCollectionCount()

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

Definition at line 34 of file System.h.

35  {
37  }
auto GetObjectCount() const
Definition: ObjectPool.h:264

◆ 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 46 of file System.h.

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

◆ 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 82 of file System.h.

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

Member Data Documentation

◆ CachedComponents

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

Definition at line 158 of file System.h.


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