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

Measures the loss and the jitter of the server's datagrams over a sliding window. More...

#include </__w/project-rtype/project-rtype/client/network/include/rtype/network_stats.hpp>

Public Types

using Clock = std::chrono::steady_clock
 Clock of the arrivals.
 

Public Member Functions

void record (std::uint16_t sequence, aegis2d::net::PacketType type, Clock::time_point arrival)
 Records a datagram received from the server.
 
NetworkSummary summary (Clock::time_point now) const
 Loss, snapshot interval and jitter of the datagrams received in the window.
 

Static Public Attributes

static constexpr std::chrono::seconds window {2}
 How far back summary() looks: 40 snapshots at 20 per second.
 

Detailed Description

Measures the loss and the jitter of the server's datagrams over a sliding window.

The server numbers every datagram it sends to this client, whatever its type (RFC section 2.2): a sequence missing between two received ones is a lost datagram. The snapshots, sent at a fixed rate, show the jitter: the spread of the times between their arrivals. Next to ClientSession::traffic() and ClientSession::rtt(), the source of the network statistics shown to the player.

Member Typedef Documentation

◆ Clock

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

Clock of the arrivals.

Member Function Documentation

◆ record()

void rtype::NetworkStats::record ( std::uint16_t  sequence,
aegis2d::net::PacketType  type,
Clock::time_point  arrival 
)

Records a datagram received from the server.

Call it for every datagram with a valid header and the session's token. A duplicate counts once; a datagram older than the window is forgotten.

Parameters
sequenceThe datagram's sequence field.
typeIts type: the Snapshot ones give the interval and the jitter.
arrivalTime it was received.

◆ summary()

NetworkSummary rtype::NetworkStats::summary ( Clock::time_point  now) const

Loss, snapshot interval and jitter of the datagrams received in the window.

Parameters
nowCurrent time: the window is (now - window, now].
Returns
The summary, all 0 before anything is received.

Member Data Documentation

◆ window

constexpr std::chrono::seconds rtype::NetworkStats::window {2}
staticconstexpr

How far back summary() looks: 40 snapshots at 20 per second.


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