3#include "EngineContext.hpp"
4#include "Scene/serverGameScene.hpp"
5#include "Scene/serverLobbyScene.hpp"
7#include "collision/collisionBuffer.hpp"
8#include "factoryDataDriven/factoryDataDriven.hpp"
9#include "sceneManager/sceneManager.hpp"
10#include "serverScene.hpp"
15#include <unordered_map>
17namespace rtype::server {
30 friend class ServerLobbyScene;
31 friend class ServerGameScene;
38 explicit Game(std::uint16_t port = 4242);
88 const std::unordered_map<std::uint32_t, std::size_t> &
getPlayers()
const {
110 _isGameActive =
false;
138 void sendExistingEntities(std::uint32_t connectionId,
140 void broadcastPlayerCreated(std::uint32_t connectionId,
142 void broadcastPlayerDestroyed(std::uint32_t connectionId,
143 std::uint32_t networkId);
153 std::unordered_map<std::uint32_t, std::size_t> _players;
154 std::array<std::uint16_t, 4> _playerArchetypes{};
155 std::uint32_t _serverTick = 0;
156 bool _running =
true;
157 bool _isGameActive =
false;
Holds the active scene and switches between a fixed set of scenes.
Definition sceneManager.hpp:32
Collisions detected during the current frame.
Definition collisionBuffer.hpp:24
Authoritative game simulation run by the server.
Definition game.hpp:29
void resetGameState()
Forgets every player and resets the tick and round state.
Definition game.hpp:107
bool shouldContinue() const
Tells the engine whether to keep running.
Definition game.cpp:366
void setGameActive(bool active)
Marks a round as started or stopped.
Definition game.hpp:102
std::size_t getPlayerCount() const
Returns the number of connected players.
Definition game.hpp:82
void onLoad(rtk::EngineContext &context)
Registers components, loads blueprints, adds the systems and starts the network server.
Definition game.cpp:40
std::uint32_t getServerTick() const
Returns the server tick.
Definition game.hpp:76
void onUnload(rtk::EngineContext &context)
Exits the scene and stops the network server.
Definition game.cpp:552
const std::unordered_map< std::uint32_t, std::size_t > & getPlayers() const
Returns the connected players.
Definition game.hpp:88
bool isGameActive() const
Tells whether a round is being played.
Definition game.hpp:96
Game(std::uint16_t port=4242)
Creates the game and its network server.
Definition game.cpp:33
void incrementServerTick()
Advances the server tick by one.
Definition game.hpp:70
void onUpdate(rtk::EngineContext &context, float dt)
Updates the active scene.
Definition game.cpp:362
Round in progress: simulates the stage and returns to the lobby when every player left.
Definition serverGameScene.hpp:17
Waiting room: starts the round with 2 players, or after 30 seconds with 1 player.
Definition serverLobbyScene.hpp:17
Game level layer over NetworkServer that decodes client messages and encodes server messages.
Definition Server.hpp:30
ServerSceneType
Identifiers of the server scenes.
Definition serverScene.hpp:14
Engine services handed to the game and its scenes.
Definition EngineContext.hpp:20
Object passed to every server scene constructor.
Definition serverScene.hpp:28