|
| | GameServer (aegis2d::net::NetworkContext &context, std::optional< std::uint64_t > seed, aegis2d::ecs::WaveSchedule waves, std::uint16_t tcp_port, std::uint16_t udp_port, std::uint32_t rate=tuning::tick_rate, std::uint32_t max_rooms=1) |
| | Opens both ports; the rooms open as their players join.
|
| |
| | GameServer (const GameServer &)=delete |
| |
| GameServer & | operator= (const GameServer &)=delete |
| |
| | GameServer (GameServer &&)=delete |
| |
| GameServer & | operator= (GameServer &&)=delete |
| |
| | ~GameServer ()=default |
| | Stops the simulation threads, then closes the sockets.
|
| |
| void | set_waves (std::map< std::string, aegis2d::ecs::WaveSchedule > waves) |
| | Sets the waves files a room may be created with, besides the server's own.
|
| |
| void | keep_scores (std::filesystem::path file) |
| | Keeps the best scores in a file: at the end of each game of a room, every player of it records its score there.
|
| |
| const Scoreboard * | scoreboard () const noexcept |
| | The best scores kept.
|
| |
| ServerNetwork & | network () noexcept |
| | The sockets and the sessions; use them on the context's thread.
|
| |
| Room & | room (std::uint32_t id=0) |
| | An open room: its game, thread and event tracker. Use it on the context's thread: the room closes there when its last player leaves.
|
| |
| std::uint32_t | open_rooms () const noexcept |
| | Number of rooms open, with a game running.
|
| |
| std::uint32_t | max_rooms () const noexcept |
| | Number of rooms played at once.
|
| |
| std::uint32_t | rate () const noexcept |
| | Ticks per second of each room.
|
| |
| void | start_trace () noexcept |
| | Records the timings of the ticks of every room opened from now on.
|
| |
| std::size_t | save_trace (const std::filesystem::path &file) |
| | Closes every room, then writes the timings recorded in the Chrome trace format, which Perfetto (ui.perfetto.dev) opens: a thread per room opened, named after it.
|
| |
| Simulation & | simulation () |
| | The thread running the game of the first room, room().simulation().
|
| |
Runs the games of its rooms for the players of its sockets, as r-type_server does.
The sockets work on the caller's context, each game in its Room, on the room's Simulation thread, and they only talk through posted tasks. Each session plays in the room of its Session::room, and everything below stays within that room:
- a player whose UDP endpoint is bound joins the game: the others get its
PlayerJoined, and it gets a PlayerJoined of every player already there, then a Spawn of every entity (RFC section 4.6);
- a player whose session ends (
Logout, Disconnect, TCP closed, UDP timeout, protocol error) leaves it: the others get its PlayerLeft with the reason, then, at the next tick, the Destroy of its ship;
- the most recent
Input of each player steers its ship;
- after each tick, the events of the tick go to every bound player, and every third tick a snapshot;
- with each snapshot, the round trip time of each player sets how far back its missiles meet the enemies (lag compensation, rewind_ticks()), when it changes.
The logins fill the first room with a free player number, then the next one, up to max_rooms() rooms (SessionTable::set_rooms()). A room opens when its first player joins: its game starts on a new thread, with the rules the room was created with (game_rules(), and the waves it names, see set_waves()). It closes when its last player leaves: its thread is stopped and joined, and its game is gone, so the next player of that room starts a new one. The caller runs the context and calls network().update() a few times per second. Destroying the server stops the simulation threads; the context must not run the tasks left in it afterwards.
| void rtype::GameServer::keep_scores |
( |
std::filesystem::path |
file | ) |
|
Keeps the best scores in a file: at the end of each game of a room, every player of it records its score there.
Reads the board of the file now (Scoreboard), and uses it on the context's thread, where the network answers ListScores with it; without a call, no score is kept and the list is empty.
- Parameters
-
| file | Where the scores are kept. |