#pragma once #include "evo/client/camera.hpp" #include "evo/render/frame.hpp" #include #include #include #include #include #include namespace evo::client_app { inline constexpr std::size_t patch_rectangles = 11; // The border keeps the 1 mm contact footprint readable; the inset is decorative. // E (gold) and M (teal) identify energy and matter stock, without invented percentages. inline void patch_box(std::vector& out, client::ScreenPoint low, client::ScreenPoint high, bool energy, bool matter, bool selected, double width, double height, bool stale = false) { const double minimum = selected ? 5 : 3; const double hx = std::max((high.x - low.x) / 2, minimum); const double hy = std::max((low.y - high.y) / 2, minimum); const double x = (low.x + high.x) / 2, y = (low.y + high.y) / 2; const auto rect = [&](double l, double t, double r, double b, render::Color color) { l = std::max(l, 0.0); t = std::max(t, 0.0); r = std::min(r, width); b = std::min(b, height); if (stale) { color.red /= 2; color.green /= 2; color.blue /= 2; } if (r > l && b > t) out.push_back({static_cast(l), static_cast(t), static_cast(r - l), static_cast(b - t), color}); }; rect(x - hx, y - hy, x + hx, y + hy, selected ? render::Color{233, 182, 85, 255} : energy ? render::Color{155, 117, 45, 255} : matter ? render::Color{49, 112, 105, 255} : render::Color{58, 69, 77, 255}); if (hx <= 6 || hy <= 6) return; const double border = selected ? 2 : 1; rect(x - hx + border, y - hy + border, x + hx - border, y + hy - border, selected ? render::Color{53, 49, 31, 255} : render::Color{17, 40, 43, 255}); if (hx >= 16 && hy >= 16) { const double top = y - hy + 7; if (energy) { const double left = matter ? x - 12 : x - 4; const render::Color gold{233, 182, 85, 255}; rect(left, top, left + 2, top + 12, gold); rect(left + 2, top, left + 8, top + 2, gold); rect(left + 2, top + 5, left + 7, top + 7, gold); rect(left + 2, top + 10, left + 8, top + 12, gold); } if (matter) { const double left = energy ? x + 3 : x - 5; const render::Color teal{90, 185, 150, 255}; rect(left, top, left + 2, top + 12, teal); rect(left + 8, top, left + 10, top + 12, teal); rect(left + 2, top + 2, left + 4, top + 5, teal); rect(left + 6, top + 2, left + 8, top + 5, teal); rect(left + 4, top + 4, left + 6, top + 7, teal); } } } // 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