r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
WaveManager.hpp
Go to the documentation of this file.
1///
2/// @file WaveManager.hpp
3/// @brief Wave-based enemy spawning management system for R-Type server
4/// @details This file contains the WaveManager class which provides a comprehensive wave-based
5/// enemy spawning system for the R-Type game server. The manager handles timing,
6/// sequencing, and spawning of enemies in predefined waves with configurable patterns.
7/// It supports multiple wave types, spawn delays, wave completion detection, and
8/// dynamic difficulty progression throughout the game.
9/// @namespace gme
10/// @author R-Type Team
11/// @date 2025
12///
13
14#pragma once
15
16#include "ECS/Registry.hpp"
18#include <functional>
19#include <vector>
20
21namespace gme
22{
23 ///
24 /// @struct EnemySpawn
25 /// @brief Definition of a single enemy spawn within a wave
26 /// @details Specifies all parameters needed to spawn an enemy including type, position,
27 /// health, and timing. Multiple EnemySpawn instances make up a complete wave.
28 ///
30 {
31 ServerEntityType type; ///< Type of enemy to spawn (ENEMY_BASIC, ENEMY_ADVANCED, or BOSS)
32 float x; ///< Spawn X position (typically off-screen right)
33 float y; ///< Spawn Y position (vertical placement on screen)
34 float health; ///< Initial health points for this enemy
35 float spawnDelay; ///< Delay in seconds from wave start before spawning this enemy
36 };
37
38 ///
39 /// @struct Wave
40 /// @brief Complete wave configuration containing multiple enemy spawns
41 /// @details Defines a complete enemy wave including all enemies to spawn, timing parameters,
42 /// completion conditions, and optional callbacks. Waves can either advance based on
43 /// time duration or wait for all enemies to be eliminated.
44 ///
45 struct Wave
46 {
47 int waveNumber; ///< Wave sequence number (1-based)
48 std::vector<EnemySpawn> enemies; ///< List of all enemies to spawn in this wave
49 float duration; ///< Maximum duration in seconds before next wave (if not waitForClear)
50 bool waitForClear; ///< If true, next wave starts only when all enemies are destroyed
51 std::function<void()> onComplete; ///< Optional callback function invoked when wave completes
52 };
53
54 ///
55 /// @class WaveManager
56 /// @brief Manages wave-based enemy spawning with configurable patterns and timing
57 /// @details This class provides a complete wave management system for the R-Type server.
58 /// Features include:
59 /// - Sequential wave progression (5 waves: 4 standard waves + 1 boss wave)
60 /// - Time-based or clear-based wave advancement
61 /// - Per-enemy spawn delays within waves
62 /// - Initial delay synchronization with client stage spawning
63 /// - Wave completion detection
64 /// - Customizable wave patterns
65 /// - Default wave configurations for standard gameplay
66 ///
67 /// The manager maintains internal state for current wave, spawn timers, and completion
68 /// status. It coordinates with the EntityManager to spawn enemies at appropriate times
69 /// and ensures proper game progression through all waves.
70 ///
71 /// @namespace gme
72 ///
74 {
75 public:
76 ///
77 /// @brief Constructor
78 /// @param entityManager Reference to entity manager for spawning enemies
79 /// @details Initializes the wave manager with default wave configurations
80 ///
81 explicit WaveManager(EntityManager &entityManager);
82
83 ///
84 /// @brief Destructor
85 ///
86 ~WaveManager() = default;
87
88 /// @brief Deleted copy constructor (non-copyable)
89 WaveManager(const WaveManager &) = delete;
90 /// @brief Deleted copy assignment operator (non-copyable)
91 WaveManager &operator=(const WaveManager &) = delete;
92 /// @brief Deleted move constructor (non-movable)
94 /// @brief Deleted move assignment operator (non-movable)
96
97 ///
98 /// @brief Update wave manager logic (called each frame)
99 /// @param registry ECS registry containing all game entities
100 /// @param dt Delta time since last frame (in seconds)
101 /// @param screenWidth Screen width for spawn X positioning
102 /// @details Processes initial delay, advances wave timers, spawns enemies according
103 /// to wave configurations, and checks for wave completion conditions
104 ///
105 void update(ecs::Registry &registry, float dt, int screenWidth);
106
107 ///
108 /// @brief Check if initial delay has passed and waves can start
109 /// @return True if initial delay has elapsed
110 /// @details Initial delay synchronizes wave spawning with client stage initialization
111 ///
112 bool isReady() const { return m_initialDelayPassed; }
113
114 ///
115 /// @brief Start the wave system
116 /// @details Activates wave processing and begins initial delay countdown
117 ///
118 void start();
119
120 ///
121 /// @brief Stop and reset the wave system to initial state
122 /// @details Stops wave processing, resets all timers, and clears wave progress
123 ///
124 void reset();
125
126 ///
127 /// @brief Check if wave system is currently active
128 /// @return True if wave system is running
129 ///
130 bool isActive() const { return m_active; }
131
132 ///
133 /// @brief Get current wave index
134 /// @return Current wave index (0-based)
135 /// @details Returns the index of the currently active or next wave
136 ///
137 int getCurrentWave() const { return m_currentWaveIndex; }
138
139 ///
140 /// @brief Get total number of configured waves
141 /// @return Total wave count (default: 5)
142 ///
143 size_t getTotalWaves() const { return m_waves.size(); }
144
145 ///
146 /// @brief Check if all waves have been completed
147 /// @return True if all waves are finished
148 /// @details Returns true when the last wave has completed and no more waves remain
149 ///
150 bool isCompleted() const { return m_completed; }
151
152 ///
153 /// @brief Add a custom wave to the wave list
154 /// @param wave Wave configuration to add
155 /// @details Appends a wave to the end of the wave sequence
156 ///
157 void addWave(const Wave &wave);
158
159 ///
160 /// @brief Clear all configured waves
161 /// @details Removes all waves from the manager. Use setupDefaultWaves() to restore defaults.
162 ///
163 void clearWaves();
164
165 ///
166 /// @brief Initialize with default wave patterns
167 /// @details Creates 5 predefined waves: 4 standard waves (30s each) + 1 boss wave (60s)
168 ///
169 void setupDefaultWaves();
170
171 private:
172 EntityManager &m_entityManager; ///< Reference to entity manager for spawning
173 std::vector<Wave> m_waves; ///< List of all configured waves
174 int m_currentWaveIndex; ///< Index of current/next wave (0-based)
175 float m_waveTimer; ///< Timer for current wave duration
176 float m_spawnTimer; ///< Timer for processing enemy spawns
177 bool m_active; ///< Whether wave system is active
178 bool m_completed; ///< Whether all waves are completed
179 bool m_waveInProgress; ///< Whether a wave is currently spawning
180 bool m_initialDelayPassed; ///< Whether initial delay has elapsed
181 float m_initialDelayTimer; ///< Timer for initial delay countdown
182 std::vector<bool> m_enemiesSpawned; ///< Track which enemies in current wave have spawned
183
184 static constexpr float INITIAL_DELAY = 0.5f; ///< Initial delay in seconds (synced with client)
185
186 ///
187 /// @brief Start the next wave in sequence
188 /// @details Advances to next wave, resets timers, and initializes spawn tracking
189 ///
190 void startNextWave();
191
192 ///
193 /// @brief Check if current wave is cleared of all enemies
194 /// @return True if no enemies remain from current wave
195 /// @details Used for waves with waitForClear flag to determine wave completion
196 ///
197 bool isWaveCleared() const;
198
199 ///
200 /// @brief Process enemy spawns for current wave
201 /// @param dt Delta time since last frame
202 /// @param screenWidth Screen width for spawn positioning
203 /// @details Checks spawn delays and creates enemies at appropriate times
204 ///
205 void processSpawns(float dt, int screenWidth);
206
207 ///
208 /// @brief Create wave 1 configuration (basic introduction wave)
209 /// @details 30-second wave with basic enemies
210 ///
211 void createWave1();
212
213 ///
214 /// @brief Create wave 2 configuration (mixed enemies)
215 /// @details 30-second wave with basic and advanced enemies
216 ///
217 void createWave2();
218
219 ///
220 /// @brief Create wave 3 configuration (increased difficulty)
221 /// @details 30-second wave with more advanced enemies
222 ///
223 void createWave3();
224
225 ///
226 /// @brief Create wave 4 configuration (final standard wave)
227 /// @details 30-second wave with challenging enemy patterns
228 ///
229 void createWave4();
230
231 ///
232 /// @brief Create boss wave configuration (final challenge)
233 /// @details 60-second wave featuring the boss enemy
234 ///
235 void createBossWave();
236 };
237
238} // namespace gme
Centralized entity lifecycle management system for R-Type server.
This file contains the Registry class declaration.
Class for managing entities and their components.
Definition Registry.hpp:25
Central entity lifecycle manager for the R-Type game server.
Manages wave-based enemy spawning with configurable patterns and timing.
~WaveManager()=default
Destructor.
bool m_waveInProgress
Whether a wave is currently spawning.
bool isActive() const
Check if wave system is currently active.
bool m_completed
Whether all waves are completed.
void startNextWave()
Start the next wave in sequence.
std::vector< Wave > m_waves
List of all configured waves.
void clearWaves()
Clear all configured waves.
float m_spawnTimer
Timer for processing enemy spawns.
void createWave3()
Create wave 3 configuration (increased difficulty)
bool isReady() const
Check if initial delay has passed and waves can start.
void update(ecs::Registry &registry, float dt, int screenWidth)
Update wave manager logic (called each frame)
WaveManager(const WaveManager &)=delete
Deleted copy constructor (non-copyable)
void start()
Start the wave system.
static constexpr float INITIAL_DELAY
Initial delay in seconds (synced with client)
bool m_initialDelayPassed
Whether initial delay has elapsed.
float m_initialDelayTimer
Timer for initial delay countdown.
size_t getTotalWaves() const
Get total number of configured waves.
WaveManager(EntityManager &entityManager)
Constructor.
void reset()
Stop and reset the wave system to initial state.
void createWave1()
Create wave 1 configuration (basic introduction wave)
bool isCompleted() const
Check if all waves have been completed.
bool isWaveCleared() const
Check if current wave is cleared of all enemies.
int m_currentWaveIndex
Index of current/next wave (0-based)
std::vector< bool > m_enemiesSpawned
Track which enemies in current wave have spawned.
int getCurrentWave() const
Get current wave index.
void processSpawns(float dt, int screenWidth)
Process enemy spawns for current wave.
EntityManager & m_entityManager
Reference to entity manager for spawning.
void createBossWave()
Create boss wave configuration (final challenge)
void setupDefaultWaves()
Initialize with default wave patterns.
void createWave4()
Create wave 4 configuration (final standard wave)
WaveManager(WaveManager &&)=delete
Deleted move constructor (non-movable)
float m_waveTimer
Timer for current wave duration.
void addWave(const Wave &wave)
Add a custom wave to the wave list.
WaveManager & operator=(WaveManager &&)=delete
Deleted move assignment operator (non-movable)
void createWave2()
Create wave 2 configuration (mixed enemies)
bool m_active
Whether wave system is active.
WaveManager & operator=(const WaveManager &)=delete
Deleted copy assignment operator (non-copyable)
ServerEntityType
Enumeration of entity types managed by the server.
Definition of a single enemy spawn within a wave.
float spawnDelay
Delay in seconds from wave start before spawning this enemy.
float health
Initial health points for this enemy.
float y
Spawn Y position (vertical placement on screen)
float x
Spawn X position (typically off-screen right)
ServerEntityType type
Type of enemy to spawn (ENEMY_BASIC, ENEMY_ADVANCED, or BOSS)
Complete wave configuration containing multiple enemy spawns.
std::vector< EnemySpawn > enemies
List of all enemies to spawn in this wave.
int waveNumber
Wave sequence number (1-based)
std::function< void()> onComplete
Optional callback function invoked when wave completes.
bool waitForClear
If true, next wave starts only when all enemies are destroyed.
float duration
Maximum duration in seconds before next wave (if not waitForClear)