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;
20
21
22import helios.engine.state.Bindings;
23import helios.engine.runtime.messaging.command.EngineCommandBuffer;
24
25import helios.engine.modules.physics.collision.types.CollisionBehavior;
26
27import helios.engine.modules.physics.collision.components.CollisionStateComponent;
28
29import helios.engine.runtime.spawn.commands.DespawnCommand;
30import helios.engine.modules.physics.collision.events;
31
32import helios.engine.mechanics.spawn.components.SpawnedByProfileComponent;
33
34import helios.engine.mechanics.lifecycle.components.Active;
35
39
40
41import helios.engine.common.tags.SystemRole;
42
44
45 /**
46 * @brief System that processes collision states and executes configured behaviors.
47 *
48 * @details This system reads the CollisionStateComponent of each entity to determine
49 * how to respond to detected collisions. Based on the configured CollisionBehavior,
50 * the system issues appropriate commands (e.g., DespawnCommand for entities marked
51 * with Despawn behavior).
52 *
53 * The system requires entities to have both a CollisionStateComponent (for collision
54 * data) and a SpawnedByProfileComponent.
55 *
56 * Supported behaviors:
57 * - **Despawn:** Issues a DespawnCommand to return the entity to its object pool.
58 *
59 * This system should run after collision detection but before collision state clearing.
60 */
62
63 public:
64
66
67 /**
68 * @brief Processes collision states and issues response commands.
69 *
70 * @details Iterates over all entities with CollisionStateComponent and PoolIdComponent.
71 * For entities with active collisions, reads the collision behavior and issues
72 * appropriate commands and/or events.
73 *
74 * @param updateContext Context providing access to the command buffer and world.
75 */
77
78 for (auto [entity, csc, sbp, active] : updateContext.view<
82 >().whereEnabled()) {
83
84 if (!csc->hasCollision()) {
85 continue;
86 }
87
88 CollisionBehavior collisionBehavior = csc->collisionBehavior();
89
90 if (hasFlag(collisionBehavior, CollisionBehavior::PassEvent)) {
91
92 if (csc->isTrigger()) {
93 updateContext.pushPass<events::TriggerCollisionEvent>(
94 entity.entityHandle(),
95 csc->collisionContext()
96 );
97 }
98
99 if (csc->isSolid()) {
100 updateContext.pushPass<events::SolidCollisionEvent>(
101 entity.entityHandle(),
102 csc->collisionContext()
103 );
104 }
105 }
106
107
108 if (hasFlag(collisionBehavior, CollisionBehavior::Despawn)) {
109 updateContext.queueCommand<DespawnCommand>(
110 entity.entityHandle(), sbp->spawnProfileId());
111 }
112 }
113
114 }
115
116 };
117
118
119}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.