|
R-Type
Distributed multiplayer game engine in C++
|
Concrete implementation of IRoom with game instance management. More...
#include <Room.hpp>


Public Member Functions | |
| Room (const std::string &id, const std::string &name="", size_t maxPlayers=4, bool isPrivate=false, float gameSpeedMultiplier=1.0f, std::shared_ptr< EventBus > eventBus=nullptr) | |
| Construct a room. | |
| ~Room () override=default | |
| bool | join (uint32_t playerId) override |
| Join a player to the room. | |
| bool | joinAsSpectator (uint32_t playerId) override |
| Join a player to the room as a spectator. | |
| bool | leave (uint32_t playerId) override |
| Remove a player from the room. | |
| std::string | getId () const override |
| Get the room's unique identifier. | |
| std::string | getName () const override |
| Get the room's display name. | |
| RoomState | getState () const override |
| Get current state of the room. | |
| void | setState (RoomState state) override |
| Set the state of the room. | |
| size_t | getPlayerCount () const override |
| Get number of players currently in room. | |
| size_t | getMaxPlayers () const override |
| Get maximum number of players allowed. | |
| bool | isFull () const override |
| Check if room is full. | |
| std::vector< uint32_t > | getPlayers () const override |
| Get list of player IDs in this room. | |
| std::vector< uint32_t > | getSpectators () const override |
| Get list of spectator IDs in this room. | |
| bool | hasPlayer (uint32_t playerId) const override |
| Check if a player is in this room. | |
| bool | hasSpectator (uint32_t playerId) const override |
| Check if a spectator is in this room. | |
| RoomInfo | getInfo () const override |
| Get room information. | |
| std::shared_ptr< IGameLogic > | getGameLogic () const |
| Get the game logic instance. | |
| ServerLoop * | getServerLoop () const |
| Get the server loop instance for this room. | |
| bool | startGame () |
| Start the game for this room. | |
| void | requestStartGame () |
| Request to start the game (initiates countdown) | |
| void | update (float deltaTime) |
| Update the room state (called by server loop) | |
| void | setHost (uint32_t playerId) |
| Set the host player ID. | |
| uint32_t | getHost () const |
| Get the host player ID. | |
| void | broadcastChatMessage (uint32_t senderId, const std::string &senderName, const std::string &message) |
| Broadcast a chat message to all players in the room. | |
| bool | isPrivate () const |
| Check if room is private. | |
| float | getGameSpeedMultiplier () const |
| Get the game speed multiplier. | |
| bool | isGameStartSent () const |
| Check if GameStart has been sent. | |
| void | setGameStartSent (bool sent) |
| Mark GameStart as sent. | |
| bool | tryMarkGameStartSent () |
| Atomically check and set GameStart sent flag (thread-safe) | |
Public Member Functions inherited from server::IRoom | |
| virtual | ~IRoom ()=default |
Private Attributes | |
| std::string | _id |
| std::string | _name |
| RoomState | _state |
| size_t | _maxPlayers |
| bool | _isPrivate |
| float | _gameSpeedMultiplier |
| uint32_t | _hostPlayerId |
| std::vector< uint32_t > | _players |
| std::vector< uint32_t > | _spectators |
| std::shared_ptr< IGameLogic > | _gameLogic |
| std::unique_ptr< ServerLoop > | _gameLoop |
| std::shared_ptr< EventBus > | _eventBus |
| std::mutex | _mutex |
| bool | _gameStartSent |
Concrete implementation of IRoom with game instance management.
|
explicit |
Construct a room.
| id | Unique room identifier |
| name | Display name for the room |
| maxPlayers | Maximum number of players (default: 4) |
| isPrivate | Whether the room is private (default: false) |
| gameSpeedMultiplier | Game speed multiplier (default: 1.0) |
| eventBus | Shared event bus for server-wide events |
Definition at line 21 of file Room.cpp.
References _eventBus, _gameLogic, _gameLoop, _gameSpeedMultiplier, _id, _isPrivate, _maxPlayers, _name, LOG_ERROR, and LOG_INFO.
|
overridedefault |
| void server::Room::broadcastChatMessage | ( | uint32_t | senderId, |
| const std::string & | senderName, | ||
| const std::string & | message | ||
| ) |
|
inline |
Get the game logic instance.
Definition at line 62 of file Room.hpp.
References _gameLogic.
|
inline |
Get the game speed multiplier.
Definition at line 121 of file Room.hpp.
References _gameSpeedMultiplier.
|
inline |
Get the host player ID.
Definition at line 100 of file Room.hpp.
References _hostPlayerId.
|
inlineoverridevirtual |
Get the room's unique identifier.
Implements server::IRoom.
Definition at line 45 of file Room.hpp.
References _id.
|
overridevirtual |
Get room information.
Implements server::IRoom.
Definition at line 161 of file Room.cpp.
References _hostPlayerId, _id, _isPrivate, _maxPlayers, _mutex, _name, _players, and _state.
|
inlineoverridevirtual |
Get maximum number of players allowed.
Implements server::IRoom.
Definition at line 50 of file Room.hpp.
References _maxPlayers.
|
inlineoverridevirtual |
Get the room's display name.
Implements server::IRoom.
Definition at line 46 of file Room.hpp.
References _name.
|
overridevirtual |
Get number of players currently in room.
Implements server::IRoom.
|
overridevirtual |
Get list of player IDs in this room.
Implements server::IRoom.
|
inline |
Get the server loop instance for this room.
Definition at line 68 of file Room.hpp.
References _gameLoop.
|
overridevirtual |
Get list of spectator IDs in this room.
Implements server::IRoom.
Definition at line 148 of file Room.cpp.
References _mutex, and _spectators.
|
inlineoverridevirtual |
Get current state of the room.
Implements server::IRoom.
Definition at line 47 of file Room.hpp.
References _state.
|
overridevirtual |
Check if a player is in this room.
| playerId | Player ID to check |
Implements server::IRoom.
Definition at line 153 of file Room.cpp.
References _players.
Referenced by join(), joinAsSpectator(), and setHost().
|
overridevirtual |
Check if a spectator is in this room.
| playerId | Spectator ID to check |
Implements server::IRoom.
Definition at line 157 of file Room.cpp.
References _spectators.
Referenced by joinAsSpectator().
|
inlineoverridevirtual |
Check if room is full.
Implements server::IRoom.
Definition at line 51 of file Room.hpp.
References _maxPlayers, and _players.
Referenced by join().
|
inline |
Check if GameStart has been sent.
Definition at line 127 of file Room.hpp.
References _gameStartSent.
|
inline |
Check if room is private.
Definition at line 115 of file Room.hpp.
References _isPrivate.
|
overridevirtual |
Join a player to the room.
| playerId | Unique identifier of the player |
Implements server::IRoom.
Definition at line 53 of file Room.cpp.
References _hostPlayerId, _id, _maxPlayers, _mutex, _players, _state, hasPlayer(), isFull(), LOG_INFO, LOG_WARNING, server::STARTING, and server::WAITING.

|
overridevirtual |
Join a player to the room as a spectator.
| playerId | Unique identifier of the player |
Implements server::IRoom.
Definition at line 80 of file Room.cpp.
References _id, _mutex, _spectators, hasPlayer(), hasSpectator(), LOG_INFO, and LOG_WARNING.

|
overridevirtual |
Remove a player from the room.
| playerId | Unique identifier of the player |
Implements server::IRoom.
Definition at line 93 of file Room.cpp.
References _gameStartSent, _hostPlayerId, _id, _mutex, _players, _spectators, _state, server::IN_PROGRESS, LOG_INFO, setState(), server::STARTING, and server::WAITING.

| void server::Room::requestStartGame | ( | ) |
Request to start the game (initiates countdown)
This is called when the host requests to start the game. It transitions the room to STARTING state and begins the countdown.
Definition at line 249 of file Room.cpp.
References _id, _players, _state, LOG_INFO, startGame(), and server::WAITING.

|
inline |
| void server::Room::setHost | ( | uint32_t | playerId | ) |
Set the host player ID.
| playerId | Player ID to set as host |
Definition at line 242 of file Room.cpp.
References _hostPlayerId, _id, hasPlayer(), and LOG_INFO.

|
overridevirtual |
Set the state of the room.
| state | New state |
Implements server::IRoom.
Definition at line 129 of file Room.cpp.
References _name, _state, and LOG_INFO.
Referenced by leave(), startGame(), and update().
| bool server::Room::startGame | ( | ) |
Start the game for this room.
Definition at line 167 of file Room.cpp.
References _gameLogic, _id, _mutex, _players, _state, server::IN_PROGRESS, LOG_ERROR, LOG_INFO, LOG_WARNING, setState(), server::STARTING, and server::WAITING.
Referenced by requestStartGame().

| bool server::Room::tryMarkGameStartSent | ( | ) |
Atomically check and set GameStart sent flag (thread-safe)
Definition at line 256 of file Room.cpp.
References _gameStartSent, and _mutex.
| void server::Room::update | ( | float | deltaTime | ) |
Update the room state (called by server loop)
| deltaTime | Time since last update |
Definition at line 230 of file Room.cpp.
References _gameLogic, _id, _state, server::FINISHED, server::IN_PROGRESS, LOG_INFO, and setState().

|
private |
|
private |
Definition at line 150 of file Room.hpp.
Referenced by getGameLogic(), Room(), startGame(), and update().
|
private |
Definition at line 151 of file Room.hpp.
Referenced by getServerLoop(), and Room().
|
private |
Definition at line 146 of file Room.hpp.
Referenced by getGameSpeedMultiplier(), and Room().
|
private |
Definition at line 154 of file Room.hpp.
Referenced by isGameStartSent(), leave(), setGameStartSent(), and tryMarkGameStartSent().
|
private |
|
private |
Definition at line 141 of file Room.hpp.
Referenced by broadcastChatMessage(), getId(), getInfo(), join(), joinAsSpectator(), leave(), requestStartGame(), Room(), setHost(), startGame(), and update().
|
private |
Definition at line 145 of file Room.hpp.
Referenced by getInfo(), isPrivate(), and Room().
|
private |
|
mutableprivate |
Definition at line 153 of file Room.hpp.
Referenced by getInfo(), getPlayerCount(), getPlayers(), getSpectators(), join(), joinAsSpectator(), leave(), startGame(), and tryMarkGameStartSent().
|
private |
|
private |
Definition at line 148 of file Room.hpp.
Referenced by getInfo(), getPlayerCount(), getPlayers(), hasPlayer(), isFull(), join(), leave(), requestStartGame(), and startGame().
|
private |
Definition at line 149 of file Room.hpp.
Referenced by getSpectators(), hasSpectator(), joinAsSpectator(), and leave().
|
private |
Definition at line 143 of file Room.hpp.
Referenced by getInfo(), getState(), join(), leave(), requestStartGame(), setState(), startGame(), and update().