r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
gme::WaveManager Class Reference

Manages wave-based enemy spawning with configurable patterns and timing. More...

#include <WaveManager.hpp>

+ Collaboration diagram for gme::WaveManager:

Public Member Functions

 WaveManager (EntityManager &entityManager)
 Constructor.
 
 ~WaveManager ()=default
 Destructor.
 
 WaveManager (const WaveManager &)=delete
 Deleted copy constructor (non-copyable)
 
WaveManageroperator= (const WaveManager &)=delete
 Deleted copy assignment operator (non-copyable)
 
 WaveManager (WaveManager &&)=delete
 Deleted move constructor (non-movable)
 
WaveManageroperator= (WaveManager &&)=delete
 Deleted move assignment operator (non-movable)
 
void update (ecs::Registry &registry, float dt, int screenWidth)
 Update wave manager logic (called each frame)
 
bool isReady () const
 Check if initial delay has passed and waves can start.
 
void start ()
 Start the wave system.
 
void reset ()
 Stop and reset the wave system to initial state.
 
bool isActive () const
 Check if wave system is currently active.
 
int getCurrentWave () const
 Get current wave index.
 
size_t getTotalWaves () const
 Get total number of configured waves.
 
bool isCompleted () const
 Check if all waves have been completed.
 
void addWave (const Wave &wave)
 Add a custom wave to the wave list.
 
void clearWaves ()
 Clear all configured waves.
 
void setupDefaultWaves ()
 Initialize with default wave patterns.
 

Private Member Functions

void startNextWave ()
 Start the next wave in sequence.
 
bool isWaveCleared () const
 Check if current wave is cleared of all enemies.
 
void processSpawns (float dt, int screenWidth)
 Process enemy spawns for current wave.
 
void createWave1 ()
 Create wave 1 configuration (basic introduction wave)
 
void createWave2 ()
 Create wave 2 configuration (mixed enemies)
 
void createWave3 ()
 Create wave 3 configuration (increased difficulty)
 
void createWave4 ()
 Create wave 4 configuration (final standard wave)
 
void createBossWave ()
 Create boss wave configuration (final challenge)
 

Private Attributes

EntityManagerm_entityManager
 Reference to entity manager for spawning.
 
std::vector< Wavem_waves
 List of all configured waves.
 
int m_currentWaveIndex
 Index of current/next wave (0-based)
 
float m_waveTimer
 Timer for current wave duration.
 
float m_spawnTimer
 Timer for processing enemy spawns.
 
bool m_active
 Whether wave system is active.
 
bool m_completed
 Whether all waves are completed.
 
bool m_waveInProgress
 Whether a wave is currently spawning.
 
bool m_initialDelayPassed
 Whether initial delay has elapsed.
 
float m_initialDelayTimer
 Timer for initial delay countdown.
 
std::vector< bool > m_enemiesSpawned
 Track which enemies in current wave have spawned.
 

Static Private Attributes

static constexpr float INITIAL_DELAY = 0.5f
 Initial delay in seconds (synced with client)
 

Detailed Description

Manages wave-based enemy spawning with configurable patterns and timing.

This class provides a complete wave management system for the R-Type server. Features include:

  • Sequential wave progression (5 waves: 4 standard waves + 1 boss wave)
  • Time-based or clear-based wave advancement
  • Per-enemy spawn delays within waves
  • Initial delay synchronization with client stage spawning
  • Wave completion detection
  • Customizable wave patterns
  • Default wave configurations for standard gameplay

The manager maintains internal state for current wave, spawn timers, and completion status. It coordinates with the EntityManager to spawn enemies at appropriate times and ensures proper game progression through all waves.

Definition at line 73 of file WaveManager.hpp.

Constructor & Destructor Documentation

◆ WaveManager() [1/3]

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

Constructor.

Parameters
entityManagerReference to entity manager for spawning enemies

Initializes the wave manager with default wave configurations

Definition at line 13 of file WaveManager.cpp.

◆ ~WaveManager()

gme::WaveManager::~WaveManager ( )
default

Destructor.

◆ WaveManager() [2/3]

gme::WaveManager::WaveManager ( const WaveManager & )
delete

Deleted copy constructor (non-copyable)

◆ WaveManager() [3/3]

gme::WaveManager::WaveManager ( WaveManager && )
delete

Deleted move constructor (non-movable)

Member Function Documentation

◆ addWave()

void gme::WaveManager::addWave ( const Wave & wave)

Add a custom wave to the wave list.

Parameters
waveWave configuration to add

Appends a wave to the end of the wave sequence

Definition at line 134 of file WaveManager.cpp.

References m_waves.

◆ clearWaves()

void gme::WaveManager::clearWaves ( )

Clear all configured waves.

Removes all waves from the manager. Use setupDefaultWaves() to restore defaults.

Definition at line 136 of file WaveManager.cpp.

References m_waves, and reset().

Referenced by setupDefaultWaves().

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

◆ createBossWave()

void gme::WaveManager::createBossWave ( )
private

Create boss wave configuration (final challenge)

60-second wave featuring the boss enemy

Definition at line 352 of file WaveManager.cpp.

References gme::BOSS, gme::Wave::duration, gme::Wave::enemies, gme::ENEMY_ADVANCED, gme::ENEMY_BASIC, m_waves, gme::Wave::waitForClear, and gme::Wave::waveNumber.

Referenced by setupDefaultWaves().

+ Here is the caller graph for this function:

◆ createWave1()

void gme::WaveManager::createWave1 ( )
private

Create wave 1 configuration (basic introduction wave)

30-second wave with basic enemies

Definition at line 241 of file WaveManager.cpp.

References gme::Wave::duration, gme::Wave::enemies, gme::ENEMY_BASIC, m_waves, gme::Wave::waitForClear, and gme::Wave::waveNumber.

Referenced by setupDefaultWaves().

+ Here is the caller graph for this function:

◆ createWave2()

void gme::WaveManager::createWave2 ( )
private

Create wave 2 configuration (mixed enemies)

30-second wave with basic and advanced enemies

Definition at line 265 of file WaveManager.cpp.

References gme::Wave::duration, gme::Wave::enemies, gme::ENEMY_ADVANCED, gme::ENEMY_BASIC, m_waves, gme::Wave::waitForClear, and gme::Wave::waveNumber.

Referenced by setupDefaultWaves().

+ Here is the caller graph for this function:

◆ createWave3()

void gme::WaveManager::createWave3 ( )
private

Create wave 3 configuration (increased difficulty)

30-second wave with more advanced enemies

Definition at line 291 of file WaveManager.cpp.

References gme::Wave::duration, gme::Wave::enemies, gme::ENEMY_ADVANCED, gme::ENEMY_BASIC, m_waves, gme::Wave::waitForClear, and gme::Wave::waveNumber.

Referenced by setupDefaultWaves().

+ Here is the caller graph for this function:

◆ createWave4()

void gme::WaveManager::createWave4 ( )
private

Create wave 4 configuration (final standard wave)

30-second wave with challenging enemy patterns

Definition at line 319 of file WaveManager.cpp.

References gme::Wave::duration, gme::Wave::enemies, gme::ENEMY_ADVANCED, gme::ENEMY_BASIC, m_waves, gme::Wave::waitForClear, and gme::Wave::waveNumber.

Referenced by setupDefaultWaves().

+ Here is the caller graph for this function:

◆ getCurrentWave()

int gme::WaveManager::getCurrentWave ( ) const
inline

Get current wave index.

Returns
Current wave index (0-based)

Returns the index of the currently active or next wave

Definition at line 137 of file WaveManager.hpp.

References m_currentWaveIndex.

◆ getTotalWaves()

size_t gme::WaveManager::getTotalWaves ( ) const
inline

Get total number of configured waves.

Returns
Total wave count (default: 5)

Definition at line 143 of file WaveManager.hpp.

References m_waves.

◆ isActive()

bool gme::WaveManager::isActive ( ) const
inline

Check if wave system is currently active.

Returns
True if wave system is running

Definition at line 130 of file WaveManager.hpp.

References m_active.

◆ isCompleted()

bool gme::WaveManager::isCompleted ( ) const
inline

Check if all waves have been completed.

Returns
True if all waves are finished

Returns true when the last wave has completed and no more waves remain

Definition at line 150 of file WaveManager.hpp.

References m_completed.

◆ isReady()

bool gme::WaveManager::isReady ( ) const
inline

Check if initial delay has passed and waves can start.

Returns
True if initial delay has elapsed

Initial delay synchronizes wave spawning with client stage initialization

Definition at line 112 of file WaveManager.hpp.

References m_initialDelayPassed.

◆ isWaveCleared()

bool gme::WaveManager::isWaveCleared ( ) const
private

Check if current wave is cleared of all enemies.

Returns
True if no enemies remain from current wave

Used for waves with waitForClear flag to determine wave completion

Definition at line 176 of file WaveManager.cpp.

References gme::EntityManager::getEnemies(), and m_entityManager.

Referenced by update().

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

◆ operator=() [1/2]

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

Deleted copy assignment operator (non-copyable)

◆ operator=() [2/2]

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

Deleted move assignment operator (non-movable)

◆ processSpawns()

void gme::WaveManager::processSpawns ( float dt,
int screenWidth )
private

Process enemy spawns for current wave.

Parameters
dtDelta time since last frame
screenWidthScreen width for spawn positioning

Checks spawn delays and creates enemies at appropriate times

Definition at line 183 of file WaveManager.cpp.

References gme::BOSS, gme::EntityManager::createAdvancedEnemy(), gme::EntityManager::createBasicEnemy(), gme::EntityManager::createBoss(), gme::Wave::enemies, gme::ENEMY_ADVANCED, gme::ENEMY_BASIC, gme::EnemySpawn::health, m_currentWaveIndex, m_enemiesSpawned, m_entityManager, m_spawnTimer, m_waves, gme::EnemySpawn::spawnDelay, gme::EnemySpawn::type, gme::EnemySpawn::x, and gme::EnemySpawn::y.

Referenced by update().

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

◆ reset()

void gme::WaveManager::reset ( )

Stop and reset the wave system to initial state.

Stops wave processing, resets all timers, and clears wave progress

Definition at line 120 of file WaveManager.cpp.

References m_active, m_completed, m_currentWaveIndex, m_enemiesSpawned, m_initialDelayPassed, m_initialDelayTimer, m_spawnTimer, m_waveInProgress, and m_waveTimer.

Referenced by clearWaves().

+ Here is the caller graph for this function:

◆ setupDefaultWaves()

void gme::WaveManager::setupDefaultWaves ( )

Initialize with default wave patterns.

Creates 5 predefined waves: 4 standard waves (30s each) + 1 boss wave (60s)

Definition at line 142 of file WaveManager.cpp.

References clearWaves(), createBossWave(), createWave1(), createWave2(), createWave3(), createWave4(), and m_waves.

+ Here is the call graph for this function:

◆ start()

void gme::WaveManager::start ( )

Start the wave system.

Activates wave processing and begins initial delay countdown

Definition at line 106 of file WaveManager.cpp.

References INITIAL_DELAY, m_active, m_completed, m_currentWaveIndex, m_initialDelayPassed, m_initialDelayTimer, m_spawnTimer, m_waveInProgress, m_waves, and m_waveTimer.

◆ startNextWave()

void gme::WaveManager::startNextWave ( )
private

Start the next wave in sequence.

Advances to next wave, resets timers, and initializes spawn tracking

Definition at line 153 of file WaveManager.cpp.

References gme::Wave::enemies, m_completed, m_currentWaveIndex, m_enemiesSpawned, m_spawnTimer, m_waveInProgress, m_waves, and m_waveTimer.

Referenced by update().

+ Here is the caller graph for this function:

◆ update()

void gme::WaveManager::update ( ecs::Registry & registry,
float dt,
int screenWidth )

Update wave manager logic (called each frame)

Parameters
registryECS registry containing all game entities
dtDelta time since last frame (in seconds)
screenWidthScreen width for spawn X positioning

Processes initial delay, advances wave timers, spawns enemies according to wave configurations, and checks for wave completion conditions

Definition at line 20 of file WaveManager.cpp.

References gme::Wave::duration, INITIAL_DELAY, isWaveCleared(), m_active, m_completed, m_currentWaveIndex, m_initialDelayPassed, m_initialDelayTimer, m_spawnTimer, m_waveInProgress, m_waves, m_waveTimer, gme::Wave::onComplete, processSpawns(), startNextWave(), and gme::Wave::waitForClear.

+ Here is the call graph for this function:

Member Data Documentation

◆ INITIAL_DELAY

float gme::WaveManager::INITIAL_DELAY = 0.5f
staticconstexprprivate

Initial delay in seconds (synced with client)

Definition at line 184 of file WaveManager.hpp.

Referenced by start(), and update().

◆ m_active

bool gme::WaveManager::m_active
private

Whether wave system is active.

Definition at line 177 of file WaveManager.hpp.

Referenced by isActive(), reset(), start(), and update().

◆ m_completed

bool gme::WaveManager::m_completed
private

Whether all waves are completed.

Definition at line 178 of file WaveManager.hpp.

Referenced by isCompleted(), reset(), start(), startNextWave(), and update().

◆ m_currentWaveIndex

int gme::WaveManager::m_currentWaveIndex
private

Index of current/next wave (0-based)

Definition at line 174 of file WaveManager.hpp.

Referenced by getCurrentWave(), processSpawns(), reset(), start(), startNextWave(), and update().

◆ m_enemiesSpawned

std::vector<bool> gme::WaveManager::m_enemiesSpawned
private

Track which enemies in current wave have spawned.

Definition at line 182 of file WaveManager.hpp.

Referenced by processSpawns(), reset(), and startNextWave().

◆ m_entityManager

EntityManager& gme::WaveManager::m_entityManager
private

Reference to entity manager for spawning.

Definition at line 172 of file WaveManager.hpp.

Referenced by isWaveCleared(), and processSpawns().

◆ m_initialDelayPassed

bool gme::WaveManager::m_initialDelayPassed
private

Whether initial delay has elapsed.

Definition at line 180 of file WaveManager.hpp.

Referenced by isReady(), reset(), start(), and update().

◆ m_initialDelayTimer

float gme::WaveManager::m_initialDelayTimer
private

Timer for initial delay countdown.

Definition at line 181 of file WaveManager.hpp.

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

◆ m_spawnTimer

float gme::WaveManager::m_spawnTimer
private

Timer for processing enemy spawns.

Definition at line 176 of file WaveManager.hpp.

Referenced by processSpawns(), reset(), start(), startNextWave(), and update().

◆ m_waveInProgress

bool gme::WaveManager::m_waveInProgress
private

Whether a wave is currently spawning.

Definition at line 179 of file WaveManager.hpp.

Referenced by reset(), start(), startNextWave(), and update().

◆ m_waves

std::vector<Wave> gme::WaveManager::m_waves
private

◆ m_waveTimer

float gme::WaveManager::m_waveTimer
private

Timer for current wave duration.

Definition at line 175 of file WaveManager.hpp.

Referenced by reset(), start(), startNextWave(), and update().


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