R-Type
Networked shoot'em up built on Aegis2D
Loading...
Searching...
No Matches
snapshot_decoder.hpp
Go to the documentation of this file.
1
3#pragma once
5#include <rtype/snapshot.hpp>
6
7#include <cstddef>
8#include <cstdint>
9#include <deque>
10#include <optional>
11#include <vector>
12
13namespace rtype {
14
23public:
25 static constexpr std::size_t capacity = 32;
26
31 [[nodiscard]] bool decodable(const DeltaSnapshot& part) const noexcept;
32
41 [[nodiscard]] std::optional<Snapshot> decode(const DeltaSnapshot& part);
42
46 [[nodiscard]] const Snapshot* find(std::uint32_t tick) const noexcept;
49 [[nodiscard]] std::size_t size() const noexcept;
52 [[nodiscard]] std::uint64_t dropped() const noexcept;
53
54private:
55 struct Rebuilt {
56 std::optional<std::uint32_t> baseline;
57 std::vector<DeltaSnapshot> parts;
58 Snapshot snapshot;
59 };
60 [[nodiscard]] static std::uint32_t tick_of(const Rebuilt& kept) noexcept;
61 [[nodiscard]] const Rebuilt* entry(std::uint32_t tick) const noexcept;
62 [[nodiscard]] const Snapshot* baseline_of(const DeltaSnapshot& part) const noexcept;
63 std::optional<Snapshot> drop() noexcept;
64
65 std::deque<Rebuilt> kept_;
66 std::uint64_t dropped_ = 0;
67};
68
69} // namespace rtype
Rebuilds the snapshots of the server from the payloads of its Snapshot datagrams.
Definition snapshot_decoder.hpp:22
const Snapshot * find(std::uint32_t tick) const noexcept
A snapshot kept.
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::size_t size() const noexcept
Number of snapshots kept.
std::optional< Snapshot > decode(const DeltaSnapshot &part)
Rebuilds the snapshot of a payload, with the payloads of its tick received so far.
std::uint64_t dropped() const noexcept
Number of payloads dropped by decode().
static constexpr std::size_t capacity
Snapshots kept, as many as the server keeps per client.
Definition snapshot_decoder.hpp:25
Snapshots encoded against a baseline the client acknowledged: only what changed.
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).
One payload of a snapshot encoded against a baseline.
Definition delta_snapshot.hpp:57
The state of the world at one tick.
Definition snapshot.hpp:94