Main game server plugin for R-Type multiplayer gameplay. More...
#include <RTypeServer.hpp>
Inheritance diagram for gme::RTypeServer:
Collaboration diagram for gme::RTypeServer:Public Member Functions | |
| RTypeServer () | |
| Constructor. | |
| ~RTypeServer () override=default | |
| Destructor. | |
| RTypeServer (const RTypeServer &)=delete | |
| Deleted copy constructor (non-copyable) | |
| RTypeServer & | operator= (const RTypeServer &)=delete |
| Deleted copy assignment operator (non-copyable) | |
| RTypeServer (RTypeServer &&)=delete | |
| Deleted move constructor (non-movable) | |
| RTypeServer & | operator= (RTypeServer &&)=delete |
| Deleted move assignment operator (non-movable) | |
| const std::string | getName () const override |
| Get plugin name. | |
| utl::PluginType | getType () const override |
| Get plugin type. | |
| State | getState () const override |
| Get current game state. | |
| void | start () override |
| Start the game server. | |
| void | stop () override |
| Stop the game server. | |
| void | update (float deltaTime) override |
| Update the game server (called each tick) | |
Public Member Functions inherited from utl::IPlugin | |
| virtual | ~IPlugin ()=default |
Private Member Functions | |
| void | processServerStartEvent (const utl::Event &event) |
| Process server start event from network layer. | |
| void | processPlayerInputEvent (const utl::Event &event) |
| Process player input event. | |
| void | processGameStartEvent (const utl::Event &event) |
| Process game start event from lobby system. | |
| void | processPlayerDisconnectEvent (const utl::Event &event) |
| Process player disconnect event. | |
| void | updateEntities (float deltaTime) |
| Update entity lifetimes and physics. | |
| void | updateSystems (float deltaTime) |
| Update all game systems (AI, collision, spawning) | |
| void | broadcastWorldState () const |
| Broadcast complete world state to all clients. | |
| void | handlePlayerShooting (std::uint32_t sessionId, float deltaTime) |
| Handle player shooting logic. | |
| void | checkGameOver () |
| Check for game over conditions. | |
Private Attributes | |
| utl::EventBus & | m_eventBus |
| Event bus for inter-system communication. | |
| ecs::Registry | m_registry |
| ECS registry containing all game entities. | |
| std::unique_ptr< EntityManager > | m_entityManager |
| Centralized entity lifecycle manager. | |
| std::unique_ptr< CollisionSystem > | m_collisionSystem |
| Collision detection and resolution system. | |
| std::unique_ptr< EnemyAISystem > | m_enemyAISystem |
| Enemy behavior and AI system. | |
| std::unique_ptr< EnemySpawnSystem > | m_enemySpawnSystem |
| Enemy spawning system (legacy/unused) | |
| std::unique_ptr< WaveManager > | m_waveManager |
| Wave-based enemy spawning manager. | |
| State | m_gameState = State::PLAYING |
| Current server state. | |
| LevelState | m_levelState = LevelState::WAITING_FOR_PLAYERS |
| Current level state. | |
| std::unordered_map< std::uint32_t, bool > | m_playerShooting |
| Map of session ID to shooting state. | |
| std::unordered_map< std::uint32_t, float > | m_lastShotTime |
| Map of session ID to last shot timestamp. | |
| float | m_lastBroadcastTime = 0.0f |
| Time since last world state broadcast. | |
| const float | PROJECTILE_COOLDOWN = 0.3f |
| Cooldown between player shots (seconds) | |
Main game server plugin for R-Type multiplayer gameplay.
This class implements the complete server-side game logic including:
The server operates at a fixed tick rate and broadcasts world state to all connected clients. All gameplay logic is server-authoritative to prevent cheating and ensure synchronized gameplay across all clients.
Definition at line 66 of file RTypeServer.hpp.
| gme::RTypeServer::RTypeServer | ( | ) |
Constructor.
Initializes the game server, ECS registry, and all game systems
Definition at line 20 of file rtypeServer.cpp.
References utl::GAME_LOGIC, utl::GAME_START, utl::INFO, utl::Logger::log(), m_collisionSystem, m_enemyAISystem, m_enemySpawnSystem, m_entityManager, m_eventBus, m_registry, m_waveManager, utl::PLAYER_INPUT_RECEIVED, utl::EventBus::registerComponent(), utl::SERVER_START, and utl::EventBus::subscribe().
Here is the call graph for this function:
|
overridedefault |
Destructor.
|
delete |
Deleted copy constructor (non-copyable)
|
delete |
Deleted move constructor (non-movable)
|
private |
Broadcast complete world state to all clients.
Sends WORLD_STATE packet containing all entity positions and states
Definition at line 532 of file rtypeServer.cpp.
References utl::Event::data, rnp::PacketWorldState::entities, rnp::PacketWorldState::entityCount, rnp::Serializer::getData(), rnp::PacketHeader::length, utl::Logger::log(), m_entityManager, m_eventBus, m_lastBroadcastTime, utl::NETWORK_SERVER, utl::EventBus::publish(), utl::SEND_TO_CLIENT, rnp::Serializer::serializeHeader(), rnp::Serializer::serializeWorldState(), rnp::PacketWorldState::serverTick, rnp::PacketHeader::sessionId, rnp::PacketHeader::type, utl::WARNING, and rnp::WORLD_STATE.
Referenced by update().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Check for game over conditions.
Checks if all players are dead or all waves are complete
Definition at line 284 of file rtypeServer.cpp.
References gme::COMPLETED, utl::GAME_LOGIC, utl::GAME_OVER, gme::IN_PROGRESS, utl::INFO, utl::Logger::log(), gme::LOOSE, m_entityManager, m_eventBus, m_levelState, m_waveManager, utl::EventBus::publish(), and gme::WAITING_FOR_PLAYERS.
Referenced by processPlayerDisconnectEvent(), and update().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inlinenodiscardoverridevirtual |
Get plugin name.
Implements utl::IPlugin.
Definition at line 94 of file RTypeServer.hpp.
|
inlinenodiscardoverridevirtual |
Get current game state.
Implements gme::IGameServer.
Definition at line 106 of file RTypeServer.hpp.
References m_gameState.
|
inlinenodiscardoverridevirtual |
Get plugin type.
Implements utl::IPlugin.
Definition at line 100 of file RTypeServer.hpp.
References utl::GAME_SERVER.
|
private |
Handle player shooting logic.
| sessionId | Player's session ID |
| deltaTime | Time elapsed since last frame |
Creates projectiles when player shoots, respecting cooldown
Definition at line 389 of file rtypeServer.cpp.
References ecs::BeamCharge::current_charge, ecs::Registry::getComponent(), ecs::INVALID_ENTITY, m_entityManager, m_lastShotTime, m_playerShooting, m_registry, PROJECTILE_COOLDOWN, utl::GameConfig::Player::SCALE, utl::GameConfig::Player::SPRITE_HEIGHT, and utl::GameConfig::Player::SPRITE_WIDTH.
Referenced by updateSystems().
Here is the call graph for this function:
Here is the caller graph for this function:
|
delete |
Deleted copy assignment operator (non-copyable)
|
delete |
Deleted move assignment operator (non-movable)
|
private |
Process game start event from lobby system.
| event | Event containing lobby and player information |
Creates player entities and starts wave system
Definition at line 247 of file rtypeServer.cpp.
References gme::IN_PROGRESS, utl::INFO, utl::Logger::log(), m_levelState, m_waveManager, and utl::WARNING.
Referenced by update().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Process player disconnect event.
| event | Event containing disconnected player's session ID |
Removes player entity and checks for game over
Definition at line 353 of file rtypeServer.cpp.
References checkGameOver(), utl::INFO, utl::Logger::log(), m_entityManager, m_levelState, m_waveManager, and gme::WAITING_FOR_PLAYERS.
Referenced by update().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Process player input event.
| event | Event containing player input data (movement, shooting) |
Applies player input to corresponding player entity
Definition at line 159 of file rtypeServer.cpp.
References utl::Event::data, ecs::Registry::getComponent(), utl::Logger::log(), m_entityManager, m_lastShotTime, m_playerShooting, m_registry, and utl::WARNING.
Referenced by update().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Process server start event from network layer.
| event | Event containing server configuration |
Initializes game systems when server is ready
Definition at line 123 of file rtypeServer.cpp.
References utl::Event::data, gme::IN_PROGRESS, utl::INFO, utl::Logger::log(), m_enemySpawnSystem, m_entityManager, m_lastShotTime, m_levelState, m_playerShooting, and gme::WAITING_FOR_PLAYERS.
Referenced by update().
Here is the call graph for this function:
Here is the caller graph for this function:
|
overridevirtual |
Start the game server.
Initializes systems and begins listening for game start events
Implements gme::IGameServer.
Definition at line 45 of file rtypeServer.cpp.
References utl::INFO, utl::Logger::log(), m_enemySpawnSystem, m_gameState, m_levelState, gme::PLAYING, and gme::WAITING_FOR_PLAYERS.
Here is the call graph for this function:
|
overridevirtual |
Stop the game server.
Cleans up all entities and resets game state
Implements gme::IGameServer.
Definition at line 57 of file rtypeServer.cpp.
References utl::INFO, utl::Logger::log(), gme::LOSE, m_enemySpawnSystem, m_entityManager, m_gameState, m_lastShotTime, m_playerShooting, and m_waveManager.
Here is the call graph for this function:
|
overridevirtual |
Update the game server (called each tick)
| deltaTime | Time elapsed since last update (in seconds) |
Processes events, updates entities, runs game systems, and broadcasts state
Implements gme::IGameServer.
Definition at line 75 of file rtypeServer.cpp.
References utl::GameConfig::Server::Network::BROADCAST_INTERVAL, broadcastWorldState(), checkGameOver(), utl::EventBus::consumeForTarget(), utl::GAME_LOGIC, utl::GAME_START, m_entityManager, m_eventBus, m_lastBroadcastTime, utl::PLAYER_DISCONNECTED, utl::PLAYER_INPUT_RECEIVED, processGameStartEvent(), processPlayerDisconnectEvent(), processPlayerInputEvent(), processServerStartEvent(), utl::SERVER_START, updateEntities(), and updateSystems().
Here is the call graph for this function:
|
private |
Update entity lifetimes and physics.
| deltaTime | Time elapsed since last frame |
Updates projectile lifetimes and entity movement
Definition at line 440 of file rtypeServer.cpp.
References ecs::Registry::getComponent(), m_entityManager, m_registry, utl::GameConfig::Player::SCALE, utl::GameConfig::Server::SCREEN_HEIGHT, utl::GameConfig::Server::SCREEN_WIDTH, utl::GameConfig::Player::SPRITE_HEIGHT, utl::GameConfig::Player::SPRITE_WIDTH, utl::GameConfig::Server::WORLD_MARGIN, ecs::Transform::x, ecs::Velocity::x, and ecs::Transform::y.
Referenced by update().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Update all game systems (AI, collision, spawning)
| deltaTime | Time elapsed since last frame |
Runs enemy AI, collision detection, and wave spawning systems
Definition at line 266 of file rtypeServer.cpp.
References handlePlayerShooting(), m_collisionSystem, m_enemyAISystem, m_entityManager, m_registry, and m_waveManager.
Referenced by update().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Collision detection and resolution system.
Definition at line 195 of file RTypeServer.hpp.
Referenced by RTypeServer(), and updateSystems().
|
private |
Enemy behavior and AI system.
Definition at line 196 of file RTypeServer.hpp.
Referenced by RTypeServer(), and updateSystems().
|
private |
Enemy spawning system (legacy/unused)
Definition at line 197 of file RTypeServer.hpp.
Referenced by processServerStartEvent(), RTypeServer(), start(), and stop().
|
private |
Centralized entity lifecycle manager.
Definition at line 194 of file RTypeServer.hpp.
Referenced by broadcastWorldState(), checkGameOver(), handlePlayerShooting(), processPlayerDisconnectEvent(), processPlayerInputEvent(), processServerStartEvent(), RTypeServer(), stop(), update(), updateEntities(), and updateSystems().
|
private |
Event bus for inter-system communication.
Definition at line 190 of file RTypeServer.hpp.
Referenced by broadcastWorldState(), checkGameOver(), RTypeServer(), and update().
|
private |
Current server state.
Definition at line 200 of file RTypeServer.hpp.
Referenced by getState(), start(), and stop().
|
private |
Time since last world state broadcast.
Definition at line 207 of file RTypeServer.hpp.
Referenced by broadcastWorldState(), and update().
|
private |
Map of session ID to last shot timestamp.
Definition at line 205 of file RTypeServer.hpp.
Referenced by handlePlayerShooting(), processPlayerInputEvent(), processServerStartEvent(), and stop().
|
private |
Current level state.
Definition at line 201 of file RTypeServer.hpp.
Referenced by checkGameOver(), processGameStartEvent(), processPlayerDisconnectEvent(), processServerStartEvent(), and start().
|
private |
Map of session ID to shooting state.
Definition at line 204 of file RTypeServer.hpp.
Referenced by handlePlayerShooting(), processPlayerInputEvent(), processServerStartEvent(), and stop().
|
private |
ECS registry containing all game entities.
Definition at line 191 of file RTypeServer.hpp.
Referenced by handlePlayerShooting(), processPlayerInputEvent(), RTypeServer(), updateEntities(), and updateSystems().
|
private |
Wave-based enemy spawning manager.
Definition at line 198 of file RTypeServer.hpp.
Referenced by checkGameOver(), processGameStartEvent(), processPlayerDisconnectEvent(), RTypeServer(), stop(), and updateSystems().
|
private |
Cooldown between player shots (seconds)
Definition at line 208 of file RTypeServer.hpp.
Referenced by handlePlayerShooting().