Skip to main content

SpawnManager Class

Manager for processing spawn and despawn requests. More...

Declaration

class helios::engine::mechanics::spawn::manager::SpawnManager { ... }

Base classes

classManager

Abstract base class for managers that process deferred operations. More...

classPoolRequestHandler

Interface for handlers that process spawn and despawn requests for a pool. More...

Public Constructors Index

SpawnManager (helios::engine::core::data::GameObjectPoolId gameObjectPoolId, std::unique_ptr< helios::engine::runtime::factory::GameObjectFactory > gameObjectFactory)

Constructs a SpawnManager for a specific pool. More...

Public Member Functions Index

boolsubmit (const helios::engine::mechanics::spawn::requests::SpawnRequest request) noexcept override

Submits a spawn request for deferred processing. More...

boolsubmit (const helios::engine::mechanics::spawn::requests::DespawnRequest request) noexcept override

Submits a despawn request for deferred processing. More...

voidflush (helios::engine::runtime::world::GameWorld &gameWorld, helios::engine::runtime::world::UpdateContext &updateContext) noexcept override

Flushes pending requests, processing despawns then spawns. More...

voidinit (helios::engine::runtime::world::GameWorld &gameWorld) noexcept

Initializes the manager, populating the pool. More...

Private Member Functions Index

voidprepareSpawn (const helios::engine::mechanics::spawn::requests::SpawnRequest &spawnRequest) const noexcept

Prepares a spawn request before execution. More...

voidspawnObjects (std::span< helios::engine::mechanics::spawn::requests::SpawnRequest > requests, helios::engine::runtime::world::GameWorld &gameWorld, helios::engine::runtime::world::UpdateContext &updateContext)

Processes spawn requests, acquiring and initializing objects. More...

voiddespawnObjects (std::span< helios::engine::mechanics::spawn::requests::DespawnRequest > requests, helios::engine::runtime::world::GameWorld &gameWorld, helios::engine::runtime::world::UpdateContext &updateContext)

Processes despawn requests, releasing objects back to pools. More...

Private Member Attributes Index

helios::engine::core::data::GameObjectPoolIdgameObjectPoolId_

The pool ID this manager is responsible for. More...

helios::engine::runtime::pooling::GameObjectPool *gameObjectPool_

Pointer to the managed pool. More...

std::vector< helios::engine::mechanics::spawn::requests::SpawnRequest >spawnRequests_

Queue of pending spawn requests. More...

std::vector< helios::engine::mechanics::spawn::requests::DespawnRequest >despawnRequests_

Queue of pending despawn requests. More...

std::shared_ptr< helios::engine::runtime::factory::GameObjectFactory >gameObjectFactory_

Factory for creating and populating pool objects. More...

helios::engine::runtime::pooling::GameObjectPoolFacadegameObjectPoolFacade_ {}

Facade for pool acquire/release operations. More...

Description

Manager for processing spawn and despawn requests.

SpawnManager is a Manager that handles the lifecycle of pooled GameObjects. It receives SpawnRequest and DespawnRequest instances, queues them, and processes them during the manager flush phase.

During flush: 1. Despawn requests are processed first, returning entities to their pools. 2. Spawn requests are then processed, acquiring entities and initializing them.

The manager uses a GameObjectFactory to populate the pool initially and a GameObjectPoolFacade for acquire/release operations.

SpawnManager also implements PoolRequestHandler, allowing it to be registered with a GameWorld for a specific pool ID.

See Also

SpawnRequest

See Also

DespawnRequest

See Also

GameObjectFactory

See Also

PoolRequestHandler

Definition at line 65 of file SpawnManager.ixx.

Public Constructors

SpawnManager()

helios::engine::mechanics::spawn::manager::SpawnManager::SpawnManager (helios::engine::core::data::GameObjectPoolId gameObjectPoolId, std::unique_ptr< helios::engine::runtime::factory::GameObjectFactory > gameObjectFactory)
inline explicit

Constructs a SpawnManager for a specific pool.

Parameters
gameObjectPoolId

The ID of the pool to manage.

gameObjectFactory

Factory for populating the pool with objects.

Definition at line 176 of file SpawnManager.ixx.

176 explicit SpawnManager(
178 std::unique_ptr<helios::engine::runtime::factory::GameObjectFactory> gameObjectFactory
179 ) :
180 gameObjectPoolId_(gameObjectPoolId),
181 gameObjectFactory_(std::move(gameObjectFactory))
182 {}

Public Member Functions

flush()

void helios::engine::mechanics::spawn::manager::SpawnManager::flush (helios::engine::runtime::world::GameWorld & gameWorld, helios::engine::runtime::world::UpdateContext & updateContext)
inline noexcept virtual

Flushes pending requests, processing despawns then spawns.

Parameters
gameWorld

The game world.

updateContext

The current update context.

Definition at line 214 of file SpawnManager.ixx.

214 void flush(
217 ) noexcept override {
218 if (despawnRequests_.size() > 0) {
219 despawnObjects(despawnRequests_, gameWorld, updateContext);
220 despawnRequests_.clear();
221 }
222
223 if (spawnRequests_.size() > 0) {
224 spawnObjects(spawnRequests_, gameWorld, updateContext);
225 spawnRequests_.clear();
226 }
227 };

init()

void helios::engine::mechanics::spawn::manager::SpawnManager::init (helios::engine::runtime::world::GameWorld & gameWorld)
inline noexcept virtual

Initializes the manager, populating the pool.

Retrieves the pool from the GameWorld, uses the factory to fill it with objects, and registers this manager as the pool's request handler.

Parameters
gameWorld

The game world containing the pool.

Definition at line 238 of file SpawnManager.ixx.

239 gameObjectPool_ = gameWorld.pool(gameObjectPoolId_);
240 assert(gameObjectPool_ != nullptr && "Unexpected nullptr for GameObjectPool");
241 gameObjectFactory_->fillPool(gameWorld, *gameObjectPool_);
242
243 gameWorld.registerPoolRequestHandler(gameObjectPoolId_, *this);
244 }

References helios::engine::runtime::world::GameWorld::pool and helios::engine::runtime::world::GameWorld::registerPoolRequestHandler.

submit()

bool helios::engine::mechanics::spawn::manager::SpawnManager::submit (const helios::engine::mechanics::spawn::requests::SpawnRequest request)
inline noexcept virtual

Submits a spawn request for deferred processing.

Parameters
request

The spawn request to queue.

Returns

Always returns true.

Definition at line 191 of file SpawnManager.ixx.

192 spawnRequests_.push_back(request);
193 return true;
194 }

submit()

bool helios::engine::mechanics::spawn::manager::SpawnManager::submit (const helios::engine::mechanics::spawn::requests::DespawnRequest request)
inline noexcept virtual

Submits a despawn request for deferred processing.

Parameters
request

The despawn request to queue.

Returns

Always returns true.

Definition at line 203 of file SpawnManager.ixx.

204 despawnRequests_.push_back(request);
205 return true;
206 }

Private Member Functions

despawnObjects()

void helios::engine::mechanics::spawn::manager::SpawnManager::despawnObjects (std::span< helios::engine::mechanics::spawn::requests::DespawnRequest > requests, helios::engine::runtime::world::GameWorld & gameWorld, helios::engine::runtime::world::UpdateContext & updateContext)
inline

Processes despawn requests, releasing objects back to pools.

Parameters
requests

Span of despawn requests to process.

gameWorld

The game world.

updateContext

The current update context.

Definition at line 155 of file SpawnManager.ixx.

155 void despawnObjects(
156 std::span<helios::engine::mechanics::spawn::requests::DespawnRequest> requests,
159
160 for (auto& despawnRequest : requests) {
161 if (despawnRequest.gameObjectPoolId.has_value()) {
162 auto gameObjectPool = gameWorld.pool(despawnRequest.gameObjectPoolId.value());
163 gameObjectPoolFacade_.release(gameWorld, *gameObjectPool, despawnRequest.entityId);
164 }
165 }
166 }

prepareSpawn()

void helios::engine::mechanics::spawn::manager::SpawnManager::prepareSpawn (const helios::engine::mechanics::spawn::requests::SpawnRequest & spawnRequest)
inline noexcept

Prepares a spawn request before execution.

Parameters
spawnRequest

The request to prepare.

Definition at line 102 of file SpawnManager.ixx.

102 void prepareSpawn(
104 ) const noexcept {
105
106 }

spawnObjects()

void helios::engine::mechanics::spawn::manager::SpawnManager::spawnObjects (std::span< helios::engine::mechanics::spawn::requests::SpawnRequest > requests, helios::engine::runtime::world::GameWorld & gameWorld, helios::engine::runtime::world::UpdateContext & updateContext)
inline

Processes spawn requests, acquiring and initializing objects.

Parameters
requests

Span of spawn requests to process.

gameWorld

The game world.

updateContext

The current update context.

Definition at line 115 of file SpawnManager.ixx.

115 void spawnObjects(
116 std::span<helios::engine::mechanics::spawn::requests::SpawnRequest> requests,
119
120 for (auto& spawnRequest : requests) {
121 auto* gameObject = gameObjectPoolFacade_.acquire(gameWorld, *gameObjectPool_);
122 if (!gameObject) {
123 return;
124 }
125
126 static auto rGen = helios::util::Random(12345);
127
131
132 auto& levelBounds = gameWorld.level().bounds();
133
134 float xPos = rGen.randomFloat(levelBounds.min()[0], levelBounds.max()[0]);
135 float yPos = rGen.randomFloat(levelBounds.min()[1], levelBounds.max()[1]);
136
137 auto position = helios::math::vec3f{xPos, yPos, 0.0f};
138 auto dir = helios::math::vec2f{rGen.randomFloat(-1.0f, 1.0f), rGen.randomFloat(-1.0f, 1.0f)};
139
140 dc->setDirection(dir.normalize().toVec3());
141 mc->move(dc->direction(), 1.0f);
142 tsc->setTranslation(position);
143
144 gameObject->setActive(true);
145 }
146 }

Private Member Attributes

despawnRequests_

std::vector<helios::engine::mechanics::spawn::requests::DespawnRequest> helios::engine::mechanics::spawn::manager::SpawnManager::despawnRequests_

Queue of pending despawn requests.

Definition at line 85 of file SpawnManager.ixx.

85 std::vector<helios::engine::mechanics::spawn::requests::DespawnRequest> despawnRequests_;

gameObjectFactory_

std::shared_ptr<helios::engine::runtime::factory::GameObjectFactory> helios::engine::mechanics::spawn::manager::SpawnManager::gameObjectFactory_

Factory for creating and populating pool objects.

Definition at line 90 of file SpawnManager.ixx.

90 std::shared_ptr<helios::engine::runtime::factory::GameObjectFactory> gameObjectFactory_;

gameObjectPool_

helios::engine::runtime::pooling::GameObjectPool* helios::engine::mechanics::spawn::manager::SpawnManager::gameObjectPool_

Pointer to the managed pool.

Definition at line 75 of file SpawnManager.ixx.

gameObjectPoolFacade_

helios::engine::runtime::pooling::GameObjectPoolFacade helios::engine::mechanics::spawn::manager::SpawnManager::gameObjectPoolFacade_ {}

Facade for pool acquire/release operations.

Definition at line 95 of file SpawnManager.ixx.

gameObjectPoolId_

helios::engine::core::data::GameObjectPoolId helios::engine::mechanics::spawn::manager::SpawnManager::gameObjectPoolId_

The pool ID this manager is responsible for.

Definition at line 70 of file SpawnManager.ixx.

spawnRequests_

std::vector<helios::engine::mechanics::spawn::requests::SpawnRequest> helios::engine::mechanics::spawn::manager::SpawnManager::spawnRequests_

Queue of pending spawn requests.

Definition at line 80 of file SpawnManager.ixx.

80 std::vector<helios::engine::mechanics::spawn::requests::SpawnRequest> spawnRequests_;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.