Wire M10.7b interpolation and the stale loss view into the client
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m55s
Foundation / checks (client) (push) Successful in 12m27s
Foundation / checks (network) (push) Successful in 12m46s
Foundation / checks (tsan) (push) Successful in 7m59s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 25m13s
Foundation / checks (postgres) (push) Canceled after 12m48s

ADR-0095. The engineering client times presentation with the tick clock:
its own marker between ticks, other markers interpolated a few ticks behind
(grey when stale). Silence beyond 3 ticks and long-gap holds are stale. A lost
session leaves its last view frozen and labelled stale until the reconnect's
fresh baseline; nothing is predicted or sent meanwhile.

evo-motion-trace --remote measures remote-marker error between two clients
through the relay, with a 1.5 s outage (motion-trace-remote-smoke CTest).
Prediction errors are recorded only for ticks inputs are scheduled for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-06 17:50:41 -04:00
co-authored by Claude Opus 5.5
parent 90cdb61e30
commit 5728e7682e
17 changed files with 651 additions and 210 deletions
+71 -14
View File
@@ -17,6 +17,12 @@
// intention that was lost or refused is sent again once nothing is in flight and the
// authority holds another vector. While following, the camera and the interest follow the
// predicted marker (or, before a marker exists, the server's default view).
//
// M10.7b (ADR-0095): a drift-corrected tick clock (observed server ticks) times the
// presentation. The own marker is drawn between ticks; other markers are interpolated
// `delay` ticks behind (adaptive), extrapolated at most two ticks, then marked stale. When the
// session is lost the last view stays frozen and stale: the own marker at its last
// authoritative position, nothing predicted or sent. A new session starts afresh.
#include "evo/client/camera.hpp"
#include "evo/client/environment_view.hpp"
#include "evo/client/input.hpp"
@@ -33,6 +39,7 @@
#include <vector>
#ifdef EVO_CLIENT_NETWORK
#include "evo/client/interpolation.hpp"
#include "evo/client/motion_prediction.hpp"
#include "evo/client/region_session.hpp"
#include "evo/network/quic_transport.hpp"
@@ -64,11 +71,18 @@ struct RemoteStatus {
// Refusal receipts (each, whether or not the input was still pending), inputs the
// predictor removed as refused or dropped as never applied, and repeated vectors.
std::uint64_t refused_inputs{}, rejected_inputs{}, dropped_inputs{}, resends{}, max_pending{};
// Interpolation (ADR-0095): the current delay in ticks, markers shown stale, and whether
// the whole view is a frozen copy from a lost session.
double interpolation_delay{}, remote_render_tick{}; // Ticks: delay, clock - delay.
std::size_t stale_markers{};
bool stale_view{};
};
// A probe marker to draw: the own one predicted and smoothed, others as replicated.
struct MarkerView {
double x_mm{}, y_mm{};
bool own{};
bool stale{}; // No current authority behind it (draw dimmed).
bool extrapolated{}; // Continued beyond the newest snapshot (at most two ticks).
};
#ifdef EVO_CLIENT_NETWORK
@@ -78,6 +92,7 @@ static_assert(std::is_same_v<client::GrantRecord, network::WireGrant>,
class RemoteSession {
public:
static constexpr std::uint16_t interest_radius = 7;
static constexpr double silent_ticks = 3; // Extrapolation limit (2) plus the clock's lead.
// Looks the endpoint up once (blocking); nothing connects until the first step().
static std::optional<RemoteSession> open(const client::ConnectMaterial& m) {
const auto address = network::quic::resolve_ipv4(m.endpoint.host);
@@ -136,7 +151,7 @@ class RemoteSession {
s.focus_y = sent_interest_->y;
s.focus_z = sent_interest_->z;
}
for (const auto& m : markers_)
for (const auto& m : markers_) {
if (m.own) {
s.marker = true;
s.marker_x_mm = m.x_mm;
@@ -144,6 +159,11 @@ class RemoteSession {
} else {
++s.other_markers;
}
s.stale_markers += m.stale ? 1 : 0;
}
s.interpolation_delay = interpolator_.delay();
s.remote_render_tick = render_tick_;
s.stale_view = stale_view_;
s.inputs_pending = predictor_.pending();
s.lead = lead_.lead();
s.corrections = predictor_.stats().corrections;
@@ -208,6 +228,10 @@ class RemoteSession {
if (!established_)
welcome(ui, launcher);
server_tick_ = c.server_tick();
if (server_tick_ != observed_tick_) { // Every watermark or snapshot tick times the clock.
observed_tick_ = server_tick_;
clock_.observe(server_tick_, now);
}
send(intention);
receipts();
snapshot();
@@ -281,6 +305,11 @@ class RemoteSession {
predictor_.reset(); // A new session has a new marker.
smoother_.reset();
lead_.reset();
clock_.reset(); // Fresh baseline: the frozen view of a lost session is dropped.
interpolator_.reset();
markers_.clear();
observed_tick_ = 0;
stale_view_ = false;
launcher.observe(client::ConnectSignal::welcome);
notify(ui, "Connected to the dev region (fresh baseline).", client::NoticeLevel::info);
std::printf("session welcome session=%llu epoch=%llu tick=%llu\n",
@@ -367,13 +396,14 @@ class RemoteSession {
static_cast<void>(organisms_.accept(std::move(*o)).has_value());
}
}
others_.clear();
std::vector<client::RemoteMarker> remote;
for (const auto& m : v->markers) {
if (m.own)
predictor_.authoritative({v->tick, m.applied_sequence, m.state, m.area});
else
others_.push_back(m);
remote.push_back({m.id, m.state});
}
interpolator_.push(v->tick, remote);
if (!following_ || v->environment.empty() || predictor_.authority())
return; // With a marker, present() follows it instead.
const auto [lx, hx] =
@@ -397,23 +427,36 @@ class RemoteSession {
: 0;
last_present_ = now;
markers_.clear();
const auto predicted = predictor_.predict(server_tick_ + lead_.lead());
interpolator_.advance(elapsed);
const auto clock = clock_.at(now).value_or(static_cast<double>(server_tick_));
// The own marker in the predicted present, between whole ticks.
const auto presented = clock + static_cast<double>(lead_.lead());
const auto whole = static_cast<std::uint64_t>(std::floor(presented));
// Errors are measured only for ticks inputs are already being scheduled for.
const auto predicted = predictor_.predict_between(
whole, presented - static_cast<double>(whole), whole <= server_tick_ + lead_.lead());
const auto& authority = predictor_.authority();
if (predicted && authority) {
smoother_.add(predictor_.take_correction());
const auto offset = smoother_.advance(elapsed);
const MarkerView own{static_cast<double>(predicted->x + offset.x) / 1000,
static_cast<double>(predicted->y + offset.y) / 1000, true};
const MarkerView own{(predicted->x + static_cast<double>(offset.x)) / 1000,
(predicted->y + static_cast<double>(offset.y)) / 1000, true};
markers_.push_back(own);
if (following_) {
recentre_ = offered_ = client::WorldPoint{own.x_mm, own.y_mm};
wanted_ = network::SessionInterest{cell(predicted->x), cell(predicted->y),
authority->area.z, interest_radius};
const auto x = static_cast<std::int64_t>(std::floor(predicted->x));
const auto y = static_cast<std::int64_t>(std::floor(predicted->y));
wanted_ =
network::SessionInterest{cell(x), cell(y), authority->area.z, interest_radius};
}
}
for (const auto& m : others_)
markers_.push_back({static_cast<double>(m.state.x) / 1000,
static_cast<double>(m.state.y) / 1000, false});
// Other markers in the recent past, interpolated.
render_tick_ = clock - interpolator_.delay();
// A silent server freezes the clock; beyond the extrapolation limit that silence is
// what makes the shown markers stale.
const bool silent = clock_.silence(now).value_or(0) > silent_ticks;
for (const auto& m : interpolator_.at(render_tick_))
markers_.push_back({m.x / 1000, m.y / 1000, false, m.stale || silent, m.extrapolated});
}
static std::int64_t cell(std::int64_t um) {
constexpr auto size = network::motion::micrometres_per_cell;
@@ -430,9 +473,19 @@ class RemoteSession {
pending_.clear();
environment_.mark_stale();
organisms_.mark_stale();
// Freeze the view as it was: the own marker at its last authoritative position,
// everything stale. Nothing is predicted or sent until a new session starts afresh.
const auto& authority = predictor_.authority();
std::erase_if(markers_, [](const MarkerView& m) { return m.own; });
if (authority)
markers_.push_back({static_cast<double>(authority->state.x) / 1000,
static_cast<double>(authority->state.y) / 1000, true});
for (auto& m : markers_) {
m.stale = true;
m.extrapolated = false;
}
stale_view_ = was_established || stale_view_;
predictor_.reset(); // The marker ended with its session.
others_.clear();
markers_.clear();
client_.reset();
established_ = false;
const bool not_ready =
@@ -483,8 +536,12 @@ class RemoteSession {
client::InputLead lead_;
std::optional<Clock::time_point> last_present_;
std::uint64_t resends_{}, refused_{};
std::vector<network::ReplicatedMarker> others_;
client::TickClock clock_;
client::MarkerInterpolator interpolator_;
std::uint64_t observed_tick_{};
double render_tick_{};
std::vector<MarkerView> markers_;
bool stale_view_{};
bool established_{}, welcomed_{}, exhausted_{};
bool following_{true}; // The camera follows the server's (default) view.
};