SpawnManager.ixx File
Manager for processing spawn and despawn commands from pools. More...
Included Headers
#include <cassert>
#include <memory>
#include <span>
#include <unordered_map>
#include <vector>
#include <helios.engine.core.data.SpawnProfileId>
#include <helios.engine.modules.physics.collision.components.AabbColliderComponent>
#include <helios.engine.runtime.pooling.GameObjectPoolManager>
#include <helios.engine.runtime.spawn.SpawnCommandHandler>
#include <helios.engine.runtime.world.UpdateContext>
#include <helios.engine.runtime.world.GameWorld>
#include <helios.engine.runtime.world.Manager>
#include <helios.engine.mechanics.spawn.components.SpawnedByProfileComponent>
#include <helios.engine.runtime.spawn.SpawnPlanCursor>
#include <helios.engine.modules.physics.collision.Bounds>
#include <helios.engine.modules.spatial.transform.components.TranslationStateComponent>
#include <helios.engine.runtime.spawn.commands.SpawnCommand>
#include <helios.engine.runtime.spawn.SpawnContext>
#include <helios.engine.runtime.spawn.SpawnProfile>
#include <helios.engine.runtime.spawn.events.SpawnPlanCommandExecutedEvent>
#include <helios.engine.mechanics.spawn.components.EmittedByComponent>
#include <helios.math>
#include <helios.engine.runtime.spawn.commands.ScheduledSpawnPlanCommand>
#include <helios.engine.runtime.spawn.commands.DespawnCommand>
#include <helios.engine.ecs.GameObject>
#include <helios.engine.modules.spatial.transform.components.ScaleStateComponent>
#include <helios.engine.modules.rendering.model.components.ModelAabbComponent>
#include <helios.engine.modules.spatial.transform.components.RotationStateComponent>
#include <helios.engine.modules.scene.components.SceneNodeComponent>
Namespaces Index
| namespace | helios |
| namespace | engine |
|
Main engine module aggregating core infrastructure and game systems. More... | |
| namespace | runtime |
|
Runtime infrastructure for game execution and lifecycle orchestration. More... | |
| namespace | spawn |
|
Entity spawning infrastructure for the helios engine. More... | |
Classes Index
| class | SpawnManager |
|
Manager for processing spawn and despawn commands. More... | |
Description
Manager for processing spawn and despawn commands from pools.
File Listing
The file content with the documentation metadata removed is:
47export namespace helios::engine::runtime::spawn {
96 class SpawnManager : public helios::engine::runtime::world::Manager,
112 std::vector<helios::engine::runtime::spawn::commands::ScheduledSpawnPlanCommand> scheduledSpawnPlanCommands_;
117 helios::engine::runtime::pooling::GameObjectPoolManager* gameObjectPoolManager_ = nullptr;
140 void ensureBounds(helios::engine::ecs::GameObject go, helios::math::aabbf& bounds) {
142 const auto* mab = go.get<helios::engine::modules::rendering::model::components::ModelAabbComponent>();
143 const auto* sca = go.get<helios::engine::modules::spatial::transform::components::ScaleStateComponent>();
144 auto* rsc = go.get<helios::engine::modules::spatial::transform::components::RotationStateComponent>();
145 const auto* scn = go.get<helios::engine::modules::scene::components::SceneNodeComponent>();
146 const auto* tsc = go.get<helios::engine::modules::spatial::transform::components::TranslationStateComponent>();
167 std::span<helios::engine::runtime::spawn::commands::ScheduledSpawnPlanCommand> commands,
168 helios::engine::runtime::world::GameWorld& gameWorld,
169 helios::engine::runtime::world::UpdateContext& updateContext
172 for (auto& scheduledSpawnPlanCommand: commands) {
183 const auto spawnProfile = it->second.get();
185 const auto gameObjectPoolId = spawnProfile->gameObjectPoolId;
206 auto* tsc = go->get<helios::engine::modules::spatial::transform::components::TranslationStateComponent>();
208 auto* sbp = go->get<helios::engine::mechanics::spawn::components::SpawnedByProfileComponent>();
211 auto* aabb = go->get<helios::engine::modules::physics::collision::components::AabbColliderComponent>();
214 auto spawnCursor = helios::engine::runtime::spawn::SpawnPlanCursor{spawnCount, i};
218 auto* ebc = go->get<helios::engine::mechanics::spawn::components::EmittedByComponent>();
228 const auto position = spawnProfile->spawnPlacer->getPosition(
229 go->entityHandle(),
231 gameWorld_->level().bounds(),
239 assert(spawnProfile->spawnInitializer && "Unexpected missing spawn initializer");
241 spawnProfile->spawnInitializer->initialize(*go, spawnCursor, spawnContext);
243 go->setActive(true);
246 updateContext.pushFrame<helios::engine::runtime::spawn::events::SpawnPlanCommandExecutedEvent>(
261 std::span<helios::engine::runtime::spawn::commands::SpawnCommand> commands,
262 helios::engine::runtime::world::GameWorld& gameWorld,
263 helios::engine::runtime::world::UpdateContext& updateContext) {
265 for (auto& spawnCommand: commands) {
272 const auto spawnProfile = it->second.get();
273 const auto gameObjectPoolId = spawnProfile->gameObjectPoolId;
285 auto* tsc = go->get<helios::engine::modules::spatial::transform::components::TranslationStateComponent>();
286 auto* sbp = go->get<helios::engine::mechanics::spawn::components::SpawnedByProfileComponent>();
289 auto* aabb = go->get<helios::engine::modules::physics::collision::components::AabbColliderComponent>();
293 auto* ebc = go->get<helios::engine::mechanics::spawn::components::EmittedByComponent>();
303 const auto position = spawnProfile->spawnPlacer->getPosition(
304 go->entityHandle(),
306 gameWorld_->level().bounds(),
315 assert(spawnProfile->spawnInitializer && "Unexpected missing spawn initializer");
317 spawnProfile->spawnInitializer->initialize(*go, {1, 1}, spawnContext);
320 go->setActive(true);
333 std::span<helios::engine::runtime::spawn::commands::DespawnCommand> commands,
334 helios::engine::runtime::world::GameWorld& gameWorld,
335 helios::engine::runtime::world::UpdateContext& updateContext) {
337 for (auto& despawnCommand : commands) {
342 const auto spawnProfile = it->second.get();
343 auto gameObjectPoolId = spawnProfile->gameObjectPoolId;
356 SpawnManager() = default;
365 bool submit(const helios::engine::runtime::spawn::commands::SpawnCommand& command) noexcept override {
377 bool submit(const helios::engine::runtime::spawn::commands::DespawnCommand& command) noexcept override {
391 const helios::engine::runtime::spawn::commands::ScheduledSpawnPlanCommand& scheduledSpawnPlanCommand
404 helios::engine::runtime::world::GameWorld& gameWorld,
405 helios::engine::runtime::world::UpdateContext& updateContext
439 const helios::engine::core::data::SpawnProfileId& spawnProfileId,
440 std::unique_ptr<const helios::engine::runtime::spawn::SpawnProfile> spawnProfile) {
444 spawnProfiles_[spawnProfileId] = std::move(spawnProfile);
456 [[nodiscard]] const helios::engine::runtime::spawn::SpawnProfile* spawnProfile(
457 const helios::engine::core::data::SpawnProfileId& spawnProfileId) const {
475 void init(helios::engine::runtime::world::GameWorld& gameWorld) noexcept override {
477 gameObjectPoolManager_ = gameWorld.getManager<helios::engine::runtime::pooling::GameObjectPoolManager>();
480 gameWorld.registerSpawnCommandHandler(spawnProfileId, *this);
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.