R-Type
Networked shoot'em up built on Aegis2D
Loading...
Searching...
No Matches
network_stats.hpp
Go to the documentation of this file.
1
3#pragma once
4#include <aegis2d/net/packet.hpp>
5
6#include <chrono>
7#include <cstdint>
8#include <deque>
9
10namespace rtype {
11
15 std::uint32_t received = 0;
17 std::uint32_t lost = 0;
19 double loss = 0.0;
21 std::uint32_t snapshots = 0;
23 std::chrono::steady_clock::duration snapshot_interval{};
26 std::chrono::steady_clock::duration snapshot_jitter{};
27};
28
36public:
38 using Clock = std::chrono::steady_clock;
40 static constexpr std::chrono::seconds window{2};
41
48 void record(std::uint16_t sequence, aegis2d::net::PacketType type, Clock::time_point arrival);
49
53 [[nodiscard]] NetworkSummary summary(Clock::time_point now) const;
54
55private:
56 struct Arrival {
57 std::uint16_t sequence = 0;
58 bool snapshot = false;
59 Clock::time_point time;
60 };
61
62 // Oldest first, as they arrived.
63 std::deque<Arrival> arrivals_;
64};
65
66} // namespace rtype
Measures the loss and the jitter of the server's datagrams over a sliding window.
Definition network_stats.hpp:35
NetworkSummary summary(Clock::time_point now) const
Loss, snapshot interval and jitter of the datagrams received in the window.
static constexpr std::chrono::seconds window
How far back summary() looks: 40 snapshots at 20 per second.
Definition network_stats.hpp:40
void record(std::uint16_t sequence, aegis2d::net::PacketType type, Clock::time_point arrival)
Records a datagram received from the server.
std::chrono::steady_clock Clock
Clock of the arrivals.
Definition network_stats.hpp:38
R-Type game code, built on the Aegis2D engine.
Definition enemy_scripts.hpp:16
What the client received from the server over the last NetworkStats::window.
Definition network_stats.hpp:13
std::chrono::steady_clock::duration snapshot_interval
Mean time between two snapshots, 0 with fewer than two.
Definition network_stats.hpp:23
std::uint32_t snapshots
Snapshot datagrams received.
Definition network_stats.hpp:21
double loss
Share of the datagrams lost, from 0 to 1: lost / (received + lost).
Definition network_stats.hpp:19
std::uint32_t lost
Sequences missing between the oldest and the newest received.
Definition network_stats.hpp:17
std::uint32_t received
Datagrams received, each sequence counted once.
Definition network_stats.hpp:15
std::chrono::steady_clock::duration snapshot_jitter
Mean distance of each interval between two snapshots from their mean: how irregularly the snapshots a...
Definition network_stats.hpp:26