|
R-Type
Networked shoot'em up built on Aegis2D
|
Runs a GameInstance on its own thread, tuning::tick_rate times per second. More...
#include </__w/project-rtype/project-rtype/server/include/rtype/simulation.hpp>
Public Types | |
| using | Command = std::function< void(GameInstance &instance)> |
| A change to make to the game, run on the simulation thread. | |
| using | TickHandler = std::function< void(GameInstance &instance)> |
| Called on the simulation thread after each tick, to read the game. | |
Public Member Functions | |
| Simulation (GameInstance &instance, std::uint32_t rate=tuning::tick_rate, TickHandler after_tick={}, bool trace=false) | |
| Starts the thread. | |
| Simulation (const Simulation &)=delete | |
| Simulation & | operator= (const Simulation &)=delete |
| Simulation (Simulation &&)=delete | |
| Simulation & | operator= (Simulation &&)=delete |
| ~Simulation () | |
| Stops the thread and waits for it. | |
| void | post (Command command) |
| Queues a command for the simulation thread. Thread-safe. | |
| void | stop () |
| Stops the thread after its current tick and waits for it. Thread-safe, but not from a command; calling it again does nothing. | |
| std::uint64_t | ticks () const noexcept |
| Number of ticks run. Thread-safe. | |
| const aegis2d::core::Profiler & | profiler () const noexcept |
The timings of the ticks, recorded with trace: a frame per tick, the tick and its systems, then after_tick (the snapshots and events). | |
| std::uint32_t | rate () const noexcept |
| Ticks per second the thread aims at. | |
Static Public Attributes | |
| static constexpr std::chrono::seconds | report_period {10} |
| How often the measured rate is logged. | |
Runs a GameInstance on its own thread, tuning::tick_rate times per second.
The thread starts in the constructor and ticks the game at a fixed rate, with or without players, using the engine's MainLoop: it sleeps until each step is due and, after a stall, catches up at most FixedTimestep::default_max_frame of steps. Every report_period it logs how many ticks ran and the rate measured.
The game belongs to the thread: other threads (the network) never touch it, they post() commands that run on the thread before the next tick. An exception thrown by a command or by a tick is logged and the thread goes on.
| using rtype::Simulation::Command = std::function<void(GameInstance& instance)> |
A change to make to the game, run on the simulation thread.
| using rtype::Simulation::TickHandler = std::function<void(GameInstance& instance)> |
Called on the simulation thread after each tick, to read the game.
|
explicit |
Starts the thread.
| instance | Game to run; it must outlive this object and is only used by the thread from now on. |
| rate | Ticks per second, tuning::tick_rate by default. |
| after_tick | Called after each tick (snapshots, events); may be empty. |
| trace | true to time each tick, its systems and what follows it, for profiler(). |
|
delete |
|
delete |
| rtype::Simulation::~Simulation | ( | ) |
Stops the thread and waits for it.
|
delete |
|
delete |
| void rtype::Simulation::post | ( | Command | command | ) |
Queues a command for the simulation thread. Thread-safe.
Commands run in the order they were posted, all of them before the next tick. Commands posted after stop() never run.
| command | Change to make to the game. |
|
noexcept |
The timings of the ticks, recorded with trace: a frame per tick, the tick and its systems, then after_tick (the snapshots and events).
Used by the thread: read it once stop() returned.
trace.
|
noexcept |
Ticks per second the thread aims at.
| void rtype::Simulation::stop | ( | ) |
Stops the thread after its current tick and waits for it. Thread-safe, but not from a command; calling it again does nothing.
|
noexcept |
Number of ticks run. Thread-safe.
|
staticconstexpr |
How often the measured rate is logged.