Skip to main content

CollisionStateResponseSystem.ixx File

System for processing collision states and executing collision behaviors. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespacemodules

Domain-specific components and systems. More...

namespacephysics

Physics simulation and collision detection subsystem for the game engine. More...

namespacecollision
namespacesystems

Collision detection and response systems. More...

Classes Index

classCollisionStateResponseSystem

System that processes collision states and executes configured behaviors. More...

Description

System for processing collision states and executing collision behaviors.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file CollisionStateResponseSystem.ixx
3 * @brief System for processing collision states and executing collision behaviors.
4 */
5module;
6
7#include <algorithm>
8#include <cassert>
9#include <cmath>
10#include <format>
11#include <helios/helios_config.h>
12#include <unordered_set>
13#include <vector>
14
15
16export module helios.engine.modules.physics.collision.systems.CollisionStateResponseSystem;
17
18import helios.engine.runtime.world.GameWorld;
19import helios.engine.runtime.world.UpdateContext;
20import helios.engine.ecs.System;
21
22import helios.engine.runtime.messaging.command.CommandBuffer;
23
24import helios.engine.modules.physics.collision.types.CollisionBehavior;
25
26import helios.engine.modules.physics.collision.components.CollisionStateComponent;
27
28import helios.engine.runtime.spawn.commands.DespawnCommand;
29import helios.engine.modules.physics.collision.events;
30
31import helios.engine.mechanics.spawn.components.SpawnedByProfileComponent;
32
33import helios.engine.mechanics.lifecycle.components.Active;
34
38
39
41
42 /**
43 * @brief System that processes collision states and executes configured behaviors.
44 *
45 * @details This system reads the CollisionStateComponent of each entity to determine
46 * how to respond to detected collisions. Based on the configured CollisionBehavior,
47 * the system issues appropriate commands (e.g., DespawnCommand for entities marked
48 * with Despawn behavior).
49 *
50 * The system requires entities to have both a CollisionStateComponent (for collision
51 * data) and a SpawnedByProfileComponent.
52 *
53 * Supported behaviors:
54 * - **Despawn:** Issues a DespawnCommand to return the entity to its object pool.
55 *
56 * This system should run after collision detection but before collision state clearing.
57 */
59
60 public:
61
62 /**
63 * @brief Processes collision states and issues response commands.
64 *
65 * @details Iterates over all entities with CollisionStateComponent and PoolIdComponent.
66 * For entities with active collisions, reads the collision behavior and issues
67 * appropriate commands and/or events.
68 *
69 * @param updateContext Context providing access to the command buffer and world.
70 */
71 void update(helios::engine::runtime::world::UpdateContext& updateContext) noexcept override {
72
73 for (auto [entity, csc, sbp, active] : gameWorld_->view<
77 >().whereEnabled()) {
78
79 if (!csc->hasCollision()) {
80 continue;
81 }
82
83 CollisionBehavior collisionBehavior = csc->collisionBehavior();
84
85 if (hasFlag(collisionBehavior, CollisionBehavior::PassEvent)) {
86
87 if (csc->isTrigger()) {
88 updateContext.pushPass<events::TriggerCollisionEvent>(
89 entity.entityHandle(),
90 csc->collisionContext()
91 );
92 }
93
94 if (csc->isSolid()) {
95 updateContext.pushPass<events::SolidCollisionEvent>(
96 entity.entityHandle(),
97 csc->collisionContext()
98 );
99 }
100 }
101
102
103 if (hasFlag(collisionBehavior, CollisionBehavior::Despawn)) {
104 updateContext.commandBuffer().add<DespawnCommand>(
105 entity.entityHandle(), sbp->spawnProfileId());
106 }
107 }
108
109 }
110
111 };
112
113
114}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.