Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
rtp::server::Player Class Reference

Represents a player in the game server. More...

#include <Player.hpp>

Collaboration diagram for rtp::server::Player:

Public Member Functions

 Player (uint32_t sessionId)
 Constructor for Player.
 
 ~Player ()
 Destructor for Player.
 
void setUsername (const std::string &username)
 Set the username of the player.
 
std::string getUsername () const
 Get the username of the player.
 
void setRoomId (uint32_t roomId)
 Set the room ID the player is in.
 
uint32_t getRoomId () const
 Get the room ID the player is in.
 
bool isInRoom () const
 Check if the player is in a room.
 
void setState (PlayerState state)
 Set the state of the player.
 
PlayerState getState () const
 Get the state of the player.
 
void setReady (bool ready)
 Set the readiness status of the player.
 
bool isReady () const
 Get the readiness status of the player.
 
void setEntityId (uint32_t entityId)
 Set the entity ID associated with the player.
 
uint32_t getId () const
 Get the unique identifier of the Session.
 
uint32_t getEntityId () const
 Get the associated entity ID.
 
void setMuted (bool muted)
 
bool isMuted () const
 
void setWeaponKind (rtp::ecs::components::WeaponKind weapon)
 Set the selected weapon kind for this player.
 
rtp::ecs::components::WeaponKind getWeaponKind () const
 Get the selected weapon kind for this player.
 
void addScore (int delta)
 Add to player's score (can be negative)
 
void setScore (int score)
 Set player's score.
 
int getScore () const
 Get player's score.
 

Private Attributes

uint32_t _sessionId
 Unique player identifier.
 
std::string _username
 Player username.
 
uint32_t _roomId
 ID of the room the player is in ; by default 0 (no room)
 
PlayerState _state
 Current state of the player.
 
bool _isReady
 Readiness status of the player.
 
uint32_t _entityId = 0
 Associated entity ID in the ECS.
 
std::mutex _mutex
 Mutex to protect access to player state.
 
bool _isMuted = false
 Mute status of the player.
 
rtp::ecs::components::WeaponKind _weaponKind {rtp::ecs::components::WeaponKind::Classic}
 Selected weapon.
 
int _score {0}
 Player score.
 

Detailed Description

Represents a player in the game server.

Definition at line 41 of file Player.hpp.

Constructor & Destructor Documentation

◆ Player()

rtp::server::Player::Player ( uint32_t  sessionId)

Constructor for Player.

Parameters
idUnique identifier for the player
usernameUsername of the player

Definition at line 17 of file Player.cpp.

References _isReady, and _roomId.

◆ ~Player()

rtp::server::Player::~Player ( )

Destructor for Player.

Definition at line 24 of file Player.cpp.

Member Function Documentation

◆ addScore()

void rtp::server::Player::addScore ( int  delta)

Add to player's score (can be negative)

Parameters
deltaScore delta

Definition at line 124 of file Player.cpp.

References _mutex, and _score.

◆ getEntityId()

uint32_t rtp::server::Player::getEntityId ( ) const

Get the associated entity ID.

Returns
Current entity ID

Definition at line 94 of file Player.cpp.

References _entityId, and _mutex.

◆ getId()

uint32_t rtp::server::Player::getId ( ) const

Get the unique identifier of the Session.

Returns
Current Session ID

Definition at line 88 of file Player.cpp.

References _mutex, and _sessionId.

◆ getRoomId()

uint32_t rtp::server::Player::getRoomId ( ) const

Get the room ID the player is in.

Returns
Current room ID

Definition at line 46 of file Player.cpp.

References _mutex, and _roomId.

◆ getScore()

int rtp::server::Player::getScore ( ) const

Get player's score.

Returns
Current score

Definition at line 136 of file Player.cpp.

References _mutex, and _score.

◆ getState()

PlayerState rtp::server::Player::getState ( ) const

Get the state of the player.

Returns
Current player state

Definition at line 64 of file Player.cpp.

References _mutex, and _state.

◆ getUsername()

std::string rtp::server::Player::getUsername ( ) const

Get the username of the player.

Returns
Current username

Definition at line 34 of file Player.cpp.

References _mutex, and _username.

◆ getWeaponKind()

rtp::ecs::components::WeaponKind rtp::server::Player::getWeaponKind ( ) const

Get the selected weapon kind for this player.

Returns
Current weapon kind

Definition at line 118 of file Player.cpp.

References _mutex, and _weaponKind.

◆ isInRoom()

bool rtp::server::Player::isInRoom ( ) const

Check if the player is in a room.

Returns
true if in a room, false otherwise

Definition at line 52 of file Player.cpp.

References _mutex, and _roomId.

◆ isMuted()

bool rtp::server::Player::isMuted ( ) const

Definition at line 106 of file Player.cpp.

References _isMuted, and _mutex.

◆ isReady()

bool rtp::server::Player::isReady ( ) const

Get the readiness status of the player.

Returns
Current readiness status

Definition at line 76 of file Player.cpp.

References _isReady, and _mutex.

◆ setEntityId()

void rtp::server::Player::setEntityId ( uint32_t  entityId)

Set the entity ID associated with the player.

Parameters
entityIdNew entity ID

Definition at line 82 of file Player.cpp.

References _entityId, and _mutex.

◆ setMuted()

void rtp::server::Player::setMuted ( bool  muted)

Definition at line 100 of file Player.cpp.

References _isMuted, and _mutex.

◆ setReady()

void rtp::server::Player::setReady ( bool  ready)

Set the readiness status of the player.

Parameters
readyNew readiness status

Definition at line 70 of file Player.cpp.

References _isReady, and _mutex.

◆ setRoomId()

void rtp::server::Player::setRoomId ( uint32_t  roomId)

Set the room ID the player is in.

Parameters
roomIdNew room ID

Definition at line 40 of file Player.cpp.

References _mutex, and _roomId.

◆ setScore()

void rtp::server::Player::setScore ( int  score)

Set player's score.

Parameters
scoreNew score

Definition at line 130 of file Player.cpp.

References _mutex, and _score.

◆ setState()

void rtp::server::Player::setState ( PlayerState  state)

Set the state of the player.

Parameters
stateNew player state

Definition at line 58 of file Player.cpp.

References _mutex, and _state.

◆ setUsername()

void rtp::server::Player::setUsername ( const std::string &  username)

Set the username of the player.

Parameters
usernameNew username

Definition at line 28 of file Player.cpp.

References _mutex, and _username.

◆ setWeaponKind()

void rtp::server::Player::setWeaponKind ( rtp::ecs::components::WeaponKind  weapon)

Set the selected weapon kind for this player.

Parameters
weaponWeapon kind

Definition at line 112 of file Player.cpp.

References _mutex, and _weaponKind.

Member Data Documentation

◆ _entityId

uint32_t rtp::server::Player::_entityId = 0
private

Associated entity ID in the ECS.

Definition at line 167 of file Player.hpp.

Referenced by getEntityId(), and setEntityId().

◆ _isMuted

bool rtp::server::Player::_isMuted = false
private

Mute status of the player.

Definition at line 169 of file Player.hpp.

Referenced by isMuted(), and setMuted().

◆ _isReady

bool rtp::server::Player::_isReady
private

Readiness status of the player.

Definition at line 165 of file Player.hpp.

Referenced by Player(), isReady(), and setReady().

◆ _mutex

std::mutex rtp::server::Player::_mutex
mutableprivate

◆ _roomId

uint32_t rtp::server::Player::_roomId
private

ID of the room the player is in ; by default 0 (no room)

Definition at line 163 of file Player.hpp.

Referenced by Player(), getRoomId(), isInRoom(), and setRoomId().

◆ _score

int rtp::server::Player::_score {0}
private

Player score.

Definition at line 171 of file Player.hpp.

Referenced by addScore(), getScore(), and setScore().

◆ _sessionId

uint32_t rtp::server::Player::_sessionId
private

Unique player identifier.

Definition at line 161 of file Player.hpp.

Referenced by getId().

◆ _state

PlayerState rtp::server::Player::_state
private

Current state of the player.

Definition at line 164 of file Player.hpp.

Referenced by getState(), and setState().

◆ _username

std::string rtp::server::Player::_username
private

Player username.

Definition at line 162 of file Player.hpp.

Referenced by getUsername(), and setUsername().

◆ _weaponKind

Selected weapon.

Definition at line 170 of file Player.hpp.

Referenced by getWeaponKind(), and setWeaponKind().


The documentation for this class was generated from the following files: