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

Main multiplayer game scene handling networked gameplay. More...

#include <GameMulti.hpp>

+ Inheritance diagram for gme::GameMulti:
+ Collaboration diagram for gme::GameMulti:

Classes

struct  PendingInput
 Input command pending server acknowledgment. More...
 

Public Member Functions

 GameMulti (eng::id assignedId, const std::shared_ptr< eng::IRenderer > &renderer, const std::shared_ptr< eng::IAudio > &audio, float skinIndex, bool &showDebug, uint32_t sessionId)
 Constructor.
 
 ~GameMulti () override=default
 Destructor.
 
 GameMulti (const GameMulti &other)=delete
 Deleted copy constructor (non-copyable)
 
GameMultioperator= (const GameMulti &other)=delete
 Deleted copy assignment operator (non-copyable)
 
 GameMulti (GameMulti &&other)=delete
 Deleted move constructor (non-movable)
 
GameMultioperator= (GameMulti &&other)=delete
 Deleted move assignment operator (non-movable)
 
void update (float dt, const eng::WindowSize &size) override
 Update the game scene (called each frame)
 
void event (const eng::Event &event) override
 Handle input events.
 
void updatePlayerSkin ()
 Update the local player's visual skin/appearance.
 
bool & playMusic ()
 Get reference to music playback flag.
 
- Public Member Functions inherited from eng::AScene
 AScene (const id assignedId)
 
 ~AScene () override=default
 
 AScene (const AScene &other)=delete
 
 AScene (AScene &&other)=delete
 
ASceneoperator= (const AScene &other)=delete
 
ASceneoperator= (AScene &&other)=delete
 
std::string & getName () override
 
id getId () const override
 
ecs::RegistrygetRegistry () override
 
void setName (const std::string &newName) override
 
void addSystem (std::unique_ptr< ecs::ISystem > system) override
 
void updateSystems (const float dt) override
 
- Public Member Functions inherited from eng::IScene
virtual ~IScene ()=default
 

Public Attributes

std::function< void()> onGameOver
 Callback invoked when game ends.
 

Private Member Functions

void setupEventSubscriptions () const
 Subscribe to event bus events.
 
void processEventBus ()
 Process pending events from the event bus.
 
void handleWorldStateUpdate (const utl::Event &event)
 Handle world state update from server.
 
void preloadCommonTextures ()
 Preload commonly used textures.
 
void updateInterpolation (std::unordered_map< uint32_t, InterpolationData > &dataMap, std::unordered_map< uint32_t, ecs::Entity > &entityMap, float smoothFactor, float dt, ecs::Registry &registry)
 Update entity position interpolation.
 
void updateInterpolation (std::unordered_map< uint32_t, InterpolationData > &dataMap, std::unordered_map< uint32_t, ecs::Entity > &entityMap, float smoothFactor, float dt, ecs::Registry &registry) const
 Update entity position interpolation (const version)
 

Private Attributes

ecs::Entity m_localPlayerEntity
 Local player entity.
 
std::unordered_map< uint32_t, ecs::Entitym_remotePlayers
 Map of session ID to remote player entities.
 
const std::shared_ptr< eng::IAudio > & m_audio
 Audio interface reference.
 
const std::shared_ptr< eng::IRenderer > & m_renderer
 Renderer interface reference.
 
float m_skinIndex
 Local player skin index.
 
std::unique_ptr< PlayerControllerMultim_playerController
 Player input controller.
 
std::unique_ptr< HUDSystemm_hudSystem
 HUD rendering system.
 
std::unordered_map< eng::Key, bool > m_keysPressed
 Current key press states.
 
bool & m_showDebug
 Debug mode flag reference.
 
bool m_playMusic = false
 Music playback flag.
 
uint32_t m_sessionId
 Local player session ID.
 
uint32_t m_eventComponentId = 10
 Event bus component ID.
 
std::unique_ptr< StageManagerm_stageManager
 Stage/level manager.
 
std::unordered_map< uint32_t, ecs::Entitym_projectileEntities
 Map of projectile ID to entity.
 
std::unordered_map< uint32_t, ecs::Entitym_enemyEntities
 Map of enemy ID to entity.
 
std::unordered_map< uint32_t, InterpolationDatam_remotePlayerData
 Interpolation data for remote players.
 
std::unordered_map< uint32_t, InterpolationDatam_projectileData
 Interpolation data for projectiles.
 
std::unordered_map< uint32_t, InterpolationDatam_enemyData
 Interpolation data for enemies.
 
std::unordered_map< uint32_t, uint32_t > m_playerSkinMap
 Map of player session ID to skin index.
 
std::deque< PendingInputm_inputHistory
 History of unacknowledged inputs.
 
uint32_t m_lastAckSeqId = 0
 Last acknowledged input sequence ID.
 
bool m_starfieldCreated = false
 Flag indicating if starfield background was created.
 
ecs::Entity m_beginSoundEntity {}
 Entity for game start sound.
 
ecs::Entity m_bossMusicEntity {}
 Entity for boss music.
 
float m_bossMusicTimer = 0.0f
 Timer for boss music duration.
 
bool m_bossMusicStarted = false
 Flag indicating if boss music has started.
 
std::unordered_set< std::string > m_loadedTextures
 Cache of loaded texture paths.
 
std::unordered_set< std::string > m_loadedFonts
 Cache of loaded font paths.
 
bool m_firstWorldState = true
 Flag indicating if this is the first world state (for player skin init)
 

Static Private Attributes

static constexpr float REMOTE_PLAYER_SMOOTH_FACTOR = 0.25f
 Interpolation speed for remote players.
 
static constexpr float PROJECTILE_SMOOTH_FACTOR = 0.5f
 Interpolation speed for projectiles.
 
static constexpr float ENEMY_SMOOTH_FACTOR = 0.18f
 Interpolation speed for enemies.
 
static constexpr float BOSS_MUSIC_DURATION = 40.0f
 Duration of boss music in seconds.
 

Additional Inherited Members

- Protected Attributes inherited from eng::AScene
utl::EventBusm_eventBus = utl::EventBus::getInstance()
 
std::uint32_t m_eventComponentId = 0
 

Detailed Description

Main multiplayer game scene handling networked gameplay.

This scene manages the core multiplayer game loop including:

  • Network synchronization with game server
  • Local and remote player entity management
  • Entity interpolation for smooth rendering
  • Client-side prediction for responsive controls
  • Enemy and projectile synchronization
  • HUD and game state display
  • Audio management (music and sound effects)
  • Stage progression

The scene uses event bus communication to receive world state updates from the network client and applies interpolation to create smooth visuals despite network latency and packet timing.

Definition at line 67 of file GameMulti.hpp.

Constructor & Destructor Documentation

◆ GameMulti() [1/3]

gme::GameMulti::GameMulti ( eng::id assignedId,
const std::shared_ptr< eng::IRenderer > & renderer,
const std::shared_ptr< eng::IAudio > & audio,
float skinIndex,
bool & showDebug,
uint32_t sessionId )

Constructor.

Parameters
assignedIdScene ID assigned by the engine
rendererShared pointer to the renderer interface
audioShared pointer to the audio interface
skinIndexPlayer skin/appearance index
showDebugReference to debug mode flag
sessionIdNetwork session ID of the local player

Definition at line 16 of file gameMulti.cpp.

References utl::Path::Audio::AUDIO_BEGIN, ecs::IComponent::id, m_beginSoundEntity, m_hudSystem, m_loadedFonts, m_loadedTextures, m_localPlayerEntity, m_playerController, m_playerSkinMap, m_sessionId, m_stageManager, preloadCommonTextures(), setupEventSubscriptions(), utl::GameConfig::Player::SPRITE_HEIGHT, ecs::Scale::x, ecs::Transform::x, and ecs::Transform::y.

+ Here is the call graph for this function:

◆ ~GameMulti()

gme::GameMulti::~GameMulti ( )
overridedefault

Destructor.

◆ GameMulti() [2/3]

gme::GameMulti::GameMulti ( const GameMulti & other)
delete

Deleted copy constructor (non-copyable)

◆ GameMulti() [3/3]

gme::GameMulti::GameMulti ( GameMulti && other)
delete

Deleted move constructor (non-movable)

Member Function Documentation

◆ event()

void gme::GameMulti::event ( const eng::Event & event)
overridevirtual

Handle input events.

Parameters
eventInput event (keyboard, mouse, etc.)

Implements eng::IScene.

Definition at line 766 of file gameMulti.cpp.

◆ handleWorldStateUpdate()

void gme::GameMulti::handleWorldStateUpdate ( const utl::Event & event)
private

◆ operator=() [1/2]

GameMulti & gme::GameMulti::operator= ( const GameMulti & other)
delete

Deleted copy assignment operator (non-copyable)

◆ operator=() [2/2]

GameMulti & gme::GameMulti::operator= ( GameMulti && other)
delete

Deleted move assignment operator (non-movable)

◆ playMusic()

bool & gme::GameMulti::playMusic ( )
inline

Get reference to music playback flag.

Returns
Reference to music flag

Definition at line 120 of file GameMulti.hpp.

References m_playMusic.

◆ preloadCommonTextures()

void gme::GameMulti::preloadCommonTextures ( )
private

◆ processEventBus()

void gme::GameMulti::processEventBus ( )
private

Process pending events from the event bus.

Polls and handles network events from the event bus

Definition at line 185 of file gameMulti.cpp.

References utl::GAME_OVER, utl::GAME_START, utl::EventBus::getInstance(), utl::INFO, utl::Logger::log(), utl::PLAYER_INPUT_RECEIVED, and utl::WORLD_STATE_RECEIVED.

+ Here is the call graph for this function:

◆ setupEventSubscriptions()

void gme::GameMulti::setupEventSubscriptions ( ) const
private

Subscribe to event bus events.

Registers callbacks for world state updates and entity events

Definition at line 175 of file gameMulti.cpp.

References utl::GAME_OVER, utl::GAME_START, utl::EventBus::getInstance(), utl::PLAYER_INPUT_RECEIVED, utl::EventBus::registerComponent(), utl::EventBus::subscribe(), and utl::WORLD_STATE_RECEIVED.

Referenced by GameMulti().

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

◆ update()

void gme::GameMulti::update ( float dt,
const eng::WindowSize & size )
overridevirtual

Update the game scene (called each frame)

Parameters
dtDelta time since last frame (in seconds)
sizeCurrent window size

Processes network events, updates interpolation, runs game systems

Implements eng::IScene.

Definition at line 688 of file gameMulti.cpp.

References utl::Path::Audio::AUDIO_BOSS, eng::Playing, and gme::StageManager::stopScrolling().

+ Here is the call graph for this function:

◆ updateInterpolation() [1/2]

void gme::GameMulti::updateInterpolation ( std::unordered_map< uint32_t, InterpolationData > & dataMap,
std::unordered_map< uint32_t, ecs::Entity > & entityMap,
float smoothFactor,
float dt,
ecs::Registry & registry )
private

Update entity position interpolation.

Parameters
dataMapMap of entity ID to interpolation data
entityMapMap of entity ID to ECS entity
smoothFactorInterpolation smoothing factor (0.0-1.0)
dtDelta time for frame-rate independent interpolation
registryECS registry containing entities

Smoothly interpolates entity positions between server updates

Definition at line 772 of file gameMulti.cpp.

References ecs::Registry::getComponent().

+ Here is the call graph for this function:

◆ updateInterpolation() [2/2]

void gme::GameMulti::updateInterpolation ( std::unordered_map< uint32_t, InterpolationData > & dataMap,
std::unordered_map< uint32_t, ecs::Entity > & entityMap,
float smoothFactor,
float dt,
ecs::Registry & registry ) const
private

Update entity position interpolation (const version)

Parameters
dataMapMap of entity ID to interpolation data
entityMapMap of entity ID to ECS entity
smoothFactorInterpolation smoothing factor (0.0-1.0)
dtDelta time for frame-rate independent interpolation
registryECS registry containing entities

◆ updatePlayerSkin()

void gme::GameMulti::updatePlayerSkin ( )

Update the local player's visual skin/appearance.

Updates player sprite based on skin index

Definition at line 808 of file gameMulti.cpp.

References utl::GameConfig::Player::SPRITE_HEIGHT.

Member Data Documentation

◆ BOSS_MUSIC_DURATION

float gme::GameMulti::BOSS_MUSIC_DURATION = 40.0f
staticconstexprprivate

Duration of boss music in seconds.

Definition at line 223 of file GameMulti.hpp.

◆ ENEMY_SMOOTH_FACTOR

float gme::GameMulti::ENEMY_SMOOTH_FACTOR = 0.18f
staticconstexprprivate

Interpolation speed for enemies.

Definition at line 216 of file GameMulti.hpp.

◆ m_audio

const std::shared_ptr<eng::IAudio>& gme::GameMulti::m_audio
private

Audio interface reference.

Definition at line 179 of file GameMulti.hpp.

◆ m_beginSoundEntity

ecs::Entity gme::GameMulti::m_beginSoundEntity {}
private

Entity for game start sound.

Definition at line 219 of file GameMulti.hpp.

Referenced by GameMulti().

◆ m_bossMusicEntity

ecs::Entity gme::GameMulti::m_bossMusicEntity {}
private

Entity for boss music.

Definition at line 220 of file GameMulti.hpp.

◆ m_bossMusicStarted

bool gme::GameMulti::m_bossMusicStarted = false
private

Flag indicating if boss music has started.

Definition at line 222 of file GameMulti.hpp.

◆ m_bossMusicTimer

float gme::GameMulti::m_bossMusicTimer = 0.0f
private

Timer for boss music duration.

Definition at line 221 of file GameMulti.hpp.

◆ m_enemyData

std::unordered_map<uint32_t, InterpolationData> gme::GameMulti::m_enemyData
private

Interpolation data for enemies.

Definition at line 198 of file GameMulti.hpp.

◆ m_enemyEntities

std::unordered_map<uint32_t, ecs::Entity> gme::GameMulti::m_enemyEntities
private

Map of enemy ID to entity.

Definition at line 193 of file GameMulti.hpp.

◆ m_eventComponentId

uint32_t gme::GameMulti::m_eventComponentId = 10
private

Event bus component ID.

Definition at line 189 of file GameMulti.hpp.

◆ m_firstWorldState

bool gme::GameMulti::m_firstWorldState = true
private

Flag indicating if this is the first world state (for player skin init)

Definition at line 228 of file GameMulti.hpp.

◆ m_hudSystem

std::unique_ptr<HUDSystem> gme::GameMulti::m_hudSystem
private

HUD rendering system.

Definition at line 183 of file GameMulti.hpp.

Referenced by GameMulti().

◆ m_inputHistory

std::deque<PendingInput> gme::GameMulti::m_inputHistory
private

History of unacknowledged inputs.

Definition at line 211 of file GameMulti.hpp.

◆ m_keysPressed

std::unordered_map<eng::Key, bool> gme::GameMulti::m_keysPressed
private

Current key press states.

Definition at line 184 of file GameMulti.hpp.

◆ m_lastAckSeqId

uint32_t gme::GameMulti::m_lastAckSeqId = 0
private

Last acknowledged input sequence ID.

Definition at line 212 of file GameMulti.hpp.

◆ m_loadedFonts

std::unordered_set<std::string> gme::GameMulti::m_loadedFonts
private

Cache of loaded font paths.

Definition at line 226 of file GameMulti.hpp.

Referenced by GameMulti().

◆ m_loadedTextures

std::unordered_set<std::string> gme::GameMulti::m_loadedTextures
private

Cache of loaded texture paths.

Definition at line 225 of file GameMulti.hpp.

Referenced by GameMulti().

◆ m_localPlayerEntity

ecs::Entity gme::GameMulti::m_localPlayerEntity
private

Local player entity.

Definition at line 176 of file GameMulti.hpp.

Referenced by GameMulti().

◆ m_playerController

std::unique_ptr<PlayerControllerMulti> gme::GameMulti::m_playerController
private

Player input controller.

Definition at line 182 of file GameMulti.hpp.

Referenced by GameMulti().

◆ m_playerSkinMap

std::unordered_map<uint32_t, uint32_t> gme::GameMulti::m_playerSkinMap
private

Map of player session ID to skin index.

Definition at line 199 of file GameMulti.hpp.

Referenced by GameMulti().

◆ m_playMusic

bool gme::GameMulti::m_playMusic = false
private

Music playback flag.

Definition at line 186 of file GameMulti.hpp.

Referenced by playMusic().

◆ m_projectileData

std::unordered_map<uint32_t, InterpolationData> gme::GameMulti::m_projectileData
private

Interpolation data for projectiles.

Definition at line 197 of file GameMulti.hpp.

◆ m_projectileEntities

std::unordered_map<uint32_t, ecs::Entity> gme::GameMulti::m_projectileEntities
private

Map of projectile ID to entity.

Definition at line 192 of file GameMulti.hpp.

◆ m_remotePlayerData

std::unordered_map<uint32_t, InterpolationData> gme::GameMulti::m_remotePlayerData
private

Interpolation data for remote players.

Definition at line 196 of file GameMulti.hpp.

◆ m_remotePlayers

std::unordered_map<uint32_t, ecs::Entity> gme::GameMulti::m_remotePlayers
private

Map of session ID to remote player entities.

Definition at line 177 of file GameMulti.hpp.

◆ m_renderer

const std::shared_ptr<eng::IRenderer>& gme::GameMulti::m_renderer
private

Renderer interface reference.

Definition at line 180 of file GameMulti.hpp.

◆ m_sessionId

uint32_t gme::GameMulti::m_sessionId
private

Local player session ID.

Definition at line 188 of file GameMulti.hpp.

Referenced by GameMulti().

◆ m_showDebug

bool& gme::GameMulti::m_showDebug
private

Debug mode flag reference.

Definition at line 185 of file GameMulti.hpp.

◆ m_skinIndex

float gme::GameMulti::m_skinIndex
private

Local player skin index.

Definition at line 181 of file GameMulti.hpp.

◆ m_stageManager

std::unique_ptr<StageManager> gme::GameMulti::m_stageManager
private

Stage/level manager.

Definition at line 190 of file GameMulti.hpp.

Referenced by GameMulti().

◆ m_starfieldCreated

bool gme::GameMulti::m_starfieldCreated = false
private

Flag indicating if starfield background was created.

Definition at line 218 of file GameMulti.hpp.

◆ onGameOver

std::function<void()> gme::GameMulti::onGameOver

Callback invoked when game ends.

Definition at line 123 of file GameMulti.hpp.

◆ PROJECTILE_SMOOTH_FACTOR

float gme::GameMulti::PROJECTILE_SMOOTH_FACTOR = 0.5f
staticconstexprprivate

Interpolation speed for projectiles.

Definition at line 215 of file GameMulti.hpp.

◆ REMOTE_PLAYER_SMOOTH_FACTOR

float gme::GameMulti::REMOTE_PLAYER_SMOOTH_FACTOR = 0.25f
staticconstexprprivate

Interpolation speed for remote players.

Definition at line 214 of file GameMulti.hpp.


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