group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
Lobby.hpp
Go to the documentation of this file.
1
3
4#pragma once
5#include "IScreen.hpp"
6#include "app/AppContext.hpp"
8#include "network/Client.hpp"
12
13#include <optional>
14#include <string>
15#include <string_view>
16#include <vector>
17
22class Lobby : public IScreen
23{
24public:
27 bool init(AppContext& ctx);
28
29 SDL_AppResult event(SDL_Event* event) override;
30 SDL_AppResult iterate() override;
31
33 void quit() override;
34
36 bool shouldStartMatch() const;
37
40 std::optional<MatchStatePacket> consumeStartMatchState();
41
44
47
50
52 bool consumeExitRequest();
53
54private:
56 bool canHostStartMatch() const;
57
60
61 NewRenderer* renderer = nullptr;
62 SDL_Window* window = nullptr;
63 Client* client = nullptr;
65 std::string_view settingsPath;
67 std::vector<LobbyPlayer> players;
69 std::optional<MatchConfig> matchConfig;
70 std::optional<MatchStatePacket> startMatchState;
71 bool startCountdownActive = false;
74 bool returnToMenu = false;
75 bool returnToHostConfig = false;
76 bool serverShutdownNotice = false;
77 bool isHosting = false;
78 std::string serverName;
79 std::string hostLanIp = "127.0.0.1";
80 uint16_t hostPort = 0;
81 bool exitRequested = false;
82 bool hostAddressesVisible = false;
83};
Borrowed dependencies shared by client screens.
TCP client for connecting to the game server.
Abstract interface for top-level application screens (lobby, in-game).
Shared lobby data types exchanged between server and clients.
Work-in-progress SDL3 GPU renderer.
TCP stream client — sends input to the server and receives state updates.
Definition Client.hpp:69
Interface implemented by each full-screen mode (Lobby, Game).
Definition IScreen.hpp:16
IScreen implementation for the pre-match lobby.
Definition Lobby.hpp:23
std::optional< MatchStatePacket > startMatchState
Set when the server signals a match start.
Definition Lobby.hpp:70
bool canHostStartMatch() const
True when at least one non-host is connected and all connected non-host players are ready.
Definition Lobby.cpp:233
bool startCountdownActive
True while the pre-match countdown is ticking.
Definition Lobby.hpp:71
bool exitRequested
Set when the user confirms "Exit to Desktop".
Definition Lobby.hpp:81
std::optional< MatchConfig > matchConfig
Latest match settings received from the server.
Definition Lobby.hpp:69
bool consumeExitRequest()
True if the user requested closing the application, then clear that request.
Definition Lobby.cpp:296
void updateStartCountdown()
Advance the local countdown timer using SDL_GetTicksNS delta.
Definition Lobby.cpp:249
float startCountdownRemaining
Seconds remaining in the countdown.
Definition Lobby.hpp:72
void quit() override
Deregister all Client callbacks.
Definition Lobby.cpp:208
SDL_Window * window
Application window; not owned.
Definition Lobby.hpp:62
bool hostAddressesVisible
Local UI flag: show listen/local addresses while hosting.
Definition Lobby.hpp:82
std::string_view settingsPath
Save path for user settings.
Definition Lobby.hpp:65
bool serverShutdownNotice
Set when the server connection closed while in the lobby.
Definition Lobby.hpp:76
bool consumeReturnToHostConfig()
True if the host requested HostConfig without shutting down the session, then clear that request.
Definition Lobby.cpp:278
bool returnToMenu
Set to true when the user wants to return to the main menu.
Definition Lobby.hpp:74
bool init(AppContext &ctx)
Bind renderer, window, and network client; register lobby callbacks.
Definition Lobby.cpp:14
std::string hostLanIp
Address shown in the hosting banner.
Definition Lobby.hpp:79
std::optional< MatchStatePacket > consumeStartMatchState()
Take ownership of the pending MatchStatePacket and clear internal countdown state.
Definition Lobby.cpp:223
bool consumeServerShutdownNotice()
True if returning home because the server connection closed, then clear that reason.
Definition Lobby.cpp:287
SDL_AppResult iterate() override
Update the screen state and render the next frame.
Definition Lobby.cpp:145
bool consumeReturnToMenu()
True if the user requested returning to the main menu, then clear that request.
Definition Lobby.cpp:269
std::string serverName
Display name for the connected server.
Definition Lobby.hpp:78
SystemMenuOverlay systemMenu_
Shared Escape menu for front-end screens.
Definition Lobby.hpp:66
Client * client
Network client; not owned.
Definition Lobby.hpp:63
SDL_AppResult event(SDL_Event *event) override
Handle an incoming SDL event.
Definition Lobby.cpp:136
UserSettings * settings
Live user settings; not owned.
Definition Lobby.hpp:64
std::vector< LobbyPlayer > players
Latest snapshot of connected players.
Definition Lobby.hpp:67
NewRenderer * renderer
Shared renderer; not owned.
Definition Lobby.hpp:61
ClientId localClientId
This client's own ID, set by the server on join.
Definition Lobby.hpp:68
Uint64 lastStartCountdownTickNs
SDL tick timestamp of the last countdown update (ns).
Definition Lobby.hpp:73
bool isHosting
True if App owns a running hosted server.
Definition Lobby.hpp:77
bool returnToHostConfig
Set when the host wants to return to HostConfig.
Definition Lobby.hpp:75
uint16_t hostPort
Server port shown in the hosting banner.
Definition Lobby.hpp:80
bool shouldStartMatch() const
True when a non-lobby MatchStatePacket has been received and is ready for handoff.
Definition Lobby.cpp:218
Graphics-team's work-in-progress SDL3 GPU renderer.
Definition NewRenderer.hpp:83
Shared Escape menu for non-gameplay screens.
Definition SystemMenuOverlay.hpp:20
Non-owning view of App-owned services and configuration.
Definition AppContext.hpp:20
Associates an entity with a connected network client.
Definition ClientId.hpp:10
Per-user gameplay settings loaded from SDL's pref-path TOML file.
Definition UserSettings.hpp:25