4#include <aegis2d/core/math.hpp>
74 float reconcile(aegis2d::Vec2 server, std::optional<std::uint16_t> acknowledged,
float delta);
97 [[nodiscard]] std::optional<aegis2d::Vec2>
drawn() const noexcept;
101 [[nodiscard]] std::optional<std::uint32_t>
ship() const noexcept;
105 [[nodiscard]] std::optional<aegis2d::Vec2>
position() const noexcept;
112 std::optional<std::uint32_t> ship_;
113 aegis2d::Vec2 position_;
115 std::uint64_t corrections_ = 0;
116 float last_correction_ = 0.0F;
Where the client's own ship is, before the server says so.
Definition ship_prediction.hpp:22
static constexpr float correction_threshold
Distance from which a reconciliation counts as a correction, in logical pixels.
Definition ship_prediction.hpp:32
void apply(const InputRecord &input, float delta)
Moves the ship by an input the client sends, and keeps the input.
static constexpr float smoothing_speed
Speed at which the drawn ship catches up with a correction, in logical pixels per second: 2 pixels a ...
Definition ship_prediction.hpp:37
const std::deque< InputRecord > & pending() const noexcept
The inputs applied since start() that the server has not acknowledged.
std::optional< std::uint32_t > ship() const noexcept
Network id of the ship predicted.
void acknowledge(std::uint16_t sequence)
Drops the inputs the server applied.
void start(std::uint32_t ship, aegis2d::Vec2 position)
Starts predicting a ship from a position of the server.
std::uint64_t corrections() const noexcept
Number of reconciliations that moved the ship by more than correction_threshold: the prediction was w...
std::optional< aegis2d::Vec2 > drawn() const noexcept
Where to draw the ship: position(), plus what is left of the corrections.
void smooth(float seconds) noexcept
Brings the drawn ship towards the predicted one, after a correction.
float reconcile(aegis2d::Vec2 server, std::optional< std::uint16_t > acknowledged, float delta)
Corrects the prediction with a snapshot (server reconciliation).
static constexpr std::size_t max_pending
Inputs kept at most: 2 seconds at 60 per second. Older ones are dropped, as no snapshot acknowledges ...
Definition ship_prediction.hpp:26
void stop() noexcept
Stops predicting: the ship is gone, or the player out of lives.
float last_correction() const noexcept
How far the last reconciliation moved the ship.
static constexpr float snap_distance
Corrections from this distance are not smoothed: the ship is far from where it was predicted (a hit,...
Definition ship_prediction.hpp:42
std::optional< aegis2d::Vec2 > position() const noexcept
Where the ship is, its inputs applied.
R-Type game code, built on the Aegis2D engine.
Definition enemy_scripts.hpp:16