R-Type
Networked shoot'em up built on Aegis2D
Loading...
Searching...
No Matches
snapshot_history.hpp
Go to the documentation of this file.
1
4#pragma once
5#include <rtype/snapshot.hpp>
6
7#include <cstddef>
8#include <cstdint>
9#include <deque>
10#include <memory>
11#include <span>
12#include <vector>
13
14namespace rtype {
15
22public:
24 static constexpr std::size_t capacity = 32;
25
29 void sent(std::shared_ptr<const Snapshot> snapshot, std::span<const std::uint16_t> sequences);
30
34 void acknowledge(std::uint16_t ack, std::uint32_t ack_bits) noexcept;
35
38 [[nodiscard]] const Snapshot* latest_acknowledged() const noexcept;
42 [[nodiscard]] const Snapshot* find(std::uint32_t tick) const noexcept;
46 [[nodiscard]] bool acknowledged(std::uint32_t tick) const noexcept;
49 [[nodiscard]] std::size_t size() const noexcept;
50
51private:
52 struct Sent {
53 std::shared_ptr<const Snapshot> snapshot;
54 // The sequences of its datagrams not acknowledged yet.
55 std::vector<std::uint16_t> waiting;
56 };
57 [[nodiscard]] const Sent* entry(std::uint32_t tick) const noexcept;
58
59 std::deque<Sent> sent_;
60};
61
62} // namespace rtype
The last snapshots sent to one client, and the ones it acknowledged.
Definition snapshot_history.hpp:21
void acknowledge(std::uint16_t ack, std::uint32_t ack_bits) noexcept
Records the acknowledgements of a datagram received from the client.
std::size_t size() const noexcept
Number of snapshots kept.
static constexpr std::size_t capacity
Snapshots kept per client.
Definition snapshot_history.hpp:24
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.
bool acknowledged(std::uint32_t tick) const noexcept
Tells whether the client acknowledged a snapshot.
const Snapshot * find(std::uint32_t tick) const noexcept
A snapshot kept, acknowledged or not.
const Snapshot * latest_acknowledged() const noexcept
The most recent snapshot the client acknowledged, among those kept.
R-Type game code, built on the Aegis2D engine.
Definition enemy_scripts.hpp:16
Snapshots of the world sent to the clients (RFC section 4.3).
The state of the world at one tick.
Definition snapshot.hpp:94