r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
JoinRoom.hpp
Go to the documentation of this file.
1///
2/// @file JoinRoom.hpp
3/// @brief Lobby browser scene for joining multiplayer games
4/// @details This file contains the join room scene where players can browse available
5/// lobbies, view lobby information (name, player count, status), and join
6/// a game. The scene provides real-time updates via the event bus and
7/// supports refreshing the lobby list on demand.
8/// @namespace gme
9/// @author R-Type Team
10/// @date 2025
11///
12
13#pragma once
14
15#include <vector>
16
19
20namespace gme
21{
22 ///
23 /// @class JoinRoomScene
24 /// @brief Scene for browsing and joining available multiplayer lobbies
25 /// @details This scene provides:
26 /// - Display of all available lobbies with their information
27 /// - Real-time lobby list updates via event bus
28 /// - Manual refresh capability
29 /// - Lobby selection and join functionality
30 /// - Navigation back to multiplayer menu
31 /// - Visual feedback for lobby status and player counts
32 ///
33 /// The scene automatically subscribes to lobby list updates and join responses
34 /// from the network layer, providing a responsive lobby browser experience.
35 ///
36 /// @namespace gme
37 ///
38 class JoinRoomScene final : public eng::AScene
39 {
40 public:
41 ///
42 /// @brief Constructor
43 /// @param assignedId Unique scene identifier
44 /// @param renderer Shared pointer to the rendering interface
45 /// @details Initializes the lobby browser UI and sets up event subscriptions
46 ///
47 JoinRoomScene(eng::id assignedId, const std::shared_ptr<eng::IRenderer> &renderer);
48
49 ///
50 /// @brief Destructor
51 ///
52 ~JoinRoomScene() override = default;
53
54 ///
55 /// @brief Deleted copy constructor (non-copyable)
56 ///
57 JoinRoomScene(const JoinRoomScene &other) = delete;
58
59 ///
60 /// @brief Deleted copy assignment operator (non-copyable)
61 ///
62 JoinRoomScene &operator=(const JoinRoomScene &other) = delete;
63
64 ///
65 /// @brief Deleted move constructor (non-movable)
66 ///
67 JoinRoomScene(JoinRoomScene &&other) = delete;
68
69 ///
70 /// @brief Deleted move assignment operator (non-movable)
71 ///
73
74 ///
75 /// @brief Update the join room scene (called each frame)
76 /// @param dt Delta time since last frame (in seconds)
77 /// @param size Current window dimensions
78 /// @details Processes event bus messages, updates animations, and refreshes UI
79 ///
80 void update(float dt, const eng::WindowSize &size) override;
81
82 ///
83 /// @brief Handle input events
84 /// @param event Input event (keyboard, mouse)
85 /// @details Handles navigation between lobbies and selection/refresh actions
86 ///
87 void event(const eng::Event &event) override;
88
89 ///
90 /// @brief Get reference to music playback flag
91 /// @return Reference to music play state
92 ///
93 bool &playMusic() { return m_playMusic; }
94
95 ///
96 /// @brief Update the displayed list of available lobbies
97 /// @param rooms Vector of lobby information structures from server
98 /// @details Refreshes the lobby list display with new data
99 ///
100 void setRooms(const std::vector<rnp::LobbyInfo> &rooms);
101
102 ///
103 /// @brief Request updated lobby list from server
104 /// @details Sends LOBBY_LIST_REQUEST to the network layer
105 ///
106 void refreshRoomList() const;
107
108 ///
109 /// @brief Callback invoked when player joins a lobby
110 /// @details Function signature: (roomId, lobbyInfo*) -> void
111 ///
112 std::function<void(int roomId, const rnp::LobbyInfo *lobbyInfo)> onJoin;
113
114 ///
115 /// @brief Callback invoked when returning to multiplayer menu
116 ///
117 std::function<void()> onBackToMulti;
118
119 ///
120 /// @brief Callback invoked when refresh is requested
121 ///
122 std::function<void()> onRefreshRequest;
123
124 private:
125 size_t m_selectedIndex = 0; ///< Currently selected lobby index
126 float m_animationTime = 0.0f; ///< Animation timer for visual effects
127 std::vector<rnp::LobbyInfo> m_rooms; ///< List of available lobbies from server
128
129 ecs::Entity m_noRoomsEntity = 0; ///< Entity displaying "No rooms available" message
130 std::vector<ecs::Entity> m_roomEntities; ///< Entities for lobby list items
131 bool m_playMusic = false; ///< Music playback state flag
132
133 ///
134 /// @brief Update the visual display of the lobby list
135 /// @details Recreates lobby list entities based on current room data
136 ///
137 void updateRoomDisplay();
138
139 ///
140 /// @brief Clear all lobby display entities
141 /// @details Removes all lobby list item entities from the scene
142 ///
143 void clearRoomEntities();
144
145 ///
146 /// @brief Process events from event bus
147 /// @details Polls and handles network events (lobby list, join response)
148 ///
149 void processEventBus();
150
151 ///
152 /// @brief Subscribe to event bus events
153 /// @details Registers for LOBBY_LIST_RESPONSE and LOBBY_JOIN_RESPONSE events
154 ///
155 void setupEventSubscriptions() const;
156
157 ///
158 /// @brief Handle lobby list response from server
159 /// @param event Event containing list of available lobbies
160 ///
162
163 ///
164 /// @brief Handle lobby join response from server
165 /// @param event Event containing join result (success/failure)
166 ///
167 void handleLobbyJoinResponse(const utl::Event &event) const;
168 }; // class JoinRoomScene
169} // namespace gme
This file contains the network protocol.
Abstract class for scene.
Definition IScene.hpp:52
Scene for browsing and joining available multiplayer lobbies.
Definition JoinRoom.hpp:39
std::vector< ecs::Entity > m_roomEntities
Entities for lobby list items.
Definition JoinRoom.hpp:130
std::vector< rnp::LobbyInfo > m_rooms
List of available lobbies from server.
Definition JoinRoom.hpp:127
ecs::Entity m_noRoomsEntity
Entity displaying "No rooms available" message.
Definition JoinRoom.hpp:129
void handleLobbyListResponse(const utl::Event &event)
Handle lobby list response from server.
Definition joinRoom.cpp:85
JoinRoomScene(JoinRoomScene &&other)=delete
Deleted move constructor (non-movable)
float m_animationTime
Animation timer for visual effects.
Definition JoinRoom.hpp:126
void clearRoomEntities()
Clear all lobby display entities.
Definition joinRoom.cpp:354
~JoinRoomScene() override=default
Destructor.
std::function< void(int roomId, const rnp::LobbyInfo *lobbyInfo)> onJoin
Callback invoked when player joins a lobby.
Definition JoinRoom.hpp:112
void event(const eng::Event &event) override
Handle input events.
Definition joinRoom.cpp:231
void setRooms(const std::vector< rnp::LobbyInfo > &rooms)
Update the displayed list of available lobbies.
Definition joinRoom.cpp:288
JoinRoomScene(const JoinRoomScene &other)=delete
Deleted copy constructor (non-copyable)
void update(float dt, const eng::WindowSize &size) override
Update the join room scene (called each frame)
Definition joinRoom.cpp:162
bool & playMusic()
Get reference to music playback flag.
Definition JoinRoom.hpp:93
size_t m_selectedIndex
Currently selected lobby index.
Definition JoinRoom.hpp:125
void refreshRoomList() const
Request updated lobby list from server.
Definition joinRoom.cpp:294
std::function< void()> onBackToMulti
Callback invoked when returning to multiplayer menu.
Definition JoinRoom.hpp:117
JoinRoomScene & operator=(const JoinRoomScene &other)=delete
Deleted copy assignment operator (non-copyable)
JoinRoomScene(eng::id assignedId, const std::shared_ptr< eng::IRenderer > &renderer)
Constructor.
Definition joinRoom.cpp:9
std::function< void()> onRefreshRequest
Callback invoked when refresh is requested.
Definition JoinRoom.hpp:122
void setupEventSubscriptions() const
Subscribe to event bus events.
Definition joinRoom.cpp:79
void processEventBus()
Process events from event bus.
Definition joinRoom.cpp:381
void updateRoomDisplay()
Update the visual display of the lobby list.
Definition joinRoom.cpp:305
bool m_playMusic
Music playback state flag.
Definition JoinRoom.hpp:131
JoinRoomScene & operator=(JoinRoomScene &&other)=delete
Deleted move assignment operator (non-movable)
void handleLobbyJoinResponse(const utl::Event &event) const
Handle lobby join response from server.
Definition joinRoom.cpp:118
Event structure for inter-component communication.
Definition Event.hpp:89
This file contains the IScene class.
std::uint32_t Entity
Definition Entity.hpp:13
unsigned int id
Definition IScene.hpp:20
Lobby information structure.
Definition Protocol.hpp:237