Skip to main content

CollisionBehavior.ixx File

Enumeration of collision response behaviors. More...

Included Headers

#include <cstdint>

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
namespacetypes

Type definitions for collision system behavior configuration. More...

Description

Enumeration of collision response behaviors.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file CollisionBehavior.ixx
3 * @brief Enumeration of collision response behaviors.
4 */
5module;
6
7#include <cstdint>
8
9export module helios.engine.modules.physics.collision.types.CollisionBehavior;
10
11
12
14
15 /**
16 * @brief Defines how an entity responds to a collision event.
17 *
18 * @details CollisionBehavior values are used as bitmasks to configure
19 * per-layer collision responses in CollisionComponent. Multiple behaviors
20 * can be combined using bitwise operations.
21 *
22 * The behavior determines what action the collision system takes when
23 * two entities collide based on their layer configuration.
24 *
25 * @note Not all behaviors are currently fully implemented. Currently supported:
26 * - `Reflect` - Fully supported
27 * - `Bounce` - Fully supported
28 * - `Despawn` - Fully supported
29 */
30 enum class CollisionBehavior : uint16_t {
31
32 /**
33 * @brief No collision response.
34 */
35 None = 0,
36
37 /**
38 * @brief Reflect the entity's velocity off the collision surface.
39 *
40 * @details Uses the surface normal to calculate a reflected velocity
41 * vector. Commonly used for projectiles bouncing off walls.
42 */
43 Reflect = 1 << 0,
44
45 /**
46 * @brief Bounce the entity with restitution applied.
47 *
48 * @details Similar to Reflect but applies a restitution coefficient
49 * to reduce velocity. Used for physics-based bouncing.
50 */
51 Bounce = 1 << 1,
52
53 /**
54 * @brief Stick the entity to the collision surface.
55 *
56 * @details Stops the entity's movement and attaches it to the
57 * collided object. Used for projectiles that embed on impact.
58 */
59 Stick = 1 << 2,
60
61 /**
62 * @brief Despawn the entity on collision.
63 *
64 * @details Marks the entity for removal from the game world.
65 * Used for projectiles that are destroyed on impact.
66 */
67 Despawn = 1 << 3,
68
69 /**
70 * @brief Emit an event without physical response.
71 *
72 * @details Generates a collision event for game logic processing
73 * without affecting the entity's physics state.
74 */
75 PassEvent = 1 << 4,
76
77 /**
78 * @brief Push collision event to the event bus.
79 *
80 * @details Pushes the collision event to the double-buffered event bus
81 * for processing in the next frame. Used for deferred collision handling.
82 */
83 PhaseEvent = 1 << 5,
84
85 /**
86 * @brief Process collision event in the current frame.
87 *
88 * @details Sends the collision event to the immediate bus for processing
89 * within the same frame. Used for time-critical collision responses.
90 */
91 FrameEvent = 1 << 6
92 };
93
94 /**
95 * @brief Number of distinct CollisionBehavior flags.
96 */
97 constexpr size_t CollisionBehaviorItemSize = 8;
98
99 /**
100 * @brief Combines two CollisionBehavior flags using bitwise OR.
101 *
102 * @param lhs Left-hand side behavior.
103 * @param rhs Right-hand side behavior.
104 *
105 * @return Combined behavior flags.
106 */
107 [[nodiscard]] constexpr CollisionBehavior operator|(CollisionBehavior lhs, CollisionBehavior rhs) noexcept {
108 return static_cast<CollisionBehavior>(
109 static_cast<uint16_t>(lhs) | static_cast<uint16_t>(rhs)
110 );
111 }
112
113 /**
114 * @brief Masks two CollisionBehavior flags using bitwise AND.
115 *
116 * @param lhs Left-hand side behavior.
117 * @param rhs Right-hand side behavior.
118 *
119 * @return Masked behavior flags.
120 */
121 [[nodiscard]] constexpr CollisionBehavior operator&(CollisionBehavior lhs, CollisionBehavior rhs) noexcept {
122 return static_cast<CollisionBehavior>(
123 static_cast<uint16_t>(lhs) & static_cast<uint16_t>(rhs)
124 );
125 }
126
127 /**
128 * @brief Checks if a behavior mask contains a specific flag.
129 *
130 * @param mask The behavior mask to check.
131 * @param flag The flag to test for.
132 *
133 * @return True if the mask contains the flag, false otherwise.
134 */
135 [[nodiscard]] constexpr bool hasFlag(const CollisionBehavior mask, const CollisionBehavior flag) noexcept {
136 return (mask & flag) == flag;
137 }
138
139}
140

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.