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

Manages match flow: lobby → countdown → in-progress → finished → lobby. More...

#include <MatchController.hpp>

Collaboration diagram for MatchController:
[legend]

Public Member Functions

void update (float deltaTime, Registry &registry, Server &server)
 Advance the match state machine by one tick.
MatchPhase getCurrentPhase ()
 Return the current match phase.
void hostStartedMatch (std::span< const ClientId > expectedPlayers)
 Start the host-authorized countdown if the match is still in the lobby phase.
void setSkipLobby (bool v)
 Enable or disable developer-mode lobby bypass.
int getWinnerId ()
 Return the winner's client ID, or -1 if no winner yet.
bool setMatchConfig (const MatchConfig &cfg)
bool setKillsToWin (int killsToWin)
bool setMaxPlayers (int maxPlayers)
MatchConfig getMatchConfig () const
void beginWarmup (std::span< const ClientId > expectedPlayers)
void markGameplayReady (ClientId clientId)
void removeExpectedPlayer (ClientId clientId)
bool allExpectedPlayersReady () const

Private Member Functions

void broadcastMatchState (Server &server)
 Send the current match phase, countdown, and winner to all clients.
bool validateKillsToWin (int killsToWin)
bool validateMaxPlayers (int maxPlayers)
bool validatePowerupTiming (float initialSpawnDelaySeconds, float respawnCooldownSeconds)
void broadcastMatchConfig (Server &server)

Private Attributes

MatchPhase currentPhase = MatchPhase::LOBBY
 Current phase of the match.
float countdownTimer = 0.0f
 Seconds remaining in the current timed phase.
int winnerId = -1
 Client ID of the winner (-1 if none).
bool skipLobby = false
 True to auto-promote lobby to countdown.
std::unordered_map< ClientId, bool > playerReadyStatus
 Tracks each player's ready status in the lobby.
MatchConfig config
 Configuration for current match (e.g. kill threshold to win).
MatchPhase lastBroadcastPhase = MatchPhase::LOBBY
int lastBroadcastWinnerId = -1
float lastBroadcastCountdown = -1.0f
int ticksSinceBroadcast = 0

Static Private Attributes

static constexpr float k_warmupDuration
 Max time to wait for players to load/spawn before starting after host start.
static constexpr float k_countdownDuration = 5.0f
 Seconds for the pre-match countdown.
static constexpr float k_finishedDuration = 5.0f
 Seconds to show the in-game result banner before post-match.

Detailed Description

Manages match flow: lobby → countdown → in-progress → finished → lobby.

Transitions between phases based on host starts, timers, and kill thresholds. Broadcasts match state to all clients every tick.

Member Function Documentation

◆ allExpectedPlayersReady()

bool MatchController::allExpectedPlayersReady ( ) const
nodiscard
Here is the caller graph for this function:

◆ beginWarmup()

void MatchController::beginWarmup ( std::span< const ClientId > expectedPlayers)
Here is the caller graph for this function:

◆ broadcastMatchConfig()

void MatchController::broadcastMatchConfig ( Server & server)
private

◆ broadcastMatchState()

void MatchController::broadcastMatchState ( Server & server)
private

Send the current match phase, countdown, and winner to all clients.

PR-4: skip the actual broadcast when nothing observable has changed since the last send.

Parameters
serverNetwork server for broadcasting.
Here is the caller graph for this function:

◆ getCurrentPhase()

MatchPhase MatchController::getCurrentPhase ( )

Return the current match phase.

◆ getMatchConfig()

MatchConfig MatchController::getMatchConfig ( ) const
nodiscard

◆ getWinnerId()

int MatchController::getWinnerId ( )

Return the winner's client ID, or -1 if no winner yet.

◆ hostStartedMatch()

void MatchController::hostStartedMatch ( std::span< const ClientId > expectedPlayers)

Start the host-authorized countdown if the match is still in the lobby phase.

Here is the call graph for this function:

◆ markGameplayReady()

void MatchController::markGameplayReady ( ClientId clientId)

◆ removeExpectedPlayer()

void MatchController::removeExpectedPlayer ( ClientId clientId)

◆ setKillsToWin()

bool MatchController::setKillsToWin ( int killsToWin)
Here is the call graph for this function:

◆ setMatchConfig()

bool MatchController::setMatchConfig ( const MatchConfig & cfg)
Here is the call graph for this function:

◆ setMaxPlayers()

bool MatchController::setMaxPlayers ( int maxPlayers)
Here is the call graph for this function:

◆ setSkipLobby()

void MatchController::setSkipLobby ( bool v)

Enable or disable developer-mode lobby bypass.

◆ update()

void MatchController::update ( float deltaTime,
Registry & registry,
Server & server )

Advance the match state machine by one tick.

Parameters
deltaTimeFixed physics delta time in seconds.
registryThe ECS registry (for win condition checks).
serverNetwork server (for broadcasting state).
Here is the call graph for this function:

◆ validateKillsToWin()

bool MatchController::validateKillsToWin ( int killsToWin)
private
Here is the caller graph for this function:

◆ validateMaxPlayers()

bool MatchController::validateMaxPlayers ( int maxPlayers)
private
Here is the caller graph for this function:

◆ validatePowerupTiming()

bool MatchController::validatePowerupTiming ( float initialSpawnDelaySeconds,
float respawnCooldownSeconds )
private
Here is the caller graph for this function:

Member Data Documentation

◆ config

MatchConfig MatchController::config
private

Configuration for current match (e.g. kill threshold to win).

◆ countdownTimer

float MatchController::countdownTimer = 0.0f
private

Seconds remaining in the current timed phase.

◆ currentPhase

MatchPhase MatchController::currentPhase = MatchPhase::LOBBY
private

Current phase of the match.

◆ k_countdownDuration

float MatchController::k_countdownDuration = 5.0f
staticconstexprprivate

Seconds for the pre-match countdown.

◆ k_finishedDuration

float MatchController::k_finishedDuration = 5.0f
staticconstexprprivate

Seconds to show the in-game result banner before post-match.

◆ k_warmupDuration

float MatchController::k_warmupDuration
staticconstexprprivate
Initial value:
=
30.0f

Max time to wait for players to load/spawn before starting after host start.

◆ lastBroadcastCountdown

float MatchController::lastBroadcastCountdown = -1.0f
private

◆ lastBroadcastPhase

MatchPhase MatchController::lastBroadcastPhase = MatchPhase::LOBBY
private

◆ lastBroadcastWinnerId

int MatchController::lastBroadcastWinnerId = -1
private

◆ playerReadyStatus

std::unordered_map<ClientId, bool> MatchController::playerReadyStatus
private

Tracks each player's ready status in the lobby.

◆ skipLobby

bool MatchController::skipLobby = false
private

True to auto-promote lobby to countdown.

◆ ticksSinceBroadcast

int MatchController::ticksSinceBroadcast = 0
private

◆ winnerId

int MatchController::winnerId = -1
private

Client ID of the winner (-1 if none).


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