R-Type
Networked shoot'em up built on Aegis2D
Loading...
Searching...
No Matches
rtype::PlayerNotices Class Reference

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.
 

Detailed Description

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.

Member Typedef Documentation

◆ Clock

using rtype::PlayerNotices::Clock = std::chrono::steady_clock

Clock of the messages.

Member Function Documentation

◆ clear()

void rtype::PlayerNotices::clear ( )
noexcept

Forgets the messages and names, for a new session.

◆ handle()

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.

Parameters
eventEvent applied by ClientWorld (ClientWorld::take_events()).
nowTime it is shown from.

◆ prune()

void rtype::PlayerNotices::prune ( Clock::time_point  now)

Drops the messages whose time is over.

Parameters
nowCurrent time.

◆ remember()

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.

Parameters
playersPlayers of the world (ClientWorld::players()).

◆ shown()

const std::vector< PlayerNotice > & rtype::PlayerNotices::shown ( ) const
noexcept

Messages to show, oldest first.

Returns
The messages.

Member Data Documentation

◆ max_shown

constexpr std::size_t rtype::PlayerNotices::max_shown = 4
staticconstexpr

Most messages shown at once: a new one pushes out the oldest.

◆ shown_for

constexpr std::chrono::seconds rtype::PlayerNotices::shown_for {5}
staticconstexpr

How long a message stays.


The documentation for this class was generated from the following file: