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 (NewRenderer *rendererPtr, SDL_Window *windowPtr, Client *clientPtr)
 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 has requested to return to the main menu, 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 if the local client is host and all 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.
std::vector< LobbyPlayerplayers
 Latest snapshot of connected players.
ClientId localClientId {-1}
 This client's own ID, set by the server on join.
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.

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 if the local client is host and all non-host players are ready.

Here is the caller graph for this function:

◆ consumeReturnToMenu()

bool Lobby::consumeReturnToMenu ( )

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

◆ 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 ( NewRenderer * rendererPtr,
SDL_Window * windowPtr,
Client * clientPtr )

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

Returns
False if renderer or window are null.

◆ 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.

◆ 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.

◆ players

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

Latest snapshot of connected players.

◆ renderer

NewRenderer* Lobby::renderer = nullptr
private

Shared renderer; not owned.

◆ returnToMenu

bool Lobby::returnToMenu = false
private

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

◆ 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.

◆ window

SDL_Window* Lobby::window = nullptr
private

Application window; not owned.


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