5#include <aegis2d/core/profiler.hpp>
6#include <aegis2d/ecs/waves.hpp>
7#include <aegis2d/net/context.hpp>
26#include <unordered_map>
75 GameServer(aegis2d::net::NetworkContext& context, std::optional<std::uint64_t> seed,
76 aegis2d::ecs::WaveSchedule waves, std::uint16_t tcp_port, std::uint16_t udp_port,
91 void set_waves(std::map<std::string, aegis2d::ecs::WaveSchedule> waves);
126 [[nodiscard]] std::uint32_t
rate() const noexcept;
148 std::uint32_t
room = 0;
149 std::uint8_t player = 0;
150 std::uint32_t rewind = 0;
154 void on_joined(
const Session& session);
156 void update_rewinds(std::uint32_t
id);
157 Room& open_room(std::uint32_t
id);
158 void close_room(std::uint32_t
id);
160 aegis2d::net::NetworkContext& context_;
163 std::optional<std::uint64_t> seed_;
164 aegis2d::ecs::WaveSchedule waves_;
165 std::map<std::string, aegis2d::ecs::WaveSchedule> named_waves_;
167 std::optional<Scoreboard> scores_;
169 std::unordered_map<std::uint32_t, Seat> seats_;
172 std::vector<std::pair<std::string, std::vector<aegis2d::core::TraceEvent>>> traces_;
175 std::vector<std::unique_ptr<Room>> rooms_;
The one game of the server, with up to tuning::max_players players.
Definition game_instance.hpp:37
Runs the games of its rooms for the players of its sockets, as r-type_server does.
Definition game_server.hpp:64
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
void start_trace() noexcept
Records the timings of the ticks of every room opened from now on.
std::uint32_t rate() const noexcept
Ticks per second of each room.
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....
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 sc...
std::uint32_t open_rooms() const noexcept
Number of rooms open, with a game running.
GameServer & operator=(GameServer &&)=delete
GameServer(GameServer &&)=delete
ServerNetwork & network() noexcept
The sockets and the sessions; use them on the context's thread.
~GameServer()=default
Stops the simulation threads, then closes the sockets.
std::uint32_t max_rooms() const noexcept
Number of rooms played at once.
const Scoreboard * scoreboard() const noexcept
The best scores kept.
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.
GameServer & operator=(const GameServer &)=delete
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 the...
Simulation & simulation()
The thread running the game of the first room, room().simulation().
One game of the server: its GameInstance, the Simulation thread that runs it, the EventTracker of wha...
Definition room.hpp:26
The max_entries best scores, best first, kept in a JSON file.
Definition scoreboard.hpp:34
The two ports the server listens on, and the TCP side of the sessions.
Definition server_network.hpp:81
Runs a GameInstance on its own thread, tuning::tick_rate times per second.
Definition simulation.hpp:30
Gameplay events sent to the clients (RFC section 4.4): spawns, destructions, deaths,...
The game run by the server, and the players of the sessions in it.
constexpr std::uint32_t tick_rate
Simulation rate of the server, in ticks per second.
Definition tuning.hpp:15
R-Type game code, built on the Aegis2D engine.
Definition enemy_scripts.hpp:16
LeaveReason
Why a player left the game, in PlayerLeft.
Definition events.hpp:49
GameRules game_rules(const RoomRules &rules) noexcept
The gameplay of the rules a room was created with.
A game of the server, with the thread that runs it.
TCP messages of the rooms (RFC sections 3.6 and 3.7): listing them, creating one, joining and leaving...
The best scores of the server, kept in a JSON file across restarts.
The R-Type simulation run by the server: world, systems and players.
Sockets of the R-Type server: the TCP port of the logins and the UDP port of the game.
Thread running the server's game at a fixed rate.
How a game plays: the rules of its room, as the gameplay reads them.
Definition server_game.hpp:35
How a room plays, chosen at its creation (CreateRoom, RFC section 3.6).
Definition rooms.hpp:60
A logged-in player (RFC section 3).
Definition sessions.hpp:24
Gameplay values of R-Type: play area, speeds, sizes, health, lives and scores.