|
R-Type
Distributed multiplayer game engine in C++
|
Manages all game rooms and matchmaking. More...
#include <RoomManager.hpp>


Public Member Functions | |
| RoomManager () | |
| RoomManager (std::shared_ptr< MatchmakingService > matchmaking, std::shared_ptr< EventBus > eventBus=nullptr) | |
| ~RoomManager () override=default | |
| std::shared_ptr< Room > | createRoom (const std::string &id, const std::string &name="", size_t maxPlayers=4, bool isPrivate=false, float gameSpeedMultiplier=1.0f) override |
| Create a new room. | |
| std::shared_ptr< Room > | getRoom (const std::string &id) override |
| Retrieve a room by ID. | |
| bool | removeRoom (const std::string &id) override |
| Remove a room by ID. | |
| std::vector< std::shared_ptr< Room > > | getAllRooms () override |
| Get all active rooms. | |
| std::vector< std::shared_ptr< Room > > | getPublicRooms () override |
| Get all public rooms (not private) | |
| size_t | getRoomCount () const override |
| Get number of active rooms. | |
| bool | update (float deltaTime) override |
| Update all rooms (called by server loop) | |
| void | addPlayerToMatchmaking (uint32_t playerId) |
| Add player to matchmaking queue. | |
| void | removePlayerFromMatchmaking (uint32_t playerId) |
| Remove player from matchmaking queue. | |
| std::shared_ptr< MatchmakingService > | getMatchmaking () |
| Get the matchmaking service. | |
| void | setRoomCreatedCallback (RoomCreatedCallback callback) |
| Set callback for when a room is created by matchmaking. | |
| std::shared_ptr< Room > | getRoomByPlayer (uint32_t playerId) |
| Get room by player ID (find which room a player is in) | |
| void | cleanupFinishedRooms () |
| Clean up finished rooms Removes rooms that are in FINISHED state and have no players. | |
Public Member Functions inherited from server::IRoomManager | |
| virtual | ~IRoomManager ()=default |
Private Member Functions | |
| void | _onMatchCreated (std::shared_ptr< Room > room) |
| Handle match created by matchmaking service. | |
Private Attributes | |
| std::unordered_map< std::string, std::shared_ptr< Room > > | _rooms |
| std::shared_ptr< MatchmakingService > | _matchmaking |
| std::shared_ptr< EventBus > | _eventBus |
| RoomCreatedCallback | _roomCreatedCallback |
| std::recursive_mutex | _mutex |
Manages all game rooms and matchmaking.
Features:
Definition at line 31 of file RoomManager.hpp.
| server::RoomManager::RoomManager | ( | ) |
Definition at line 13 of file RoomManager.cpp.
References _matchmaking, _onMatchCreated(), and LOG_INFO.

|
explicit |
Definition at line 19 of file RoomManager.cpp.
References _matchmaking, _onMatchCreated(), and LOG_INFO.

|
overridedefault |
|
private |
Handle match created by matchmaking service.
| room | Newly created room with matched players |
Definition at line 192 of file RoomManager.cpp.
References _mutex, _roomCreatedCallback, _rooms, LOG_INFO, LOG_WARNING, and server::STARTING.
Referenced by RoomManager(), and RoomManager().
| void server::RoomManager::addPlayerToMatchmaking | ( | uint32_t | playerId | ) |
Add player to matchmaking queue.
| playerId | Player ID to add |
Definition at line 29 of file RoomManager.cpp.
References _matchmaking, LOG_ERROR, and LOG_INFO.
| void server::RoomManager::cleanupFinishedRooms | ( | ) |
Clean up finished rooms Removes rooms that are in FINISHED state and have no players.
Definition at line 171 of file RoomManager.cpp.
References _mutex, _rooms, server::FINISHED, and LOG_INFO.
|
overridevirtual |
Create a new room.
| id | Room identifier |
| name | Display name (optional) |
| maxPlayers | Maximum players (default: 4) |
| isPrivate | Whether room is private (default: false) |
| gameSpeedMultiplier | Game speed multiplier (0.25 to 1.0, default: 1.0) |
Implements server::IRoomManager.
Definition at line 49 of file RoomManager.cpp.
References _eventBus, _mutex, _rooms, LOG_ERROR, LOG_INFO, and LOG_WARNING.
|
overridevirtual |
Get all active rooms.
Implements server::IRoomManager.
Definition at line 96 of file RoomManager.cpp.
|
inline |
Get the matchmaking service.
Definition at line 64 of file RoomManager.hpp.
References _matchmaking.
|
overridevirtual |
Get all public rooms (not private)
Implements server::IRoomManager.
Definition at line 109 of file RoomManager.cpp.
References _mutex, _rooms, and server::FINISHED.
|
overridevirtual |
Retrieve a room by ID.
| id | Room identifier |
Implements server::IRoomManager.
Definition at line 72 of file RoomManager.cpp.
| std::shared_ptr< Room > server::RoomManager::getRoomByPlayer | ( | uint32_t | playerId | ) |
Get room by player ID (find which room a player is in)
| playerId | Player ID to search for |
Definition at line 159 of file RoomManager.cpp.
|
overridevirtual |
Get number of active rooms.
Implements server::IRoomManager.
Definition at line 124 of file RoomManager.cpp.
| void server::RoomManager::removePlayerFromMatchmaking | ( | uint32_t | playerId | ) |
Remove player from matchmaking queue.
| playerId | Player ID to remove |
Definition at line 40 of file RoomManager.cpp.
References _matchmaking, and LOG_INFO.
|
overridevirtual |
Remove a room by ID.
| id | Room identifier |
Implements server::IRoomManager.
Definition at line 83 of file RoomManager.cpp.
|
inline |
Set callback for when a room is created by matchmaking.
| callback | Function to call when a room is created with matched players |
Definition at line 70 of file RoomManager.hpp.
References _roomCreatedCallback.
|
overridevirtual |
Update all rooms (called by server loop)
| deltaTime | Time since last update |
Implements server::IRoomManager.
Definition at line 129 of file RoomManager.cpp.
References _matchmaking, _mutex, _rooms, server::FINISHED, and LOG_INFO.
|
private |
Definition at line 94 of file RoomManager.hpp.
Referenced by createRoom().
|
private |
Definition at line 93 of file RoomManager.hpp.
Referenced by addPlayerToMatchmaking(), getMatchmaking(), removePlayerFromMatchmaking(), RoomManager(), RoomManager(), and update().
|
mutableprivate |
Definition at line 97 of file RoomManager.hpp.
Referenced by _onMatchCreated(), cleanupFinishedRooms(), createRoom(), getAllRooms(), getPublicRooms(), getRoom(), getRoomByPlayer(), getRoomCount(), removeRoom(), and update().
|
private |
Definition at line 95 of file RoomManager.hpp.
Referenced by _onMatchCreated(), and setRoomCreatedCallback().
|
private |
Definition at line 92 of file RoomManager.hpp.
Referenced by _onMatchCreated(), cleanupFinishedRooms(), createRoom(), getAllRooms(), getPublicRooms(), getRoom(), getRoomByPlayer(), getRoomCount(), removeRoom(), and update().