group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
MatchController.hpp
Go to the documentation of this file.
1
3#pragma once
4
8#include "network/Server.hpp"
9
15{
16public:
21 void update(float deltaTime, Registry& registry, Server& server);
22
25
27 void hostStartedMatch(std::span<const ClientId> expectedPlayers);
28
30 void setSkipLobby(bool v);
31
33 int getWinnerId();
34
35 bool setMatchConfig(const MatchConfig& cfg);
36 bool setKillsToWin(int killsToWin);
37 bool setMaxPlayers(int maxPlayers);
38 [[nodiscard]] MatchConfig getMatchConfig() const;
39
40 void beginWarmup(std::span<const ClientId> expectedPlayers);
41 void markGameplayReady(ClientId clientId);
42 void removeExpectedPlayer(ClientId clientId);
43 [[nodiscard]] bool allExpectedPlayersReady() const;
44
45private:
47 float countdownTimer = 0.0f;
48 int winnerId = -1;
49 bool skipLobby = false;
50
51 std::unordered_map<ClientId, bool> playerReadyStatus;
52
53 static constexpr float k_warmupDuration =
54 30.0f;
55 static constexpr float k_countdownDuration = 5.0f;
56 static constexpr float k_finishedDuration = 5.0f;
57
59
60 // PR-4 (server-perf): match-state replicate-on-change.
61 //
62 // Pre-PR-4 the controller broadcast `MATCH_STATE` every tick
63 // (128 Hz) regardless of whether anything changed — at 200 bots
64 // that was 25.6 k enqueues/sec all under stateMutex_, which
65 // dominated the `match` scope's 100+ ms p99 at 200 bots in PR-3.
66 // The on-wire payload is tiny (a few bytes) and the only thing
67 // that ever changes meaningfully is `currentPhase` plus the
68 // countdownTimer (which the client smoothes locally between
69 // ticks). We now broadcast only when those values move enough
70 // to be observable on the client.
75
81
82 bool validateKillsToWin(int killsToWin);
83 bool validateMaxPlayers(int maxPlayers);
84 bool validatePowerupTiming(float initialSpawnDelaySeconds, float respawnCooldownSeconds);
86};
Shared definitions for match status and state synchronization between server and clients.
MatchPhase
Definition MatchStatus.hpp:8
@ LOBBY
Pre-match lobby phase; players are not yet spawned in-world.
Definition MatchStatus.hpp:9
Shared ECS registry type alias for the game engine.
entt::registry Registry
Shared ECS registry type alias.
Definition Registry.hpp:11
TCP game server that accepts clients and dispatches incoming packets.
Manages match flow: lobby → countdown → in-progress → finished → lobby.
Definition MatchController.hpp:15
void setSkipLobby(bool v)
Enable or disable developer-mode lobby bypass.
Definition MatchController.cpp:82
MatchConfig config
Configuration for current match (e.g. kill threshold to win).
Definition MatchController.hpp:58
void markGameplayReady(ClientId clientId)
Definition MatchController.cpp:203
void broadcastMatchConfig(Server &server)
Definition MatchController.cpp:153
int winnerId
Client ID of the winner (-1 if none).
Definition MatchController.hpp:48
void removeExpectedPlayer(ClientId clientId)
Definition MatchController.cpp:211
bool validateKillsToWin(int killsToWin)
Definition MatchController.cpp:133
float countdownTimer
Seconds remaining in the current timed phase.
Definition MatchController.hpp:47
static constexpr float k_countdownDuration
Seconds for the pre-match countdown.
Definition MatchController.hpp:55
bool setMatchConfig(const MatchConfig &cfg)
Definition MatchController.cpp:158
MatchConfig getMatchConfig() const
Definition MatchController.cpp:186
bool validateMaxPlayers(int maxPlayers)
Definition MatchController.cpp:141
int ticksSinceBroadcast
Definition MatchController.hpp:74
bool setKillsToWin(int killsToWin)
Definition MatchController.cpp:168
MatchPhase lastBroadcastPhase
Definition MatchController.hpp:71
static constexpr float k_finishedDuration
Seconds to show the in-game result banner before post-match.
Definition MatchController.hpp:56
float lastBroadcastCountdown
Definition MatchController.hpp:73
MatchPhase currentPhase
Current phase of the match.
Definition MatchController.hpp:46
void broadcastMatchState(Server &server)
Send the current match phase, countdown, and winner to all clients.
Definition MatchController.cpp:92
static constexpr float k_warmupDuration
Max time to wait for players to load/spawn before starting after host start.
Definition MatchController.hpp:53
void update(float deltaTime, Registry &registry, Server &server)
Advance the match state machine by one tick.
Definition MatchController.cpp:10
void beginWarmup(std::span< const ClientId > expectedPlayers)
Definition MatchController.cpp:191
bool validatePowerupTiming(float initialSpawnDelaySeconds, float respawnCooldownSeconds)
Definition MatchController.cpp:146
int lastBroadcastWinnerId
Definition MatchController.hpp:72
bool allExpectedPlayersReady() const
Definition MatchController.cpp:216
bool skipLobby
True to auto-promote lobby to countdown.
Definition MatchController.hpp:49
bool setMaxPlayers(int maxPlayers)
Definition MatchController.cpp:177
void hostStartedMatch(std::span< const ClientId > expectedPlayers)
Start the host-authorized countdown if the match is still in the lobby phase.
Definition MatchController.cpp:73
int getWinnerId()
Return the winner's client ID, or -1 if no winner yet.
Definition MatchController.cpp:87
MatchPhase getCurrentPhase()
Return the current match phase.
Definition MatchController.cpp:68
std::unordered_map< ClientId, bool > playerReadyStatus
Tracks each player's ready status in the lobby.
Definition MatchController.hpp:51
TCP stream socket — receives client packets and echoes them back.
Definition Server.hpp:42
Definition LagCompMath.hpp:10
Associates an entity with a connected network client.
Definition ClientId.hpp:10
Definition MatchConfig.hpp:4