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

Rebuilds the snapshots of the server from the payloads of its Snapshot datagrams. More...

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

Public Member Functions

bool decodable (const DeltaSnapshot &part) const noexcept
 Tells whether a payload can be decoded: a full snapshot, or a delta whose baseline is kept.
 
std::optional< Snapshot > decode (const DeltaSnapshot &part)
 Rebuilds the snapshot of a payload, with the payloads of its tick received so far.
 
const Snapshot * find (std::uint32_t tick) const noexcept
 A snapshot kept.
 
std::size_t size () const noexcept
 Number of snapshots kept.
 
std::uint64_t dropped () const noexcept
 Number of payloads dropped by decode().
 

Static Public Attributes

static constexpr std::size_t capacity = 32
 Snapshots kept, as many as the server keeps per client.
 

Detailed Description

Rebuilds the snapshots of the server from the payloads of its Snapshot datagrams.

Each payload is encoded against a baseline the client acknowledged, or none (write_delta_snapshot()). The decoder keeps the last capacity snapshots it rebuilt, as the baselines of the next ones, and the payloads of each one, as a snapshot may come in several datagrams. A payload whose baseline it no longer has, or that does not match it, is dropped: the datagram that carried it must not be acknowledged, so that the server never picks that snapshot as a baseline.

Member Function Documentation

◆ decodable()

bool rtype::SnapshotDecoder::decodable ( const DeltaSnapshot &  part) const
noexcept

Tells whether a payload can be decoded: a full snapshot, or a delta whose baseline is kept.

Parameters
partA payload read by read_delta_snapshot().
Returns
true if decode() can rebuild its snapshot.

◆ decode()

std::optional< Snapshot > rtype::SnapshotDecoder::decode ( const DeltaSnapshot &  part)

Rebuilds the snapshot of a payload, with the payloads of its tick received so far.

The snapshot is kept, replacing the one of the same tick, and the oldest beyond capacity is forgotten. Call it once per datagram: a duplicate would count twice.

Parameters
partA payload read by read_delta_snapshot().
Returns
The snapshot, or std::nullopt if the payload is dropped (counted by dropped()).

◆ dropped()

std::uint64_t rtype::SnapshotDecoder::dropped ( ) const
noexcept

Number of payloads dropped by decode().

Returns
The count since the construction.

◆ find()

const Snapshot * rtype::SnapshotDecoder::find ( std::uint32_t  tick) const
noexcept

A snapshot kept.

Parameters
tickIts tick.
Returns
The snapshot, or nullptr if none of that tick is kept.

◆ size()

std::size_t rtype::SnapshotDecoder::size ( ) const
noexcept

Number of snapshots kept.

Returns
From 0 to capacity.

Member Data Documentation

◆ capacity

constexpr std::size_t rtype::SnapshotDecoder::capacity = 32
staticconstexpr

Snapshots kept, as many as the server keeps per client.


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