Leviathan  0.8.0.0
Leviathan game engine
Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects > Class Template Reference

Creates objects in a shared memory region. More...

#include <ObjectPool.h>

Public Member Functions

 ObjectPoolTracked ()
 
 ~ObjectPoolTracked ()
 
template<typename... Args>
ElementType * ConstructNew (KeyType forentity, Args &&... args)
 Constructs a new component of the held type for entity. More...
 
bool HasElementsInRemoved () const
 Returns true if there are objects in Removed. More...
 
bool HasElementsInAdded () const
 Returns true if there are objects in Added. More...
 
bool HasElementsInQueued () const
 Returns true if there are objects in Queued. More...
 
template<typename... Args>
void ReleaseQueued (Args &&... args)
 Calls Release with the specified arguments on elements that are queued for destruction. More...
 
template<typename... Args>
void Release (KeyType id, bool addtoremoved, Args &&... args)
 Calls Release on an object and then removes it from the pool. More...
 
template<typename... Args>
bool ReleaseIfExists (KeyType id, bool addtoremoved, Args &&... args)
 Calls Release on an object if it is in this pool and then removes it from the pool. More...
 
void ClearQueued ()
 Removes elements that are queued for destruction without calling release. More...
 
const auto & GetRemoved () const
 Returns a reference to the vector of removed elements. More...
 
auto & GetAdded ()
 Returns a reference to the vector of added elements. More...
 
void ClearAdded ()
 Clears the added list. More...
 
void ClearRemoved ()
 Clears the removed list. More...
 
template<typename Any >
void RemoveBasedOnKeyTupleList (const std::vector< std::tuple< Any, KeyType >> &values, bool addtoremoved=false)
 Destroys without releasing elements based on ids in vector. More...
 
template<typename... Args>
void ReleaseAllAndClear (Args &&... args)
 Calls release on all objects and clears everything. More...
 
void RemoveFromAdded (KeyType id)
 Removes a specific id from the added list. More...
 
ElementType * Find (KeyType id) const
 
void Destroy (KeyType id, bool addtoremoved=true)
 Destroys a component based on id. More...
 
bool DestroyIfExists (KeyType id, bool addtoremoved=true)
 Destroys a component based on id if exists. More...
 
void QueueDestroy (KeyType id)
 Queues destruction of an element. More...
 
void Call (std::function< bool(ElementType &, KeyType)> function)
 Calls an function on all the objects in the pool. More...
 
void Clear ()
 Clears the index and replaces the pool with a new one. More...
 
auto GetObjectCount () const
 
std::unordered_map< KeyType, ElementType * > & GetIndex ()
 Returns a direct access to Index. More...
 

Protected Member Functions

bool RemoveFromIndex (KeyType id)
 Removes an component from the index but doesn't destruct it. More...
 
template<typename... Args>
void _ReleaseCommon (ElementType *object, KeyType id, bool addtoremoved, Args &&... args)
 
void _DestroyCommon (ElementType *object, KeyType id, bool addtoremoved)
 

Protected Attributes

std::unordered_map< KeyType, ElementType * > Index
 Used for looking up element belonging to id. More...
 
std::vector< std::tuple< ElementType *, KeyType > > Removed
 
std::vector< std::tuple< ElementType *, KeyType > > Queued
 
std::vector< std::tuple< ElementType *, KeyType > > Added
 Used for detecting created elements. More...
 
boost::pool Elements
 Pool for objects. More...
 

Detailed Description

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
class Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >

Creates objects in a shared memory region.

Tracks the creation and destruction of elements as needed by components in a GameWorld

Todo:
Created and destroyed vectors could use swap with last and remove the last to remove more effectively

Definition at line 267 of file ObjectPool.h.

Constructor & Destructor Documentation

◆ ObjectPoolTracked()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::ObjectPoolTracked ( )
inline

Definition at line 269 of file ObjectPool.h.

269 : Elements(sizeof(ElementType), 16) {}
boost::pool Elements
Pool for objects.
Definition: ObjectPool.h:672

◆ ~ObjectPoolTracked()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::~ObjectPoolTracked ( )
inline

Definition at line 271 of file ObjectPool.h.

272  {
273 
274  if(!AutoCleanupObjects)
275  return;
276 
277  Clear();
278  }
void Clear()
Clears the index and replaces the pool with a new one.
Definition: ObjectPool.h:578

Member Function Documentation

◆ _DestroyCommon()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
void Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::_DestroyCommon ( ElementType *  object,
KeyType  id,
bool  addtoremoved 
)
inlineprotected

Definition at line 642 of file ObjectPool.h.

643  {
644  object->~ElementType();
645  Elements.free(object);
646 
647  if(addtoremoved)
648  Removed.push_back(std::make_tuple(object, id));
649 
650  RemoveFromIndex(id);
651  RemoveFromAdded(id);
652  }
bool RemoveFromIndex(KeyType id)
Removes an component from the index but doesn&#39;t destruct it.
Definition: ObjectPool.h:611
void RemoveFromAdded(KeyType id)
Removes a specific id from the added list.
Definition: ObjectPool.h:482
boost::pool Elements
Pool for objects.
Definition: ObjectPool.h:672
std::vector< std::tuple< ElementType *, KeyType > > Removed
Definition: ObjectPool.h:661

◆ _ReleaseCommon()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
template<typename... Args>
void Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::_ReleaseCommon ( ElementType *  object,
KeyType  id,
bool  addtoremoved,
Args &&...  args 
)
inlineprotected

Definition at line 628 of file ObjectPool.h.

629  {
630  object->Release(std::forward<Args>(args)...);
631 
632  object->~ElementType();
633  Elements.free(object);
634 
635  if(addtoremoved)
636  Removed.push_back(std::make_tuple(object, id));
637 
638  RemoveFromIndex(id);
639  RemoveFromAdded(id);
640  }
bool RemoveFromIndex(KeyType id)
Removes an component from the index but doesn&#39;t destruct it.
Definition: ObjectPool.h:611
void RemoveFromAdded(KeyType id)
Removes a specific id from the added list.
Definition: ObjectPool.h:482
boost::pool Elements
Pool for objects.
Definition: ObjectPool.h:672
std::vector< std::tuple< ElementType *, KeyType > > Removed
Definition: ObjectPool.h:661

◆ Call()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
void Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::Call ( std::function< bool(ElementType &, KeyType)>  function)
inline

Calls an function on all the objects in the pool.

Note
The order of the objects is not guaranteed and can change between runs
Parameters
functionThe function that is called with all of the components of this type the first parameter is the component, the second is the id of the entity owning the component, the return value specifies if the component should be destroyed (true being yes and false being no)

Definition at line 558 of file ObjectPool.h.

559  {
560 
561  for(auto iter = Index.begin(); iter != Index.end();) {
562 
563  if(function(*iter->second, iter->first)) {
564 
565  iter->second->~ElementType();
566  Elements.free(iter->second);
567  iter = Index.erase(iter);
568 
569  } else {
570 
571  ++iter;
572  }
573  }
574  }
std::unordered_map< KeyType, ElementType * > Index
Used for looking up element belonging to id.
Definition: ObjectPool.h:656
boost::pool Elements
Pool for objects.
Definition: ObjectPool.h:672

◆ Clear()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
void Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::Clear ( )
inline

Clears the index and replaces the pool with a new one.

Warning
All objects after this call are invalid

Definition at line 578 of file ObjectPool.h.

579  {
580 
581  for(auto iter = Index.begin(); iter != Index.end(); ++iter) {
582 
583  iter->second->~ElementType();
584  Elements.free(iter->second);
585  }
586 
587  Index.clear();
588  Removed.clear();
589  Queued.clear();
590  Added.clear();
591  }
std::unordered_map< KeyType, ElementType * > Index
Used for looking up element belonging to id.
Definition: ObjectPool.h:656
std::vector< std::tuple< ElementType *, KeyType > > Queued
Definition: ObjectPool.h:666
boost::pool Elements
Pool for objects.
Definition: ObjectPool.h:672
std::vector< std::tuple< ElementType *, KeyType > > Removed
Definition: ObjectPool.h:661
std::vector< std::tuple< ElementType *, KeyType > > Added
Used for detecting created elements.
Definition: ObjectPool.h:669

◆ ClearAdded()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
void Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::ClearAdded ( )
inline

Clears the added list.

Definition at line 416 of file ObjectPool.h.

417  {
418 
419  Added.clear();
420  }
std::vector< std::tuple< ElementType *, KeyType > > Added
Used for detecting created elements.
Definition: ObjectPool.h:669

◆ ClearQueued()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
void Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::ClearQueued ( )
inline

Removes elements that are queued for destruction without calling release.

Definition at line 384 of file ObjectPool.h.

385  {
386 
387  for(auto iter = Queued.begin(); iter != Queued.end(); ++iter) {
388 
389  auto object = std::get<0>(*iter);
390  const auto id = std::get<1>(*iter);
391 
392  object->~ElementType();
393  Elements.free(object);
394  Removed.push_back(std::make_tuple(object, id));
395  RemoveFromIndex(id);
396  }
397 
398  Queued.clear();
399  }
bool RemoveFromIndex(KeyType id)
Removes an component from the index but doesn&#39;t destruct it.
Definition: ObjectPool.h:611
std::vector< std::tuple< ElementType *, KeyType > > Queued
Definition: ObjectPool.h:666
boost::pool Elements
Pool for objects.
Definition: ObjectPool.h:672
std::vector< std::tuple< ElementType *, KeyType > > Removed
Definition: ObjectPool.h:661

◆ ClearRemoved()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
void Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::ClearRemoved ( )
inline

Clears the removed list.

Definition at line 423 of file ObjectPool.h.

424  {
425 
426  Removed.clear();
427  }
std::vector< std::tuple< ElementType *, KeyType > > Removed
Definition: ObjectPool.h:661

◆ ConstructNew()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
template<typename... Args>
ElementType* Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::ConstructNew ( KeyType  forentity,
Args &&...  args 
)
inline

Constructs a new component of the held type for entity.

Exceptions
Exceptionwhen component has not been created

Definition at line 283 of file ObjectPool.h.

284  {
285 
286  if(Find(forentity))
287  throw Exception("Entity with ID already has object in pool of this type");
288 
289  // Get memory to hold the object //
290  void* memoryForObject = Elements.malloc();
291 
292  if(!memoryForObject)
293  throw Exception("Out of memory for element");
294 
295  // Construct the object //
296  ElementType* created;
297  try {
298  created = new(memoryForObject) ElementType(std::forward<Args>(args)...);
299  } catch(...) {
300 
301  Elements.free(memoryForObject);
302  throw;
303  }
304 
305  // Add to index for finding later //
306  Index.insert(std::make_pair(forentity, created));
307 
308  Added.push_back(std::make_tuple(created, forentity));
309 
310  return created;
311  }
std::unordered_map< KeyType, ElementType * > Index
Used for looking up element belonging to id.
Definition: ObjectPool.h:656
boost::pool Elements
Pool for objects.
Definition: ObjectPool.h:672
ElementType * Find(KeyType id) const
Definition: ObjectPool.h:496
std::vector< std::tuple< ElementType *, KeyType > > Added
Used for detecting created elements.
Definition: ObjectPool.h:669

◆ Destroy()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
void Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::Destroy ( KeyType  id,
bool  addtoremoved = true 
)
inline

Destroys a component based on id.

Definition at line 508 of file ObjectPool.h.

509  {
510 
511  auto object = Find(id);
512 
513  if(!object)
514  throw InvalidArgument("ID is not in index");
515 
516  _DestroyCommon(object, id, addtoremoved);
517  }
void _DestroyCommon(ElementType *object, KeyType id, bool addtoremoved)
Definition: ObjectPool.h:642
ElementType * Find(KeyType id) const
Definition: ObjectPool.h:496

◆ DestroyIfExists()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
bool Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::DestroyIfExists ( KeyType  id,
bool  addtoremoved = true 
)
inline

Destroys a component based on id if exists.

Definition at line 520 of file ObjectPool.h.

521  {
522  auto object = Find(id);
523 
524  if(!object)
525  return false;
526 
527  _DestroyCommon(object, id, addtoremoved);
528  return true;
529  }
void _DestroyCommon(ElementType *object, KeyType id, bool addtoremoved)
Definition: ObjectPool.h:642
ElementType * Find(KeyType id) const
Definition: ObjectPool.h:496

◆ Find()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
ElementType* Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::Find ( KeyType  id) const
inline
Returns
The found component or NULL

Definition at line 496 of file ObjectPool.h.

497  {
498 
499  auto iter = Index.find(id);
500 
501  if(iter == Index.end())
502  return nullptr;
503 
504  return iter->second;
505  }
std::unordered_map< KeyType, ElementType * > Index
Used for looking up element belonging to id.
Definition: ObjectPool.h:656

◆ GetAdded()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
auto& Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::GetAdded ( )
inline

Returns a reference to the vector of added elements.

Definition at line 409 of file ObjectPool.h.

410  {
411 
412  return Added;
413  }
std::vector< std::tuple< ElementType *, KeyType > > Added
Used for detecting created elements.
Definition: ObjectPool.h:669

◆ GetIndex()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
std::unordered_map<KeyType, ElementType*>& Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::GetIndex ( )
inline

Returns a direct access to Index.

Note
Do not change the returned index it is intended only for looping. Okay, you may change it but you have to be extremely careful

Definition at line 602 of file ObjectPool.h.

603  {
604 
605  return Index;
606  }
std::unordered_map< KeyType, ElementType * > Index
Used for looking up element belonging to id.
Definition: ObjectPool.h:656

◆ GetObjectCount()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
auto Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::GetObjectCount ( ) const
inline

Definition at line 593 of file ObjectPool.h.

594  {
595 
596  return Index.size();
597  }
std::unordered_map< KeyType, ElementType * > Index
Used for looking up element belonging to id.
Definition: ObjectPool.h:656

◆ GetRemoved()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
const auto& Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::GetRemoved ( ) const
inline

Returns a reference to the vector of removed elements.

Definition at line 402 of file ObjectPool.h.

403  {
404 
405  return Removed;
406  }
std::vector< std::tuple< ElementType *, KeyType > > Removed
Definition: ObjectPool.h:661

◆ HasElementsInAdded()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
bool Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::HasElementsInAdded ( ) const
inline

Returns true if there are objects in Added.

Definition at line 321 of file ObjectPool.h.

322  {
323 
324  return !Added.empty();
325  }
std::vector< std::tuple< ElementType *, KeyType > > Added
Used for detecting created elements.
Definition: ObjectPool.h:669

◆ HasElementsInQueued()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
bool Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::HasElementsInQueued ( ) const
inline

Returns true if there are objects in Queued.

Definition at line 328 of file ObjectPool.h.

329  {
330 
331  return !Queued.empty();
332  }
std::vector< std::tuple< ElementType *, KeyType > > Queued
Definition: ObjectPool.h:666

◆ HasElementsInRemoved()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
bool Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::HasElementsInRemoved ( ) const
inline

Returns true if there are objects in Removed.

Definition at line 314 of file ObjectPool.h.

315  {
316 
317  return !Removed.empty();
318  }
std::vector< std::tuple< ElementType *, KeyType > > Removed
Definition: ObjectPool.h:661

◆ QueueDestroy()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
void Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::QueueDestroy ( KeyType  id)
inline

Queues destruction of an element.

Exceptions
InvalidArgumentwhen key is not found (is already deleted)
Note
This has to be used for objects that require calling Release

Definition at line 534 of file ObjectPool.h.

535  {
536  auto end = Index.end();
537  for(auto iter = Index.begin(); iter != end; ++iter) {
538 
539  if(iter->first == id) {
540 
541  Queued.push_back(std::make_tuple(iter->second, id));
542 
543  RemoveFromAdded(id);
544 
545  return;
546  }
547  }
548 
549  throw InvalidArgument("ID is not in index");
550  }
void RemoveFromAdded(KeyType id)
Removes a specific id from the added list.
Definition: ObjectPool.h:482
std::unordered_map< KeyType, ElementType * > Index
Used for looking up element belonging to id.
Definition: ObjectPool.h:656
std::vector< std::tuple< ElementType *, KeyType > > Queued
Definition: ObjectPool.h:666

◆ Release()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
template<typename... Args>
void Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::Release ( KeyType  id,
bool  addtoremoved,
Args &&...  args 
)
inline

Calls Release on an object and then removes it from the pool.

Definition at line 358 of file ObjectPool.h.

359  {
360  auto* object = Find(id);
361 
362  if(!object)
363  throw NotFound("id not in pool");
364 
365  _ReleaseCommon(object, id, addtoremoved, std::forward<Args>(args)...);
366  }
ElementType * Find(KeyType id) const
Definition: ObjectPool.h:496
void _ReleaseCommon(ElementType *object, KeyType id, bool addtoremoved, Args &&... args)
Definition: ObjectPool.h:628

◆ ReleaseAllAndClear()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
template<typename... Args>
void Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::ReleaseAllAndClear ( Args &&...  args)
inline

Calls release on all objects and clears everything.

Definition at line 457 of file ObjectPool.h.

458  {
459 
460  for(auto iter = Index.begin(); iter != Index.end(); ++iter) {
461 
462  auto object = iter->second;
463 
464  object->Release(std::forward<Args>(args)...);
465 
466  object->~ElementType();
467  Elements.free(object);
468  }
469 
470  // Skip double free
471  Index.clear();
472 
473  // And then clear the rest of things
474  Clear();
475  }
void Clear()
Clears the index and replaces the pool with a new one.
Definition: ObjectPool.h:578
std::unordered_map< KeyType, ElementType * > Index
Used for looking up element belonging to id.
Definition: ObjectPool.h:656
boost::pool Elements
Pool for objects.
Definition: ObjectPool.h:672

◆ ReleaseIfExists()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
template<typename... Args>
bool Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::ReleaseIfExists ( KeyType  id,
bool  addtoremoved,
Args &&...  args 
)
inline

Calls Release on an object if it is in this pool and then removes it from the pool.

Definition at line 371 of file ObjectPool.h.

372  {
373  auto* object = Find(id);
374 
375  if(!object)
376  return false;
377 
378  _ReleaseCommon(object, id, addtoremoved, std::forward<Args>(args)...);
379  return true;
380  }
ElementType * Find(KeyType id) const
Definition: ObjectPool.h:496
void _ReleaseCommon(ElementType *object, KeyType id, bool addtoremoved, Args &&... args)
Definition: ObjectPool.h:628

◆ ReleaseQueued()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
template<typename... Args>
void Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::ReleaseQueued ( Args &&...  args)
inline

Calls Release with the specified arguments on elements that are queued for destruction.

Definition at line 337 of file ObjectPool.h.

338  {
339 
340  for(auto iter = Queued.begin(); iter != Queued.end(); ++iter) {
341 
342  auto object = std::get<0>(*iter);
343  const auto id = std::get<1>(*iter);
344 
345  object->Release(std::forward<Args>(args)...);
346 
347  object->~ElementType();
348  Elements.free(object);
349  Removed.push_back(std::make_tuple(object, id));
350  RemoveFromIndex(id);
351  }
352 
353  Queued.clear();
354  }
bool RemoveFromIndex(KeyType id)
Removes an component from the index but doesn&#39;t destruct it.
Definition: ObjectPool.h:611
std::vector< std::tuple< ElementType *, KeyType > > Queued
Definition: ObjectPool.h:666
boost::pool Elements
Pool for objects.
Definition: ObjectPool.h:672
std::vector< std::tuple< ElementType *, KeyType > > Removed
Definition: ObjectPool.h:661

◆ RemoveBasedOnKeyTupleList()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
template<typename Any >
void Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::RemoveBasedOnKeyTupleList ( const std::vector< std::tuple< Any, KeyType >> &  values,
bool  addtoremoved = false 
)
inline

Destroys without releasing elements based on ids in vector.

Parameters
addtoremovedIf true will add the elements to the Removed index for (possibly) using them to remove attached resources

Definition at line 433 of file ObjectPool.h.

435  {
436  for(auto iter = values.begin(); iter != values.end(); ++iter) {
437 
438  auto todelete = Index.find(std::get<1>(*iter));
439 
440  if(todelete == Index.end())
441  continue;
442 
443  todelete->second->~ElementType();
444  Elements.free(todelete->second);
445 
446  if(addtoremoved)
447  Removed.push_back(std::make_tuple(todelete->second, todelete->first));
448 
449  RemoveFromAdded(todelete->first);
450 
451  Index.erase(todelete);
452  }
453  }
void RemoveFromAdded(KeyType id)
Removes a specific id from the added list.
Definition: ObjectPool.h:482
std::unordered_map< KeyType, ElementType * > Index
Used for looking up element belonging to id.
Definition: ObjectPool.h:656
boost::pool Elements
Pool for objects.
Definition: ObjectPool.h:672
std::vector< std::tuple< ElementType *, KeyType > > Removed
Definition: ObjectPool.h:661

◆ RemoveFromAdded()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
void Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::RemoveFromAdded ( KeyType  id)
inline

Removes a specific id from the added list.

Used to remove entries that have been deleted before clearing the added ones

Todo:
Check if this gives better performance than noticing missing elements during node construction

Definition at line 482 of file ObjectPool.h.

483  {
484 
485  for(auto iter = Added.begin(); iter != Added.end(); ++iter) {
486 
487  if(std::get<1>(*iter) == id) {
488 
489  Added.erase(iter);
490  return;
491  }
492  }
493  }
std::vector< std::tuple< ElementType *, KeyType > > Added
Used for detecting created elements.
Definition: ObjectPool.h:669

◆ RemoveFromIndex()

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
bool Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::RemoveFromIndex ( KeyType  id)
inlineprotected

Removes an component from the index but doesn't destruct it.

Note
The component will only be deallocated once this object is destructed

Definition at line 611 of file ObjectPool.h.

612  {
613 
614  auto end = Index.end();
615  for(auto iter = Index.begin(); iter != end; ++iter) {
616 
617  if(iter->first == id) {
618 
619  Index.erase(iter);
620  return true;
621  }
622  }
623 
624  return false;
625  }
std::unordered_map< KeyType, ElementType * > Index
Used for looking up element belonging to id.
Definition: ObjectPool.h:656

Member Data Documentation

◆ Added

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
std::vector<std::tuple<ElementType*, KeyType> > Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::Added
protected

Used for detecting created elements.

Definition at line 669 of file ObjectPool.h.

◆ Elements

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
boost::pool Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::Elements
protected

Pool for objects.

Definition at line 672 of file ObjectPool.h.

◆ Index

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
std::unordered_map<KeyType, ElementType*> Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::Index
protected

Used for looking up element belonging to id.

Definition at line 656 of file ObjectPool.h.

◆ Queued

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
std::vector<std::tuple<ElementType*, KeyType> > Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::Queued
protected

Used for marking elements to be deleted later at a suitable time GameWorld uses this to control when components are deleted

Definition at line 666 of file ObjectPool.h.

◆ Removed

template<class ElementType, typename KeyType, bool AutoCleanupObjects = true>
std::vector<std::tuple<ElementType*, KeyType> > Leviathan::ObjectPoolTracked< ElementType, KeyType, AutoCleanupObjects >::Removed
protected

Used for detecting deleted elements later Can be used to unlink resources that have pointers to elements

Definition at line 661 of file ObjectPool.h.


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