Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
Player.hpp
Go to the documentation of this file.
1
8 #ifndef RTYPE_GAME_PLAYER_HPP_
9 #define RTYPE_GAME_PLAYER_HPP_
10
11 #include <cstdint>
12 #include <string>
13 #include <mutex>
14 #include <memory>
17
22namespace rtp::server
23{
28 enum class PlayerState {
29 None,
32 InLobby,
33 InRoom,
34 InGame
35 };
36
41 class Player {
42 public:
48 Player(uint32_t sessionId);
49
53 ~Player();
54
59 void setUsername(const std::string &username);
60
65 std::string getUsername() const;
66
71 void setRoomId(uint32_t roomId);
72
77 uint32_t getRoomId() const;
78
83 bool isInRoom() const;
84
89 void setState(PlayerState state);
90
95 PlayerState getState() const;
96
101 void setReady(bool ready);
102
107 bool isReady() const;
108
113 void setEntityId(uint32_t entityId);
114
119 uint32_t getId() const;
120
125 uint32_t getEntityId() const;
126
127 void setMuted(bool muted);
128 bool isMuted() const;
129
135
141
146 void addScore(int delta);
147
152 void setScore(int score);
153
158 int getScore() const;
159
160 private:
161 uint32_t _sessionId;
162 std::string _username;
163 uint32_t _roomId;
165 bool _isReady;
167 uint32_t _entityId = 0;
168 mutable std::mutex _mutex;
169 bool _isMuted = false;
171 int _score{0};
172 };
173
178 using PlayerPtr = std::shared_ptr<Player>;
179
180} // namespace rtp::server
181#endif /* !RTYPE_GAME_PLAYER_HPP_ */
Represents a player in the game server.
Definition Player.hpp:41
uint32_t _sessionId
Unique player identifier.
Definition Player.hpp:161
uint32_t getId() const
Get the unique identifier of the Session.
Definition Player.cpp:88
void setRoomId(uint32_t roomId)
Set the room ID the player is in.
Definition Player.cpp:40
std::string getUsername() const
Get the username of the player.
Definition Player.cpp:34
void setScore(int score)
Set player's score.
Definition Player.cpp:130
void setWeaponKind(rtp::ecs::components::WeaponKind weapon)
Set the selected weapon kind for this player.
Definition Player.cpp:112
uint32_t _entityId
Associated entity ID in the ECS.
Definition Player.hpp:167
void setState(PlayerState state)
Set the state of the player.
Definition Player.cpp:58
void setReady(bool ready)
Set the readiness status of the player.
Definition Player.cpp:70
uint32_t getRoomId() const
Get the room ID the player is in.
Definition Player.cpp:46
bool isReady() const
Get the readiness status of the player.
Definition Player.cpp:76
void setEntityId(uint32_t entityId)
Set the entity ID associated with the player.
Definition Player.cpp:82
int _score
Player score.
Definition Player.hpp:171
std::string _username
Player username.
Definition Player.hpp:162
uint32_t getEntityId() const
Get the associated entity ID.
Definition Player.cpp:94
bool _isReady
Readiness status of the player.
Definition Player.hpp:165
uint32_t _roomId
ID of the room the player is in ; by default 0 (no room)
Definition Player.hpp:163
void addScore(int delta)
Add to player's score (can be negative)
Definition Player.cpp:124
void setMuted(bool muted)
Definition Player.cpp:100
rtp::ecs::components::WeaponKind getWeaponKind() const
Get the selected weapon kind for this player.
Definition Player.cpp:118
int getScore() const
Get player's score.
Definition Player.cpp:136
void setUsername(const std::string &username)
Set the username of the player.
Definition Player.cpp:28
~Player()
Destructor for Player.
Definition Player.cpp:24
PlayerState _state
Current state of the player.
Definition Player.hpp:164
bool _isMuted
Mute status of the player.
Definition Player.hpp:169
bool isInRoom() const
Check if the player is in a room.
Definition Player.cpp:52
PlayerState getState() const
Get the state of the player.
Definition Player.cpp:64
std::mutex _mutex
Mutex to protect access to player state.
Definition Player.hpp:168
rtp::ecs::components::WeaponKind _weaponKind
Selected weapon.
Definition Player.hpp:170
bool isMuted() const
Definition Player.cpp:106
WeaponKind
Types of player weapons.
@ Classic
Default spam/charge laser.
File : GameManager.hpp License: MIT Author : Elias Josué HAJJAR LLAUQUEN elias-josue....
std::shared_ptr< Player > PlayerPtr
Shared pointer type for Player.
Definition Player.hpp:178
PlayerState
Enum representing the state of a player in the session.
Definition Player.hpp:28