Skip to main content

LevelBoundsBehaviorComponent.ixx File

Component defining behavior when an entity interacts with level boundaries. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

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

namespacemechanics

High-level gameplay systems and components for game logic. More...

namespacebounds
namespacecomponents

Boundary behavior configuration components. More...

Classes Index

classLevelBoundsBehaviorComponent

Component that defines how an entity reacts to level boundaries. More...

Description

Component defining behavior when an entity interacts with level boundaries.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file LevelBoundsBehaviorComponent.ixx
3 * @brief Component defining behavior when an entity interacts with level boundaries.
4 */
5module;
6
7#include <algorithm>
8#include <cassert>
9
10export module helios.engine.mechanics.bounds.components.LevelBoundsBehaviorComponent;
11
12
13
14import helios.engine.modules.physics.collision.types.CollisionBehavior;
15
16import helios.engine.modules.physics.collision.types.CollisionResponse;
17
19
20
21 /**
22 * @brief Component that defines how an entity reacts to level boundaries.
23 *
24 * @details
25 * This component stores properties related to boundary interactions, such as
26 * restitution (bounciness) when colliding with level walls, used by physics
27 * or movement systems to resolve out-of-bounds conditions.
28 */
30
31 private:
32 /**
33 * @brief Coefficient of restitution (bounciness).
34 *
35 * @details
36 * A value of 1 means a perfectly elastic collision (no energy lost).
37 * A value of 0 means a perfectly inelastic collision (no bounce).
38 * Default is 0.5.
39 */
40 float restitution_ = 0.5f;
41
42 /**
43 * @brief The behavior type for boundary collisions.
44 *
45 * @details Defines how the entity reacts when hitting level bounds
46 * (e.g., Bounce, Reflect, Clamp, Despawn).
47 */
49
51
52 /**
53 * @brief Whether this component is enabled.
54 */
55 bool isEnabled_ = true;
56
57 public:
58
59 /**
60 * @brief Checks whether this component is enabled.
61 *
62 * @return True if enabled, false otherwise.
63 */
64 [[nodiscard]] bool isEnabled() const noexcept {
65 return isEnabled_;
66 }
67
68 /**
69 * @brief Enables this component.
70 */
71 void enable() noexcept {
72 isEnabled_ = true;
73 }
74
75 /**
76 * @brief Disables this component.
77 */
78 void disable() noexcept {
79 isEnabled_ = false;
80 }
81
82 /**
83 * @brief Constructs a LevelBoundsBehaviorComponent with a specified restitution.
84 *
85 * @param restitution The coefficient of restitution (0.0 to 1.0).
86 */
88 restitution_(restitution) {}
89
90 /**
91 * @brief Constructs a LevelBoundsBehaviorComponent with a specified collision behavior.
92 *
93 * @param collisionBehavior The collision behavior type (default: Reflect).
94 */
98 collisionBehavior_(collisionBehavior),
99 collisionResponse_(collisionResponse)
100 {}
101
102 /**
103 * @brief Copy constructor.
104 *
105 * @param other The component to copy from.
106 */
108 restitution_(other.restitution_),
109 collisionBehavior_(other.collisionBehavior_),
110 collisionResponse_(other.collisionResponse_)
111 {}
112
116
117 /**
118 * @brief Retrieves the restitution coefficient.
119 *
120 * @return The restitution value.
121 */
122 [[nodiscard]] float restitution() const noexcept {
123 return restitution_;
124 }
125
126 /**
127 * @brief Retrieves the collision behavior type.
128 *
129 * @return The collision behavior (e.g., Bounce, Reflect, Clamp, Despawn).
130 */
132 return collisionBehavior_;
133 }
134
135 /**
136 * @brief Retrieves the collision response type.
137 *
138 * @return The collision response type (e.g., None, Event).
139 */
141 return collisionResponse_;
142 }
143
144 /**
145 * @brief Sets the collision response type.
146 *
147 * @param collisionResponse The new collision response to set.
148 */
150 collisionResponse_ = collisionResponse;
151 }
152
153 /**
154 * @brief Sets the collision behavior type.
155 *
156 * @param collisionBehavior The new collision behavior to set.
157 */
159 collisionBehavior_ = collisionBehavior;
160 }
161
162 /**
163 * @brief Sets the coefficient of restitution (bounciness).
164 *
165 * @param restitution The new restitution value to set. Must be within the
166 * range [0.0, 1.0]. Values outside this range will be clamped.
167 */
168 void setRestitution(const float restitution) noexcept {
169 assert(restitution >= 0.0f && restitution <= 1.0f && "Unexpected value for restitution");
170 restitution_ = std::clamp(restitution, 0.0f, 1.0f);
171 }
172
173
174 };
175
176
177}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.