diff --git a/apps/evo-client/main.cpp b/apps/evo-client/main.cpp index 85fb44b..8492b17 100644 --- a/apps/evo-client/main.cpp +++ b/apps/evo-client/main.cpp @@ -184,6 +184,18 @@ std::optional parse_point(std::string_view value) { return std::nullopt; return evo::client::ScreenPoint{static_cast(x), static_cast(y)}; } +// A probe marker (ADR-0094): the own one larger and amber, others smaller and blue; clipped. +void marker_box(std::vector& out, double x, double y, bool own, + double width, double height) { + const double half = own ? 7 : 4; + const double x0 = std::max(x - half, 0.0), y0 = std::max(y - half, 0.0); + const double x1 = std::min(x + half, width), y1 = std::min(y + half, height); + if (x1 > x0 && y1 > y0) + out.push_back( + {static_cast(x0), static_cast(y0), static_cast(x1 - x0), + static_cast(y1 - y0), + own ? evo::render::Color{250, 190, 40, 255} : evo::render::Color{90, 170, 250, 255}}); +} void outline(std::vector& out, double l, double t, double r, double b, double width, double height) { const auto rect = [&](double x0, double y0, double x1, double y1) { @@ -529,6 +541,10 @@ int main(int argc, char** argv) try { return 1; drawn_organisms = static_cast(report->drawn); const double width = state.logical_width, height = state.logical_height; + if (const auto* remote = host.session(); remote && mode() == Mode::remote) + for (const auto& m : remote->markers()) + if (const auto at = camera->world_to_screen({m.x_mm, m.y_mm})) + marker_box(boxes, at->x, at->y, m.own, width, height); if (const auto* o = selection.organism(orgs)) { const auto b = evo::render::organism_bounds(*o, *camera); outline(boxes, b.left - 3, b.top - 3, b.right + 3, b.bottom + 3, width, height); diff --git a/apps/evo-client/panels.cpp b/apps/evo-client/panels.cpp index 95fbc7f..84a3cb7 100644 --- a/apps/evo-client/panels.cpp +++ b/apps/evo-client/panels.cpp @@ -1,6 +1,7 @@ #include "panels.hpp" #include "evo/client/labels.hpp" #include +#include #include #include #include @@ -355,6 +356,18 @@ void session(const PanelView& v) { row("Interest", std::to_string(s.focus_x) + ", " + std::to_string(s.focus_y) + ", z " + std::to_string(s.focus_z) + " (radius 7)"); row("Snapshot bytes", std::to_string(s.snapshot_bytes)); + if (s.marker) { // Probe marker (ADR-0094, EXPERIMENT): predicted and smoothed. + char position[64]; + std::snprintf(position, sizeof position, "%.2f, %.2f m", s.marker_x_mm / 1000, + s.marker_y_mm / 1000); + row("Probe marker", position); + row("Prediction", std::to_string(s.inputs_pending) + " pending, lead " + + std::to_string(s.lead) + " ticks"); + row("Corrections", std::to_string(s.corrections) + ", max error " + + std::to_string(s.max_error_um / 1000) + " mm, " + + std::to_string(s.snaps) + " snaps"); + row("Other markers", std::to_string(s.other_markers)); + } ImGui::EndTable(); } disabled_wrapped("Intentions (newest first; this is the record, toasts expire):"); diff --git a/apps/evo-client/remote_session.hpp b/apps/evo-client/remote_session.hpp index c77897a..54dcce6 100644 --- a/apps/evo-client/remote_session.hpp +++ b/apps/evo-client/remote_session.hpp @@ -10,6 +10,13 @@ // a reconnect loop inside the region's per-account attempt limit. Views come from the // newest applied snapshot. The camera follows the server's default view until the user // moves it; from then on it drives the interest (radius 7), at most every 250 ms. +// +// M10.6b (ADR-0094, EXPERIMENT): the session's probe marker is predicted. Each input is +// recorded with the predictor and scheduled `lead` ticks ahead (adapted to refusals); each +// snapshot's own marker rebases the prediction; corrections are smoothed for display. An +// 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). #include "evo/client/camera.hpp" #include "evo/client/environment_view.hpp" #include "evo/client/input.hpp" @@ -23,8 +30,10 @@ #include #include #include +#include #ifdef EVO_CLIENT_NETWORK +#include "evo/client/motion_prediction.hpp" #include "evo/client/region_session.hpp" #include "evo/network/quic_transport.hpp" #include "evo/world/coordinates.hpp" @@ -47,6 +56,16 @@ struct RemoteStatus { std::size_t cells{}, organisms{}; std::int64_t focus_x{}, focus_y{}, focus_z{}; bool focused{}; + // The predicted probe marker (ADR-0094). + bool marker{}; + double marker_x_mm{}, marker_y_mm{}; + std::size_t inputs_pending{}, other_markers{}; + std::uint64_t lead{}, corrections{}, max_error_um{}, snaps{}; +}; +// A probe marker to draw: the own one predicted and smoothed, others as replicated. +struct MarkerView { + double x_mm{}, y_mm{}; + bool own{}; }; #ifdef EVO_CLIENT_NETWORK @@ -56,7 +75,6 @@ static_assert(std::is_same_v, class RemoteSession { public: static constexpr std::uint16_t interest_radius = 7; - static constexpr std::uint64_t intention_lead = 2; // Ticks ahead of the server tick. // Looks the endpoint up once (blocking); nothing connects until the first step(). static std::optional open(const client::ConnectMaterial& m) { const auto address = network::quic::resolve_ipv4(m.endpoint.host); @@ -115,8 +133,25 @@ class RemoteSession { s.focus_y = sent_interest_->y; s.focus_z = sent_interest_->z; } + for (const auto& m : markers_) + if (m.own) { + s.marker = true; + s.marker_x_mm = m.x_mm; + s.marker_y_mm = m.y_mm; + } else { + ++s.other_markers; + } + s.inputs_pending = predictor_.pending(); + s.lead = lead_.lead(); + s.corrections = predictor_.stats().corrections; + s.max_error_um = predictor_.stats().max_error_um; + s.snaps = smoother_.snaps(); return s; } + // Markers to draw this frame (empty without a session or snapshot). + [[nodiscard]] const std::vector& markers() const noexcept { + return markers_; + } // Where the camera should be while it follows the server's view: the middle of the // newest snapshot's square, offered whenever it changes (the first snapshots may still // be filling in, nearest cells first). @@ -164,6 +199,7 @@ class RemoteSession { send(intention); receipts(); snapshot(); + present(now); if (wanted_ && (!sent_interest_ || *wanted_ != *sent_interest_) && now - interest_at_ >= std::chrono::milliseconds{250} && c.set_interest(*wanted_)) { sent_interest_ = wanted_; @@ -228,8 +264,11 @@ class RemoteSession { session_ = w.session; epoch_ = w.epoch; sent_tick_.reset(); // New session: resend the current intention. - sent_x_ = sent_y_ = 0; + sent_ = {}; sent_interest_.reset(); // The server starts from its default interest. + predictor_.reset(); // A new session has a new marker. + smoother_.reset(); + lead_.reset(); 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", @@ -238,16 +277,23 @@ class RemoteSession { static_cast(w.server_tick)); } void send(const client::Intention& intention) { - const bool changed = intention.move_x != sent_x_ || intention.move_y != sent_y_; - if (!changed || server_tick_ == 0 || (sent_tick_ && server_tick_ <= *sent_tick_)) + const network::motion::Vector want{intention.move_x, intention.move_y}; + if (server_tick_ == 0 || (sent_tick_ && server_tick_ <= *sent_tick_) || predictor_.full()) return; - const auto tick = server_tick_ + intention_lead; + // Resend when the authority holds another vector and nothing in flight will change + // it (the last intention was lost or refused). + const auto& authority = predictor_.authority(); + const bool stale = + authority && authority->state.vector != want && predictor_.pending() == 0; + if (want == sent_ && !stale) + return; + const auto tick = server_tick_ + lead_.lead(); // Refused until the datagram extension is negotiated: retried next frame. - const auto sequence = client_->send_intention(tick, intention.move_x, intention.move_y); + const auto sequence = client_->send_intention(tick, want.x, want.y); if (!sequence) return; - sent_x_ = intention.move_x; - sent_y_ = intention.move_y; + static_cast(predictor_.input({*sequence, tick, want})); + sent_ = want; sent_tick_ = server_tick_; const auto entry = next_entry_++; log_.record({entry, client::OutcomeState::sent, 0, tick}); @@ -267,7 +313,11 @@ class RemoteSession { if (r.status == network::AdmitStatus::admitted) { log_.record({it->entry, client::OutcomeState::admitted, 0, it->tick}); it->admitted = true; + lead_.admitted(it->tick, r.server_tick); } else { + predictor_.rejected(r.sequence); // It never takes effect. + if (r.status == network::AdmitStatus::outside_window) + lead_.too_late(); // Arrived after its tick: schedule further ahead. log_.record({it->entry, client::OutcomeState::rejected, static_cast(r.status), it->tick}); pending_.erase(it); @@ -303,8 +353,15 @@ class RemoteSession { static_cast(organisms_.accept(std::move(*o)).has_value()); } } - if (!following_ || v->environment.empty()) - return; + others_.clear(); + 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); + } + if (!following_ || v->environment.empty() || predictor_.authority()) + return; // With a marker, present() follows it instead. const auto [lx, hx] = std::minmax_element(v->environment.begin(), v->environment.end(), [](const auto& a, const auto& b) { return a.voxel.x < b.voxel.x; }); @@ -318,6 +375,36 @@ class RemoteSession { if (!offered_ || middle.x_mm != offered_->x_mm || middle.y_mm != offered_->y_mm) recentre_ = offered_ = middle; } + // The predicted own marker (smoothed) and the others; while following, the camera and + // the interest follow the own marker. + void present(Clock::time_point now) { + const double elapsed = + last_present_ ? std::chrono::duration(now - *last_present_).count() + : 0; + last_present_ = now; + markers_.clear(); + const auto predicted = predictor_.predict(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(predicted->x + offset.x) / 1000, + static_cast(predicted->y + 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}; + } + } + for (const auto& m : others_) + markers_.push_back({static_cast(m.state.x) / 1000, + static_cast(m.state.y) / 1000, false}); + } + static std::int64_t cell(std::int64_t um) { + constexpr auto size = network::motion::micrometres_per_cell; + return um >= 0 || um % size == 0 ? um / size : (um / size) - 1; + } // The connection ended: decide what the launcher hears and pause before the next grant. void end(Clock::time_point now, client::UiState& ui, client::Launcher& launcher) { using network::SessionCloseReason; @@ -329,6 +416,9 @@ class RemoteSession { pending_.clear(); environment_.mark_stale(); organisms_.mark_stale(); + predictor_.reset(); // The marker ended with its session. + others_.clear(); + markers_.clear(); client_.reset(); established_ = false; const bool not_ready = @@ -373,7 +463,13 @@ class RemoteSession { std::optional wanted_, sent_interest_; std::optional recentre_, offered_; std::int64_t slice_z_{}; - std::int16_t sent_x_{}, sent_y_{}; + network::motion::Vector sent_; + client::MotionPredictor predictor_; + client::CorrectionSmoother smoother_; + client::InputLead lead_; + std::optional last_present_; + std::vector others_; + std::vector markers_; bool established_{}, welcomed_{}, exhausted_{}; bool following_{true}; // The camera follows the server's (default) view. }; @@ -399,6 +495,9 @@ class RemoteSession { [[nodiscard]] std::optional take_recentre() { return std::nullopt; } + [[nodiscard]] const std::vector& markers() const noexcept { + return markers_; + } void focus(client::WorldPoint) {} void step(std::chrono::steady_clock::time_point, const client::Intention&, client::UiState&, client::Launcher&) {} @@ -407,6 +506,7 @@ class RemoteSession { client::EnvironmentLayer environment_; client::OrganismLayer organisms_; client::OutcomeLog log_; + std::vector markers_; }; #endif } // namespace evo::client_app diff --git a/apps/evo-server/m10_bridge.hpp b/apps/evo-server/m10_bridge.hpp index efda408..f7a7449 100644 --- a/apps/evo-server/m10_bridge.hpp +++ b/apps/evo-server/m10_bridge.hpp @@ -9,6 +9,7 @@ // Session control and action records use their own connection under the host's lease. // M10.5 (ADR-0093): once per simulated tick every session's snapshot is built from the // region's own stores for its interest (default: the region's first habitat site, radius 7). +// M10.6 (ADR-0094): sessions' probe markers move within the habitat sites' bounding cells. #include "evo/persistence/postgres.hpp" #include "evo/persistence/region_lease.hpp" #include @@ -149,6 +150,7 @@ template class M10Bridge { const auto v = sites.front().voxel; default_interest_ = network::SessionInterest{v.x, v.y, v.z, 7}; sessions_->set_default_interest(*default_interest_); + set_motion_area(sites, v); } sessions_->replicate(s.simulated_tick, [&](const network::SessionInterest& in) { return source(c, in, s.simulated_tick); @@ -196,6 +198,26 @@ template class M10Bridge { static const processes::EnvironmentalCommunity& community(const processes::LineageRegion& r) { return r.community(); } + // Probe markers (ADR-0094, EXPERIMENT) move within the habitat sites' bounding cells of + // the default slice and spawn at the centre of its first site. + template void set_motion_area(const Sites& sites, world::VoxelAddress first) { + constexpr auto cell = network::motion::micrometres_per_cell; + network::motion::Area area{first.x * cell, first.y * cell, (first.x * cell) + cell - 1, + (first.y * cell) + cell - 1, first.z}; + for (const auto& site : sites) + if (site.voxel.z == first.z) { + area.min_x = std::min(area.min_x, site.voxel.x * cell); + area.min_y = std::min(area.min_y, site.voxel.y * cell); + area.max_x = std::max(area.max_x, (site.voxel.x * cell) + cell - 1); + area.max_y = std::max(area.max_y, (site.voxel.y * cell) + cell - 1); + } + if (sessions_->set_motion_area(area, (first.x * cell) + (cell / 2), + (first.y * cell) + (cell / 2))) + std::printf("m10 motion area %lld %lld %lld %lld z=%lld\n", + static_cast(area.min_x), static_cast(area.min_y), + static_cast(area.max_x), static_cast(area.max_y), + static_cast(area.z)); + } // A read-only copy of the region's stores within one interest: the habitat sites of its // square in its slice. The region has no placed individuals: organisms stay empty. network::ReplicationSource source(const processes::EnvironmentalCommunity& c, diff --git a/apps/evo-session-probe/main.cpp b/apps/evo-session-probe/main.cpp index 24c9499..c46b01d 100644 --- a/apps/evo-session-probe/main.cpp +++ b/apps/evo-session-probe/main.cpp @@ -23,6 +23,8 @@ // resolved HOST ADDRESS (a host name was looked up; IPv4) // snapshot TICK CELLS ORGANISMS MINX MINY MAXX MAXY Z (each newly applied snapshot; // --snapshots N waits for N; --interest asks for another focus than the default) +// marker TICK X Y APPLIED (the session's own probe marker in each new snapshot: um +// position after TICK and the newest applied intention sequence; ADR-0094) // closed REASON TRANSPORT (TRANSPORT names why QUIC ended: untrusted means the server // answered but failed the pinned CA/name check; idle means nothing answered) // Statuses, results and reasons are the session-v1 wire values. Exits 0 once every @@ -332,6 +334,12 @@ int run(const RunOptions& o) { v->organisms.size(), static_cast(min_x), static_cast(min_y), static_cast(max_x), static_cast(max_y), static_cast(v->slice_z)); + for (const auto& m : v->markers) + if (m.own) + std::printf( + "marker %llu %lld %lld %llu\n", static_cast(v->tick), + static_cast(m.state.x), static_cast(m.state.y), + static_cast(m.applied_sequence)); } for (const auto& r : c.take_action_receipts()) std::printf("receipt %llu %u %llu\n", static_cast(r.action_id), diff --git a/cmake/ClientProbe.cmake b/cmake/ClientProbe.cmake index 1602c4b..1ec2bb8 100644 --- a/cmake/ClientProbe.cmake +++ b/cmake/ClientProbe.cmake @@ -72,7 +72,7 @@ if(EVO_BUILD_CLIENT) if(EVO_BUILD_QUIC) # M10.5c remote dev session mode over M10 QUIC sessions (ADR-0093); replaces the M9.7 # TCP session (ADR-0083), whose dev route is gone (ADR-0087). - target_link_libraries(evo-client PRIVATE evo_session_client) + target_link_libraries(evo-client PRIVATE evo_session_client evo_client_prediction) target_compile_definitions(evo-client PRIVATE EVO_CLIENT_NETWORK=1) endif() evo_owned_target(evo-client) @@ -85,7 +85,8 @@ if(EVO_BUILD_CLIENT) add_executable(evo-client-remote-tests tests/client_remote_session.cpp) target_include_directories(evo-client-remote-tests PRIVATE "${PROJECT_SOURCE_DIR}/apps/evo-client") target_compile_definitions(evo-client-remote-tests PRIVATE EVO_CLIENT_NETWORK=1) - target_link_libraries(evo-client-remote-tests PRIVATE evo_client_ui evo_session_client evo_session_server) + target_link_libraries(evo-client-remote-tests PRIVATE evo_client_ui evo_session_client + evo_session_server evo_client_prediction) evo_owned_target(evo-client-remote-tests) evo_msquic_runtime(evo-client-remote-tests) add_test(NAME client-remote-session COMMAND evo-client-remote-tests) diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 6b628e5..f577405 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -530,7 +530,8 @@ probe) with process evidence done; 10.5c engineering client switched to M10 sess (snapshot views, camera interest, grant bundles, msquic.dll in the Windows package) done. 10.6 split (ADR-0094, EXPERIMENT probe marker, not an organism movement rule): 10.6a shared probe-motion-v1 rule, server markers, session protocol v3 marker records and the client -predictor done; 10.6b wiring and 10.6c impaired traces follow. +predictor done; 10.6b wiring (sessions, evo-server, probe, GUI marker) done; 10.6c impaired +traces follow. 10.6-10.9 planned. **Entry:** M9 client/session evidence and M7/M8 dev/stage durability. Read diff --git a/docs/STATUS.md b/docs/STATUS.md index c8cc710..fc44e21 100644 --- a/docs/STATUS.md +++ b/docs/STATUS.md @@ -55,7 +55,9 @@ is a maintainer step. M10.6a (ADR-0094) adds the probe-motion experiment: one non-biological marker per session moved by intentions with a shared integer rule, session protocol v3 marker records (v2, deployed, is frozen and refused), and the client predictor (bounded replay from the authoritative marker, corrections, smoothing, adaptive input lead). -Next: 10.6b wiring into sessions, evo-server, the probe and the GUI. +M10.6b wires it: evo-server gives every session a marker in the habitat area, the probe +prints it, and the engineering client predicts and draws it (WASD), following it with +camera and interest. Next: 10.6c impaired traces and the correction report. ## Previous gate - 2026-10-02 diff --git a/docs/adr/0094-m10-probe-motion-experiment.md b/docs/adr/0094-m10-probe-motion-experiment.md index 314a7f5..337ea85 100644 --- a/docs/adr/0094-m10-probe-motion-experiment.md +++ b/docs/adr/0094-m10-probe-motion-experiment.md @@ -66,3 +66,33 @@ rules. Session protocol v2 was deployed to evolution-dev on 2026-10-06 and is fr client resends after 10.6b's rules). - Markers add at most 32 x 78 bytes per snapshot; their state is not durable and not part of any checkpoint or simulation version. + +## M10.6b wiring (2026-10-06) +- **RegionSessions** owns `ProbeMarkers`. Once the host calls `set_motion_area`: + - every established session gets a marker (also those open at that moment); + - an admitted intention schedules its marker; + - each poll advances markers to the simulated tick (while ready) before admitting; + - close and loss remove the marker; + - a new epoch clears all markers; + - `replicate` adds the markers and area to every source. +- **evo-server** sets the area with the default interest: the bounding cells of the + region's habitat sites in that slice, spawning at the centre of the first site. It prints + `m10 motion area`. +- **Probe:** one `marker TICK X Y APPLIED` line per snapshot holding its own marker. +- **Engineering client:** + - inputs are scheduled with the adaptive lead and recorded with the predictor; + - each snapshot's own marker rebases the prediction; + - a refusal removes the input, and `outside_window` raises the lead; + - an intention is sent again when the authority holds another vector and nothing is in + flight (after a loss or refusal); + - the predicted marker is presented at server tick + lead, with corrections smoothed. + + While following, the camera and the interest follow the predicted own marker, until the + user pans or zooms. Markers are drawn as squares: own amber, others blue. The Session + panel shows the marker position, pending inputs, lead, corrections, maximum error and + snaps. There is no sub-tick interpolation: the marker steps at 20 Hz. +- Evidence: + - `client-remote-session`: the marker at the spawn, followed by camera and interest; an + intention moves the predicted marker and the authority confirms it with zero error. + - The real-process test: the probe's marker moved +x with its intention applied, and + evo-server reported the motion area. diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index 0e30793..16aa8f9 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -4526,3 +4526,39 @@ Not done: - impaired traces (10.6c). Deployed v2 servers refuse v3 clients until redeployed. + +## 2026-10-06 — M10.6b probe-marker wiring (ADR-0094) + +Implemented: +- `RegionSessions` markers (`set_motion_area`, schedule on admission, advance per poll, + close and loss, clear on a new epoch, markers in every snapshot source); +- the evo-server motion area (the habitat sites' bounding cells, `m10 motion area`); +- the probe's `marker` lines; +- the engineering client's prediction, adaptive lead, resend after loss or refusal, + smoothing, marker drawing, the follow camera and interest, and Session panel rows. + +Evidence: +- `client-remote-session`: the marker at its spawn, followed by camera and interest; an + intention moves the predicted marker +x, and the authority confirms it with zero maximum + error and no pending inputs. Passed 3 times in a row. +- The real-process test (`region_m10_session_tests`): the probe's own marker moved +x with + its intention applied, and evo-server printed its motion area. The snapshot report is + now 8,966 bytes in 40 ticks, including the marker records. + +Executed: +- **Linux GCC 14:** + - preset `client-network`: CTest 14/14; + - preset `quic`: 4/4; + - `postgres-check.sh` with QUIC: 20 suites. +- **Linux Clang 19:** build, plus clang-tidy 19 on the client app, the remote test, + RegionSessions, the probe and probe_motion. +- **Windows MSVC 19.44** (fresh binaries; built while the formatting pass ran, which + changed whitespace only): + - preset `quic`: 4/4; + - preset `client-network`: 12/12. + +clang-format 19 was applied to the changed files. + +Not done: +- impaired traces (10.6c); +- a GUI run against evolution-dev, which needs a v3 server. diff --git a/docs/networking/M10_CLIENT_SESSIONS.md b/docs/networking/M10_CLIENT_SESSIONS.md index 7196410..d83696a 100644 --- a/docs/networking/M10_CLIENT_SESSIONS.md +++ b/docs/networking/M10_CLIENT_SESSIONS.md @@ -31,9 +31,12 @@ evo-client --connect void.aeternalisgames.com:7400 --server-name NAME --ca dev-c - The view follows the region's default view until you pan or zoom; then the 15 x 15 cells around the camera centre are replicated (radius 7). -- W A S D send movement intentions; the Session panel lists each as sent, admitted, - rejected, simulated (final; intentions are never durable) or unknown. +- W A S D send movement intentions. They move your probe marker (amber square; others + are blue), an engineering experiment, not an organism (ADR-0094). It is predicted + locally and corrected by the server; the camera follows it until you pan or zoom. + The Session panel lists each intention as sent, admitted, rejected, simulated (final; + intentions are never durable) or unknown, plus the prediction figures. - Each reconnect uses the next grant. A second client with a bundle for the same account takes the session over; the first stops (do not share bundles). -- A server still on session protocol v1 refuses the client (`unsupported_version`): - deploy the v2 server first. +- A server on an older session protocol (v1, v2) refuses the client + (`unsupported_version`): deploy a v3 server first. diff --git a/include/evo/network/probe_motion.hpp b/include/evo/network/probe_motion.hpp index b524156..146006a 100644 --- a/include/evo/network/probe_motion.hpp +++ b/include/evo/network/probe_motion.hpp @@ -62,6 +62,7 @@ class ProbeMarkers { // A marker for the session, at the spawn, holding no movement. [[nodiscard]] std::expected open(std::uint64_t session); void close(std::uint64_t session); + // Removes every marker and forgets the tick (a new epoch may restart at an earlier one). void clear() noexcept; // An admitted intention: from its tick on, the marker holds its vector. Intentions // arrive in sequence order; the newest per tick wins. Bounded per marker. diff --git a/include/evo/server/region_sessions.hpp b/include/evo/server/region_sessions.hpp index fb522c8..103363c 100644 --- a/include/evo/server/region_sessions.hpp +++ b/include/evo/server/region_sessions.hpp @@ -1,5 +1,6 @@ #pragma once #include "evo/network/intent_admission.hpp" +#include "evo/network/probe_motion.hpp" #include "evo/network/quic_transport.hpp" #include "evo/network/replication.hpp" #include "evo/network/session_control.hpp" @@ -29,6 +30,9 @@ // M10.5 (ADR-0093): every established session has a spatial interest (the default set by // the host until the client sends its own); the host calls replicate() once per simulated // tick and each session receives its snapshot chunks as datagrams sized to its path. +// M10.6 (ADR-0094, EXPERIMENT): once the host sets a motion area, every established session +// has a probe marker; admitted intentions schedule its movement, each poll advances markers +// to the simulated tick, and snapshots carry them. A new epoch starts without markers. // With a ControlLedger, control is durable and unique per world: a session that loses its // durable control (another region accepted a newer grant) closes with `superseded`, and // one whose control cannot be renewed in time closes with `shutdown`. @@ -98,6 +102,11 @@ class RegionSessions { const std::function& source, const network::Perceives& perceives = {}); [[nodiscard]] network::ReplicationStats replication_stats() const; + // Where probe markers live and spawn (ADR-0094); sessions already established receive a + // marker. False for an invalid area. + [[nodiscard]] bool set_motion_area(const network::motion::Area& area, std::int64_t spawn_x, + std::int64_t spawn_y); + [[nodiscard]] const network::motion::ProbeMarkers& markers() const noexcept; // Closes every connection with `shutdown` (flushed by later polls). void shutdown(std::chrono::steady_clock::time_point now); [[nodiscard]] std::vector take_events(); diff --git a/src/network/protocol/probe_motion.cpp b/src/network/protocol/probe_motion.cpp index dec7be4..a76d2d2 100644 --- a/src/network/protocol/probe_motion.cpp +++ b/src/network/protocol/probe_motion.cpp @@ -65,6 +65,7 @@ void ProbeMarkers::close(std::uint64_t session) { void ProbeMarkers::clear() noexcept { entries_.clear(); markers_.clear(); + tick_ = 0; } std::expected ProbeMarkers::schedule(std::uint64_t session, diff --git a/src/server/session/region_sessions.cpp b/src/server/session/region_sessions.cpp index 8be7134..709a166 100644 --- a/src/server/session/region_sessions.cpp +++ b/src/server/session/region_sessions.cpp @@ -65,7 +65,8 @@ struct RegionSessions::Impl { network::GrantVerifier v, network::SessionControl s, network::IntentAdmission i, network::ReplicationServer r) : config{std::move(c)}, endpoint{std::move(e)}, verifier{std::move(v)}, - control{std::move(s)}, intents{std::move(i)}, replication{std::move(r)} {} + control{std::move(s)}, intents{std::move(i)}, replication{std::move(r)}, + markers{config.control.max_sessions} {} RegionSessionsConfig config; std::unique_ptr endpoint; @@ -73,6 +74,7 @@ struct RegionSessions::Impl { network::SessionControl control; network::IntentAdmission intents; network::ReplicationServer replication; + network::motion::ProbeMarkers markers; // Ephemeral probe markers (ADR-0094). std::optional default_interest; HostFacts facts; std::vector connections; @@ -116,6 +118,7 @@ struct RegionSessions::Impl { if (c.state == State::established) { intents.close(c.session); replication.close(c.session); + markers.close(c.session); } if (c.session != 0) // May already be released (superseded, expired, epoch). (void)control.close(c.session).has_value(); @@ -194,6 +197,8 @@ struct RegionSessions::Impl { } if (default_interest) (void)replication.set_interest(c.session, *default_interest).has_value(); + if (markers.area()) // Full or refused: the session simply has no marker. + (void)markers.open(c.session).has_value(); c.state = State::established; c.welcome.server_tick = facts.simulated_tick; send(c, c.welcome); @@ -262,7 +267,11 @@ struct RegionSessions::Impl { const auto* m = std::get_if(&*decoded); if (!m) return close(c, SessionCloseReason::protocol, now); - send_datagram(c, intents.intention(c.session, *m, admission())); + const auto receipt = intents.intention(c.session, *m, admission()); + if (receipt.status == network::AdmitStatus::admitted) // Moves the session's marker. + (void)markers.schedule(c.session, m->sequence, m->tick, {m->move_x, m->move_y}) + .has_value(); + send_datagram(c, receipt); } void deliver(const std::vector& outcomes) { @@ -369,7 +378,11 @@ void RegionSessions::poll(const HostFacts& facts, std::uint64_t now_seconds, if (auto* c = m.by_session(session)) m.close(*c, SessionCloseReason::stale_epoch, now); (void)m.intents.abandon(); // Kept for queries; no session is left to tell. + m.markers.clear(); // The new epoch may restart at an earlier tick. } + // Markers reach the simulated tick before this poll's intentions are admitted. + if (facts.ready) + m.markers.advance(facts.simulated_tick); for (auto& e : m.endpoint->poll()) { using network::quic::EventKind; if (e.kind == EventKind::connected) { @@ -388,6 +401,7 @@ void RegionSessions::poll(const HostFacts& facts, std::uint64_t now_seconds, if (it->state == Impl::State::established) { m.intents.close(it->session); m.replication.close(it->session); + m.markers.close(it->session); } if (it->state == Impl::State::pending) { (void)m.control.close(it->session).has_value(); @@ -459,7 +473,14 @@ void RegionSessions::replicate( const auto* c = m.by_session(session); return c && c->state == Impl::State::established ? m.endpoint->datagram_limit(c->id) : 0; }; - for (const auto& [session, chunks] : m.replication.tick(tick, source, perceives, payload)) + // The host's state plus the probe markers (all of them; filtered per session). + const auto with_markers = [&](const network::SessionInterest& in) { + auto s = source(in); + s.markers = m.markers.markers(); + s.marker_area = m.markers.area(); + return s; + }; + for (const auto& [session, chunks] : m.replication.tick(tick, with_markers, perceives, payload)) if (const auto* c = m.by_session(session); c && c->state == Impl::State::established) for (const auto& chunk : chunks) m.send_datagram(*c, chunk); // A refused chunk leaves the snapshot unacknowledged. @@ -469,6 +490,21 @@ network::ReplicationStats RegionSessions::replication_stats() const { return impl_->replication.stats(); } +bool RegionSessions::set_motion_area(const network::motion::Area& area, std::int64_t spawn_x, + std::int64_t spawn_y) { + auto& m = *impl_; + if (!m.markers.set_area(area, spawn_x, spawn_y)) + return false; + for (const auto& c : m.connections) + if (c.state == Impl::State::established && !m.markers.of(c.session)) + (void)m.markers.open(c.session).has_value(); + return true; +} + +const network::motion::ProbeMarkers& RegionSessions::markers() const noexcept { + return impl_->markers; +} + void RegionSessions::shutdown(Clock::time_point now) { for (auto& c : impl_->connections) impl_->close(c, SessionCloseReason::shutdown, now); diff --git a/tests/client_remote_session.cpp b/tests/client_remote_session.cpp index 1e8f862..544cf7e 100644 --- a/tests/client_remote_session.cpp +++ b/tests/client_remote_session.cpp @@ -108,6 +108,9 @@ struct Region { CHECK(made.has_value()); sessions = std::move(*made); sessions->set_default_interest({3, 3, -7, 7}); + // Probe markers (ADR-0094) over the slice's cells, spawning in the middle of (3, 3). + CHECK(sessions->set_motion_area({-10'000'000, -10'000'000, 10'999'999, 10'999'999, -7}, + 3'500'000, 3'500'000)); } WireGrant grant(const AccountId& who, std::uint64_t serial, std::uint64_t in_region = region) const { @@ -203,12 +206,16 @@ void views_interest_and_intentions(Region& r) { return e.voxel.x >= -4 && e.voxel.x <= 10 && e.voxel.y >= -4 && e.voxel.y <= 10; })); CHECK(s.environment().freshness() == client::Freshness::current); - // The camera follows the view: the middle of its square, offered once per change. + // The session's probe marker, predicted at its spawn; the camera follows it, and so does + // the interest (its cell is the default's centre: the same view). + CHECK(c.until(r, [&] { return s.status().marker; }, 20)); + CHECK(s.markers().size() == 1 && s.markers()[0].own && s.status().marker_x_mm == 3500); const auto centre = s.take_recentre().value_or(client::WorldPoint{-1, -1}); CHECK(centre.x_mm == 3500 && centre.y_mm == 3500 && !s.take_recentre()); - s.focus(centre); // Where the view put it: still following, no interest sent. + s.focus(centre); // Where the session put it: still following. static_cast(c.until(r, [] { return false; }, 20, std::chrono::milliseconds{300})); - CHECK(!s.status().focused && c.cells() == 225); // 300 ms of ticks: the same view. + CHECK(s.status().focused && s.status().focus_x == 3 && s.status().focus_y == 3 && + c.cells() == 225); // 300 ms of ticks: the same view. // The user moves the camera: its centre's voxel becomes the interest (clipped). s.focus({-5500, -5200}); CHECK(c.until(r, [&] { return c.cells() == 144; }, 20)); // x, y in -10..1. @@ -221,6 +228,11 @@ void views_interest_and_intentions(Region& r) { CHECK(c.until(r, [&] { return c.has(OutcomeState::simulated); }, 20)); const auto& first = s.outcomes().entries().front(); CHECK(first.sequence == 1 && first.tick != 0 && s.status().simulated_tick >= first.tick); + // The marker moves +x at 70 mm per tick, predicted ahead of the authority, and the + // authority confirms the prediction (loopback: no correction needed). + CHECK(c.until(r, [&] { return s.status().marker_x_mm > 4000; }, 20)); + CHECK(s.status().marker_y_mm == 3500 && s.status().max_error_um == 0 && + s.status().inputs_pending == 0); // A new epoch closes the session: the open intention is unknown, the views are stale, // and the session reconnects with the bundle's next grant after its pause. const auto old_session = s.status().session; diff --git a/tests/region_m10_session_tests.cpp b/tests/region_m10_session_tests.cpp index fac5243..d8c128d 100644 --- a/tests/region_m10_session_tests.cpp +++ b/tests/region_m10_session_tests.cpp @@ -9,11 +9,14 @@ #include "evo/network/session_grant.hpp" #include "fixtures/server_process.hpp" #include +#include #include #include #include #include #include +#include +#include #include #include @@ -320,7 +323,7 @@ void end_to_end() { "--actions", "2", "--action-base", "10", "--query", "10", - "--snapshots", "3"}}; + "--snapshots", "8"}}; int code = -1; for (const auto end = Clock::now() + 30s; Clock::now() < end && code < 0;) { server->pump(); @@ -332,9 +335,22 @@ void end_to_end() { p.printed("outcome 10 1 ") && p.printed("outcome 11 1 ") && p.printed("snapshot ") && p.printed("snapshot-bytes ")); CHECK(!record(bob, 10).empty() && !record(bob, 11).empty()); + // The probe's marker (ADR-0094): its intentions (100, 0) were applied and moved it +x. + std::vector> marks; // tick, x, y, applied + for (const auto& line : p.lines()) + if (line.starts_with("marker ")) { + std::array m{}; + std::istringstream in{line.substr(7)}; + in >> m[0] >> m[1] >> m[2] >> m[3]; + if (in) + marks.push_back(m); + } + CHECK(marks.size() >= 2 && marks.back()[3] >= 1 && marks.back()[1] > marks.front()[1] && + marks.back()[2] == marks.front()[2]); server->child->signal(SIGTERM); CHECK(server->child->wait_exit(30s) == 0); - CHECK(server->child->printed("m10 opened ") && server->child->printed("m10 committed ")); + CHECK(server->child->printed("m10 opened ") && server->child->printed("m10 committed ") && + server->child->printed("m10 motion area ")); } } // namespace