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

The last seconds of the network statistics, for the graphs of the lagometer. More...

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

Public Types

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

Public Member Functions

void update (const aegis2d::net::RttEstimator &rtt, const aegis2d::net::TrafficCounters &traffic, const NetworkStats &stats, Clock::time_point now, std::uint64_t corrections=0)
 Takes a sample of the statistics if sample_interval went by since the last one.
 
void add (const LagSample &sample)
 Adds a sample, forgetting the oldest beyond length.
 
void clear () noexcept
 Forgets every sample, for a new session.
 
const std::deque< LagSample > & samples () const noexcept
 The samples kept.
 
LagSample latest () const noexcept
 The last sample.
 
double scale (LagGraph graph) const noexcept
 Top of a graph: its largest value kept, but never below a floor (100 ms for the RTT, 10 % for the loss...), so that a sound link draws low bars.
 

Static Public Attributes

static constexpr std::chrono::milliseconds sample_interval {100}
 Time between two samples.
 
static constexpr std::size_t length = 100
 Samples kept: the last 10 seconds.
 

Detailed Description

The last seconds of the network statistics, for the graphs of the lagometer.

update() takes a sample every sample_interval and keeps the last length ones, oldest first: a graph draws one bar per sample, on the scale() of its graph.

Member Typedef Documentation

◆ Clock

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

Clock of the samples.

Member Function Documentation

◆ add()

void rtype::Lagometer::add ( const LagSample &  sample)

Adds a sample, forgetting the oldest beyond length.

Parameters
sampleSample to add.

◆ clear()

void rtype::Lagometer::clear ( )
noexcept

Forgets every sample, for a new session.

◆ latest()

LagSample rtype::Lagometer::latest ( ) const
noexcept

The last sample.

Returns
It, or a sample of zeros before the first one.

◆ samples()

const std::deque< LagSample > & rtype::Lagometer::samples ( ) const
noexcept

The samples kept.

Returns
At most length samples, oldest first.

◆ scale()

double rtype::Lagometer::scale ( LagGraph  graph) const
noexcept

Top of a graph: its largest value kept, but never below a floor (100 ms for the RTT, 10 % for the loss...), so that a sound link draws low bars.

Parameters
graphGraph to scale.
Returns
The value drawn at the full height of the graph.

◆ update()

void rtype::Lagometer::update ( const aegis2d::net::RttEstimator &  rtt,
const aegis2d::net::TrafficCounters &  traffic,
const NetworkStats &  stats,
Clock::time_point  now,
std::uint64_t  corrections = 0 
)

Takes a sample of the statistics if sample_interval went by since the last one.

Parameters
rttRound trip time to the server.
trafficDatagrams exchanged with the server.
statsLoss and snapshots of the server's datagrams.
nowCurrent time.
correctionsCorrections of the predicted ship so far (ShipPrediction::corrections()): the sample gives those since the last one, per second.

Member Data Documentation

◆ length

constexpr std::size_t rtype::Lagometer::length = 100
staticconstexpr

Samples kept: the last 10 seconds.

◆ sample_interval

constexpr std::chrono::milliseconds rtype::Lagometer::sample_interval {100}
staticconstexpr

Time between two samples.


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