R-Type
Networked shoot'em up built on Aegis2D
Loading...
Searching...
No Matches
rtype::Room Class Reference

One game of the server: its GameInstance, the Simulation thread that runs it, the EventTracker of what its clients learnt, and the names of its players. More...

#include </__w/project-rtype/project-rtype/server/include/rtype/room.hpp>

Public Types

using TickHandler = std::function< void(Room &room, GameInstance &instance)>
 Called on the simulation thread after each tick of the room.
 

Public Member Functions

 Room (std::uint32_t id, std::optional< std::uint64_t > seed, aegis2d::ecs::WaveSchedule waves, std::uint32_t rate, TickHandler after_tick, bool trace=false, GameRules rules={})
 Creates the game and starts its thread.
 
 Room (const Room &)=delete
 
Room & operator= (const Room &)=delete
 
 Room (Room &&)=delete
 
Room & operator= (Room &&)=delete
 
 ~Room ()=default
 Stops the thread, then destroys the game.
 
std::uint32_t id () const noexcept
 Number of the room in its server.
 
GameInstance & instance () noexcept
 The game of the room.
 
Simulation & simulation () noexcept
 The thread running the game.
 
EventTracker & events () noexcept
 What the clients of the room learnt of its entities.
 
std::array< std::optional< std::string >, tuning::max_players > & names () noexcept
 Names of the players in the room's game, by number.
 

Detailed Description

One game of the server: its GameInstance, the Simulation thread that runs it, the EventTracker of what its clients learnt, and the names of its players.

The game, the tracker and the names belong to the simulation thread: other threads post() to simulation() to use them, or wait until it stopped. The thread starts once the rest of the room is built, and stops first when the room is destroyed. The rooms of a server run side by side, each on its own thread, and its sessions play in the room of their Session::room.

Member Typedef Documentation

◆ TickHandler

using rtype::Room::TickHandler = std::function<void(Room& room, GameInstance& instance)>

Called on the simulation thread after each tick of the room.

Constructor & Destructor Documentation

◆ Room() [1/3]

rtype::Room::Room ( std::uint32_t  id,
std::optional< std::uint64_t >  seed,
aegis2d::ecs::WaveSchedule  waves,
std::uint32_t  rate,
TickHandler  after_tick,
bool  trace = false,
GameRules  rules = {} 
)

Creates the game and starts its thread.

Parameters
idNumber of the room in its server, its sessions' Session::room.
seedSeed of the random spawns, or std::nullopt for none (see ServerGame).
wavesWaves to play in every game of the room, at their start.
rateTicks per second.
after_tickCalled after each tick, on the simulation thread.
tracetrue to record the timings of its ticks (Simulation::profiler()).
rulesHow the games of the room play.

◆ Room() [2/3]

rtype::Room::Room ( const Room &  )
delete

◆ Room() [3/3]

rtype::Room::Room ( Room &&  )
delete

◆ ~Room()

rtype::Room::~Room ( )
default

Stops the thread, then destroys the game.

Member Function Documentation

◆ events()

EventTracker & rtype::Room::events ( )
noexcept

What the clients of the room learnt of its entities.

Returns
The tracker; use it from the simulation thread.

◆ id()

std::uint32_t rtype::Room::id ( ) const
noexcept

Number of the room in its server.

Returns
The id given to the constructor.

◆ instance()

GameInstance & rtype::Room::instance ( )
noexcept

The game of the room.

Returns
It; use it from the simulation thread, or once simulation() stopped.

◆ names()

std::array< std::optional< std::string >, tuning::max_players > & rtype::Room::names ( )
noexcept

Names of the players in the room's game, by number.

Returns
An empty slot for a number with no player; use them from the simulation thread.

◆ operator=() [1/2]

Room & rtype::Room::operator= ( const Room &  )
delete

◆ operator=() [2/2]

Room & rtype::Room::operator= ( Room &&  )
delete

◆ simulation()

Simulation & rtype::Room::simulation ( )
noexcept

The thread running the game.

Returns
The simulation.

The documentation for this class was generated from the following file: