Bomberman Multiplayer
Authoritative multiplayer networking layer for Bomberman.
Loading...
Searching...
No Matches
LobbyScene.h
Go to the documentation of this file.
1
6#ifndef BOMBERMAN_SCENES_LOBBYSCENE_H
7#define BOMBERMAN_SCENES_LOBBYSCENE_H
8
9#include <array>
10#include <cstdint>
11#include <memory>
12#include <optional>
13#include <string_view>
14
15#include "Entities/Text.h"
16#include "Net/NetCommon.h"
17#include "Scenes/Scene.h"
18
19namespace bomberman
20{
21 namespace net { class NetClient; }
22
30 class LobbyScene final : public Scene
31 {
32 public:
34 {
35 std::shared_ptr<Text> seatText = nullptr;
36 std::shared_ptr<Text> localTagText = nullptr;
37 std::shared_ptr<Text> nameText = nullptr;
38 std::shared_ptr<Text> winsText = nullptr;
39 std::shared_ptr<Text> stateText = nullptr;
40 };
41
42 explicit LobbyScene(Game* game);
43
44 void onEvent(const SDL_Event& event) override;
45 void update(unsigned int delta) override;
46
47 private:
48 void handleReadyTogglePressed(net::NetClient& netClient);
49 bool tryEnterPendingMatch(net::NetClient& netClient);
50 void syncPendingReadyState(const net::MsgLobbyState& lobbyState, uint8_t localPlayerId);
51 void refreshLobbyPresentationIfChanged(const net::MsgLobbyState& lobbyState, uint8_t localPlayerId);
52 void setStatus(std::string_view message, SDL_Color color);
53 void setCountdownText(std::string_view message, SDL_Color color);
54 void rebuildLobbyPresentation(const net::MsgLobbyState& lobbyState, uint8_t localPlayerId);
55 void returnToMenu(bool disconnectClient, std::string_view reason);
56
57 std::shared_ptr<Text> titleText_ = nullptr;
58 std::shared_ptr<Text> statusText_ = nullptr;
59 std::shared_ptr<Text> countdownText_ = nullptr;
60 std::shared_ptr<Text> helpText_ = nullptr;
61 std::shared_ptr<Text> seatHeaderText_ = nullptr;
62 std::shared_ptr<Text> playerHeaderText_ = nullptr;
63 std::shared_ptr<Text> winsHeaderText_ = nullptr;
64 std::shared_ptr<Text> stateHeaderText_ = nullptr;
65 std::array<SeatRowWidgets, net::kMaxPlayers> seatRows_{};
66
67 net::MsgLobbyState lastRenderedLobbyState_{};
68 std::optional<bool> pendingReadyState_{};
69 uint32_t lastReadyRequestMs_ = 0;
70 bool hasRenderedLobbyState_ = false;
71 bool lobbyStateStale_ = false;
72 bool lastRenderedLobbyStale_ = false;
73 bool returningToMenu_ = false;
74 };
75} // namespace bomberman
76
77#endif // BOMBERMAN_SCENES_LOBBYSCENE_H
Shared client/server wire contract for the multiplayer protocol.
Definition Game.h:23
Multiplayer lobby scene backed by authoritative server seat state.
Definition LobbyScene.h:31
void onEvent(const SDL_Event &event) override
Trigger on SDL2 event if scene is active.
Definition LobbyScene.cpp:253
void update(unsigned int delta) override
Trigger on update if scene is active.
Definition LobbyScene.cpp:278
Scene base class.
Definition Scene.h:17
ENet client connection and protocol endpoint.
Definition NetClient.h:75
Definition LobbyScene.h:34
Passive lobby seat snapshot sent reliably by the server.
Definition NetCommon.h:599