|
R-Type
Networked shoot'em up built on Aegis2D
|
Turns PlayerJoined and PlayerLeft events into messages for the players who stay.
More...
#include </__w/project-rtype/project-rtype/client/network/include/rtype/player_notices.hpp>
Public Types | |
| using | Clock = std::chrono::steady_clock |
| Clock of the messages. | |
Public Member Functions | |
| void | handle (const GameEvent &event, Clock::time_point now) |
Adds the message of an event, if it is a PlayerJoined or a PlayerLeft. | |
| void | remember (const std::array< std::optional< RemotePlayer >, tuning::max_players > &players) |
Keeps the names of the players, for the next PlayerLeft. | |
| void | prune (Clock::time_point now) |
| Drops the messages whose time is over. | |
| const std::vector< PlayerNotice > & | shown () const noexcept |
| Messages to show, oldest first. | |
| void | clear () noexcept |
| Forgets the messages and names, for a new session. | |
Static Public Attributes | |
| static constexpr std::chrono::seconds | shown_for {5} |
| How long a message stays. | |
| static constexpr std::size_t | max_shown = 4 |
| Most messages shown at once: a new one pushes out the oldest. | |
Turns PlayerJoined and PlayerLeft events into messages for the players who stay.
A PlayerLeft only carries the player's number, and ClientWorld forgets the player when it applies the event: remember() keeps the names of the players of the last frame, so the message can name who left. The players already there when this client joined are not announced: the server tells their names with the first events, all of the same tick, so a PlayerJoined of that tick or older is only remembered.
| using rtype::PlayerNotices::Clock = std::chrono::steady_clock |
Clock of the messages.
|
noexcept |
Forgets the messages and names, for a new session.
| void rtype::PlayerNotices::handle | ( | const GameEvent & | event, |
| Clock::time_point | now | ||
| ) |
Adds the message of an event, if it is a PlayerJoined or a PlayerLeft.
| event | Event applied by ClientWorld (ClientWorld::take_events()). |
| now | Time it is shown from. |
| void rtype::PlayerNotices::prune | ( | Clock::time_point | now | ) |
Drops the messages whose time is over.
| now | Current time. |
| void rtype::PlayerNotices::remember | ( | const std::array< std::optional< RemotePlayer >, tuning::max_players > & | players | ) |
Keeps the names of the players, for the next PlayerLeft.
Call it once the events of a frame are handled. A player without a name yet keeps the name it had.
| players | Players of the world (ClientWorld::players()). |
|
noexcept |
Messages to show, oldest first.
|
staticconstexpr |
Most messages shown at once: a new one pushes out the oldest.
|
staticconstexpr |
How long a message stays.