Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
RoomSystem.hpp
Go to the documentation of this file.
1
8#ifndef RTYPE_ROOM_SYSTEM_HPP_
9 #define RTYPE_ROOM_SYSTEM_HPP_
10
11 #include "RType/ECS/ISystem.hpp"
12 #include "RType/ECS/Registry.hpp"
14
18 #include "Systems/NetworkSyncSystem.hpp"
19 #include "Game/Room.hpp"
20
21 #include <memory>
22 #include <map>
23
28namespace rtp::server {
33 class RoomSystem : public ecs::ISystem
34 {
35 public:
40 using RoomStartedCb = std::function<void(uint32_t roomId)>;
41
46 void setOnRoomStarted(RoomStartedCb cb) { _onRoomStarted = std::move(cb); }
47
53 RoomSystem(ServerNetwork& network, ecs::Registry& registry, NetworkSyncSystem& networkSync);
54
60 void update(float dt) override;
61
75 uint32_t createRoom(uint32_t sessionId, const std::string &roomName, uint8_t maxPlayers,
76 float difficulty, float speed, Room::RoomType type,
77 uint32_t levelId, uint32_t seed, uint32_t durationMinutes);
78
84 bool joinRoom(PlayerPtr player, uint32_t roomId, bool asSpectator = false);
85
90 bool joinLobby(PlayerPtr player);
91
97 bool leaveRoom(PlayerPtr player);
98
103 void disconnectPlayer(uint32_t sessionId);
104
110 void listAllRooms(uint32_t sessionId);
111
117 void chatInRoom(uint32_t sessionId, const net::Packet& packet);
118
122 void launchReadyRooms(float dt);
123
129 std::shared_ptr<Room> getRoom(uint32_t roomId);
130
131 private:
132 void despawnPlayerEntity(const PlayerPtr& player,
133 const std::shared_ptr<Room>& room);
137 std::map<uint32_t,
138 std::shared_ptr<Room>> _rooms{};
139 std::map<uint32_t, uint32_t> _playerRoomMap;
140 uint32_t _nextRoomId = 1;
141 uint32_t _lobbyId = 0;
142 mutable std::mutex _mutex;
145 };
146} // namespace rtp::server
147
148#endif /* !RTYPE_ROOM_SYSTEM_HPP_ */
Interface for ECS systems.
Network packet implementation for R-Type protocol.
Abstract base class for all ECS systems.
Definition ISystem.hpp:57
Network packet with header and serializable body.
Definition Packet.hpp:471
System to handle network-related operations on the server side.
System to handle room-related operations on the server side.
void launchReadyRooms(float dt)
Launch all rooms that are ready to start the game.
bool joinLobby(PlayerPtr player)
Join the lobby room.
ServerNetwork & _network
Reference to the server network manager.
uint32_t _nextRoomId
Next available room ID.
void disconnectPlayer(uint32_t sessionId)
Disconnect a player from all rooms.
std::mutex _mutex
Mutex for thread-safe operations.
void despawnPlayerEntity(const PlayerPtr &player, const std::shared_ptr< Room > &room)
std::shared_ptr< Room > getRoom(uint32_t roomId)
Get a room by its ID.
bool joinRoom(PlayerPtr player, uint32_t roomId, bool asSpectator=false)
Join an existing room based on client request.
std::function< void(uint32_t roomId)> RoomStartedCb
Callback type for when a room starts.
void setOnRoomStarted(RoomStartedCb cb)
Set the callback to be invoked when a room starts.
RoomStartedCb _onRoomStarted
Callback for when a room starts.
void update(float dt) override
Update system logic for one frame.
uint32_t _lobbyId
ID of the main lobby room.
uint32_t createRoom(uint32_t sessionId, const std::string &roomName, uint8_t maxPlayers, float difficulty, float speed, Room::RoomType type, uint32_t levelId, uint32_t seed, uint32_t durationMinutes)
Create a new room based on client request.
NetworkSyncSystem & _networkSync
Reference to the network sync system.
std::map< uint32_t, uint32_t > _playerRoomMap
Map of player session ID to room ID.
std::map< uint32_t, std::shared_ptr< Room > > _rooms
Map of room ID to Room instances.
bool leaveRoom(PlayerPtr player)
Leave the current room based on client request.
void listAllRooms(uint32_t sessionId)
List all available rooms based on client request.
void chatInRoom(uint32_t sessionId, const net::Packet &packet)
Handle chat message in the room based on client request.
ecs::Registry & _registry
Reference to the entity registry.
Implementation ASIO du serveur réseau (TCP + UDP)
File : GameManager.hpp License: MIT Author : Elias Josué HAJJAR LLAUQUEN elias-josue....
std::shared_ptr< Player > PlayerPtr
Shared pointer type for Player.
Definition Player.hpp:178