EntityPoolManager Class Template
High-level manager for Entity pooling operations. More...
Declaration
Public Member Typedefs Index
template <typename TEntity> | |
| using | EngineRoleTag = helios::engine::runtime::world::tags::ManagerRole |
Private Member Typedefs Index
template <typename TEntity> | |
| using | Handle_type = typename TEntity::Handle_type |
template <typename TEntity> | |
| using | Entity_type = TEntity |
Public Constructors Index
template <typename TEntity> | |
| EntityPoolManager (helios::engine::runtime::world::EngineWorld &engineWorld) | |
Public Member Functions Index
template <typename TEntity> | |
| EntityPoolManager & | addPoolConfig (std::unique_ptr< EntityPoolConfig > entityPoolConfig) |
|
Registers a pool configuration for later initialization. More... | |
template <typename TEntity> | |
| helios::engine::runtime::pooling::EntityPoolSnapshot | poolSnapshot (const helios::engine::runtime::pooling::types::EntityPoolId entityPoolId) const |
|
Returns a snapshot of the pool's current state. More... | |
template <typename TEntity> | |
| auto | release (const helios::engine::runtime::pooling::types::EntityPoolId entityPoolId, const Handle_type &entityHandle) -> std::optional< TEntity > |
|
Releases a Entity back to its pool. More... | |
template <typename TEntity> | |
| auto | acquire (const helios::engine::runtime::pooling::types::EntityPoolId entityPoolId) -> std::optional< TEntity > |
|
Acquires an inactive Entity from the pool. More... | |
template <typename TEntity> | |
| void | init (CommandHandlerRegistry &commandHandlerRegistry) |
|
Initializes all registered pools. More... | |
template <typename TEntity> | |
| void | flush (helios::engine::runtime::world::UpdateContext &update_context) noexcept |
|
Manager flush callback (currently unused). More... | |
template <typename TEntity> | |
| auto | pool (const helios::engine::runtime::pooling::types::EntityPoolId entityPoolId) const -> EntityPool< Handle_type > * |
|
Retrieves a pool by its ID. More... | |
template <typename TEntity> | |
| void | reset () |
|
Resets all pools by releasing all active Entities. More... | |
template <typename TEntity> | |
| void | reset (const types::EntityPoolId poolId) |
|
Reset the pool with the specified poolId. More... | |
Private Member Functions Index
template <typename TEntity> | |
| void | fillPool (const helios::engine::runtime::pooling::types::EntityPoolId entityPoolId, TEntity entityPrefab) |
|
Populates a pool with cloned prefab instances and locks it. More... | |
Private Member Attributes Index
template <typename TEntity> | |
| helios::engine::runtime::pooling::EntityPoolRegistry< Handle_type > | pools_ {} |
|
Registry of EntityPools for entity recycling. More... | |
template <typename TEntity> | |
| helios::engine::runtime::world::EngineWorld * | engineWorld_ = nullptr |
|
Non-owning pointer to the associated GameWorld. More... | |
template <typename TEntity> | |
| std::unordered_map< helios::engine::runtime::pooling::types::EntityPoolId, std::unique_ptr< EntityPoolConfig > > | poolConfigs_ |
|
Pending pool configurations awaiting initialization. More... | |
Description
High-level manager for Entity pooling operations.
EntityPoolManager provides a unified interface for managing multiple EntityPools. It handles pool configuration, initialization, and the acquire/release lifecycle of pooled Entities.
The manager integrates with the GameWorld to clone prefabs during pool initialization and to look up Entities by their EntityHandle during acquire/release operations.
Definition at line 111 of file EntityPoolManager.ixx.
Public Member Typedefs
EngineRoleTag
|
Definition at line 184 of file EntityPoolManager.ixx.
Private Member Typedefs
Entity_type
|
Definition at line 114 of file EntityPoolManager.ixx.
Handle_type
|
Definition at line 113 of file EntityPoolManager.ixx.
Public Constructors
EntityPoolManager()
| inline explicit |
Definition at line 187 of file EntityPoolManager.ixx.
Public Member Functions
acquire()
| inline |
Acquires an inactive Entity from the pool.
Retrieves the next available inactive entity and calls onAcquire() to trigger component initialization hooks. The caller is responsible for activating the entity via setActive(true).
If an acquired entity is no longer valid in the GameWorld (stale handle), it is removed from the pool and the next available entity is tried.
- Parameters
-
entityPoolId The pool to acquire from.
- Returns
Optional containing the acquired Entity if available, std::nullopt if the pool is exhausted.
Definition at line 278 of file EntityPoolManager.ixx.
References helios::engine::runtime::world::EngineWorld::find, helios::engine::runtime::pooling::EntityPoolManager< TEntity >::pool and helios::engine::runtime::pooling::registerComponents.
addPoolConfig()
| inline |
Registers a pool configuration for later initialization.
The configuration specifies the pool ID, capacity, and prefab to use for cloning. Configurations are processed during init().
- Parameters
-
entityPoolConfig The pool configuration to register.
- Returns
Reference to this manager for method chaining.
- Exceptions
-
std::runtime_error If a pool with the same ID is already registered.
Definition at line 201 of file EntityPoolManager.ixx.
Reference helios::engine::runtime::pooling::registerComponents.
flush()
| inline noexcept |
Manager flush callback (currently unused).
Reserved for future use. May be used to process deferred release requests or pool maintenance operations.
- Parameters
-
gameWorld The associated GameWorld.
update_context The current frame's update context.
Definition at line 344 of file EntityPoolManager.ixx.
init()
| inline |
Initializes all registered pools.
Creates EntityPool instances from the pending configurations and populates them by cloning the specified prefabs into the GameWorld.
- Parameters
-
gameWorld The GameWorld to associate with this manager.
Definition at line 312 of file EntityPoolManager.ixx.
References helios::engine::runtime::pooling::EntityPoolRegistry< THandle >::addPool, helios::engine::runtime::pooling::EntityPoolManager< TEntity >::pool, helios::engine::runtime::pooling::registerComponents and helios::engine::runtime::world::EngineWorld::view.
pool()
| inline |
Retrieves a pool by its ID.
- Parameters
-
entityPoolId The pool ID to look up.
- Returns
Pointer to the EntityPool.
- Precondition
The pool must be registered with this manager.
Definition at line 359 of file EntityPoolManager.ixx.
References helios::engine::runtime::pooling::EntityPoolRegistry< THandle >::has, helios::engine::runtime::pooling::EntityPoolRegistry< THandle >::pool and helios::engine::runtime::pooling::registerComponents.
Referenced by helios::engine::runtime::pooling::EntityPoolManager< TEntity >::acquire, helios::engine::runtime::pooling::EntityPoolManager< TEntity >::init, helios::engine::runtime::pooling::EntityPoolManager< TEntity >::poolSnapshot, helios::engine::runtime::pooling::EntityPoolManager< TEntity >::release and helios::engine::runtime::pooling::EntityPoolManager< TEntity >::reset.
poolSnapshot()
| inline |
Returns a snapshot of the pool's current state.
Provides the active and inactive counts for monitoring and debugging purposes.
- Parameters
-
entityPoolId The pool to query.
- Returns
A EntityPoolSnapshot containing active and inactive counts.
Definition at line 222 of file EntityPoolManager.ixx.
References helios::engine::runtime::pooling::EntityPoolManager< TEntity >::pool and helios::engine::runtime::pooling::registerComponents.
release()
| inline |
Releases a Entity back to its pool.
Marks the entity as inactive in both the pool and the GameWorld. Calls onRelease() on the Entity to trigger component cleanup hooks, then deactivates it.
- Parameters
-
entityPoolId The pool that owns this entity.
entityHandle The EntityHandle of the entity to release.
- Returns
Optional containing the released Entity if found, std::nullopt if the entity was not found in the GameWorld.
Definition at line 245 of file EntityPoolManager.ixx.
References helios::engine::runtime::world::EngineWorld::find, helios::engine::runtime::pooling::EntityPoolManager< TEntity >::pool and helios::engine::runtime::pooling::registerComponents.
Referenced by helios::engine::runtime::pooling::EntityPoolManager< TEntity >::reset.
reset()
| inline |
Resets all pools by releasing all active Entities.
Iterates through all registered pools and releases every active entity back to its pool. This effectively returns all pooled objects to their inactive state without destroying them.
Useful for level transitions or game restarts where all pooled objects should be recycled.
- See Also
Definition at line 378 of file EntityPoolManager.ixx.
References helios::engine::runtime::pooling::EntityPoolRegistry< THandle >::pools, helios::engine::runtime::pooling::registerComponents and helios::engine::runtime::pooling::EntityPoolManager< TEntity >::reset.
Referenced by helios::engine::runtime::pooling::EntityPoolManager< TEntity >::reset.
reset()
| inline |
Reset the pool with the specified poolId.
Releases every active entity back to its pool specified by poolId. This effectively returns all pooled objects to their inactive state without destroying them.
- Parameters
-
poolId The ID of the pool to reset.
Definition at line 393 of file EntityPoolManager.ixx.
References helios::engine::runtime::pooling::EntityPoolManager< TEntity >::pool, helios::engine::runtime::pooling::registerComponents and helios::engine::runtime::pooling::EntityPoolManager< TEntity >::release.
Private Member Functions
fillPool()
| inline |
Populates a pool with cloned prefab instances and locks it.
Clones the prefab Entity until the pool reaches its configured capacity. Each clone is:
- Added to the GameWorld
- Immediately deactivated (setActive(false))
- Prepared for pooling (onRelease())
- Registered as inactive in the pool
After all clones are created, the pool is locked via lock(). Locking finalizes the sparse array sizing based on the min/max EntityIds and enables O(1) acquire/release operations. Once locked, no new EntityHandles can be added to the pool.
- Parameters
-
entityPoolId The pool to fill.
entityPrefab The prefab to clone.
- Postcondition
The pool is locked and ready for acquire/release operations.
Definition at line 162 of file EntityPoolManager.ixx.
Private Member Attributes
engineWorld_
|
Non-owning pointer to the associated GameWorld.
Set during init(). Used for cloning prefabs and looking up Entities by their EntityHandle.
Definition at line 130 of file EntityPoolManager.ixx.
poolConfigs_
|
Pending pool configurations awaiting initialization.
Configurations are consumed during init() to create and populate the actual pools.
Definition at line 140 of file EntityPoolManager.ixx.
pools_
|
Registry of EntityPools for entity recycling.
Pools enable efficient reuse of Entities without repeated allocation/deallocation. Each pool is identified by a EntityPoolId.
Definition at line 122 of file EntityPoolManager.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.