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

Pre-game lobby scene where players wait before match starts. More...

#include <WaitingRoom.hpp>

+ Inheritance diagram for gme::WaitingRoomScene:
+ Collaboration diagram for gme::WaitingRoomScene:

Public Member Functions

 WaitingRoomScene (eng::id assignedId, const std::shared_ptr< eng::IRenderer > &renderer)
 Constructor.
 
 ~WaitingRoomScene () override=default
 Destructor.
 
 WaitingRoomScene (const WaitingRoomScene &other)=delete
 Deleted copy constructor (non-copyable)
 
WaitingRoomSceneoperator= (const WaitingRoomScene &other)=delete
 Deleted copy assignment operator (non-copyable)
 
 WaitingRoomScene (WaitingRoomScene &&other)=delete
 Deleted move constructor (non-movable)
 
WaitingRoomSceneoperator= (WaitingRoomScene &&other)=delete
 Deleted move assignment operator (non-movable)
 
void update (float dt, const eng::WindowSize &size) override
 Update the waiting room scene (called each frame)
 
void event (const eng::Event &event) override
 Handle input events.
 
void setLobbyId (std::uint32_t lobbyId)
 Set the lobby ID.
 
void setLobbyInfo (const rnp::LobbyInfo &lobbyInfo)
 Update lobby information.
 
void setIsHost (const bool isHost)
 Set whether local player is the lobby host.
 
bool isHost () const
 Check if local player is the lobby host.
 
std::uint32_t getLobbyId () const
 Get current lobby ID.
 
bool & playMusic ()
 Get reference to music playback flag.
 
void startGame ()
 Initiate game start sequence.
 
- 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()> onLeaveLobby
 Callback invoked when player leaves lobby.
 
std::function< void()> onGameStart
 Callback invoked when game starts.
 

Private Member Functions

void setupEventSubscriptions () const
 Subscribe to event bus events.
 
void processEventBus ()
 Process events from event bus.
 
void handleLobbyUpdate (const utl::Event &event)
 Handle lobby update event from server.
 
void handleGameStart (const utl::Event &event) const
 Handle game start event from server.
 
void updatePlayerDisplay ()
 Update the player list display.
 
void clearPlayerEntities ()
 Clear all player display entities.
 
void leaveLobby () const
 Send leave lobby request to server.
 

Private Attributes

const std::shared_ptr< eng::IRenderer > & m_renderer
 Renderer interface reference.
 
std::uint32_t m_lobbyId = 0
 Current lobby ID.
 
rnp::LobbyInfo m_currentLobbyInfo {}
 Current lobby state.
 
bool m_hasLobbyInfo = false
 Whether lobby info has been received.
 
float m_animationTime = 0.0f
 Timer for UI animations.
 
int m_selectedButton = 0
 Currently selected button index.
 
ecs::Entity m_lobbyIdEntity = 0
 Entity displaying lobby ID.
 
ecs::Entity m_playerCountEntity = 0
 Entity displaying player count.
 
ecs::Entity m_statusEntity = 0
 Entity displaying lobby status.
 
ecs::Entity m_leaveButtonEntity = 0
 Leave button entity.
 
ecs::Entity m_startButtonEntity = 0
 Start game button entity (host only)
 
ecs::Entity m_readyButtonEntity = 0
 Ready button entity.
 
std::vector< ecs::Entitym_playerEntities
 Entities for player name displays.
 
bool m_isHost = false
 Whether local player is lobby host.
 
bool m_playMusic = false
 Music playback state.
 

Static Private Attributes

static constexpr int BUTTON_LEAVE = 0
 Leave lobby button index.
 
static constexpr int BUTTON_READY = 1
 Ready button index.
 
static constexpr int BUTTON_START = 2
 Start game button index (host only)
 
static constexpr int BUTTON_COUNT = 3
 Total number of buttons.
 

Additional Inherited Members

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

Detailed Description

Pre-game lobby scene where players wait before match starts.

This scene provides:

  • Real-time display of lobby information (name, player count, status)
  • List of connected players in the lobby
  • Host controls (start game button)
  • Player controls (ready button, leave button)
  • Animated UI elements for visual feedback
  • Event bus integration for network updates

The scene automatically updates when lobby state changes (players join/leave) and transitions to the game scene when the host starts the game.

Definition at line 44 of file WaitingRoom.hpp.

Constructor & Destructor Documentation

◆ WaitingRoomScene() [1/3]

gme::WaitingRoomScene::WaitingRoomScene ( eng::id assignedId,
const std::shared_ptr< eng::IRenderer > & renderer )

Constructor.

Parameters
assignedIdUnique scene identifier
rendererShared pointer to the rendering interface

Initializes the waiting room UI and sets up event subscriptions

Definition at line 17 of file waitingRoom.cpp.

References eng::Color::a, eng::Color::b, CYAN_ELECTRIC, utl::Path::Font::FONTS_RTYPE, eng::Color::g, GRAY_BLUE_SUBTLE, ecs::IComponent::id, INFO_TEXT_COLOR, eng::AScene::m_eventBus, eng::AScene::m_eventComponentId, m_leaveButtonEntity, m_lobbyIdEntity, m_playerCountEntity, m_readyButtonEntity, m_startButtonEntity, m_statusEntity, eng::Color::r, utl::EventBus::registerComponent(), setupEventSubscriptions(), and TEXT_VALUE_COLOR.

+ Here is the call graph for this function:

◆ ~WaitingRoomScene()

gme::WaitingRoomScene::~WaitingRoomScene ( )
overridedefault

Destructor.

◆ WaitingRoomScene() [2/3]

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

Deleted copy constructor (non-copyable)

◆ WaitingRoomScene() [3/3]

gme::WaitingRoomScene::WaitingRoomScene ( WaitingRoomScene && other)
delete

Deleted move constructor (non-movable)

Member Function Documentation

◆ clearPlayerEntities()

void gme::WaitingRoomScene::clearPlayerEntities ( )
private

Clear all player display entities.

Definition at line 408 of file waitingRoom.cpp.

References m_playerEntities.

Referenced by updatePlayerDisplay().

+ Here is the caller graph for this function:

◆ event()

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

Handle input events.

Parameters
eventInput event (keyboard, mouse)

Handles navigation between buttons and activation of controls

Implements eng::IScene.

Definition at line 232 of file waitingRoom.cpp.

References BUTTON_LEAVE, BUTTON_READY, BUTTON_START, eng::Down, eng::Enter, eng::Escape, event(), utl::INFO, eng::KeyPressed, leaveLobby(), utl::Logger::log(), m_isHost, m_selectedButton, eng::Space, startGame(), and eng::Up.

Referenced by event(), handleGameStart(), handleLobbyUpdate(), and processEventBus().

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

◆ getLobbyId()

std::uint32_t gme::WaitingRoomScene::getLobbyId ( ) const
inline

Get current lobby ID.

Returns
Lobby identifier

Definition at line 124 of file WaitingRoom.hpp.

References m_lobbyId.

◆ handleGameStart()

void gme::WaitingRoomScene::handleGameStart ( const utl::Event & event) const
private

Handle game start event from server.

Parameters
eventEvent indicating game is starting

Definition at line 138 of file waitingRoom.cpp.

References rnp::Serializer::deserializeGameStart(), event(), utl::INFO, rnp::PacketGameStart::lobbyId, utl::Logger::log(), onGameStart, and utl::WARNING.

+ Here is the call graph for this function:

◆ handleLobbyUpdate()

void gme::WaitingRoomScene::handleLobbyUpdate ( const utl::Event & event)
private

Handle lobby update event from server.

Parameters
eventEvent containing updated lobby information

Definition at line 114 of file waitingRoom.cpp.

References rnp::LobbyInfo::currentPlayers, rnp::Serializer::deserializeLobbyUpdate(), event(), utl::INFO, rnp::LobbyInfo::lobbyId, rnp::PacketLobbyUpdate::lobbyInfo, utl::Logger::log(), m_currentLobbyInfo, m_hasLobbyInfo, rnp::LobbyInfo::maxPlayers, updatePlayerDisplay(), and utl::WARNING.

Referenced by processEventBus().

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

◆ isHost()

bool gme::WaitingRoomScene::isHost ( ) const
inlinenodiscard

Check if local player is the lobby host.

Returns
True if local player is host

Definition at line 118 of file WaitingRoom.hpp.

References m_isHost.

Referenced by setIsHost().

+ Here is the caller graph for this function:

◆ leaveLobby()

void gme::WaitingRoomScene::leaveLobby ( ) const
private

Send leave lobby request to server.

Definition at line 425 of file waitingRoom.cpp.

References utl::INFO, utl::LOBBY_LEAVE, utl::Logger::log(), eng::AScene::m_eventBus, eng::AScene::m_eventComponentId, m_lobbyId, utl::NETWORK_CLIENT, onLeaveLobby, and utl::EventBus::publish().

Referenced by event().

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

◆ operator=() [1/2]

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

Deleted copy assignment operator (non-copyable)

◆ operator=() [2/2]

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

Deleted move assignment operator (non-movable)

◆ playMusic()

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

Get reference to music playback flag.

Returns
Reference to music play state

Definition at line 130 of file WaitingRoom.hpp.

References m_playMusic.

◆ processEventBus()

void gme::WaitingRoomScene::processEventBus ( )
private

Process events from event bus.

Polls and handles network events

Definition at line 457 of file waitingRoom.cpp.

References utl::EventBus::consumeForTarget(), event(), utl::GAME_START, handleLobbyUpdate(), utl::INFO, utl::LOBBY_UPDATE, utl::Logger::log(), eng::AScene::m_eventBus, eng::AScene::m_eventComponentId, and onGameStart.

Referenced by update().

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

◆ setIsHost()

void gme::WaitingRoomScene::setIsHost ( const bool isHost)
inline

Set whether local player is the lobby host.

Parameters
isHostTrue if local player is host

Definition at line 112 of file WaitingRoom.hpp.

References isHost(), and m_isHost.

Referenced by gme::RTypeClientMulti::setupScenes().

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

◆ setLobbyId()

void gme::WaitingRoomScene::setLobbyId ( std::uint32_t lobbyId)

Set the lobby ID.

Parameters
lobbyIdUnique lobby identifier

Definition at line 304 of file waitingRoom.cpp.

References ecs::Text::content, utl::INFO, utl::Logger::log(), m_lobbyId, and m_lobbyIdEntity.

Referenced by gme::RTypeClientMulti::setupScenes().

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

◆ setLobbyInfo()

void gme::WaitingRoomScene::setLobbyInfo ( const rnp::LobbyInfo & lobbyInfo)

Update lobby information.

Parameters
lobbyInfoCurrent lobby state from server

Updates the displayed lobby information and player list

Definition at line 316 of file waitingRoom.cpp.

References rnp::LobbyInfo::currentPlayers, utl::INFO, rnp::LobbyInfo::lobbyId, utl::Logger::log(), m_currentLobbyInfo, m_hasLobbyInfo, m_lobbyId, rnp::LobbyInfo::maxPlayers, and updatePlayerDisplay().

Referenced by gme::RTypeClientMulti::setupScenes().

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

◆ setupEventSubscriptions()

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

Subscribe to event bus events.

Registers for LOBBY_UPDATE and GAME_START events

Definition at line 108 of file waitingRoom.cpp.

References utl::GAME_START, utl::LOBBY_UPDATE, eng::AScene::m_eventBus, eng::AScene::m_eventComponentId, and utl::EventBus::subscribe().

Referenced by WaitingRoomScene().

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

◆ startGame()

void gme::WaitingRoomScene::startGame ( )

Initiate game start sequence.

Called when host presses start button

Definition at line 440 of file waitingRoom.cpp.

References utl::INFO, utl::LOBBY_CREATE, utl::Logger::log(), eng::AScene::m_eventBus, eng::AScene::m_eventComponentId, m_isHost, m_lobbyId, utl::NETWORK_CLIENT, utl::EventBus::publish(), and utl::WARNING.

Referenced by event().

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

◆ update()

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

Update the waiting room scene (called each frame)

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

Updates animations, processes event bus messages, and refreshes UI

Implements eng::IScene.

Definition at line 160 of file waitingRoom.cpp.

References ecs::Color::a, ecs::Color::b, eng::Color::b, BUTTON_LEAVE, BUTTON_READY, BUTTON_START, ecs::Text::content, CYAN_ELECTRIC, ecs::Color::g, eng::Color::g, GRAY_BLUE_SUBTLE, m_animationTime, m_hasLobbyInfo, m_isHost, m_leaveButtonEntity, m_readyButtonEntity, m_selectedButton, m_startButtonEntity, m_statusEntity, processEventBus(), ecs::Color::r, and eng::Color::r.

+ Here is the call graph for this function:

◆ updatePlayerDisplay()

void gme::WaitingRoomScene::updatePlayerDisplay ( )
private

Update the player list display.

Recreates player name entities based on current lobby info

Definition at line 327 of file waitingRoom.cpp.

References eng::Color::a, eng::Color::b, clearPlayerEntities(), ecs::Text::content, rnp::LobbyInfo::currentPlayers, utl::Path::Font::FONTS_RTYPE, eng::Color::g, GREEN_READY, utl::INFO, INFO_TEXT_COLOR, rnp::LobbyInfo::lobbyId, utl::Logger::log(), m_currentLobbyInfo, m_hasLobbyInfo, m_lobbyIdEntity, m_playerCountEntity, m_playerEntities, m_statusEntity, rnp::LobbyInfo::maxPlayers, and eng::Color::r.

Referenced by handleLobbyUpdate(), and setLobbyInfo().

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

Member Data Documentation

◆ BUTTON_COUNT

int gme::WaitingRoomScene::BUTTON_COUNT = 3
staticconstexprprivate

Total number of buttons.

Definition at line 160 of file WaitingRoom.hpp.

◆ BUTTON_LEAVE

int gme::WaitingRoomScene::BUTTON_LEAVE = 0
staticconstexprprivate

Leave lobby button index.

Definition at line 157 of file WaitingRoom.hpp.

Referenced by event(), and update().

◆ BUTTON_READY

int gme::WaitingRoomScene::BUTTON_READY = 1
staticconstexprprivate

Ready button index.

Definition at line 158 of file WaitingRoom.hpp.

Referenced by event(), and update().

◆ BUTTON_START

int gme::WaitingRoomScene::BUTTON_START = 2
staticconstexprprivate

Start game button index (host only)

Definition at line 159 of file WaitingRoom.hpp.

Referenced by event(), and update().

◆ m_animationTime

float gme::WaitingRoomScene::m_animationTime = 0.0f
private

Timer for UI animations.

Definition at line 154 of file WaitingRoom.hpp.

Referenced by update().

◆ m_currentLobbyInfo

rnp::LobbyInfo gme::WaitingRoomScene::m_currentLobbyInfo {}
private

Current lobby state.

Definition at line 152 of file WaitingRoom.hpp.

Referenced by handleLobbyUpdate(), setLobbyInfo(), and updatePlayerDisplay().

◆ m_hasLobbyInfo

bool gme::WaitingRoomScene::m_hasLobbyInfo = false
private

Whether lobby info has been received.

Definition at line 153 of file WaitingRoom.hpp.

Referenced by handleLobbyUpdate(), setLobbyInfo(), update(), and updatePlayerDisplay().

◆ m_isHost

bool gme::WaitingRoomScene::m_isHost = false
private

Whether local player is lobby host.

Definition at line 171 of file WaitingRoom.hpp.

Referenced by event(), isHost(), setIsHost(), startGame(), and update().

◆ m_leaveButtonEntity

ecs::Entity gme::WaitingRoomScene::m_leaveButtonEntity = 0
private

Leave button entity.

Definition at line 166 of file WaitingRoom.hpp.

Referenced by update(), and WaitingRoomScene().

◆ m_lobbyId

std::uint32_t gme::WaitingRoomScene::m_lobbyId = 0
private

Current lobby ID.

Definition at line 151 of file WaitingRoom.hpp.

Referenced by getLobbyId(), leaveLobby(), setLobbyId(), setLobbyInfo(), and startGame().

◆ m_lobbyIdEntity

ecs::Entity gme::WaitingRoomScene::m_lobbyIdEntity = 0
private

Entity displaying lobby ID.

Definition at line 163 of file WaitingRoom.hpp.

Referenced by setLobbyId(), updatePlayerDisplay(), and WaitingRoomScene().

◆ m_playerCountEntity

ecs::Entity gme::WaitingRoomScene::m_playerCountEntity = 0
private

Entity displaying player count.

Definition at line 164 of file WaitingRoom.hpp.

Referenced by updatePlayerDisplay(), and WaitingRoomScene().

◆ m_playerEntities

std::vector<ecs::Entity> gme::WaitingRoomScene::m_playerEntities
private

Entities for player name displays.

Definition at line 169 of file WaitingRoom.hpp.

Referenced by clearPlayerEntities(), and updatePlayerDisplay().

◆ m_playMusic

bool gme::WaitingRoomScene::m_playMusic = false
private

Music playback state.

Definition at line 172 of file WaitingRoom.hpp.

Referenced by playMusic().

◆ m_readyButtonEntity

ecs::Entity gme::WaitingRoomScene::m_readyButtonEntity = 0
private

Ready button entity.

Definition at line 168 of file WaitingRoom.hpp.

Referenced by update(), and WaitingRoomScene().

◆ m_renderer

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

Renderer interface reference.

Definition at line 149 of file WaitingRoom.hpp.

◆ m_selectedButton

int gme::WaitingRoomScene::m_selectedButton = 0
private

Currently selected button index.

Definition at line 156 of file WaitingRoom.hpp.

Referenced by event(), and update().

◆ m_startButtonEntity

ecs::Entity gme::WaitingRoomScene::m_startButtonEntity = 0
private

Start game button entity (host only)

Definition at line 167 of file WaitingRoom.hpp.

Referenced by update(), and WaitingRoomScene().

◆ m_statusEntity

ecs::Entity gme::WaitingRoomScene::m_statusEntity = 0
private

Entity displaying lobby status.

Definition at line 165 of file WaitingRoom.hpp.

Referenced by update(), updatePlayerDisplay(), and WaitingRoomScene().

◆ onGameStart

std::function<void()> gme::WaitingRoomScene::onGameStart

Callback invoked when game starts.

Definition at line 140 of file WaitingRoom.hpp.

Referenced by handleGameStart(), and processEventBus().

◆ onLeaveLobby

std::function<void()> gme::WaitingRoomScene::onLeaveLobby

Callback invoked when player leaves lobby.

Definition at line 135 of file WaitingRoom.hpp.

Referenced by leaveLobby().


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