Add M10.7a tick clock and remote-marker interpolation
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (ecs) (push) Successful in 1m59s
Foundation / checks (client) (push) Successful in 12m44s
Foundation / checks (network) (push) Successful in 12m45s
Foundation / checks (tsan) (push) Successful in 8m5s
Foundation / checks (checks) (push) Successful in 32m4s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 21m38s

ADR-0095 (presentation only): a drift-corrected monotonic tick clock that
never runs more than one tick past the newest observation; remote probe
markers shown 2-6 ticks behind (adaptive to snapshot gaps), interpolated,
extrapolated for at most 2 ticks and then marked stale; appearance and
removal at their snapshot ticks; organisms never extrapolated; sub-tick
own-marker prediction.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-06 17:16:20 -04:00
co-authored by Claude Opus 5.5
parent 61d899de3c
commit 90cdb61e30
12 changed files with 539 additions and 5 deletions
+110
View File
@@ -0,0 +1,110 @@
#pragma once
#include "evo/network/probe_motion.hpp"
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <deque>
#include <optional>
#include <span>
#include <vector>
// M10.7 client tick clock and remote-entity interpolation (ADR-0095). Headless,
// single-owner, presentation only: nothing here is authority or decides an outcome.
namespace evo::client {
// A drift-corrected, monotonic estimate of the server's simulated tick between snapshots.
// Each observation (a tick the client just learned the server had simulated) slews the
// estimate toward it by a fraction; a large disagreement snaps forward, never backward. The
// estimate never runs more than `max_ahead` ticks beyond the newest observation, so a
// paused or silent server freezes it instead of inventing time.
struct TickClockLimits {
double tick_ms{50};
double gain{0.1}; // Fraction of the error corrected per observation.
double snap_ticks{4}; // Errors beyond this snap (forward) instead of slewing.
double max_ahead{1.0}; // Ticks beyond the newest observation.
};
class TickClock {
public:
using Clock = std::chrono::steady_clock;
explicit TickClock(TickClockLimits limits = {}) : limits_{limits} {}
void reset() noexcept;
void observe(std::uint64_t tick, Clock::time_point now);
// The estimated server tick (fractional) at `now`; nothing before the first observation.
// Never decreases between resets.
[[nodiscard]] std::optional<double> at(Clock::time_point now);
[[nodiscard]] std::uint64_t snaps() const noexcept {
return snaps_;
}
private:
[[nodiscard]] double raw(double base, Clock::time_point now) const;
TickClockLimits limits_;
std::optional<double> base_tick_;
Clock::time_point base_time_{};
std::uint64_t newest_{};
double returned_{};
std::uint64_t snaps_{};
};
// Remote probe markers (other sessions'), shown `delay` ticks behind the clock and
// interpolated between the buffered snapshots around that render tick. Beyond the newest
// snapshot a marker continues its replicated held vector for at most `max_extrapolation`
// ticks, then freezes and is marked stale. A marker appears at the tick of the snapshot that
// added it and disappears at the tick of the one that removed it (never interpolated toward a
// removal). Snapshots further apart than `max_gap` are not interpolated across (the newer
// one is shown from its tick). The delay adapts to the observed gaps between received
// snapshots (lost or late ones), within [min_delay, max_delay].
struct InterpolationLimits {
double min_delay{2}, max_delay{6}; // Ticks (ADR-0095).
double max_extrapolation{2}; // Ticks beyond the newest snapshot.
std::uint64_t max_gap{8}; // Ticks between snapshots still interpolated.
std::size_t max_snapshots{16}; // Buffered snapshots.
std::size_t gap_window{40}; // Recent arrivals the delay adapts to.
double raise_per_second{2}, lower_per_second{0.5}; // Delay adaptation speed (ticks/s).
};
struct RemoteMarker {
std::uint64_t id{};
network::motion::State state;
};
struct PresentedMarker {
std::uint64_t id{};
double x{}, y{}; // Micrometres.
bool extrapolated{}, stale{};
};
struct InterpolationStats {
std::uint64_t snapshots{}, ignored{}, extrapolated_frames{}, stale_frames{}, gap_snaps{};
};
class MarkerInterpolator {
public:
explicit MarkerInterpolator(InterpolationLimits limits = {})
: limits_{limits}, delay_{limits.min_delay}, target_{limits.min_delay} {}
void reset();
// A complete snapshot's remote markers (all of them: absence means removal). Snapshots
// not newer than the newest buffered one are ignored (reordering).
void push(std::uint64_t tick, std::span<const RemoteMarker> markers);
// Moves the delay toward its target (call once per frame).
void advance(double elapsed_ms);
// Markers at render tick `clock - delay()`.
[[nodiscard]] std::vector<PresentedMarker> at(double render_tick);
[[nodiscard]] double delay() const noexcept {
return delay_;
}
[[nodiscard]] double target_delay() const noexcept {
return target_;
}
[[nodiscard]] const InterpolationStats& stats() const noexcept {
return stats_;
}
private:
struct Snapshot {
std::uint64_t tick{};
std::vector<RemoteMarker> markers; // Sorted by id.
};
InterpolationLimits limits_;
std::deque<Snapshot> snapshots_;
std::deque<std::uint64_t> gaps_;
double delay_, target_;
InterpolationStats stats_;
};
} // namespace evo::client
+6
View File
@@ -54,6 +54,12 @@ class MotionPredictor {
// The predicted state after `tick` (the presented tick: server tick plus input lead);
// nothing before the first authoritative state.
[[nodiscard]] std::optional<network::motion::State> predict(std::uint64_t tick);
// M10.7 (ADR-0095): the position `fraction` (0..1) of the way from tick to tick + 1, for
// presentation between ticks; records the prediction for `tick` like predict().
struct Point {
double x{}, y{}; // Micrometres.
};
[[nodiscard]] std::optional<Point> predict_between(std::uint64_t tick, double fraction);
// The jump rebasing made to the newest prediction (old minus new), since the last call.
struct Offset {
std::int64_t x{}, y{};