r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
EnemySpawnSystem.hpp
Go to the documentation of this file.
1///
2/// @file EnemySpawnSystem.hpp
3/// @brief Server-side enemy spawning system for R-Type game progression
4/// @details This file contains the enemy spawning system that controls the timing and
5/// placement of enemy waves throughout the game. The system manages spawn timing,
6/// enemy type distribution, wave progression, and boss encounters based on level time.
7/// All spawning is server-authoritative to ensure synchronized gameplay.
8/// @namespace gme
9/// @author R-Type Team
10/// @date 2025
11///
12
13#pragma once
14
17#include <random>
18#include <vector>
19
20namespace gme
21{
22 ///
23 /// @struct SpawnWave
24 /// @brief Configuration data for a single enemy spawn wave
25 /// @details Defines when and how many enemies spawn during a specific wave.
26 /// Waves are triggered based on level time and can contain multiple enemy types
27 /// including bosses. Each wave spawns enemies gradually over time using the
28 /// spawn interval.
29 ///
30 struct SpawnWave
31 {
32 float spawnTime; ///< Time from level start when wave begins (seconds)
33 int basicEnemyCount; ///< Number of basic enemies to spawn in this wave
34 int advancedEnemyCount; ///< Number of advanced enemies to spawn in this wave
35 bool bossSpawn; ///< Whether this wave spawns a boss enemy
36 float spawnInterval; ///< Time between individual enemy spawns within wave (seconds)
37 int spawnedCount; ///< Number of enemies already spawned from this wave (internal counter)
38 };
39
40 ///
41 /// @class EnemySpawnSystem
42 /// @brief Server-side system that manages enemy wave spawning and level progression
43 /// @details This ECS system controls the flow of enemy spawns throughout a game session.
44 /// Features include:
45 /// - Time-based wave triggering
46 /// - Multiple enemy types per wave (basic, advanced, boss)
47 /// - Gradual spawning with configurable intervals
48 /// - Random spawn position generation
49 /// - Wave progression tracking
50 /// - Spawn statistics for debugging
51 ///
52 /// The system maintains internal state for level time and wave progression,
53 /// and spawns enemies at the right edge of the screen with random Y positions.
54 /// All spawning is deterministic based on server time to ensure synchronized
55 /// gameplay across all clients.
56 ///
57 /// @namespace gme
58 ///
59 class EnemySpawnSystem final : public ecs::ASystem
60 {
61 public:
62 ///
63 /// @brief Constructor
64 /// @param entityManager Entity manager for creating enemy entities
65 /// @details Initializes the spawn system and sets up initial wave configurations
66 ///
67 explicit EnemySpawnSystem(EntityManager &entityManager);
68
69 ///
70 /// @brief Destructor
71 ///
72 ~EnemySpawnSystem() override = default;
73
74 /// @brief Deleted copy constructor (non-copyable)
76 /// @brief Deleted copy assignment operator (non-copyable)
78 /// @brief Deleted move constructor (non-movable)
80 /// @brief Deleted move assignment operator (non-movable)
82
83 ///
84 /// @brief Update the spawn system (called each frame)
85 /// @param registry ECS registry containing all entities
86 /// @param deltaTime Time elapsed since last frame (in seconds)
87 /// @details Advances level time, checks for wave triggers, and spawns enemies
88 /// according to wave configurations
89 ///
90 void update(ecs::Registry &registry, float deltaTime) override;
91
92 ///
93 /// @brief Reset the spawn system to initial state
94 /// @details Resets level time, wave index, and spawn counters. Used when starting a new game.
95 ///
96 void reset();
97
98 ///
99 /// @brief Enable or disable enemy spawning
100 /// @param enabled True to enable spawning, false to disable
101 /// @details When disabled, no enemies will spawn regardless of wave timing
102 ///
103 void setEnabled(bool enabled) { m_enabled = enabled; }
104
105 ///
106 /// @brief Check if enemy spawning is currently enabled
107 /// @return True if spawning is enabled
108 ///
109 bool isEnabled() const { return m_enabled; }
110
111 ///
112 /// @brief Get total number of enemies spawned since reset
113 /// @return Total enemy spawn count
114 /// @details Useful for statistics and debugging
115 ///
117
118 ///
119 /// @brief Get current wave index
120 /// @return Index of the currently active or next wave
121 /// @details Returns the index in the wave array, useful for level progression tracking
122 ///
123 size_t getCurrentWaveIndex() const { return m_currentWaveIndex; }
124
125 ///
126 /// @brief Get elapsed time since level start
127 /// @return Level time in seconds
128 /// @details Used for wave timing and level progression
129 ///
130 float getLevelTime() const { return m_levelTime; }
131
132 private:
133 EntityManager &m_entityManager; ///< Entity manager for spawning enemies
134 float m_levelTime; ///< Elapsed time since level start (seconds)
135 size_t m_currentWaveIndex; ///< Index of current/next wave to process
136 float m_waveSpawnTimer; ///< Timer for spawning enemies within current wave
137 bool m_enabled; ///< Whether spawning is currently enabled
138 size_t m_totalEnemiesSpawned; ///< Total number of enemies spawned this session
139
140 std::vector<SpawnWave> m_waves; ///< List of all spawn waves for the level
141 std::mt19937 m_rng; ///< Random number generator for spawn positions
142 std::uniform_real_distribution<float> m_yDistribution; ///< Distribution for random Y positions
143
144 ///
145 /// @brief Initialize all spawn waves for the level
146 /// @details Populates the m_waves vector with predefined wave configurations
147 /// including timing, enemy counts, and boss spawns
148 ///
149 void initializeWaves();
150
151 ///
152 /// @brief Process a single spawn wave
153 /// @param wave Wave configuration to process
154 /// @param deltaTime Time elapsed since last frame
155 /// @details Handles the spawning of enemies from this wave according to spawn interval,
156 /// spawning enemies gradually over time
157 ///
158 void processWave(SpawnWave &wave, float deltaTime);
159
160 ///
161 /// @brief Generate random Y position for enemy spawn
162 /// @return Random Y coordinate within valid screen bounds
163 /// @details Uses uniform distribution to place enemies at various heights
164 ///
165 float getRandomY();
166
167 ///
168 /// @brief Get X position for enemy spawns (right side of screen)
169 /// @return X coordinate for spawn position (2000.0f)
170 /// @details Enemies spawn off-screen to the right and move left
171 ///
172 float getSpawnX() const { return 2000.0f; }
173 };
174
175} // namespace gme
Centralized entity lifecycle management system for R-Type server.
This file contains the interface for systems.
Abstract class for system.
Definition ISystems.hpp:34
Class for managing entities and their components.
Definition Registry.hpp:25
Server-side system that manages enemy wave spawning and level progression.
EnemySpawnSystem(const EnemySpawnSystem &)=delete
Deleted copy constructor (non-copyable)
std::mt19937 m_rng
Random number generator for spawn positions.
void processWave(SpawnWave &wave, float deltaTime)
Process a single spawn wave.
void initializeWaves()
Initialize all spawn waves for the level.
size_t getTotalEnemiesSpawned() const
Get total number of enemies spawned since reset.
EntityManager & m_entityManager
Entity manager for spawning enemies.
~EnemySpawnSystem() override=default
Destructor.
size_t m_currentWaveIndex
Index of current/next wave to process.
EnemySpawnSystem(EntityManager &entityManager)
Constructor.
void reset()
Reset the spawn system to initial state.
bool isEnabled() const
Check if enemy spawning is currently enabled.
void update(ecs::Registry &registry, float deltaTime) override
Update the spawn system (called each frame)
float m_waveSpawnTimer
Timer for spawning enemies within current wave.
bool m_enabled
Whether spawning is currently enabled.
EnemySpawnSystem & operator=(const EnemySpawnSystem &)=delete
Deleted copy assignment operator (non-copyable)
EnemySpawnSystem(EnemySpawnSystem &&)=delete
Deleted move constructor (non-movable)
EnemySpawnSystem & operator=(EnemySpawnSystem &&)=delete
Deleted move assignment operator (non-movable)
size_t getCurrentWaveIndex() const
Get current wave index.
float m_levelTime
Elapsed time since level start (seconds)
void setEnabled(bool enabled)
Enable or disable enemy spawning.
std::vector< SpawnWave > m_waves
List of all spawn waves for the level.
std::uniform_real_distribution< float > m_yDistribution
Distribution for random Y positions.
float getRandomY()
Generate random Y position for enemy spawn.
size_t m_totalEnemiesSpawned
Total number of enemies spawned this session.
float getSpawnX() const
Get X position for enemy spawns (right side of screen)
float getLevelTime() const
Get elapsed time since level start.
Central entity lifecycle manager for the R-Type game server.
Configuration data for a single enemy spawn wave.
bool bossSpawn
Whether this wave spawns a boss enemy.
float spawnInterval
Time between individual enemy spawns within wave (seconds)
int basicEnemyCount
Number of basic enemies to spawn in this wave.
int spawnedCount
Number of enemies already spawned from this wave (internal counter)
int advancedEnemyCount
Number of advanced enemies to spawn in this wave.
float spawnTime
Time from level start when wave begins (seconds)