Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
aegis2d::net::RttEstimator Class Reference

Smoothed round trip time and its variation, from round trip samples. More...

#include <aegis2d/net/rtt.hpp>

Public Types

using Duration = std::chrono::steady_clock::duration
 Durations of the samples and of the estimate.
 

Public Member Functions

void add_sample (Duration sample) noexcept
 Takes a round trip sample into the estimate.
 
bool has_estimate () const noexcept
 Whether a sample was taken.
 
Duration smoothed () const noexcept
 Smoothed round trip time (SRTT).
 
Duration jitter () const noexcept
 Jitter: the smoothed variation of the samples (RTTVAR).
 
Duration latest () const noexcept
 Last sample taken.
 
std::uint64_t samples () const noexcept
 Number of samples taken.
 

Detailed Description

Smoothed round trip time and its variation, from round trip samples.

Follows RFC 6298 (TCP's retransmission timer), section 2: the first sample R sets the smoothed RTT to R and the variation to R / 2; each next one updates the variation to 3/4 · variation + 1/4 · |smoothed − R|, then the smoothed RTT to 7/8 · smoothed + 1/8 · R. The variation is the jitter: how far the samples stray from the smoothed RTT.

ReliableChannel feeds one per peer, see ReliableChannel::rtt().

Member Typedef Documentation

◆ Duration

using aegis2d::net::RttEstimator::Duration = std::chrono::steady_clock::duration

Durations of the samples and of the estimate.

Member Function Documentation

◆ add_sample()

void aegis2d::net::RttEstimator::add_sample ( Duration  sample)
noexcept

Takes a round trip sample into the estimate.

Parameters
sampleTime between sending a datagram and receiving its first acknowledgement; a negative one counts as 0.

◆ has_estimate()

bool aegis2d::net::RttEstimator::has_estimate ( ) const
inlinenoexcept

Whether a sample was taken.

Returns
true once add_sample() was called; before, the durations are 0.

◆ jitter()

Duration aegis2d::net::RttEstimator::jitter ( ) const
inlinenoexcept

Jitter: the smoothed variation of the samples (RTTVAR).

Returns
The variation, 0 before the first sample.

◆ latest()

Duration aegis2d::net::RttEstimator::latest ( ) const
inlinenoexcept

Last sample taken.

Returns
The sample, 0 before the first one.

◆ samples()

std::uint64_t aegis2d::net::RttEstimator::samples ( ) const
inlinenoexcept

Number of samples taken.

Returns
The count since the estimator was created.

◆ smoothed()

Duration aegis2d::net::RttEstimator::smoothed ( ) const
inlinenoexcept

Smoothed round trip time (SRTT).

Returns
The estimate, 0 before the first sample.

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