|
Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
|
Represents a game room in the server. More...
#include <Room.hpp>
Public Types | |
| enum | State { Waiting , InGame , Finished } |
| Enum representing the state of the room. More... | |
| enum | RoomType { Lobby , Public , Private } |
| enum | PlayerType { None , Player , Spectator } |
| Enum representing the type of player in the room. More... | |
Public Member Functions | |
| Room (ecs::Registry ®istry, NetworkSyncSystem &network, uint32_t id, const std::string &name, uint32_t maxPlayers, float difficulty, float speed, RoomType type, uint32_t creatorSessionId=0, uint32_t levelId=1, uint32_t seed=0, uint32_t durationMinutes=0) | |
| Constructor for Room. | |
| ~Room () | |
| Destructor for Room. | |
| bool | canJoin (void) const |
| Add a player to the room. | |
| bool | addPlayer (const PlayerPtr &player, PlayerType type=PlayerType::Player) |
| Add a player to the room. | |
| void | removePlayer (uint32_t sessionId, bool disconnected=false) |
| Remove a player from the room. | |
| const std::list< PlayerPtr > | getPlayers (void) const |
| Get the list of players in the room. | |
| uint32_t | getId (void) const |
| Get the unique identifier of the room. | |
| RoomType | getType (void) const |
| Get the type of the room. | |
| float | getDifficulty (void) const |
| Get the difficulty level of the room. | |
| float | getSpeed (void) const |
| Get the speed multiplier of the room. | |
| uint32_t | getLevelId (void) const |
| Get the level identifier of the room. | |
| uint32_t | getSeed (void) const |
| Get the random seed of the room. | |
| uint32_t | getDurationMinutes (void) const |
| Get the duration in minutes of the room. | |
| PlayerType | getPlayerType (uint32_t sessionId) const |
| Get the type of a player in the room. | |
| void | setPlayerType (uint32_t sessionId, PlayerType type) |
| Set the type of a player in the room. | |
| bool | hasActivePlayers () const |
| Check if there are any active players (non-spectators) | |
| std::string | getName (void) const |
| Get the name of the room. | |
| uint32_t | getMaxPlayers (void) const |
| Get the maximum number of players allowed in the room. | |
| uint32_t | getCurrentPlayerCount (void) const |
| Get the current number of players in the room. | |
| State | getState (void) const |
| Get the current state of the room. | |
| bool | startGame (float dt) |
| Start the game in the room. | |
| void | forceFinishGame (void) |
| Finish the game in the room. | |
| void | update (uint32_t serverTick, float dt) |
| Update the room state. | |
| void | broadcastRoomState (uint32_t serverTick) |
| Broadcast the current room state to all connected players. | |
| void | banUser (const std::string &username) |
| bool | isBanned (const std::string &username) const |
Private Member Functions | |
| void | broadcastSystemMessage (const std::string &message) |
Private Attributes | |
| NetworkSyncSystem | _network |
| Reference to the server network manager. | |
| ecs::Registry & | _registry |
| Reference to the entity registry. | |
| uint32_t | _id |
| Unique room identifier. | |
| std::string | _name |
| Name of the room. | |
| uint32_t | _maxPlayers |
| Maximum number of players allowed. | |
| std::list< std::pair< PlayerPtr, PlayerType > > | _players |
| List of player ptr's in the room. | |
| State | _state |
| Current state of the room. | |
| RoomType | _type |
| Type of the room. | |
| uint32_t | _creatorSessionId |
| Session ID of the room creator (Administrator) | |
| std::pair< std::string, int > | _bestRoomScore |
| Best score achieved in the room. | |
| uint32_t | _levelId = 0 |
| Level identifier for the room. | |
| uint32_t | _seed = 0 |
| Seed for random generation in the room. | |
| float | _difficulty = 0 |
| Difficulty multiplier for the room 0 -> 1. | |
| float | _speed = 0 |
| Speed multiplier for the room 0 -> 2. | |
| uint32_t | durationMinutes = 0 |
| Duration of the game in minutes. | |
| float | _startedDt = 0.0f |
| Delta time accumulator since game start. | |
| uint32_t | _currentTimeSeconds |
| Current time in seconds since the game started. | |
| std::mutex | _mutex |
| Mutex to protect access to room state. | |
| std::unordered_set< std::string > | _bannedUsers |
| Banned usernames. | |
| float | _scoreTick {0.0f} |
| Score tick accumulator. | |
Represents a game room in the server.
A Room can hold multiple players and manage their states.
| rtp::server::Room::Room | ( | ecs::Registry & | registry, |
| NetworkSyncSystem & | network, | ||
| uint32_t | id, | ||
| const std::string & | name, | ||
| uint32_t | maxPlayers, | ||
| float | difficulty, | ||
| float | speed, | ||
| RoomType | type, | ||
| uint32_t | creatorSessionId = 0, |
||
| uint32_t | levelId = 1, |
||
| uint32_t | seed = 0, |
||
| uint32_t | durationMinutes = 0 |
||
| ) |
Constructor for Room.
| id | Unique identifier for the room |
| name | Name of the room |
| maxPlayers | Maximum number of players allowed in the room |
Definition at line 45 of file Room.cpp.
References _id, _maxPlayers, _name, and rtp::log::info().
| rtp::server::Room::~Room | ( | ) |
| bool rtp::server::Room::addPlayer | ( | const PlayerPtr & | player, |
| PlayerType | type = PlayerType::Player |
||
| ) |
Add a player to the room.
| player | Shared pointer to the player to add |
Definition at line 78 of file Room.cpp.
References _bannedUsers, _id, _maxPlayers, _mutex, _name, _network, _players, _state, _type, broadcastSystemMessage(), rtp::log::info(), rtp::net::JoinRoom, Lobby, Player, rtp::server::NetworkSyncSystem::sendPacketToSession(), Spectator, rtp::net::TCP, Waiting, and rtp::log::warning().
| void rtp::server::Room::banUser | ( | const std::string & | username | ) |
Definition at line 195 of file Room.cpp.
References _bannedUsers, and _mutex.
| void rtp::server::Room::broadcastRoomState | ( | uint32_t | serverTick | ) |
Broadcast the current room state to all connected players.
| serverTick | Current server tick count |
Definition at line 379 of file Room.cpp.
References _id, _mutex, _network, _players, _registry, _state, _type, rtp::ecs::Registry::get(), InGame, Lobby, rtp::net::RoomUpdate, rtp::server::NetworkSyncSystem::sendPacketToSession(), and rtp::net::UDP.
Referenced by update().
|
private |
Definition at line 170 of file Room.cpp.
References _mutex, _network, _players, rtp::net::RoomChatReceived, rtp::server::NetworkSyncSystem::sendPacketToSession(), rtp::net::RoomChatReceivedPayload::sessionId, and rtp::net::TCP.
Referenced by addPlayer(), and removePlayer().
| bool rtp::server::Room::canJoin | ( | void | ) | const |
Add a player to the room.
| player | Shared pointer to the player to add |
Definition at line 72 of file Room.cpp.
References _maxPlayers, _mutex, and _players.
| void rtp::server::Room::forceFinishGame | ( | void | ) |
Finish the game in the room.
Definition at line 337 of file Room.cpp.
References _id, _mutex, _name, _state, Finished, rtp::log::info(), InGame, and rtp::log::warning().
| uint32_t rtp::server::Room::getCurrentPlayerCount | ( | void | ) | const |
| float rtp::server::Room::getDifficulty | ( | void | ) | const |
Get the difficulty level of the room.
Definition at line 229 of file Room.cpp.
References _difficulty.
| uint32_t rtp::server::Room::getDurationMinutes | ( | void | ) | const |
Get the duration in minutes of the room.
Definition at line 249 of file Room.cpp.
References durationMinutes.
| uint32_t rtp::server::Room::getId | ( | void | ) | const |
Get the unique identifier of the room.
Definition at line 219 of file Room.cpp.
References _id.
Referenced by rtp::server::startGame().
| uint32_t rtp::server::Room::getLevelId | ( | void | ) | const |
| uint32_t rtp::server::Room::getMaxPlayers | ( | void | ) | const |
Get the maximum number of players allowed in the room.
Definition at line 304 of file Room.cpp.
References _maxPlayers.
| std::string rtp::server::Room::getName | ( | void | ) | const |
| const std::list< PlayerPtr > rtp::server::Room::getPlayers | ( | void | ) | const |
| Room::PlayerType rtp::server::Room::getPlayerType | ( | uint32_t | sessionId | ) | const |
| uint32_t rtp::server::Room::getSeed | ( | void | ) | const |
| float rtp::server::Room::getSpeed | ( | void | ) | const |
| Room::State rtp::server::Room::getState | ( | void | ) | const |
| Room::RoomType rtp::server::Room::getType | ( | void | ) | const |
| bool rtp::server::Room::hasActivePlayers | ( | ) | const |
| bool rtp::server::Room::isBanned | ( | const std::string & | username | ) | const |
Definition at line 201 of file Room.cpp.
References _bannedUsers, and _mutex.
| void rtp::server::Room::removePlayer | ( | uint32_t | sessionId, |
| bool | disconnected = false |
||
| ) |
Remove a player from the room.
| sessionId | Unique identifier of the player to remove |
Definition at line 130 of file Room.cpp.
References _id, _mutex, _name, _players, _type, broadcastSystemMessage(), rtp::log::info(), Lobby, None, Spectator, and rtp::log::warning().
| void rtp::server::Room::setPlayerType | ( | uint32_t | sessionId, |
| PlayerType | type | ||
| ) |
Set the type of a player in the room.
| sessionId | Unique identifier of the player |
| type | New PlayerType to set |
Definition at line 269 of file Room.cpp.
References _id, _mutex, _name, _players, rtp::log::info(), rtp::toString(), and rtp::log::warning().
| bool rtp::server::Room::startGame | ( | float | dt | ) |
Start the game in the room.
| dt | Get the delta time since last update |
Definition at line 321 of file Room.cpp.
References _id, _mutex, _name, _startedDt, _state, rtp::log::info(), InGame, Waiting, and rtp::log::warning().
| void rtp::server::Room::update | ( | uint32_t | serverTick, |
| float | dt | ||
| ) |
Update the room state.
| dt | Time elapsed since last update in seconds |
Definition at line 350 of file Room.cpp.
References _mutex, _network, _players, _scoreTick, _state, broadcastRoomState(), InGame, Player, rtp::net::ScoreUpdate, rtp::server::NetworkSyncSystem::sendPacketToSession(), and rtp::net::TCP.
|
private |
Banned usernames.
Definition at line 250 of file Room.hpp.
Referenced by addPlayer(), banUser(), and isBanned().
|
private |
|
private |
|
private |
|
private |
Difficulty multiplier for the room 0 -> 1.
Definition at line 242 of file Room.hpp.
Referenced by getDifficulty().
|
private |
Unique room identifier.
Definition at line 228 of file Room.hpp.
Referenced by Room(), ~Room(), addPlayer(), broadcastRoomState(), forceFinishGame(), getId(), getPlayerType(), removePlayer(), setPlayerType(), and startGame().
|
private |
|
private |
Maximum number of players allowed.
Definition at line 230 of file Room.hpp.
Referenced by Room(), addPlayer(), canJoin(), and getMaxPlayers().
|
mutableprivate |
Mutex to protect access to room state.
Definition at line 249 of file Room.hpp.
Referenced by addPlayer(), banUser(), broadcastRoomState(), broadcastSystemMessage(), canJoin(), forceFinishGame(), getCurrentPlayerCount(), getPlayers(), getPlayerType(), getState(), hasActivePlayers(), isBanned(), removePlayer(), setPlayerType(), startGame(), and update().
|
private |
Name of the room.
Definition at line 229 of file Room.hpp.
Referenced by Room(), ~Room(), addPlayer(), forceFinishGame(), getName(), getPlayerType(), removePlayer(), setPlayerType(), and startGame().
|
private |
Reference to the server network manager.
Definition at line 225 of file Room.hpp.
Referenced by addPlayer(), broadcastRoomState(), broadcastSystemMessage(), and update().
|
private |
List of player ptr's in the room.
Definition at line 232 of file Room.hpp.
Referenced by addPlayer(), broadcastRoomState(), broadcastSystemMessage(), canJoin(), getCurrentPlayerCount(), getPlayers(), getPlayerType(), hasActivePlayers(), removePlayer(), setPlayerType(), and update().
|
private |
Reference to the entity registry.
Definition at line 226 of file Room.hpp.
Referenced by broadcastRoomState().
|
private |
|
private |
|
private |
Speed multiplier for the room 0 -> 2.
Definition at line 243 of file Room.hpp.
Referenced by getSpeed().
|
private |
Delta time accumulator since game start.
Definition at line 246 of file Room.hpp.
Referenced by startGame().
|
private |
Current state of the room.
Definition at line 233 of file Room.hpp.
Referenced by addPlayer(), broadcastRoomState(), forceFinishGame(), getState(), startGame(), and update().
|
private |
Type of the room.
Definition at line 234 of file Room.hpp.
Referenced by addPlayer(), broadcastRoomState(), getType(), and removePlayer().
|
private |
Duration of the game in minutes.
Definition at line 244 of file Room.hpp.
Referenced by getDurationMinutes().