Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
Loading...
Searching...
No Matches
GameManager.hpp
Go to the documentation of this file.
1
8#ifndef RTYPE_GAME_GAMEMANAGER_HPP_
9 #define RTYPE_GAME_GAMEMANAGER_HPP_
10
11 #include <cstdint>
12 #include <string>
13 #include <vector>
14 #include <memory>
15 #include <map>
16 #include <mutex>
17 #include <thread>
18 #include <chrono>
19
20 #include "RType/Logger.hpp"
21 #include "Game/Room.hpp"
22 #include "Game/Player.hpp"
24 #include "RType/ECS/Registry.hpp"
25
26 /* Systems */
27 #include "Systems/NetworkSyncSystem.hpp"
29 #include "Systems/AuthSystem.hpp"
30 #include "Systems/RoomSystem.hpp"
42
43 /* Components */
61
66namespace rtp::server
67{
73 public:
78 GameManager(ServerNetwork &networkManager);
79
84
89 void gameLoop(void);
90
95 void startGame(Room &room);
96
97 private:
99 // Network Event Processing
101
106 void processNetworkEvents(void);
107
112 void handlePlayerConnect(uint32_t sessionId);
113
118 void handlePlayerDisconnect(uint32_t sessionId);
119
125 void handlePlayerLoginAuth(uint32_t sessionId, const net::Packet &packet);
126
132 void handlePlayerRegisterAuth(uint32_t sessionId, const net::Packet &packet);
133
139 void handleListRooms(uint32_t sessionId);
140
146 void handleCreateRoom(uint32_t sessionId, const net::Packet &packet);
147
153 void handleJoinRoom(uint32_t sessionId, const net::Packet &packet);
154
160 void handleLeaveRoom(uint32_t sessionId, const net::Packet &packet);
161
167 void handleSetReady(uint32_t sessionId, const net::Packet &packet);
168
172 void handleUpdateSelectedWeapon(uint32_t sessionId, const net::Packet &packet);
173
179 void handleRoomChatSended(uint32_t sessionId, const net::Packet &packet);
180
186 void handlePacket(uint32_t sessionId, const net::Packet &packet);
187 void handlePing(uint32_t sessionId, const net::Packet &packet);
188
189 bool handleChatCommand(PlayerPtr player, const std::string& message);
190 void sendChatToSession(uint32_t sessionId, const std::string& message);
191 void sendSystemMessageToRoom(uint32_t roomId, const std::string& message);
192
193 void sendEntitySpawnToSessions(const ecs::Entity& entity,
194 const std::vector<uint32_t>& sessions);
195 void sendRoomEntitySpawnsToSession(uint32_t roomId, uint32_t sessionId);
196
197 private:
202 std::unique_ptr<NetworkSyncSystem> _networkSyncSystem;
203 std::unique_ptr<MovementSystem> _movementSystem;
204 std::unique_ptr<AuthSystem> _authSystem;
205 std::unique_ptr<RoomSystem> _roomSystem;
206 std::unique_ptr<PlayerSystem> _playerSystem;
207 std::unique_ptr<EntitySystem> _entitySystem;
208 std::unique_ptr<PlayerMouvementSystem> _playerMouvementSystem;
209 std::unique_ptr<PlayerShootSystem> _playerShootSystem;
210 std::unique_ptr<EnemyAISystem> _enemyAISystem;
211 std::unique_ptr<LevelSystem> _levelSystem;
212 std::unique_ptr<HomingSystem> _homingSystem;
213 std::unique_ptr<BoomerangSystem> _boomerangSystem;
214 std::unique_ptr<CollisionSystem> _collisionSystem;
215 std::unique_ptr<EnemyShootSystem> _enemyShootSystem;
216 std::unique_ptr<BulletCleanupSystem> _bulletCleanupSystem;
218 uint32_t _serverTick = 0;
219 mutable std::mutex _mutex;
220 bool _gamePaused = false;
221 float _gameSpeed = 1.0f;
222 };
223}
224
225#endif // RTYPE_GAME_GAMEMANAGER_HPP_
Logger declaration with support for multiple log levels.
Represents an entity in the ECS (Entity-Component-System) architecture.
Definition Entity.hpp:63
Network packet with header and serializable body.
Definition Packet.hpp:471
Manages game state, rooms, and player interactions on the server side.
void handlePing(uint32_t sessionId, const net::Packet &packet)
std::unique_ptr< RoomSystem > _roomSystem
Room system for handling room management.
std::unique_ptr< MovementSystem > _movementSystem
Movement system for updating entity positions.
void handlePlayerDisconnect(uint32_t sessionId)
Handle a player disconnection.
void handleJoinRoom(uint32_t sessionId, const net::Packet &packet)
Handle a generic incoming packet from a player.
std::unique_ptr< PlayerMouvementSystem > _playerMouvementSystem
Player movement system for handling player-specific movement logic.
std::unique_ptr< NetworkSyncSystem > _networkSyncSystem
Server network system for handling network-related ECS operations.
std::unique_ptr< EnemyAISystem > _enemyAISystem
Enemy AI system for movement patterns.
std::unique_ptr< BoomerangSystem > _boomerangSystem
Boomerang system for boomerang projectiles.
uint32_t _serverTick
Current server tick for synchronization.
std::mutex _mutex
Mutex for thread-safe operations.
void handleRoomChatSended(uint32_t sessionId, const net::Packet &packet)
Handle a generic incoming packet from a player.
void handleListRooms(uint32_t sessionId)
Handle a request to list available rooms.
void gameLoop(void)
Main game loop.
std::unique_ptr< EnemyShootSystem > _enemyShootSystem
Enemy shooting system.
void handleLeaveRoom(uint32_t sessionId, const net::Packet &packet)
Handle a generic incoming packet from a player.
void handleCreateRoom(uint32_t sessionId, const net::Packet &packet)
Handle a generic incoming packet from a player.
void sendRoomEntitySpawnsToSession(uint32_t roomId, uint32_t sessionId)
bool handleChatCommand(PlayerPtr player, const std::string &message)
void processNetworkEvents(void)
Process incoming network events with OpCode handling.
~GameManager()
Destructor for GameManager.
std::unique_ptr< LevelSystem > _levelSystem
Level system for timed spawns.
std::unique_ptr< CollisionSystem > _collisionSystem
Collision system for pickups/obstacles.
float _gameSpeed
Global game speed multiplier.
std::unique_ptr< HomingSystem > _homingSystem
Homing system for tracker bullets.
ServerNetwork & _networkManager
Reference to the ServerNetwork instance.
std::unique_ptr< PlayerSystem > _playerSystem
Player system for handling player-related operations.
void sendSystemMessageToRoom(uint32_t roomId, const std::string &message)
void handlePacket(uint32_t sessionId, const net::Packet &packet)
Handle an incoming packet from a player.
bool _gamePaused
Global game pause flag.
void handlePlayerLoginAuth(uint32_t sessionId, const net::Packet &packet)
Handle player login with provided username if successful then join the lobby.
void handleUpdateSelectedWeapon(uint32_t sessionId, const net::Packet &packet)
Handle an update to the selected weapon sent by client.
ecs::Registry _registry
ECS Registry for managing entities and components.
void handleSetReady(uint32_t sessionId, const net::Packet &packet)
Handle a generic incoming packet from a player.
void startGame(Room &room)
Start a game in the specified room.
void handlePlayerRegisterAuth(uint32_t sessionId, const net::Packet &packet)
Handle player registration with provided username.
void sendChatToSession(uint32_t sessionId, const std::string &message)
std::unique_ptr< PlayerShootSystem > _playerShootSystem
Player shooting system for handling bullets.
std::unique_ptr< BulletCleanupSystem > _bulletCleanupSystem
Bullet cleanup system.
std::unique_ptr< EntitySystem > _entitySystem
Entity system for handling entity-related operations.
void handlePlayerConnect(uint32_t sessionId)
Handle a new player connection.
void sendEntitySpawnToSessions(const ecs::Entity &entity, const std::vector< uint32_t > &sessions)
std::unique_ptr< AuthSystem > _authSystem
Authentication system for handling player logins.
Represents a game room in the server.
Definition Room.hpp:35
Implementation ASIO du serveur réseau (TCP + UDP)
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