Skip to main content

ShootComponent.ixx File

Component for handling projectile shooting mechanics. 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...

namespacecombat

Combat-related gameplay systems, components, and commands. More...

namespacecomponents

Combat-specific components for aiming, shooting, and attack tracking. More...

Classes Index

classShootComponent

Component for handling projectile shooting with rate limiting. More...

Description

Component for handling projectile shooting mechanics.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file ShootComponent.ixx
3 * @brief Component for handling projectile shooting mechanics.
4 */
5module;
6
7#include <cassert>
8
9export module helios.engine.mechanics.combat.components.ShootComponent;
10
11import helios.math;
12
13import helios.engine.ecs.GameObject;
14import helios.engine.mechanics.combat.components.Aim2DComponent;
15import helios.engine.modules.spatial.transform.components.ComposeTransformComponent;
16
17import helios.engine.core.data.ComponentTypeId;
18
20
21 /**
22 * @brief Component for handling projectile shooting with rate limiting.
23 *
24 * @details Manages the shooting mechanics for a GameObject by coordinating with
25 * aim-components for direction and a projectile pool for projectile spawning. Implements
26 * a cooldown timer to control fire rate.
27 *
28 *
29 * Example usage:
30 * ```cpp
31 * auto shootComponent = std::make_unique<ShootComponent>();
32 * gameObject.add(std::move(shootComponent));
33 *
34 * // Trigger shooting (typically from ShootCommand)
35 * shootComponent->shoot(1.0f);
36 * ```
37 */
39
40 protected:
41
42 /**
43 * @brief Current fire intensity (0.0 to 1.0).
44 *
45 * @details Set by shoot() and cleared when intensity is zero.
46 * Controls whether projectiles are spawned during update().
47 */
48 float intensity_ = 0.0f;
49
50 /**
51 * @brief Cooldown interval between shots, in seconds.
52 *
53 * @details Derived from fireRate (1.0 / fireRate). Determines the minimum
54 * time that must pass between consecutive projectile spawns.
55 */
56 float cooldownDelta_ = 0.0f;
57
58 /**
59 * @brief Accumulated time since last shot, in seconds.
60 *
61 * @details Accumulates delta time multiplied by intensity. When this value
62 * exceeds cooldownDelta, projectiles are spawned and the timer is reduced.
63 */
64 float cooldownTimer_ = 0.0f;
65
66
67 /**
68 * @brief The projectile speed, in meters per second.
69 */
70 float projectileSpeed_ = 60.0f;
71
72 /**
73 * @brief Velocity of the source object in three-dimensional space.
74 *
75 * Used to adjust the trajectory of projectiles emitted by the source's movement.
76 */
78
79
80 /**
81 * @brief Fire rate per second, i.e. projectiles than can be shot per second.
82 */
83 float fireRate_ = 1.0f;
84
85 /**
86 * @brief Whether this component is enabled.
87 */
88 bool isEnabled_ = true;
89
90 public:
91
92 /**
93 * @brief Checks whether this component is enabled.
94 *
95 * @return True if enabled, false otherwise.
96 */
97 [[nodiscard]] bool isEnabled() const noexcept {
98 return isEnabled_;
99 }
100
101 /**
102 * @brief Enables this component.
103 */
104 void enable() noexcept {
105 isEnabled_ = true;
106 }
107
108 /**
109 * @brief Disables this component.
110 */
111 void disable() noexcept {
112 isEnabled_ = false;
113 }
114
115 /**
116 * @brief Constructs a new ShootComponent with default settings.
117 */
118 ShootComponent() = default;
119
120 ShootComponent(const ShootComponent&) = default;
122 ShootComponent(ShootComponent&&) noexcept = default;
123 ShootComponent& operator=(ShootComponent&&) noexcept = default;
124
125
126 /**
127 * @brief Sets the shooting intensity.
128 *
129 * @details Call with a non-zero value to start shooting, or zero to stop.
130 * The intensity affects whether projectiles are spawned during update().
131 *
132 * @param intensity Fire intensity (0.0 to 1.0). Zero stops firing.
133 * @param sourceVelocity The velocity of the object emitting the projectile.
134 */
135 void shoot(const float intensity, const helios::math::vec3f sourceVelocity) {
136
138 intensity_ = 0.0f;
139 return;
140 }
143 }
144
145
146 /**
147 * @brief Returns the cooldown interval between shots.
148 *
149 * @return Cooldown interval in seconds (derived from 1 / fireRate).
150 */
151 [[nodiscard]] float cooldownDelta() const noexcept {
152 return cooldownDelta_;
153 }
154
155 /**
156 * @brief Returns the current fire intensity.
157 *
158 * @return The intensity value (0.0 to 1.0).
159 */
160 [[nodiscard]] float intensity() const noexcept {
161 return intensity_;
162 }
163
164 /**
165 * @brief Returns the accumulated time since last shot.
166 *
167 * @return Accumulated cooldown timer in seconds.
168 */
169 [[nodiscard]] float cooldownTimer() const noexcept {
170 return cooldownTimer_;
171 }
172
173 /**
174 * @brief Sets the accumulated cooldown timer.
175 *
176 * @param cooldown New timer value in seconds.
177 */
178 void setCooldownTimer(float cooldown) noexcept {
179 cooldownTimer_ = cooldown;
180 }
181
182 /**
183 * @brief Adds delta time to the cooldown timer.
184 *
185 * @param delta Time to add in seconds.
186 */
187 void updateCooldownTimerBy(float delta) noexcept {
188 cooldownTimer_ += delta;
189 }
190
191 /**
192 * @brief Returns the projectile speed.
193 *
194 * @return Projectile speed in meters per second.
195 */
196 [[nodiscard]] float projectileSpeed() const noexcept {
197 return projectileSpeed_;
198 }
199
200 /**
201 * @brief Sets the projectile speed.
202 *
203 * @param speed New projectile speed in meters per second.
204 */
205 void setProjectileSpeed(float speed) noexcept {
206 projectileSpeed_ = speed;
207 }
208
209
210 /**
211 * @brief Returns the source object's velocity.
212 *
213 * @return Velocity vector used for projectile trajectory adjustment.
214 */
215 [[nodiscard]] helios::math::vec3f sourceVelocity() const noexcept {
216 return sourceVelocity_;
217 }
218
219 /**
220 * @brief Returns the fire rate in projectiles per second.
221 *
222 * @return Fire rate (projectiles/second).
223 */
224 [[nodiscard]] float fireRate() const noexcept {
225 return fireRate_;
226 }
227
228 /**
229 * @brief Sets the fire rate.
230 *
231 * @details Updates the cooldown delta based on the new fire rate.
232 *
233 * @param fireRate The number of projectiles per second. Must be greater than zero.
234 */
235 void setFireRate(const float fireRate) noexcept {
237
240 }
241
242
243 };
244
245
246}
247

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.