R-Type 0.1
Loading...
Searching...
No Matches
rtype::server::Game Class Reference

Authoritative game simulation run by the server. More...

#include <game.hpp>

Public Member Functions

 Game (std::uint16_t port=4242)
 Creates the game and its network server.
 
void onLoad (rtk::EngineContext &context)
 Registers components, loads blueprints, adds the systems and starts the network server.
 
void onUpdate (rtk::EngineContext &context, float dt)
 Updates the active scene.
 
void onUnload (rtk::EngineContext &context)
 Exits the scene and stops the network server.
 
bool shouldContinue () const
 Tells the engine whether to keep running.
 
void incrementServerTick ()
 Advances the server tick by one.
 
std::uint32_t getServerTick () const
 Returns the server tick.
 
std::size_t getPlayerCount () const
 Returns the number of connected players.
 
const std::unordered_map< std::uint32_t, std::size_t > & getPlayers () const
 Returns the connected players.
 
bool isGameActive () const
 Tells whether a round is being played.
 
void setGameActive (bool active)
 Marks a round as started or stopped.
 
void resetGameState ()
 Forgets every player and resets the tick and round state.
 

Detailed Description

Authoritative game simulation run by the server.

Owns the network server, the lobby and in game scenes, and the player entities, and replicates the world to every connected client.

Constructor & Destructor Documentation

◆ Game()

rtype::server::Game::Game ( std::uint16_t port = 4242)
explicit

Creates the game and its network server.

Parameters
portUDP port to listen on.

Member Function Documentation

◆ onLoad()

void rtype::server::Game::onLoad ( rtk::EngineContext & context)

Registers components, loads blueprints, adds the systems and starts the network server.

Parameters
contextEngine services.

◆ onUpdate()

void rtype::server::Game::onUpdate ( rtk::EngineContext & context,
float dt )

Updates the active scene.

Parameters
contextEngine services.
dtElapsed time since the last frame, in seconds.

◆ onUnload()

void rtype::server::Game::onUnload ( rtk::EngineContext & context)

Exits the scene and stops the network server.

Parameters
contextEngine services.

◆ shouldContinue()

bool rtype::server::Game::shouldContinue ( ) const

Tells the engine whether to keep running.

Returns
True while the server runs.

◆ getServerTick()

std::uint32_t rtype::server::Game::getServerTick ( ) const
inline

Returns the server tick.

Returns
Number of simulated frames since the game started.

◆ getPlayerCount()

std::size_t rtype::server::Game::getPlayerCount ( ) const
inline

Returns the number of connected players.

Returns
The player count.

◆ getPlayers()

const std::unordered_map< std::uint32_t, std::size_t > & rtype::server::Game::getPlayers ( ) const
inline

Returns the connected players.

Returns
Map from connection id to player entity.

◆ isGameActive()

bool rtype::server::Game::isGameActive ( ) const
inline

Tells whether a round is being played.

Returns
True in the in game scene.

◆ setGameActive()

void rtype::server::Game::setGameActive ( bool active)
inline

Marks a round as started or stopped.

Parameters
activeTrue while a round is played.