EntityPoolManager.ixx File
Manager for Entity pooling and lifecycle management. More...
Included Headers
#include <cassert>
#include <memory>
#include <optional>
#include <stdexcept>
#include <unordered_map>
#include <cstddef>
#include <helios.engine.runtime.world.tags>
#include <helios.engine.core.types>
#include <helios.ecs.types.EntityHandle>
#include <helios.engine.runtime.pooling.components.PrefabIdComponent>
#include <helios.engine.runtime.pooling.EntityPoolRegistry>
#include <helios.engine.runtime.pooling.EntityPoolSnapshot>
#include <helios.engine.runtime.pooling.EntityPool>
#include <helios.engine.runtime.messaging.command.CommandHandlerRegistry>
#include <helios.engine.runtime.pooling.EntityPoolConfig>
#include <helios.engine.runtime.world.EngineWorld>
#include <helios.engine.runtime.world.UpdateContext>
#include <helios.engine.runtime.pooling.types.EntityPoolId>
#include <helios.ecs.Entity>
Namespaces Index
| namespace | helios |
| namespace | engine |
| namespace | runtime |
| namespace | pooling |
Classes Index
| class | EntityPoolManager<TEntity> |
|
High-level manager for Entity pooling operations. More... | |
Description
Manager for Entity pooling and lifecycle management.
File Listing
The file content with the documentation metadata removed is:
38using namespace helios::engine::runtime::messaging::command;
39export namespace helios::engine::runtime::pooling {
111 class EntityPoolManager {
114 using Entity_type = TEntity;
130 helios::engine::runtime::world::EngineWorld* engineWorld_ = nullptr;
163 const helios::engine::runtime::pooling::types::EntityPoolId entityPoolId,
164 TEntity entityPrefab
166 Handle_type entityHandle{};
168 auto* entityPool = pool(entityPoolId);
170 const size_t used = entityPool->activeCount() + entityPool->inactiveCount();
171 const size_t space = used < entityPool->size() ? entityPool->size() - used : 0;
174 Entity_type go = engineWorld_->clone(entityPrefab.handle());
175 go.setActive(false);
176 go.onRelease();
177 entityPool->addInactive(go.handle());
180 entityPool->lock();
187 explicit EntityPoolManager(helios::engine::runtime::world::EngineWorld& engineWorld) : engineWorld_(&engineWorld) {}
201 EntityPoolManager& addPoolConfig(std::unique_ptr<EntityPoolConfig> entityPoolConfig) {
203 if (poolConfigs_.contains(entityPoolConfig->entityPoolId)) {
207 poolConfigs_[entityPoolConfig->entityPoolId] = std::move(entityPoolConfig);
223 const helios::engine::runtime::pooling::types::EntityPoolId entityPoolId
225 auto* entityPool = pool(entityPoolId);
228 entityPool->activeCount(), entityPool->inactiveCount()
246 const helios::engine::runtime::pooling::types::EntityPoolId entityPoolId,
247 const Handle_type& entityHandle
249 auto* entityPool = pool(entityPoolId);
251 auto worldGo = engineWorld_->find<Handle_type>(entityHandle);
253 if (worldGo) {
254 if (entityPool->release(entityHandle)) {
255 worldGo->onRelease();
256 worldGo->setActive(false);
260 return worldGo;
279 const helios::engine::runtime::pooling::types::EntityPoolId entityPoolId
281 Handle_type entityHandle{};
283 auto* entityPool = pool(entityPoolId);
285 while (entityPool->acquire(entityHandle)) {
287 auto worldGo = engineWorld_->find(entityHandle);
289 if (worldGo) {
290 worldGo->onAcquire();
291 return worldGo;
297 entityPool->releaseAndRemove(entityHandle);
312 void init(CommandHandlerRegistry& commandHandlerRegistry) {
315 for (const auto& [entityPoolId, poolConfig] : poolConfigs_) {
317 auto pool = std::make_unique<helios::engine::runtime::pooling::EntityPool<Handle_type>>(
318 poolConfig->amount);
324 helios::engine::runtime::pooling::components::PrefabIdComponent<Handle_type>>().whereEnabled()) {
325 if (pic->prefabId() == poolConfig->prefabId) {
326 fillPool(entityPoolId, entity);
360 const helios::engine::runtime::pooling::types::EntityPoolId entityPoolId
363 return pools_.pool(entityPoolId);
393 void reset(const types::EntityPoolId poolId) {
397 auto activeSpan = poolPtr->activeEntities();
398 auto toRelease = std::vector(activeSpan.begin(), activeSpan.end());
399 for (auto entityHandle : toRelease) {
400 release(poolId, entityHandle);
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.