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

The last snapshots sent to one client, and the ones it acknowledged. More...

#include </__w/project-rtype/project-rtype/server/include/rtype/snapshot_history.hpp>

Public Member Functions

void sent (std::shared_ptr< const Snapshot > snapshot, std::span< const std::uint16_t > sequences)
 Records a snapshot sent to the client, forgetting the oldest beyond capacity.
 
void acknowledge (std::uint16_t ack, std::uint32_t ack_bits) noexcept
 Records the acknowledgements of a datagram received from the client.
 
const Snapshot * latest_acknowledged () const noexcept
 The most recent snapshot the client acknowledged, among those kept.
 
const Snapshot * find (std::uint32_t tick) const noexcept
 A snapshot kept, acknowledged or not.
 
bool acknowledged (std::uint32_t tick) const noexcept
 Tells whether the client acknowledged a snapshot.
 
std::size_t size () const noexcept
 Number of snapshots kept.
 

Static Public Attributes

static constexpr std::size_t capacity = 32
 Snapshots kept per client.
 

Detailed Description

The last snapshots sent to one client, and the ones it acknowledged.

A client acknowledges a snapshot by the ack and ack_bits fields of the datagrams it sends (RFC section 5.1): a snapshot is acknowledged once every datagram that carried it is. Only the last capacity snapshots sent are kept, as possible baselines of the next ones.

Member Function Documentation

◆ acknowledge()

void rtype::SnapshotHistory::acknowledge ( std::uint16_t  ack,
std::uint32_t  ack_bits 
)
noexcept

Records the acknowledgements of a datagram received from the client.

Parameters
ackIts ack field: the latest sequence of the server it received.
ack_bitsIts ack_bits field: bit n set if it received ack - n - 1.

◆ acknowledged()

bool rtype::SnapshotHistory::acknowledged ( std::uint32_t  tick) const
noexcept

Tells whether the client acknowledged a snapshot.

Parameters
tickIts tick.
Returns
true if a snapshot of that tick is kept and acknowledged.

◆ find()

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

A snapshot kept, acknowledged or not.

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

◆ latest_acknowledged()

const Snapshot * rtype::SnapshotHistory::latest_acknowledged ( ) const
noexcept

The most recent snapshot the client acknowledged, among those kept.

Returns
The snapshot of the highest tick acknowledged, or nullptr if none is.

◆ sent()

void rtype::SnapshotHistory::sent ( std::shared_ptr< const Snapshot >  snapshot,
std::span< const std::uint16_t >  sequences 
)

Records a snapshot sent to the client, forgetting the oldest beyond capacity.

Parameters
snapshotSnapshot sent, shared with the histories of the other clients.
sequencesSequences of the datagrams that carried it.

◆ size()

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

Number of snapshots kept.

Returns
From 0 to capacity.

Member Data Documentation

◆ capacity

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

Snapshots kept per client.


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