|
CoriEngine
|
Creates a pool with disposable entities. More...
#include <DisposableEntityPool.hpp>
Public Member Functions | |
| DisposableEntityPool () | |
| void | Init (SceneHandle scene, std::function< Entity(SceneHandle &)> &&compositor, std::function< void(Entity &)> &&resetter) |
| Initializes the pool. | |
| std::expected< std::pair< Entity, uint16_t >, Core::PossibleErrors< Core::CoriError< uint16_t >, Core::CoriError<> > > | GetFreeEntity () |
| Finds a free entity in a pool (if any) in O(1) time. After retrieving the entity will be considered busy and will no longer be retrievable until you call FreeIndex on this entity index. | |
| std::expected< Entity, Core::PossibleErrors< Core::CoriError< uint16_t >, Core::CoriError<> > > | GetEntityAtIndex (const uint16_t index) |
| Retries the entity at a particular index, regardless if it's free or not. | |
| void | FreeIndex (const uint16_t slot) |
| Frees the entity at the given index, a resetter will be run for the entity at the specified index, the entity will be considered free after calling this. | |
| uint16_t | Capacity () const |
| Returns the total capacity of the pool, how many entities can it fit in total. | |
| uint16_t | Size () const |
| Returns the amount of free entities currently present in the pool. | |
| void | FreeAll () |
| Frees all indexes at once. | |
Creates a pool with disposable entities.
It is usefully when you need some entity to perform some task, but you don't want to keep track of it, so basically fire and forget style.
Without this class you would need to:
1: Create the entity
2: Add components that you need to it
3: Do the work you need to do
4: Delete the entity
This is far from optimal, DisposableEntityPool lets you create and define your entities once and then reuse them.
| PoolSize | Desired size of the pool. |
Definition at line 20 of file DisposableEntityPool.hpp.
|
inline |
Definition at line 22 of file DisposableEntityPool.hpp.
|
inlinenodiscard |
Returns the total capacity of the pool, how many entities can it fit in total.
Definition at line 102 of file DisposableEntityPool.hpp.
|
inline |
Frees all indexes at once.
Definition at line 117 of file DisposableEntityPool.hpp.

|
inline |
Frees the entity at the given index, a resetter will be run for the entity at the specified index, the entity will be considered free after calling this.
| slot | Slot or index to free. |
Definition at line 88 of file DisposableEntityPool.hpp.

|
inline |
Retries the entity at a particular index, regardless if it's free or not.
| index | Index to retrieve an entity from. |
Definition at line 72 of file DisposableEntityPool.hpp.
|
inline |
Finds a free entity in a pool (if any) in O(1) time. After retrieving the entity will be considered busy and will no longer be retrievable until you call FreeIndex on this entity index.
Definition at line 49 of file DisposableEntityPool.hpp.

|
inline |
Initializes the pool.
| scene | Scene that pool will live in. |
| compositor | Entity compositor, you need to define how to create the entity here, you're given scene handle and expected to return Entity, this functor will be used to create the entities. |
| resetter | Lets you define how to clean entities after they've been used, you're given the entity that is being freed, wll be run for every entity that you're freeing with FreeIndex. |
Definition at line 33 of file DisposableEntityPool.hpp.

|
inlinenodiscard |
Returns the amount of free entities currently present in the pool.
Definition at line 110 of file DisposableEntityPool.hpp.