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) | |
| GameMulti & | operator= (const GameMulti &other)=delete |
| Deleted copy assignment operator (non-copyable) | |
| GameMulti (GameMulti &&other)=delete | |
| Deleted move constructor (non-movable) | |
| GameMulti & | operator= (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 | |
| AScene & | operator= (const AScene &other)=delete |
| AScene & | operator= (AScene &&other)=delete |
| std::string & | getName () override |
| id | getId () const override |
| ecs::Registry & | getRegistry () 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 ®istry) |
| 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 ®istry) const |
| Update entity position interpolation (const version) | |
Private Attributes | |
| ecs::Entity | m_localPlayerEntity |
| Local player entity. | |
| std::unordered_map< uint32_t, ecs::Entity > | m_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< PlayerControllerMulti > | m_playerController |
| Player input controller. | |
| std::unique_ptr< HUDSystem > | m_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< StageManager > | m_stageManager |
| Stage/level manager. | |
| std::unordered_map< uint32_t, ecs::Entity > | m_projectileEntities |
| Map of projectile ID to entity. | |
| std::unordered_map< uint32_t, ecs::Entity > | m_enemyEntities |
| Map of enemy ID to entity. | |
| std::unordered_map< uint32_t, InterpolationData > | m_remotePlayerData |
| Interpolation data for remote players. | |
| std::unordered_map< uint32_t, InterpolationData > | m_projectileData |
| Interpolation data for projectiles. | |
| std::unordered_map< uint32_t, InterpolationData > | m_enemyData |
| Interpolation data for enemies. | |
| std::unordered_map< uint32_t, uint32_t > | m_playerSkinMap |
| Map of player session ID to skin index. | |
| std::deque< PendingInput > | m_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::EventBus & | m_eventBus = utl::EventBus::getInstance() |
| std::uint32_t | m_eventComponentId = 0 |
Main multiplayer game scene handling networked gameplay.
This scene manages the core multiplayer game loop including:
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.
| 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.
| assignedId | Scene ID assigned by the engine |
| renderer | Shared pointer to the renderer interface |
| audio | Shared pointer to the audio interface |
| skinIndex | Player skin/appearance index |
| showDebug | Reference to debug mode flag |
| sessionId | Network 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:
|
overridedefault |
Destructor.
|
delete |
Deleted copy constructor (non-copyable)
|
delete |
Deleted move constructor (non-movable)
|
overridevirtual |
Handle input events.
| event | Input event (keyboard, mouse, etc.) |
Implements eng::IScene.
Definition at line 766 of file gameMulti.cpp.
|
private |
Handle world state update from server.
| event | World state event containing entity data |
Updates entity positions, creates/destroys entities as needed
Definition at line 217 of file gameMulti.cpp.
References utl::GameConfig::Explosion::ANIMATION_DURATION, utl::GameConfig::Explosion::ANIMATION_FRAMES, rnp::BOSS, utl::GameConfig::Hitbox::BOSS_RADIUS, utl::calculateHitboxOffsets(), utl::Event::data, rnp::Serializer::deserializeWorldState(), rnp::ENEMY, rnp::ENEMY_ADVANCED, utl::GameConfig::Hitbox::ENEMY_RADIUS, rnp::PacketWorldState::entities, utl::GameConfig::Explosion::FRAMES_PER_ROW, utl::EventBus::getInstance(), utl::INFO, utl::GameConfig::Explosion::LIFETIME, utl::Logger::log(), utl::NETWORK_CLIENT, rnp::PLAYER, rnp::PROJECTILE, rnp::PROJECTILE_ENEMY, rnp::PROJECTILE_PLAYER_SUPERCHARGED, utl::EventBus::publish(), utl::REQUEST_DISCONNECT, utl::GameConfig::Explosion::SCALE, utl::GameConfig::Player::SCALE, utl::GameConfig::Explosion::SPRITE_HEIGHT, utl::GameConfig::Player::SPRITE_HEIGHT, utl::GameConfig::Explosion::SPRITE_WIDTH, utl::GameConfig::Player::SPRITE_WIDTH, utl::Path::Texture::TEXTURE_BOSS, utl::Path::Texture::TEXTURE_ENEMY_ADVANCED, utl::Path::Texture::TEXTURE_ENEMY_BASIC, utl::Path::Texture::TEXTURE_ENEMY_PROJECTILE, utl::Path::Texture::TEXTURE_EXPLOSION, utl::Path::Texture::TEXTURE_PLAYER, utl::Path::Texture::TEXTURE_SHOOT, utl::Path::Texture::TEXTURE_SHOOT_CHARGED, and utl::WARNING.
Here is the call graph for this function:Deleted copy assignment operator (non-copyable)
Deleted move assignment operator (non-movable)
|
inline |
Get reference to music playback flag.
Definition at line 120 of file GameMulti.hpp.
References m_playMusic.
|
private |
Preload commonly used textures.
Loads textures into cache to avoid runtime loading hitches
Definition at line 150 of file gameMulti.cpp.
References utl::Path::Texture::TEXTURE_BOSS, utl::Path::Texture::TEXTURE_ENEMY_ADVANCED, utl::Path::Texture::TEXTURE_ENEMY_BASIC, utl::Path::Texture::TEXTURE_ENEMY_PROJECTILE, utl::Path::Texture::TEXTURE_EXPLOSION, utl::Path::Texture::TEXTURE_PLAYER, utl::Path::Texture::TEXTURE_SHOOT, and utl::Path::Texture::TEXTURE_SHOOT_CHARGED.
Referenced by GameMulti().
Here is the caller graph for this function:
|
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:
|
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:
|
overridevirtual |
Update the game scene (called each frame)
| dt | Delta time since last frame (in seconds) |
| size | Current 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:
|
private |
Update entity position interpolation.
| dataMap | Map of entity ID to interpolation data |
| entityMap | Map of entity ID to ECS entity |
| smoothFactor | Interpolation smoothing factor (0.0-1.0) |
| dt | Delta time for frame-rate independent interpolation |
| registry | ECS 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:
|
private |
Update entity position interpolation (const version)
| dataMap | Map of entity ID to interpolation data |
| entityMap | Map of entity ID to ECS entity |
| smoothFactor | Interpolation smoothing factor (0.0-1.0) |
| dt | Delta time for frame-rate independent interpolation |
| registry | ECS registry containing entities |
| 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.
|
staticconstexprprivate |
Duration of boss music in seconds.
Definition at line 223 of file GameMulti.hpp.
|
staticconstexprprivate |
Interpolation speed for enemies.
Definition at line 216 of file GameMulti.hpp.
|
private |
Audio interface reference.
Definition at line 179 of file GameMulti.hpp.
|
private |
Entity for game start sound.
Definition at line 219 of file GameMulti.hpp.
Referenced by GameMulti().
|
private |
Entity for boss music.
Definition at line 220 of file GameMulti.hpp.
|
private |
Flag indicating if boss music has started.
Definition at line 222 of file GameMulti.hpp.
|
private |
Timer for boss music duration.
Definition at line 221 of file GameMulti.hpp.
|
private |
Interpolation data for enemies.
Definition at line 198 of file GameMulti.hpp.
|
private |
Map of enemy ID to entity.
Definition at line 193 of file GameMulti.hpp.
|
private |
Event bus component ID.
Definition at line 189 of file GameMulti.hpp.
|
private |
Flag indicating if this is the first world state (for player skin init)
Definition at line 228 of file GameMulti.hpp.
|
private |
|
private |
History of unacknowledged inputs.
Definition at line 211 of file GameMulti.hpp.
|
private |
Current key press states.
Definition at line 184 of file GameMulti.hpp.
|
private |
Last acknowledged input sequence ID.
Definition at line 212 of file GameMulti.hpp.
|
private |
Cache of loaded font paths.
Definition at line 226 of file GameMulti.hpp.
Referenced by GameMulti().
|
private |
Cache of loaded texture paths.
Definition at line 225 of file GameMulti.hpp.
Referenced by GameMulti().
|
private |
|
private |
|
private |
Map of player session ID to skin index.
Definition at line 199 of file GameMulti.hpp.
Referenced by GameMulti().
|
private |
|
private |
Interpolation data for projectiles.
Definition at line 197 of file GameMulti.hpp.
|
private |
Map of projectile ID to entity.
Definition at line 192 of file GameMulti.hpp.
|
private |
Interpolation data for remote players.
Definition at line 196 of file GameMulti.hpp.
|
private |
Map of session ID to remote player entities.
Definition at line 177 of file GameMulti.hpp.
|
private |
Renderer interface reference.
Definition at line 180 of file GameMulti.hpp.
|
private |
|
private |
Debug mode flag reference.
Definition at line 185 of file GameMulti.hpp.
|
private |
Local player skin index.
Definition at line 181 of file GameMulti.hpp.
|
private |
|
private |
Flag indicating if starfield background was created.
Definition at line 218 of file GameMulti.hpp.
| std::function<void()> gme::GameMulti::onGameOver |
Callback invoked when game ends.
Definition at line 123 of file GameMulti.hpp.
|
staticconstexprprivate |
Interpolation speed for projectiles.
Definition at line 215 of file GameMulti.hpp.
|
staticconstexprprivate |
Interpolation speed for remote players.
Definition at line 214 of file GameMulti.hpp.