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.math>
#include <helios.engine.modules.physics.collision.components.AabbColliderComponent>
#include <helios.engine.ecs.GameObject>
#include <helios.engine.runtime.pooling.GameObjectPoolManager>
#include <helios.engine.runtime.world.GameWorld>
#include <helios.engine.modules.scene.components.SceneNodeComponent>
#include <helios.engine.runtime.spawn.types>
#include <helios.engine.runtime.spawn.types.SpawnPlanCursor>
#include <helios.engine.modules.rendering.model.components.ModelAabbComponent>
#include <helios.engine.modules.spatial.transform.components.ScaleStateComponent>
#include <helios.engine.runtime.spawn.types.SpawnContext>
#include <helios.engine.runtime.spawn.scheduling.SpawnScheduler>
#include <helios.engine.common.tags.ManagerRole>
#include <helios.engine.runtime.spawn.types.SpawnProfile>
#include <helios.engine.runtime.spawn.events.SpawnPlanCommandExecutedEvent>
#include <helios.engine.modules.physics.collision.Bounds>
#include <helios.engine.mechanics.spawn.components.SpawnedByProfileComponent>
#include <helios.engine.mechanics.spawn.components.EmittedByComponent>
#include <helios.engine.runtime.spawn.commands.DespawnCommand>
#include <helios.engine.runtime.world.UpdateContext>
#include <helios.engine.runtime.spawn.commands.SpawnCommand>
#include <helios.engine.modules.spatial.transform.components.TranslationStateComponent>
#include <helios.engine.runtime.spawn.commands.ScheduledSpawnPlanCommand>
#include <helios.engine.modules.spatial.transform.components.RotationStateComponent>
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:
53using namespace helios::engine::runtime::messaging::command;
54using namespace helios::engine::runtime::spawn::commands;
55using namespace helios::engine::runtime::spawn::types;
56export namespace helios::engine::runtime::spawn {
105 class SpawnManager {
116 std::vector<std::unique_ptr<helios::engine::runtime::spawn::scheduling::SpawnScheduler>> spawnSchedulers_;
136 helios::engine::runtime::pooling::GameObjectPoolManager* gameObjectPoolManager_ = nullptr;
159 void ensureBounds(helios::engine::ecs::GameObject go, helios::math::aabbf& bounds) {
161 const auto* mab = go.get<helios::engine::modules::rendering::model::components::ModelAabbComponent>();
162 const auto* sca = go.get<helios::engine::modules::spatial::transform::components::ScaleStateComponent>();
163 auto* rsc = go.get<helios::engine::modules::spatial::transform::components::RotationStateComponent>();
164 const auto* scn = go.get<helios::engine::modules::scene::components::SceneNodeComponent>();
165 const auto* tsc = go.get<helios::engine::modules::spatial::transform::components::TranslationStateComponent>();
186 std::span<ScheduledSpawnPlanCommand> commands,
187 helios::engine::runtime::world::UpdateContext& updateContext
190 for (auto& scheduledSpawnPlanCommand: commands) {
201 const auto spawnProfile = it->second.get();
203 const auto gameObjectPoolId = spawnProfile->gameObjectPoolId;
224 auto* tsc = go->get<helios::engine::modules::spatial::transform::components::TranslationStateComponent>();
226 auto* sbp = go->get<helios::engine::mechanics::spawn::components::SpawnedByProfileComponent>();
229 auto* aabb = go->get<helios::engine::modules::physics::collision::components::AabbColliderComponent>();
232 auto spawnCursor = SpawnPlanCursor{spawnCount, i};
236 auto* ebc = go->get<helios::engine::mechanics::spawn::components::EmittedByComponent>();
246 const auto position = spawnProfile->spawnPlacer->getPosition(
247 go->entityHandle(),
257 assert(spawnProfile->spawnInitializer && "Unexpected missing spawn initializer");
259 spawnProfile->spawnInitializer->initialize(*go, spawnCursor, spawnContext);
261 go->setActive(true);
264 updateContext.pushFrame<helios::engine::runtime::spawn::events::SpawnPlanCommandExecutedEvent>(
279 std::span<SpawnCommand> commands,
280 helios::engine::runtime::world::UpdateContext& updateContext) {
282 for (auto& spawnCommand: commands) {
289 const auto spawnProfile = it->second.get();
290 const auto gameObjectPoolId = spawnProfile->gameObjectPoolId;
302 auto* tsc = go->get<helios::engine::modules::spatial::transform::components::TranslationStateComponent>();
303 auto* sbp = go->get<helios::engine::mechanics::spawn::components::SpawnedByProfileComponent>();
306 auto* aabb = go->get<helios::engine::modules::physics::collision::components::AabbColliderComponent>();
310 auto* ebc = go->get<helios::engine::mechanics::spawn::components::EmittedByComponent>();
320 const auto position = spawnProfile->spawnPlacer->getPosition(
321 go->entityHandle(),
332 assert(spawnProfile->spawnInitializer && "Unexpected missing spawn initializer");
334 spawnProfile->spawnInitializer->initialize(*go, {1, 1}, spawnContext);
337 go->setActive(true);
350 std::span<DespawnCommand> commands,
351 helios::engine::runtime::world::UpdateContext& updateContext) {
353 for (auto& despawnCommand : commands) {
358 const auto spawnProfile = it->second.get();
359 auto gameObjectPoolId = spawnProfile->gameObjectPoolId;
373 SpawnManager() = default;
382 bool submit(const SpawnCommand command) noexcept {
383 spawnCommands_.push_back(command);
396 void addScheduler(std::unique_ptr<helios::engine::runtime::spawn::scheduling::SpawnScheduler> scheduler) {
407 bool submit(const DespawnCommand command) noexcept {
408 despawnCommands_.push_back(command);
421 const ScheduledSpawnPlanCommand scheduledSpawnPlanCommand
434 helios::engine::runtime::world::UpdateContext& updateContext
468 const SpawnProfileId& spawnProfileId,
469 std::unique_ptr<const SpawnProfile> spawnProfile) {
473 spawnProfiles_[spawnProfileId] = std::move(spawnProfile);
485 [[nodiscard]] const SpawnProfile* spawnProfile(
486 const SpawnProfileId& spawnProfileId) const {
504 void init(helios::engine::runtime::world::GameWorld& gameWorld) noexcept {
506 assert(gameWorld.hasManager<helios::engine::runtime::pooling::GameObjectPoolManager>() && "Unexpected missing GameObjectPoolManager");
507 gameObjectPoolManager_ = gameWorld.tryManager<helios::engine::runtime::pooling::GameObjectPoolManager>();
509 gameWorld.registerCommandHandler<SpawnCommand, DespawnCommand, ScheduledSpawnPlanCommand>(*this);
541 std::span<std::unique_ptr<helios::engine::runtime::spawn::scheduling::SpawnScheduler>> spawnSchedulers() {
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.