r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
gme::EnemySpawnSystem Class Referencefinal

Server-side system that manages enemy wave spawning and level progression. More...

#include <EnemySpawnSystem.hpp>

+ Inheritance diagram for gme::EnemySpawnSystem:
+ Collaboration diagram for gme::EnemySpawnSystem:

Public Member Functions

 EnemySpawnSystem (EntityManager &entityManager)
 Constructor.
 
 ~EnemySpawnSystem () override=default
 Destructor.
 
 EnemySpawnSystem (const EnemySpawnSystem &)=delete
 Deleted copy constructor (non-copyable)
 
EnemySpawnSystemoperator= (const EnemySpawnSystem &)=delete
 Deleted copy assignment operator (non-copyable)
 
 EnemySpawnSystem (EnemySpawnSystem &&)=delete
 Deleted move constructor (non-movable)
 
EnemySpawnSystemoperator= (EnemySpawnSystem &&)=delete
 Deleted move assignment operator (non-movable)
 
void update (ecs::Registry &registry, float deltaTime) override
 Update the spawn system (called each frame)
 
void reset ()
 Reset the spawn system to initial state.
 
void setEnabled (bool enabled)
 Enable or disable enemy spawning.
 
bool isEnabled () const
 Check if enemy spawning is currently enabled.
 
size_t getTotalEnemiesSpawned () const
 Get total number of enemies spawned since reset.
 
size_t getCurrentWaveIndex () const
 Get current wave index.
 
float getLevelTime () const
 Get elapsed time since level start.
 
- Public Member Functions inherited from ecs::ASystem
bool isEnable () override
 
void setEnable (const bool enable) override
 
- Public Member Functions inherited from ecs::ISystem
virtual ~ISystem ()=default
 

Private Member Functions

void initializeWaves ()
 Initialize all spawn waves for the level.
 
void processWave (SpawnWave &wave, float deltaTime)
 Process a single spawn wave.
 
float getRandomY ()
 Generate random Y position for enemy spawn.
 
float getSpawnX () const
 Get X position for enemy spawns (right side of screen)
 

Private Attributes

EntityManagerm_entityManager
 Entity manager for spawning enemies.
 
float m_levelTime
 Elapsed time since level start (seconds)
 
size_t m_currentWaveIndex
 Index of current/next wave to process.
 
float m_waveSpawnTimer
 Timer for spawning enemies within current wave.
 
bool m_enabled
 Whether spawning is currently enabled.
 
size_t m_totalEnemiesSpawned
 Total number of enemies spawned this session.
 
std::vector< SpawnWavem_waves
 List of all spawn waves for the level.
 
std::mt19937 m_rng
 Random number generator for spawn positions.
 
std::uniform_real_distribution< float > m_yDistribution
 Distribution for random Y positions.
 

Detailed Description

Server-side system that manages enemy wave spawning and level progression.

This ECS system controls the flow of enemy spawns throughout a game session. Features include:

  • Time-based wave triggering
  • Multiple enemy types per wave (basic, advanced, boss)
  • Gradual spawning with configurable intervals
  • Random spawn position generation
  • Wave progression tracking
  • Spawn statistics for debugging

The system maintains internal state for level time and wave progression, and spawns enemies at the right edge of the screen with random Y positions. All spawning is deterministic based on server time to ensure synchronized gameplay across all clients.

Definition at line 59 of file EnemySpawnSystem.hpp.

Constructor & Destructor Documentation

◆ EnemySpawnSystem() [1/3]

gme::EnemySpawnSystem::EnemySpawnSystem ( EntityManager & entityManager)
explicit

Constructor.

Parameters
entityManagerEntity manager for creating enemy entities

Initializes the spawn system and sets up initial wave configurations

Definition at line 13 of file EnemySpawnSystem.cpp.

References utl::INFO, initializeWaves(), utl::Logger::log(), m_rng, and m_waves.

+ Here is the call graph for this function:

◆ ~EnemySpawnSystem()

gme::EnemySpawnSystem::~EnemySpawnSystem ( )
overridedefault

Destructor.

◆ EnemySpawnSystem() [2/3]

gme::EnemySpawnSystem::EnemySpawnSystem ( const EnemySpawnSystem & )
delete

Deleted copy constructor (non-copyable)

◆ EnemySpawnSystem() [3/3]

gme::EnemySpawnSystem::EnemySpawnSystem ( EnemySpawnSystem && )
delete

Deleted move constructor (non-movable)

Member Function Documentation

◆ getCurrentWaveIndex()

size_t gme::EnemySpawnSystem::getCurrentWaveIndex ( ) const
inline

Get current wave index.

Returns
Index of the currently active or next wave

Returns the index in the wave array, useful for level progression tracking

Definition at line 123 of file EnemySpawnSystem.hpp.

References m_currentWaveIndex.

◆ getLevelTime()

float gme::EnemySpawnSystem::getLevelTime ( ) const
inline

Get elapsed time since level start.

Returns
Level time in seconds

Used for wave timing and level progression

Definition at line 130 of file EnemySpawnSystem.hpp.

References m_levelTime.

◆ getRandomY()

float gme::EnemySpawnSystem::getRandomY ( )
private

Generate random Y position for enemy spawn.

Returns
Random Y coordinate within valid screen bounds

Uses uniform distribution to place enemies at various heights

Definition at line 197 of file EnemySpawnSystem.cpp.

References m_rng, and m_yDistribution.

Referenced by processWave().

+ Here is the caller graph for this function:

◆ getSpawnX()

float gme::EnemySpawnSystem::getSpawnX ( ) const
inlineprivate

Get X position for enemy spawns (right side of screen)

Returns
X coordinate for spawn position (2000.0f)

Enemies spawn off-screen to the right and move left

Definition at line 172 of file EnemySpawnSystem.hpp.

Referenced by processWave().

+ Here is the caller graph for this function:

◆ getTotalEnemiesSpawned()

size_t gme::EnemySpawnSystem::getTotalEnemiesSpawned ( ) const
inline

Get total number of enemies spawned since reset.

Returns
Total enemy spawn count

Useful for statistics and debugging

Definition at line 116 of file EnemySpawnSystem.hpp.

References m_totalEnemiesSpawned.

◆ initializeWaves()

void gme::EnemySpawnSystem::initializeWaves ( )
private

Initialize all spawn waves for the level.

Populates the m_waves vector with predefined wave configurations including timing, enemy counts, and boss spawns

Definition at line 85 of file EnemySpawnSystem.cpp.

References gme::SpawnWave::advancedEnemyCount, gme::SpawnWave::basicEnemyCount, gme::SpawnWave::bossSpawn, m_waves, gme::SpawnWave::spawnedCount, gme::SpawnWave::spawnInterval, and gme::SpawnWave::spawnTime.

Referenced by EnemySpawnSystem().

+ Here is the caller graph for this function:

◆ isEnabled()

bool gme::EnemySpawnSystem::isEnabled ( ) const
inline

Check if enemy spawning is currently enabled.

Returns
True if spawning is enabled

Definition at line 109 of file EnemySpawnSystem.hpp.

References m_enabled.

◆ operator=() [1/2]

EnemySpawnSystem & gme::EnemySpawnSystem::operator= ( const EnemySpawnSystem & )
delete

Deleted copy assignment operator (non-copyable)

◆ operator=() [2/2]

EnemySpawnSystem & gme::EnemySpawnSystem::operator= ( EnemySpawnSystem && )
delete

Deleted move assignment operator (non-movable)

◆ processWave()

void gme::EnemySpawnSystem::processWave ( SpawnWave & wave,
float deltaTime )
private

Process a single spawn wave.

Parameters
waveWave configuration to process
deltaTimeTime elapsed since last frame

Handles the spawning of enemies from this wave according to spawn interval, spawning enemies gradually over time

Definition at line 140 of file EnemySpawnSystem.cpp.

References gme::SpawnWave::advancedEnemyCount, gme::SpawnWave::basicEnemyCount, gme::SpawnWave::bossSpawn, gme::EntityManager::createAdvancedEnemy(), gme::EntityManager::createBasicEnemy(), gme::EntityManager::createBoss(), getRandomY(), getSpawnX(), utl::INFO, utl::Logger::log(), m_entityManager, m_totalEnemiesSpawned, m_waveSpawnTimer, gme::SpawnWave::spawnedCount, and gme::SpawnWave::spawnInterval.

Referenced by update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset()

void gme::EnemySpawnSystem::reset ( )

Reset the spawn system to initial state.

Resets level time, wave index, and spawn counters. Used when starting a new game.

Definition at line 68 of file EnemySpawnSystem.cpp.

References utl::INFO, utl::Logger::log(), m_currentWaveIndex, m_enabled, m_levelTime, m_totalEnemiesSpawned, m_waves, and m_waveSpawnTimer.

+ Here is the call graph for this function:

◆ setEnabled()

void gme::EnemySpawnSystem::setEnabled ( bool enabled)
inline

Enable or disable enemy spawning.

Parameters
enabledTrue to enable spawning, false to disable

When disabled, no enemies will spawn regardless of wave timing

Definition at line 103 of file EnemySpawnSystem.hpp.

References m_enabled.

◆ update()

void gme::EnemySpawnSystem::update ( ecs::Registry & registry,
float deltaTime )
overridevirtual

Update the spawn system (called each frame)

Parameters
registryECS registry containing all entities
deltaTimeTime elapsed since last frame (in seconds)

Advances level time, checks for wave triggers, and spawns enemies according to wave configurations

Implements ecs::ISystem.

Definition at line 26 of file EnemySpawnSystem.cpp.

References utl::INFO, utl::Logger::log(), m_currentWaveIndex, m_enabled, m_levelTime, m_waves, m_waveSpawnTimer, and processWave().

+ Here is the call graph for this function:

Member Data Documentation

◆ m_currentWaveIndex

size_t gme::EnemySpawnSystem::m_currentWaveIndex
private

Index of current/next wave to process.

Definition at line 135 of file EnemySpawnSystem.hpp.

Referenced by getCurrentWaveIndex(), reset(), and update().

◆ m_enabled

bool gme::EnemySpawnSystem::m_enabled
private

Whether spawning is currently enabled.

Definition at line 137 of file EnemySpawnSystem.hpp.

Referenced by isEnabled(), reset(), setEnabled(), and update().

◆ m_entityManager

EntityManager& gme::EnemySpawnSystem::m_entityManager
private

Entity manager for spawning enemies.

Definition at line 133 of file EnemySpawnSystem.hpp.

Referenced by processWave().

◆ m_levelTime

float gme::EnemySpawnSystem::m_levelTime
private

Elapsed time since level start (seconds)

Definition at line 134 of file EnemySpawnSystem.hpp.

Referenced by getLevelTime(), reset(), and update().

◆ m_rng

std::mt19937 gme::EnemySpawnSystem::m_rng
private

Random number generator for spawn positions.

Definition at line 141 of file EnemySpawnSystem.hpp.

Referenced by EnemySpawnSystem(), and getRandomY().

◆ m_totalEnemiesSpawned

size_t gme::EnemySpawnSystem::m_totalEnemiesSpawned
private

Total number of enemies spawned this session.

Definition at line 138 of file EnemySpawnSystem.hpp.

Referenced by getTotalEnemiesSpawned(), processWave(), and reset().

◆ m_waves

std::vector<SpawnWave> gme::EnemySpawnSystem::m_waves
private

List of all spawn waves for the level.

Definition at line 140 of file EnemySpawnSystem.hpp.

Referenced by EnemySpawnSystem(), initializeWaves(), reset(), and update().

◆ m_waveSpawnTimer

float gme::EnemySpawnSystem::m_waveSpawnTimer
private

Timer for spawning enemies within current wave.

Definition at line 136 of file EnemySpawnSystem.hpp.

Referenced by processWave(), reset(), and update().

◆ m_yDistribution

std::uniform_real_distribution<float> gme::EnemySpawnSystem::m_yDistribution
private

Distribution for random Y positions.

Definition at line 142 of file EnemySpawnSystem.hpp.

Referenced by getRandomY().


The documentation for this class was generated from the following files: