R-Type
Networked shoot'em up built on Aegis2D
Loading...
Searching...
No Matches
player_notices.hpp
Go to the documentation of this file.
1
3#pragma once
5#include <rtype/events.hpp>
6#include <rtype/tuning.hpp>
7
8#include <array>
9#include <chrono>
10#include <cstddef>
11#include <cstdint>
12#include <optional>
13#include <string>
14#include <vector>
15
16namespace rtype {
17
21 std::uint8_t player = 0;
23 std::string text;
25 std::chrono::steady_clock::time_point until;
26};
27
36public:
38 using Clock = std::chrono::steady_clock;
40 static constexpr std::chrono::seconds shown_for{5};
42 static constexpr std::size_t max_shown = 4;
43
47 void handle(const GameEvent& event, Clock::time_point now);
48
53 void remember(const std::array<std::optional<RemotePlayer>, tuning::max_players>& players);
54
57 void prune(Clock::time_point now);
58
61 [[nodiscard]] const std::vector<PlayerNotice>& shown() const noexcept;
62
64 void clear() noexcept;
65
66private:
67 void add(std::uint8_t player, std::string text, Clock::time_point now);
68 [[nodiscard]] std::string name_of(std::uint8_t player) const;
69
70 std::array<std::string, tuning::max_players> names_;
71 std::vector<PlayerNotice> shown_;
72 std::optional<std::uint32_t> first_tick_;
73};
74
80[[nodiscard]] std::string left_message(const std::string& name, LeaveReason reason);
81
82} // namespace rtype
Turns PlayerJoined and PlayerLeft events into messages for the players who stay.
Definition player_notices.hpp:35
void remember(const std::array< std::optional< RemotePlayer >, tuning::max_players > &players)
Keeps the names of the players, for the next PlayerLeft.
const std::vector< PlayerNotice > & shown() const noexcept
Messages to show, oldest first.
void prune(Clock::time_point now)
Drops the messages whose time is over.
static constexpr std::size_t max_shown
Most messages shown at once: a new one pushes out the oldest.
Definition player_notices.hpp:42
static constexpr std::chrono::seconds shown_for
How long a message stays.
Definition player_notices.hpp:40
void clear() noexcept
Forgets the messages and names, for a new session.
void handle(const GameEvent &event, Clock::time_point now)
Adds the message of an event, if it is a PlayerJoined or a PlayerLeft.
std::chrono::steady_clock Clock
Clock of the messages.
Definition player_notices.hpp:38
The client's copy of the server's world, built from snapshots and events.
Gameplay events sent to the clients (RFC section 4.4): spawns, destructions, deaths,...
constexpr std::size_t max_players
Players in one game, as the subject requires.
Definition tuning.hpp:33
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
std::variant< SpawnEvent, DestroyEvent, DeathEvent, PlayerJoinedEvent, PlayerLeftEvent > GameEvent
One of the gameplay events the server sends.
Definition events.hpp:160
std::string left_message(const std::string &name, LeaveReason reason)
Sentence telling why a player left.
A message about a player, shown for a few seconds.
Definition player_notices.hpp:19
std::chrono::steady_clock::time_point until
When the message goes away.
Definition player_notices.hpp:25
std::string text
Sentence shown, such as "Lolo left the game".
Definition player_notices.hpp:23
std::uint8_t player
Player number, 0 to 3, for the color of its slot.
Definition player_notices.hpp:21
Gameplay values of R-Type: play area, speeds, sizes, health, lives and scores.