diff --git a/apps/evo-client/cellular_scene.hpp b/apps/evo-client/cellular_scene.hpp index fda5198..5fdd792 100644 --- a/apps/evo-client/cellular_scene.hpp +++ b/apps/evo-client/cellular_scene.hpp @@ -2,6 +2,10 @@ #include "evo/client/camera.hpp" #include "evo/render/frame.hpp" #include +#include +#include +#include +#include #include namespace evo::client_app { @@ -60,4 +64,57 @@ inline void patch_box(std::vector& out, client::ScreenPoint l } } } +// 2026-10-16: a cell faces the way it last moved, flagella trailing. The heading comes +// from the last world displacement of at least `step_mm`, projected with the current +// camera (so panning never turns a cell), and eases toward it so a turn is visible. +class CellHeadings { + public: + static constexpr double step_mm = 0.02; + static constexpr float ease = 0.18F; + // Per frame, per drawn cell: its screen heading, or none before it has moved. + std::optional update(std::uint64_t id, client::WorldPoint at, + const client::Camera& camera) { + auto& t = tracks_[id]; + t.frame = frame_; + if (!t.anchored) { + t.anchor = at; + t.anchored = true; + } else if (std::hypot(at.x_mm - t.anchor.x_mm, at.y_mm - t.anchor.y_mm) >= step_mm) { + const auto from = camera.world_to_screen(t.anchor); + const auto to = camera.world_to_screen(at); + if (from && to && (to->x != from->x || to->y != from->y)) { + t.target = static_cast(std::atan2(to->y - from->y, to->x - from->x)); + if (!t.facing) + t.heading = t.target; + t.facing = true; + } + t.anchor = at; + } + if (!t.facing) + return std::nullopt; + constexpr float pi = 3.14159265F; + float turn = t.target - t.heading; + while (turn > pi) + turn -= 2 * pi; + while (turn < -pi) + turn += 2 * pi; + t.heading += turn * ease; + return t.heading; + } + // After the frame's cells: forget cells no longer drawn. + void end_frame() { + std::erase_if(tracks_, [&](const auto& entry) { return entry.second.frame != frame_; }); + ++frame_; + } + + private: + struct Track { + client::WorldPoint anchor{}; + float heading{}, target{}; + bool anchored{}, facing{}; + std::uint64_t frame{}; + }; + std::unordered_map tracks_; + std::uint64_t frame_{}; +}; } // namespace evo::client_app diff --git a/apps/evo-client/main.cpp b/apps/evo-client/main.cpp index 510b7b2..5ad5d9c 100644 --- a/apps/evo-client/main.cpp +++ b/apps/evo-client/main.cpp @@ -467,7 +467,8 @@ int main(int argc, char** argv) try { bool auth_connect = false; // Connect when the requested grant arrives. auto grant_requested = std::chrono::steady_clock::time_point{}; int drawn_organisms = -1; - evo::client_app::CellularScene scene; // Rebuilt each frame in cellular play. + evo::client_app::CellularScene scene; // Rebuilt each frame in cellular play. + evo::client_app::CellHeadings headings; // Where each drawn cell last moved. bool scene_active = false; evo::client_app::PanelActions actions; (*app)->set_overlay([&] { @@ -783,8 +784,20 @@ int main(int argc, char** argv) try { c.stale = org_layer && org_layer->freshness() != evo::client::Freshness::current; c.seed = cell.id; + // The organism projection's world position (organism_bounds). + constexpr auto pitch = static_cast(evo::world::cell_pitch_mm); + const evo::client::WorldPoint at{ + static_cast(cell.voxel.x) * pitch + + static_cast(cell.x.value) / 1000, + static_cast(cell.voxel.y) * pitch + + static_cast(cell.y.value) / 1000}; + if (const auto heading = headings.update(cell.id, at, *camera)) { + c.facing = true; + c.heading = *heading; + } scene.cells.push_back(c); } + headings.end_frame(); drawn_organisms = static_cast(scene.cells.size()); scene_active = true; } else { diff --git a/apps/evo-client/panels.cpp b/apps/evo-client/panels.cpp index e8b66b3..9652827 100644 --- a/apps/evo-client/panels.cpp +++ b/apps/evo-client/panels.cpp @@ -692,7 +692,7 @@ ImVec2 times(ImVec2 a, float k) noexcept { // only the viewer's own cell gets a faint focus ring. void draw_cell(ImDrawList& list, const SceneCell& c, float time) { const float r = std::max(c.radius, 5.0F); - const float angle = static_cast(c.seed % 628U) / 100.0F; + const float angle = c.facing ? c.heading : static_cast(c.seed % 628U) / 100.0F; const ImVec2 axis{std::cos(angle), std::sin(angle)}; const ImVec2 normal{-axis.y, axis.x}; const ImVec2 centre{c.x, c.y}; @@ -1301,6 +1301,12 @@ void evolution_window(const PanelView& v, FormBuffers& form, PanelActions& a, bo form.evolution_open = false; ImGui::SameLine(); disabled_wrapped("Earned feeding brings the next offer."); + // A click outside closes the offer (the offer stays; E or the callout reopens it). Not + // on the frame it appears: the click that opened it is outside it. + if (!ImGui::IsWindowAppearing() && ImGui::IsMouseClicked(ImGuiMouseButton_Left) && + !ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows | + ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) + form.evolution_open = false; ImGui::End(); } void cellular(const PanelView& v, FormBuffers& form, PanelActions& a) { diff --git a/apps/evo-client/panels.hpp b/apps/evo-client/panels.hpp index 9ac1d86..8d14114 100644 --- a/apps/evo-client/panels.hpp +++ b/apps/evo-client/panels.hpp @@ -29,7 +29,9 @@ struct SceneCell { float x{}, y{}, radius{}, membrane{}; int flagella{}, organelles{}; bool own{}, dead{}, stale{}; - std::uint64_t seed{}; // Stable per organism: orientation and organelle layout. + std::uint64_t seed{}; // Stable per organism: organelle layout (and orientation at rest). + bool facing{}; // Heading is known: the cell faces it, flagella trailing. + float heading{}; // Screen radians. }; struct ScenePatch { float x{}, y{}, half{}; // Centre and half side of the 1 mm contact footprint. diff --git a/deploy/kubernetes/region/dev-session-route/listener.yaml b/deploy/kubernetes/region/dev-session-route/listener.yaml index 9bc4f31..2039429 100644 --- a/deploy/kubernetes/region/dev-session-route/listener.yaml +++ b/deploy/kubernetes/region/dev-session-route/listener.yaml @@ -12,7 +12,7 @@ spec: env: - {name: REGION_SESSION, value: "dev"} - {name: REGION_SESSION_LISTEN, value: "0.0.0.0:7400"} - - {name: REGION_SESSION_WINDOW, value: "dev-20261016T153551-32866:1792175751"} + - {name: REGION_SESSION_WINDOW, value: "dev-20261016T153552-98691:1792175752"} - {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"} ports: # QUIC (ADR-0090): UDP only; nothing listens on TCP 7400. diff --git a/tests/client_panels.cpp b/tests/client_panels.cpp index 0d19c06..421052f 100644 --- a/tests/client_panels.cpp +++ b/tests/client_panels.cpp @@ -517,6 +517,22 @@ void cellular_panels(const std::filesystem::path& review) { CHECK(app->request_screenshot((review / "cellular-evolution.bmp").string())); draw(); } + // A click outside closes it; E opens it again. + const float outside_x = evolution->Pos.x / 2; + const float outside_y = evolution->Pos.y + evolution->Size.y / 2; + mouse(id, SDL_EVENT_MOUSE_MOTION, outside_x, outside_y); + mouse(id, SDL_EVENT_MOUSE_BUTTON_DOWN, outside_x, outside_y); + mouse(id, SDL_EVENT_MOUSE_BUTTON_UP, outside_x, outside_y); + for (int i = 0; i < 3; ++i) + draw(); + CHECK(!form.evolution_open); + (void)app->take_navigation(); + CHECK(SDL_PushEvent(&e_key)); + draw(); + CHECK(SDL_PushEvent(&e_up)); + for (int i = 0; i < 3; ++i) + draw(); + CHECK(form.evolution_open); // Click the first production choice. Pointer ownership prevents world selection. const auto probe = [&](const ImGuiWindow* panel, float x_fraction, const auto& done) { const float x = panel->Pos.x + panel->Size.x * x_fraction; diff --git a/tests/client_ui_model.cpp b/tests/client_ui_model.cpp index ab4e39d..0168b12 100644 --- a/tests/client_ui_model.cpp +++ b/tests/client_ui_model.cpp @@ -11,6 +11,7 @@ #include "evo/client/session_host.hpp" #include #include +#include #include #include #include @@ -511,6 +512,38 @@ void cellular_energy_and_birth_wait() { } } // namespace +// A cell faces the way it moved (y up in the world is up on screen), eases into a turn, +// ignores sub-step jitter and camera panning, and is forgotten once it is not drawn. +void cell_headings() { + using namespace evo::client_app; + auto camera = Camera::create({800, 600, 800, 600}, {5, 5}, 100); + CHECK(camera); + CellHeadings headings; + CHECK(!headings.update(1, {5, 5}, *camera)); + headings.end_frame(); + CHECK(!headings.update(1, {5.001, 5}, *camera)); // Below the step: still unknown. + headings.end_frame(); + const auto east = headings.update(1, {5.1, 5}, *camera); + CHECK(east && std::abs(*east) < 1e-4F); + headings.end_frame(); + auto panned = Camera::create({800, 600, 800, 600}, {9, 2}, 100); + CHECK(panned); + const auto still = headings.update(1, {5.1, 5}, *panned); + CHECK(still && std::abs(*still) < 1e-4F); + headings.end_frame(); + // Moving north is screen up (negative y): the heading eases toward -pi/2. + const auto turning = headings.update(1, {5.1, 5.2}, *camera); + CHECK(turning && *turning < 0 && *turning > -1.5707F); + headings.end_frame(); + float heading = turning.value_or(0); + for (int i = 0; i < 60; ++i) { + heading = headings.update(1, {5.1, 5.2}, *camera).value_or(0); + headings.end_frame(); + } + CHECK(std::abs(heading + 1.5708F) < 1e-3F); + headings.end_frame(); // Not drawn this frame: forgotten. + CHECK(!headings.update(1, {6, 6}, *camera)); +} int main() try { labels(); selection(); @@ -520,6 +553,7 @@ int main() try { cellular_play(); cellular_energy_and_birth_wait(); cellular_assistance(); + cell_headings(); std::puts("client UI model tests passed"); return 0; } catch (const std::exception& e) {