12#include <unordered_map>
34 explicit RoomManager(std::shared_ptr<MatchmakingService> matchmaking,
35 std::shared_ptr<EventBus> eventBus =
nullptr);
38 std::shared_ptr<Room>
createRoom(
const std::string &
id,
const std::string &name =
"",
39 size_t maxPlayers = 4,
bool isPrivate =
false,
40 float gameSpeedMultiplier = 1.0f)
override;
41 std::shared_ptr<Room>
getRoom(
const std::string &
id)
override;
42 bool removeRoom(
const std::string &
id)
override;
43 std::vector<std::shared_ptr<Room>>
getAllRooms()
override;
46 bool update(
float deltaTime)
override;
92 std::unordered_map<std::string, std::shared_ptr<Room>>
_rooms;
96 mutable std::recursive_mutex
Interface for managing game rooms.
Manages all game rooms and matchmaking.
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.
bool update(float deltaTime) override
Update all rooms (called by server loop)
std::shared_ptr< Room > getRoom(const std::string &id) override
Retrieve a room by ID.
RoomCreatedCallback _roomCreatedCallback
void setRoomCreatedCallback(RoomCreatedCallback callback)
Set callback for when a room is created by matchmaking.
std::vector< std::shared_ptr< Room > > getAllRooms() override
Get all active rooms.
void removePlayerFromMatchmaking(uint32_t playerId)
Remove player from matchmaking queue.
void cleanupFinishedRooms()
Clean up finished rooms Removes rooms that are in FINISHED state and have no players.
std::shared_ptr< MatchmakingService > _matchmaking
bool removeRoom(const std::string &id) override
Remove a room by ID.
std::recursive_mutex _mutex
std::shared_ptr< MatchmakingService > getMatchmaking()
Get the matchmaking service.
size_t getRoomCount() const override
Get number of active rooms.
std::shared_ptr< EventBus > _eventBus
std::shared_ptr< Room > getRoomByPlayer(uint32_t playerId)
Get room by player ID (find which room a player is in)
~RoomManager() override=default
std::vector< std::shared_ptr< Room > > getPublicRooms() override
Get all public rooms (not private)
void addPlayerToMatchmaking(uint32_t playerId)
Add player to matchmaking queue.
void _onMatchCreated(std::shared_ptr< Room > room)
Handle match created by matchmaking service.
std::unordered_map< std::string, std::shared_ptr< Room > > _rooms
std::function< void(std::shared_ptr< Room >)> RoomCreatedCallback