R-Type
Networked shoot'em up built on Aegis2D
Loading...
Searching...
No Matches
room.hpp
Go to the documentation of this file.
1
3#pragma once
4#include <aegis2d/ecs/waves.hpp>
5
9#include <rtype/tuning.hpp>
10
11#include <array>
12#include <cstdint>
13#include <functional>
14#include <optional>
15#include <string>
16
17namespace rtype {
18
26class Room {
27public:
29 using TickHandler = std::function<void(Room& room, GameInstance& instance)>;
30
39 Room(std::uint32_t id, std::optional<std::uint64_t> seed, aegis2d::ecs::WaveSchedule waves,
40 std::uint32_t rate, TickHandler after_tick, bool trace = false, GameRules rules = {});
41
42 Room(const Room&) = delete;
43 Room& operator=(const Room&) = delete;
44 Room(Room&&) = delete;
45 Room& operator=(Room&&) = delete;
47 ~Room() = default;
48
51 [[nodiscard]] std::uint32_t id() const noexcept;
52
55 [[nodiscard]] GameInstance& instance() noexcept;
56
59 [[nodiscard]] Simulation& simulation() noexcept;
60
63 [[nodiscard]] EventTracker& events() noexcept;
64
68 [[nodiscard]] std::array<std::optional<std::string>, tuning::max_players>& names() noexcept;
69
70private:
71 std::uint32_t id_;
72 GameInstance instance_;
73 EventTracker events_;
74 std::array<std::optional<std::string>, tuning::max_players> names_{};
75 // Last: its thread starts once the rest is ready, and stops first.
76 Simulation simulation_;
77};
78
79} // namespace rtype
Finds what changed in the game at each tick, as events.
Definition event_tracker.hpp:31
The one game of the server, with up to tuning::max_players players.
Definition game_instance.hpp:37
One game of the server: its GameInstance, the Simulation thread that runs it, the EventTracker of wha...
Definition room.hpp:26
std::array< std::optional< std::string >, tuning::max_players > & names() noexcept
Names of the players in the room's game, by number.
Room(const Room &)=delete
Room(Room &&)=delete
GameInstance & instance() noexcept
The game of the room.
std::function< void(Room &room, GameInstance &instance)> TickHandler
Called on the simulation thread after each tick of the room.
Definition room.hpp:29
~Room()=default
Stops the thread, then destroys the game.
Room & operator=(const Room &)=delete
std::uint32_t id() const noexcept
Number of the room in its server.
Simulation & simulation() noexcept
The thread running the game.
EventTracker & events() noexcept
What the clients of the room learnt of its entities.
Room & operator=(Room &&)=delete
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.
Runs a GameInstance on its own thread, tuning::tick_rate times per second.
Definition simulation.hpp:30
What changed in the server's game at each tick, as the events of RFC section 4.4.
The game run by the server, and the players of the sessions in it.
R-Type game code, built on the Aegis2D engine.
Definition enemy_scripts.hpp:16
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
Gameplay values of R-Type: play area, speeds, sizes, health, lives and scores.