group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
Lobby Class Reference

IScreen implementation for the pre-match lobby. More...

#include <Lobby.hpp>

Inheritance diagram for Lobby:
[legend]
Collaboration diagram for Lobby:
[legend]

Public Member Functions

bool init (AppContext &ctx)
 Bind renderer, window, and network client; register lobby callbacks.
SDL_AppResult event (SDL_Event *event) override
 Handle an incoming SDL event.
SDL_AppResult iterate () override
 Update the screen state and render the next frame.
void quit () override
 Deregister all Client callbacks.
bool shouldStartMatch () const
 True when a non-lobby MatchStatePacket has been received and is ready for handoff.
std::optional< MatchStatePacketconsumeStartMatchState ()
 Take ownership of the pending MatchStatePacket and clear internal countdown state.
bool consumeReturnToMenu ()
 True if the user requested returning to the main menu, then clear that request.
bool consumeReturnToHostConfig ()
 True if the host requested HostConfig without shutting down the session, then clear that request.
bool consumeServerShutdownNotice ()
 True if returning home because the server connection closed, then clear that reason.
bool consumeExitRequest ()
 True if the user requested closing the application, then clear that request.
Public Member Functions inherited from IScreen
virtual ~IScreen ()=default
virtual void shutdownAfterRenderer ()
 Perform cleanup that must happen after the App-owned renderer shuts down.

Private Member Functions

bool canHostStartMatch () const
 True when at least one non-host is connected and all connected non-host players are ready.
void updateStartCountdown ()
 Advance the local countdown timer using SDL_GetTicksNS delta.

Private Attributes

NewRendererrenderer = nullptr
 Shared renderer; not owned.
SDL_Window * window = nullptr
 Application window; not owned.
Clientclient = nullptr
 Network client; not owned.
UserSettingssettings = nullptr
 Live user settings; not owned.
std::string_view settingsPath
 Save path for user settings.
SystemMenuOverlay systemMenu_
 Shared Escape menu for front-end screens.
std::vector< LobbyPlayerplayers
 Latest snapshot of connected players.
ClientId localClientId {-1}
 This client's own ID, set by the server on join.
std::optional< MatchConfigmatchConfig
 Latest match settings received from the server.
std::optional< MatchStatePacketstartMatchState
 Set when the server signals a match start.
bool startCountdownActive = false
 True while the pre-match countdown is ticking.
float startCountdownRemaining = 0.0f
 Seconds remaining in the countdown.
Uint64 lastStartCountdownTickNs = 0
 SDL tick timestamp of the last countdown update (ns).
bool returnToMenu = false
 Set to true when the user wants to return to the main menu.
bool returnToHostConfig = false
 Set when the host wants to return to HostConfig.
bool serverShutdownNotice = false
 Set when the server connection closed while in the lobby.
bool isHosting = false
 True if App owns a running hosted server.
std::string serverName
 Display name for the connected server.
std::string hostLanIp = "127.0.0.1"
 Address shown in the hosting banner.
uint16_t hostPort = 0
 Server port shown in the hosting banner.
bool exitRequested = false
 Set when the user confirms "Exit to Desktop".
bool hostAddressesVisible = false
 Local UI flag: show listen/local addresses while hosting.

Additional Inherited Members

Static Protected Member Functions inherited from IScreen
static SDL_AppResult processCommonImguiEvent (SDL_Event *event)
 Forward event to ImGui and detect SDL_EVENT_QUIT.
static bool handleSystemMenuEvent (SDL_Event *event, SystemMenuOverlay &menu, UserSettings *settings)
 Handle Escape-toggle of a SystemMenuOverlay and forward consumed events.
static void beginMenuFrame (NewRenderer *renderer)
 Start a new ImGui frame and paint the shared menu background.
static void presentMenuFrame (NewRenderer &renderer)
 Render the ImGui draw data and present a default-camera frame.

Detailed Description

IScreen implementation for the pre-match lobby.

Subscribes to lobby-state and match-state callbacks from Client, renders the player list via LobbyUI, and signals App when a match transition is ready.

Member Function Documentation

◆ canHostStartMatch()

bool Lobby::canHostStartMatch ( ) const
private

True when at least one non-host is connected and all connected non-host players are ready.

Here is the caller graph for this function:

◆ consumeExitRequest()

bool Lobby::consumeExitRequest ( )

True if the user requested closing the application, then clear that request.

◆ consumeReturnToHostConfig()

bool Lobby::consumeReturnToHostConfig ( )

True if the host requested HostConfig without shutting down the session, then clear that request.

◆ consumeReturnToMenu()

bool Lobby::consumeReturnToMenu ( )

True if the user requested returning to the main menu, then clear that request.

◆ consumeServerShutdownNotice()

bool Lobby::consumeServerShutdownNotice ( )

True if returning home because the server connection closed, then clear that reason.

◆ consumeStartMatchState()

std::optional< MatchStatePacket > Lobby::consumeStartMatchState ( )

Take ownership of the pending MatchStatePacket and clear internal countdown state.

Returns
The packet that triggered the match start, or nullopt if none was pending.

◆ event()

SDL_AppResult Lobby::event ( SDL_Event * event)
overridevirtual

Handle an incoming SDL event.

Parameters
eventThe SDL event to process.
Returns
SDL_APP_CONTINUE to keep running, SDL_APP_FAILURE to exit.

Implements IScreen.

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

◆ init()

bool Lobby::init ( AppContext & ctx)

Bind renderer, window, and network client; register lobby callbacks.

Returns
False if renderer or window are null.
Here is the call graph for this function:

◆ iterate()

SDL_AppResult Lobby::iterate ( )
overridevirtual

Update the screen state and render the next frame.

Returns
SDL_APP_CONTINUE to keep running, SDL_APP_FAILURE to exit.

Implements IScreen.

Here is the call graph for this function:

◆ quit()

void Lobby::quit ( )
overridevirtual

Deregister all Client callbacks.

Implements IScreen.

◆ shouldStartMatch()

bool Lobby::shouldStartMatch ( ) const

True when a non-lobby MatchStatePacket has been received and is ready for handoff.

◆ updateStartCountdown()

void Lobby::updateStartCountdown ( )
private

Advance the local countdown timer using SDL_GetTicksNS delta.

Here is the caller graph for this function:

Member Data Documentation

◆ client

Client* Lobby::client = nullptr
private

Network client; not owned.

◆ exitRequested

bool Lobby::exitRequested = false
private

Set when the user confirms "Exit to Desktop".

◆ hostAddressesVisible

bool Lobby::hostAddressesVisible = false
private

Local UI flag: show listen/local addresses while hosting.

◆ hostLanIp

std::string Lobby::hostLanIp = "127.0.0.1"
private

Address shown in the hosting banner.

◆ hostPort

uint16_t Lobby::hostPort = 0
private

Server port shown in the hosting banner.

◆ isHosting

bool Lobby::isHosting = false
private

True if App owns a running hosted server.

◆ lastStartCountdownTickNs

Uint64 Lobby::lastStartCountdownTickNs = 0
private

SDL tick timestamp of the last countdown update (ns).

◆ localClientId

ClientId Lobby::localClientId {-1}
private

This client's own ID, set by the server on join.

◆ matchConfig

std::optional<MatchConfig> Lobby::matchConfig
private

Latest match settings received from the server.

◆ players

std::vector<LobbyPlayer> Lobby::players
private

Latest snapshot of connected players.

◆ renderer

NewRenderer* Lobby::renderer = nullptr
private

Shared renderer; not owned.

◆ returnToHostConfig

bool Lobby::returnToHostConfig = false
private

Set when the host wants to return to HostConfig.

◆ returnToMenu

bool Lobby::returnToMenu = false
private

Set to true when the user wants to return to the main menu.

◆ serverName

std::string Lobby::serverName
private

Display name for the connected server.

◆ serverShutdownNotice

bool Lobby::serverShutdownNotice = false
private

Set when the server connection closed while in the lobby.

◆ settings

UserSettings* Lobby::settings = nullptr
private

Live user settings; not owned.

◆ settingsPath

std::string_view Lobby::settingsPath
private

Save path for user settings.

◆ startCountdownActive

bool Lobby::startCountdownActive = false
private

True while the pre-match countdown is ticking.

◆ startCountdownRemaining

float Lobby::startCountdownRemaining = 0.0f
private

Seconds remaining in the countdown.

◆ startMatchState

std::optional<MatchStatePacket> Lobby::startMatchState
private

Set when the server signals a match start.

◆ systemMenu_

SystemMenuOverlay Lobby::systemMenu_
private

Shared Escape menu for front-end screens.

◆ window

SDL_Window* Lobby::window = nullptr
private

Application window; not owned.


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