diff --git a/apps/evo-client/main.cpp b/apps/evo-client/main.cpp index c902476..510b7b2 100644 --- a/apps/evo-client/main.cpp +++ b/apps/evo-client/main.cpp @@ -467,6 +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. + bool scene_active = false; evo::client_app::PanelActions actions; (*app)->set_overlay([&] { evo::client_app::PanelView view; @@ -488,6 +490,7 @@ int main(int argc, char** argv) try { view.cellular_feed_target = cellular_feed_target; } view.visible_organisms = drawn_organisms; + view.cellular_scene = scene_active ? &scene : nullptr; view.bindings = &(*app)->bindings(); controls.fill(view); actions = evo::client_app::draw_panels(view, buffers, display); @@ -719,10 +722,16 @@ int main(int argc, char** argv) try { *camera, display)) return 1; const double width = state.logical_width, height = state.logical_height; - // Cellular patches under the organisms, so the own cell draws on top of them. - if (const auto* remote = host.session(); - remote && mode() == Mode::remote && cellular_trial) - if (const auto* perception = remote->cellular_perception()) + // 2026-10-16 microscope view: in cellular play, patches and cells are a scene the + // panels draw as granules and living cells; elsewhere organisms stay rectangles. + scene.patches.clear(); + scene.cells.clear(); + scene_active = false; + const auto* cellular_remote = host.session(); + const bool microscope = cellular_remote && mode() == Mode::remote && cellular_trial; + if (microscope) { + const bool fresh = cellular_remote->cellular_play().fresh(); + if (const auto* perception = cellular_remote->cellular_perception()) for (const auto& patch : perception->patches) { const auto low = camera->world_to_screen({static_cast(patch.x_um) / 1000, @@ -730,20 +739,62 @@ int main(int argc, char** argv) try { const auto high = camera->world_to_screen( {(static_cast(patch.x_um) + 1000) / 1000, (static_cast(patch.y_um) + 1000) / 1000}); - if (low && high) - evo::client_app::patch_box( - boxes, *low, *high, patch.energy_pj != 0, - std::ranges::any_of(patch.matter_fg, [](auto v) { return v != 0; }), - cellular_feed_target && cellular_feed_target->first == patch.x_um && - cellular_feed_target->second == patch.y_um, - width, height, !remote->cellular_play().fresh()); + if (!low || !high) + continue; + evo::client_app::ScenePatch p; + p.x = static_cast((low->x + high->x) / 2); + p.y = static_cast((low->y + high->y) / 2); + p.half = static_cast(std::abs(high->x - low->x) / 2); + p.stock = {patch.energy_pj, patch.matter_fg[0], patch.matter_fg[1], + patch.matter_fg[2], patch.matter_fg[3]}; + p.target = cellular_feed_target && + cellular_feed_target->first == patch.x_um && + cellular_feed_target->second == patch.y_um; + p.stale = !fresh; + p.seed = (static_cast(patch.x_um) << 32U) ^ patch.y_um; + scene.patches.push_back(p); } - const auto report = evo::render::append_organisms( - boxes, organism_budget, orgs, - org_layer ? org_layer->freshness() : evo::client::Freshness::none, *camera); - if (!report) - return 1; - drawn_organisms = static_cast(report->drawn); + const auto own = cellular_remote->cellular_play().life(); + if (orgs) + for (const auto& cell : orgs->cells()) { + const auto bounds = evo::render::organism_bounds(cell, *camera); + if (bounds.right < 0 || bounds.left > width || bounds.bottom < 0 || + bounds.top > height) + continue; + const auto& ph = cell.phenotype; + evo::client_app::SceneCell c; + c.x = static_cast((bounds.left + bounds.right) / 2); + c.y = static_cast((bounds.top + bounds.bottom) / 2); + c.radius = static_cast((bounds.right - bounds.left) / 2); + // One flagellum per 150 um/s of speed (a founder swims at 200). + c.flagella = ph.movement_speed == 0 + ? 0 + : static_cast(std::min( + 6, 1 + ph.movement_speed / 150)); + const double wall = ph.total_mass == 0 + ? 0.0 + : static_cast(ph.membrane_mass) / + static_cast(ph.total_mass); + c.membrane = static_cast(std::clamp(1.0 + wall * 6.0, 1.0, 7.0)); + c.organelles = 2 + static_cast(std::min( + 3, ph.conversion_per_thousand / 250)); + c.own = own != 0 && cell.id == own; + c.dead = cell.state == evo::client::OrganismState::dead; + c.stale = + org_layer && org_layer->freshness() != evo::client::Freshness::current; + c.seed = cell.id; + scene.cells.push_back(c); + } + drawn_organisms = static_cast(scene.cells.size()); + scene_active = true; + } else { + const auto report = evo::render::append_organisms( + boxes, organism_budget, orgs, + org_layer ? org_layer->freshness() : evo::client::Freshness::none, *camera); + if (!report) + return 1; + drawn_organisms = static_cast(report->drawn); + } 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})) @@ -772,7 +823,7 @@ int main(int argc, char** argv) try { 8, 8, {240, 240, 240, 255}}); - const auto frame = evo::render::Frame::create(boxes, {16, 20, 28, 255}); + const auto frame = evo::render::Frame::create(boxes, {14, 12, 18, 255}); // Ink. if (!frame) return 1; if (!screenshot.empty() && count + 1 == frames && !(*app)->request_screenshot(screenshot)) diff --git a/apps/evo-client/panels.cpp b/apps/evo-client/panels.cpp index 25645c2..e8b66b3 100644 --- a/apps/evo-client/panels.cpp +++ b/apps/evo-client/panels.cpp @@ -2,10 +2,12 @@ #include "evo/client/labels.hpp" #include #include +#include #include #include #include #include +#include namespace evo::client_app { namespace { @@ -48,8 +50,9 @@ void swatch(const char* id, render::Color c, const char* label) { ImGui::SameLine(); ImGui::TextUnformatted(label); } -constexpr ImVec4 amber{0.94F, 0.67F, 0.16F, 1.0F}, red{0.95F, 0.35F, 0.35F, 1.0F}, - green{0.35F, 0.80F, 0.60F, 1.0F}; +// 2026-10-16 palette: lavender for what is ready or yours, amber for what is short. +constexpr ImVec4 amber{0.961F, 0.710F, 0.267F, 1.0F}, red{0.95F, 0.38F, 0.38F, 1.0F}, + lavender{0.663F, 0.608F, 1.0F, 1.0F}, green = lavender; ImVec4 freshness_color(client::Freshness f) { return f == client::Freshness::current ? green : f == client::Freshness::stale ? amber : red; } @@ -592,370 +595,730 @@ void cell_record(const CellActionRecord& record) { record.refusal != network::AdmitStatus::admitted) disabled_wrapped(std::string{cellular_admission_message(record.refusal)}.c_str()); } -void cell_vitals(const PanelView& v) { - const auto* p = v.cellular_perception; - const auto* play = v.cellular_play; - ImGui::TextColored(green, "VITAL SIGNS"); - if (!play || !play->fresh()) - ImGui::TextColored(amber, "Waiting for a fresh server view"); - if (!p || !p->diagnostics || !play || play->life() == 0) { - disabled_wrapped("Your cell's reserves will appear here when a living cell is visible."); +// 2026-10-16 microscope UI: the world is drawn as living cells under an eyepiece, and the +// panels are a heads-up display around it. Nutrient colours are shared by food granules, +// reserve bars and costs, so a colour always means the same nutrient. +constexpr std::array nutrient_colors{ + IM_COL32(255, 214, 107, 255), // Energy. + IM_COL32(201, 138, 91, 255), // Carbon. + IM_COL32(111, 183, 255, 255), // Nitrogen. + IM_COL32(255, 127, 178, 255), // Phosphorus. + IM_COL32(184, 178, 196, 255) // Other matter. +}; +constexpr std::array nutrient_names{"Energy", "Carbon", "Nitrogen", "Phosphorus", + "Other matter"}; +ImVec4 nutrient(std::size_t i) { + return ImGui::ColorConvertU32ToFloat4(nutrient_colors.at(i)); +} +// A filled dot in line with text (the UI font has no bullet glyph). +void dot(ImU32 color, bool hollow = false) { + const float size = ImGui::GetTextLineHeight(); + const ImVec2 at = ImGui::GetCursorScreenPos(); + const ImVec2 centre{at.x + size * 0.5F, at.y + size * 0.5F}; + auto& list = *ImGui::GetWindowDrawList(); + if (hollow) + list.AddCircle(centre, size * 0.28F, color, 0, 1.5F); + else + list.AddCircleFilled(centre, size * 0.28F, color); + ImGui::Dummy({size, size}); +} +// One table row: a nutrient's dot and name, a bar filled to `share`, and a value. +void nutrient_row(std::size_t channel, const char* name, float share, const std::string& value) { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + dot(nutrient_colors.at(channel)); + ImGui::SameLine(0, ImGui::GetStyle().ItemInnerSpacing.x); + ImGui::TextUnformatted(name); + ImGui::TableNextColumn(); + const float width = ImGui::GetContentRegionAvail().x; + const float line = ImGui::GetTextLineHeight(); + const float height = std::max(3.0F, line * 0.35F); + const ImVec2 at = ImGui::GetCursorScreenPos(); + const float top = at.y + (line - height) * 0.5F; + auto& list = *ImGui::GetWindowDrawList(); + list.AddRectFilled({at.x, top}, {at.x + width, top + height}, IM_COL32(42, 36, 51, 255), + height / 2); + list.AddRectFilled({at.x, top}, {at.x + width * std::clamp(share, 0.0F, 1.0F), top + height}, + nutrient_colors.at(channel), height / 2); + ImGui::Dummy({width, line}); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(value.c_str()); +} +bool begin_nutrient_table(const char* id) { + if (!ImGui::BeginTable(id, 3, ImGuiTableFlags_SizingFixedFit)) + return false; + ImGui::TableSetupColumn("name", ImGuiTableColumnFlags_WidthFixed, px(104)); + ImGui::TableSetupColumn("bar", ImGuiTableColumnFlags_WidthStretch); + ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthFixed, px(64)); + return true; +} +// Three significant digits in the largest unit that keeps the value at least 1. +std::string scaled(std::uint64_t value, const std::array& units) { + double v = static_cast(value); + std::size_t unit = 0; + while (v >= 1000.0 && unit + 1 < units.size()) { + v /= 1000.0; + ++unit; + } + const int decimals = unit == 0 || v >= 100.0 ? 0 : v >= 10.0 ? 1 : 2; + std::array out{}; + std::snprintf(out.data(), out.size(), "%.*f %s", decimals, v, units.at(unit)); + return out.data(); +} +std::string energy_text(std::uint64_t picojoules) { + return scaled(picojoules, {"pJ", "nJ", "\xC2\xB5J", "mJ"}); +} +std::string mass_text(std::uint64_t femtograms) { + return scaled(femtograms, {"fg", "pg", "ng", "\xC2\xB5g"}); +} +std::uint64_t mix(std::uint64_t x) noexcept { + x += 0x9E3779B97F4A7C15ULL; + x = (x ^ (x >> 30U)) * 0xBF58476D1CE4E5B9ULL; + x = (x ^ (x >> 27U)) * 0x94D049BB133111EBULL; + return x ^ (x >> 31U); +} +float unit_of(std::uint64_t x) noexcept { + return static_cast(mix(x) % 10000U) / 10000.0F; +} +ImVec2 add(ImVec2 a, ImVec2 b) noexcept { + return {a.x + b.x, a.y + b.y}; +} +ImVec2 times(ImVec2 a, float k) noexcept { + return {a.x * k, a.y * k}; +} +// One cell: an ellipse membrane (thicker wall for more membrane), flagella waving behind +// the long axis (one per movement step), coral organelles and a nucleus. Dead cells show a +// torn membrane. Nothing here is a player/NPC label: every cell is drawn by biology alone; +// 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 ImVec2 axis{std::cos(angle), std::sin(angle)}; + const ImVec2 normal{-axis.y, axis.x}; + const ImVec2 centre{c.x, c.y}; + const ImVec2 radius{r * 1.25F, r * 0.82F}; + const auto alpha = static_cast(c.stale ? 120 : 255); + const ImU32 wall = c.dead ? IM_COL32(138, 132, 176, alpha * 2 / 3) + : c.own ? IM_COL32(201, 212, 255, alpha) + : IM_COL32(150, 144, 190, alpha * 9 / 10); + const ImU32 body = c.own ? IM_COL32(170, 185, 255, 38) : IM_COL32(170, 160, 220, 28); + if (!c.dead) { + for (int i = 0; i < c.flagella; ++i) { + const float spread = + c.flagella == 1 + ? 0.0F + : (static_cast(i) / static_cast(c.flagella - 1) - 0.5F) * 1.1F; + const float wave = std::sin(time * 6.0F + static_cast(i) * 1.7F + + static_cast(c.seed % 13U)) * + r * 0.35F; + const float length = r * 1.7F; + const ImVec2 base = + add(add(centre, times(axis, -radius.x * 0.92F)), times(normal, spread * radius.y)); + list.AddBezierCubic(base, + add(add(base, times(axis, -length * 0.35F)), times(normal, wave)), + add(add(base, times(axis, -length * 0.7F)), times(normal, -wave)), + add(add(base, times(axis, -length)), + times(normal, spread * r * 0.6F + wave * 0.5F)), + wall, std::max(1.2F, r * 0.07F)); + } + } + list.AddEllipseFilled(centre, radius, body, angle); + if (c.dead) { + list.PathArcTo(centre, r, angle + 0.4F, angle + 2.6F); + list.PathStroke(wall, 0, std::max(1.5F, c.membrane * 0.7F)); + list.PathArcTo(centre, r, angle + 3.3F, angle + 5.6F); + list.PathStroke(wall, 0, std::max(1.5F, c.membrane * 0.7F)); + list.AddCircleFilled(centre, r * 0.25F, IM_COL32(120, 104, 112, alpha)); return; } - const auto& d = *p->diagnostics; - ImGui::TextDisabled("ENERGY RESERVE"); - ImGui::PushFont(nullptr, 24); - ImGui::TextWrapped("%llu pJ", static_cast(d.reserve_energy_pj)); - ImGui::PopFont(); - if (const auto& change = play->energy_change(); change) { - ImGui::TextColored(change->falling ? amber : green, "%s%llu pJ net", - change->falling ? "-" : "+", - static_cast(change->amount)); - ImGui::TextDisabled("Across %llu observed ticks", - static_cast(change->to_tick - change->from_tick)); - if (change->falling) - disabled_wrapped( - "Energy is falling. Feeding may not cover upkeep, movement or actions."); + list.AddEllipse(centre, radius, wall, angle, 0, std::max(1.0F, c.membrane)); + const ImU32 organelle = c.own ? IM_COL32(255, 122, 102, 235) : IM_COL32(184, 90, 76, 220); + for (int k = 0; k < c.organelles; ++k) { + const auto key = c.seed * 31U + static_cast(k); + const float u = unit_of(key) - 0.55F, v = unit_of(key + 7U) - 0.5F; + list.AddCircleFilled( + add(add(centre, times(axis, u * radius.x * 1.1F)), times(normal, v * radius.y * 0.9F)), + std::max(1.5F, r * 0.16F), organelle); } - if (v.cellular_feed_target) { - const auto patch = std::ranges::find_if(p->patches, [&](const auto& candidate) { + const ImVec2 nucleus = add(centre, times(axis, radius.x * 0.42F)); + list.AddCircleFilled(nucleus, std::max(2.0F, r * 0.3F), IM_COL32(224, 86, 63, 220)); + list.AddCircleFilled(nucleus, std::max(1.0F, r * 0.14F), IM_COL32(255, 156, 134, 235)); + if (c.own) + list.AddEllipse(centre, {radius.x * 1.2F + 4.0F, radius.y * 1.2F + 4.0F}, + IM_COL32(169, 155, 255, 110), angle, 0, 2.0F); +} +// A food patch as granules, one colour per nutrient, more granules for more stock; a +// nutrient that runs out loses its colour. The faint square is the 1 mm contact footprint. +void draw_patch(ImDrawList& list, const ScenePatch& p) { + const float half = std::max(p.half, 6.0F); + const ImVec2 low{p.x - half, p.y - half}, high{p.x + half, p.y + half}; + list.AddRectFilled(low, high, IM_COL32(40, 32, 44, p.stale ? 40 : 70), half * 0.35F); + if (p.target) + list.AddRect(low, high, IM_COL32(169, 155, 255, 170), half * 0.35F, 0, 2.0F); + const float grain = std::clamp(half * 0.07F, 1.5F, 5.0F); + for (std::size_t channel = 0; channel < p.stock.size(); ++channel) { + const auto amount = p.stock.at(channel); + if (amount == 0) + continue; + const auto count = std::clamp( + static_cast(2.0 + 2.5 * std::log10(static_cast(amount) / 1.0e5)), 1, 18); + for (int i = 0; i < count; ++i) { + const auto key = p.seed * 131U + channel * 977U + static_cast(i); + const float a = unit_of(key) * 6.2832F, d = std::sqrt(unit_of(key + 3U)) * half * 0.85F; + auto color = nutrient_colors.at(channel); + if (p.stale) + color = (color & 0x00FFFFFFU) | (110U << IM_COL32_A_SHIFT); + list.AddCircleFilled({p.x + std::cos(a) * d, p.y + std::sin(a) * d}, + grain * (0.7F + 0.6F * unit_of(key + 5U)), color); + } + } +} +// The eyepiece: everything outside a rounded viewport is masked (a thick rounded stroke +// covers the corners) and a vignette darkens toward the rim. Zooming out of the cellular +// plane will later shrink this frame. +void draw_eyepiece(ImDrawList& list, ImVec2 size) { + const float inset = 8.0F; + const float rounding = std::min(size.x, size.y) * 0.17F; + const float mask = rounding * 1.4F + inset; + list.AddRect({inset - mask / 2, inset - mask / 2}, + {size.x - inset + mask / 2, size.y - inset + mask / 2}, IM_COL32(5, 4, 7, 255), + rounding + mask / 2, 0, mask); + // Many thin, faint steps, each the width of its spacing: a gradient without bands. + constexpr int steps = 28; + const float step = rounding * 0.025F; + for (int i = 0; i < steps; ++i) { + const float d = static_cast(i) * step; + const auto alpha = static_cast(60.0F * (1.0F - static_cast(i) / steps)); + list.AddRect({inset + d, inset + d}, {size.x - inset - d, size.y - inset - d}, + IM_COL32(0, 0, 0, alpha / 3), std::max(0.0F, rounding - d), 0, step + 0.5F); + } +} +void draw_scene(const PanelView& v) { + if (!v.cellular_scene) + return; + auto& list = *ImGui::GetBackgroundDrawList(); + const auto time = static_cast(ImGui::GetTime()); + for (const auto& patch : v.cellular_scene->patches) + draw_patch(list, patch); + for (const auto& cell : v.cellular_scene->cells) + draw_cell(list, cell, time); + draw_eyepiece(list, ImGui::GetIO().DisplaySize); +} +// The eyepiece corner radius in logical units: HUD windows keep clear of it. +float eyepiece_clearance() { + const auto& io = ImGui::GetIO(); + return std::min(io.DisplaySize.x, io.DisplaySize.y) * 0.17F * 0.45F + 8.0F; +} +constexpr ImGuiWindowFlags hud_flags = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | + ImGuiWindowFlags_NoCollapse | + ImGuiWindowFlags_NoSavedSettings; +void section(const char* label) { + ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled)); + ImGui::TextUnformatted(label); + ImGui::PopStyleColor(); +} +const network::CellularLifeDiagnostics* diagnostics(const PanelView& v) { + return v.cellular_perception && v.cellular_perception->diagnostics + ? &*v.cellular_perception->diagnostics + : nullptr; +} +bool bud_known(const network::CellularLifeDiagnostics& d) { + return d.bud_cost_energy_pj != 0 || + std::ranges::any_of(d.bud_cost_matter_fg, [](std::uint64_t x) { return x != 0; }); +} +// Status pill at the top: region, phase, tick, and the two always-available actions. +void hud_status(const PanelView& v, PanelActions& a) { + const auto& io = ImGui::GetIO(); + ImGui::SetNextWindowPos({io.DisplaySize.x * 0.5F, px(18)}, ImGuiCond_Always, {0.5F, 0}); + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, px(18)); + ImGui::Begin("##mode", nullptr, + ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | + ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings); + const bool connected = v.remote && v.remote->phase == "connected"; + dot(ImGui::ColorConvertFloat4ToU32(connected ? lavender : amber), !connected); + ImGui::SameLine(); + if (v.remote) + ImGui::Text("Region %llu", static_cast(v.remote->region)); + ImGui::SameLine(); + ImGui::TextDisabled("%s%s", v.remote ? v.remote->phase.c_str() : "?", + v.remote && v.remote->stale_view ? " - view frozen" : ""); + if (v.remote) { + ImGui::SameLine(); + ImGui::TextDisabled("tick %llu", static_cast(v.remote->server_tick)); + } + ImGui::SameLine(); + if (ImGui::SmallButton("Controls")) + a.open_controls = true; + ImGui::SameLine(); + if (ImGui::SmallButton("Disconnect")) + a.ask_disconnect = true; + if (v.auth.signed_in) { + ImGui::SameLine(); + ImGui::BeginDisabled(v.auth.busy); + if (ImGui::SmallButton("Sign out")) + a.sign_out = true; + ImGui::EndDisabled(); + } + ImGui::End(); + ImGui::PopStyleVar(); +} +// Lower left: energy in readable units, its trend, and the matter reserve. When the bud +// cost is known, each bar is progress toward the next bud on that nutrient. +void hud_vitals(const PanelView& v, bool compact) { + const auto& io = ImGui::GetIO(); + const float clearance = eyepiece_clearance(); + const float width = std::min(px(300), io.DisplaySize.x - 2 * px(12)); + if (compact) + ImGui::SetNextWindowPos({px(12), px(64)}, ImGuiCond_Always); + else + ImGui::SetNextWindowPos({clearance, io.DisplaySize.y - px(16)}, ImGuiCond_Always, {0, 1}); + const auto* play = v.cellular_play; + const auto* d = diagnostics(v); + if (!play || play->life() == 0) + return; // The life window speaks for a cell that is not alive. + ImGui::SetNextWindowSizeConstraints({width, 0}, {width, io.DisplaySize.y}); + ImGui::Begin("Vitals", nullptr, + hud_flags | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize); + if (!play->fresh()) + ImGui::TextColored(amber, "Waiting for a fresh server view"); + if (!d) { + disabled_wrapped("Your cell's reserves appear with the next server view."); + ImGui::End(); + return; + } + section("ENERGY"); + if (const auto& change = play->energy_change(); change) { + ImGui::SameLine(); + ImGui::TextColored(change->falling ? amber : lavender, "%s%s", change->falling ? "-" : "+", + energy_text(change->amount).c_str()); + } + ImGui::PushFont(nullptr, px(26)); + ImGui::TextUnformatted(energy_text(d->reserve_energy_pj).c_str()); + ImGui::PopFont(); + if (const auto& change = play->energy_change(); change && change->falling) + disabled_wrapped("Energy is falling: feeding may not cover upkeep and movement."); + if (v.cellular_feed_target && v.cellular_perception) { + const auto& patches = v.cellular_perception->patches; + const auto patch = std::ranges::find_if(patches, [&](const auto& candidate) { return v.cellular_feed_target == std::pair{candidate.x_um, candidate.y_um}; }); - if (patch != p->patches.end() && patch->energy_pj == 0) - ImGui::TextWrapped("FEED TARGET HAS NO ENERGY. Check Food for another patch."); + if (patch != patches.end() && patch->energy_pj == 0) + ImGui::TextColored(amber, "Feed target has no energy left"); } ImGui::Separator(); - if (ImGui::BeginTable("matter", 2, ImGuiTableFlags_SizingStretchSame)) { - constexpr std::array names{"Carbon", "Nitrogen", "Phosphorus", "Other matter"}; - for (std::size_t i = 0; i < names.size(); ++i) { - ImGui::TableNextColumn(); - ImGui::TextDisabled("%s", names[i]); - ImGui::Text("%llu fg", static_cast(d.reserve_matter_fg[i])); + const bool toward_bud = bud_known(*d); + if (begin_nutrient_table("matter")) { + for (std::size_t i = 0; i < d->reserve_matter_fg.size(); ++i) { + const auto have = d->reserve_matter_fg.at(i); + const auto need = d->bud_cost_matter_fg.at(i); + const float share = + toward_bud && need != 0 + ? static_cast(static_cast(have) / static_cast(need)) + : 1.0F; + nutrient_row(i + 1, nutrient_names.at(i + 1), share, mass_text(have)); } ImGui::EndTable(); } - ImGui::Separator(); - if (!d.has_tick_effects) { - disabled_wrapped("Tick effects are unavailable until the next committed tick."); - return; + if (toward_bud) + disabled_wrapped("Bars: progress toward your next bud."); + if (d->has_tick_effects) { + constexpr std::array movement{"", "Resting", "Moving", "Movement blocked", + "Too little energy to move"}; + constexpr std::array intake{"", "Not feeding", "Feeding", "Food patch gone", + "Touch food to feed"}; + ImGui::TextDisabled("%s / %s / upkeep %s", + movement.at(static_cast(d->movement)), + intake.at(static_cast(d->intake)), + energy_text(d->maintenance_cost_pj).c_str()); } - ImGui::TextWrapped("Last tick: upkeep %llu pJ / movement %llu pJ", - static_cast(d.maintenance_cost_pj), - static_cast(d.movement_cost_pj)); - constexpr std::array movement{"Unavailable", "Resting", "Moving", "Movement blocked", - "Not enough energy to move"}; - constexpr std::array intake{"Unavailable", "Not feeding", "Feeding attempt processed", - "Food patch missing", "Move into contact to feed"}; - constexpr std::array engulf{"Unavailable", - "Not requested", - "Prey engulfed", - "No eligible prey in contact", - "Engulf unsupported here", - "Engulf failed: no cell touching yours", - "Engulf failed: prey is too large", - "Engulf failed: prey's membrane is too thick"}; - constexpr std::array bud{"Unavailable", - "Not requested", - "Wildlife bud created", - "Cell cannot bud yet", - "Not enough resources to bud", - "No space for a bud"}; - ImGui::TextWrapped("%s", movement.at(static_cast(d.movement))); - ImGui::TextWrapped("%s", intake.at(static_cast(d.intake))); - if (d.intake == network::CellularIntakeResult::acquired) - disabled_wrapped("A feeding attempt can yield zero energy. Watch the reserve change."); - if (const auto& feedback = play->engulf_feedback(); feedback) - ImGui::TextWrapped("%s (tick %llu)", engulf.at(static_cast(feedback->second)), - static_cast(feedback->first)); - if (const auto& feedback = play->bud_feedback(); feedback) - ImGui::TextWrapped("%s (tick %llu)", bud.at(static_cast(feedback->second)), - static_cast(feedback->first)); + ImGui::End(); } -void cell_food(const PanelView& v, PanelActions& a, FormBuffers& form) { - ImGui::TextColored(green, "FEED & SURVIVE"); - ImGui::Checkbox("Feed automatically", &form.cellular_controls.auto_feed); - disabled_wrapped("Map: gold E = energy / teal M = matter. Zoom in to read markers."); - if (ImGui::CollapsingHeader("Steering assistance")) { - ImGui::Checkbox("Slow near food", &form.cellular_controls.slow_near_food); - ImGui::Checkbox("Precision steering (20%)", &form.cellular_controls.precision); - ImGui::SetNextItemWidth(-1); - ImGui::SliderInt("##speed", &form.cellular_controls.speed_percent, 1, 100, "Speed: %d%%"); - } - if (ImGui::CollapsingHeader("Feeding & energy explained")) - disabled_wrapped("Patch stock is finite and shared. Matter does not replenish energy. " - "Uptake is limited by your cell and upkeep is paid before feeding. " - "Auto feed prefers energy in contact. Choose a patch for manual feeding."); - const bool active = v.cellular_play && v.cellular_play->fresh() && v.cellular_play->life() != 0; +// Bottom centre: the three things a cell does, with what a bud still needs and the last +// discrete result explained. +void hud_dock(const PanelView& v, FormBuffers& form, PanelActions& a, bool compact) { + const auto& io = ImGui::GetIO(); + const auto* play = v.cellular_play; + const auto* d = diagnostics(v); + const float button = compact ? px(120) : px(150); + const float width = std::min(3 * button + 2 * ImGui::GetStyle().ItemSpacing.x + + 2 * ImGui::GetStyle().WindowPadding.x, + io.DisplaySize.x - 2 * px(12)); + // Centred, but never over the vitals card at the lower left. + float left = io.DisplaySize.x * 0.5F - width * 0.5F; + if (!compact && play && play->life() != 0) + left = std::max(left, eyepiece_clearance() + std::min(px(300), io.DisplaySize.x) + px(12)); + left = std::max(px(12), std::min(left, io.DisplaySize.x - width - px(12))); + ImGui::SetNextWindowPos({left, io.DisplaySize.y - px(16)}, ImGuiCond_Always, {0, 1}); + ImGui::SetNextWindowSizeConstraints({width, 0}, {width, io.DisplaySize.y}); + ImGui::Begin("Actions", nullptr, + hud_flags | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize); + const float each = + (ImGui::GetContentRegionAvail().x - 2 * ImGui::GetStyle().ItemSpacing.x) / 3.0F; + const bool active = play && play->fresh() && play->life() != 0; ImGui::BeginDisabled(!active); - if (v.cellular_feed_target && ImGui::Button("Stop feeding", {-1, 0})) - a.stop_feeding = true; - if (const auto* p = v.cellular_perception) { - if (p->patches.empty()) - disabled_wrapped("No food is visible within sensor range."); - for (const bool target_first : {true, false}) { + if (ImGui::Button(form.cellular_controls.auto_feed ? "Feed: auto" : "Feed: manual", + {each, px(44)})) + form.cellular_controls.auto_feed = !form.cellular_controls.auto_feed; + ImGui::EndDisabled(); + ImGui::SameLine(); + ImGui::BeginDisabled(!play || !play->can_act()); + if (ImGui::Button("Engulf", {each, px(44)})) + a.cell_action = CellAction::engulf; + ImGui::SameLine(); + if (ImGui::Button("Bud", {each, px(44)})) + a.cell_action = CellAction::bud; + ImGui::EndDisabled(); + // What a bud needs, by nutrient (ADR-0129 amendment). + if (d && play && play->life() != 0) { + if (!bud_known(*d)) { + disabled_wrapped("This genome cannot bud."); + } else { + const auto short_on = bud_shortfall(*d); + std::string missing; + for (std::size_t i = 0; i < short_on.size(); ++i) + if (short_on.at(i)) + missing += std::string{missing.empty() ? "" : ", "} + nutrient_names.at(i); + if (missing.empty()) + ImGui::TextColored(lavender, "Bud ready (needs %s, %s carbon)", + energy_text(d->bud_cost_energy_pj).c_str(), + mass_text(d->bud_cost_matter_fg[0]).c_str()); + else + ImGui::TextColored(amber, "Bud: short on %s", missing.c_str()); + } + } + if (play) { + constexpr std::array engulf{"", + "", + "Prey engulfed", + "No prey in contact", + "Engulf unsupported here", + "Engulf failed: no cell touching yours", + "Engulf failed: prey too large", + "Engulf failed: prey's membrane too thick"}; + constexpr std::array bud{"", + "", + "Bud created: a descendant split off", + "Bud failed: not fully grown", + "Bud failed: not enough resources", + "Bud failed: no space beside you"}; + if (const auto& f = play->engulf_feedback(); + f && !std::string_view{engulf.at(static_cast(f->second))}.empty()) + ImGui::TextWrapped("%s", engulf.at(static_cast(f->second))); + if (const auto& f = play->bud_feedback(); + f && !std::string_view{bud.at(static_cast(f->second))}.empty()) + ImGui::TextWrapped("%s", bud.at(static_cast(f->second))); + if (const auto& pending = play->pending(); pending) { + cell_record(*pending); + if (pending->state == CellActionState::unresolved) { + disabled_wrapped("The reply was lost. Checking the original request; no second " + "action is created."); + if (ImGui::Button("Keep result as unknown", {-1, 0})) + a.keep_unknown = true; + } + } + } + ImGui::End(); +} +// Upper left: what the colours mean, steering, food in range, recent actions. +void hud_notes(const PanelView& v, FormBuffers& form, PanelActions& a, bool compact) { + if (compact) + return; + const auto& io = ImGui::GetIO(); + const float clearance = eyepiece_clearance(); + ImGui::SetNextWindowPos({clearance, px(64)}, ImGuiCond_Always); + ImGui::SetNextWindowSizeConstraints({px(260), 0}, + {px(260), std::max(px(120), io.DisplaySize.y * 0.45F)}); + ImGui::Begin("Field notes", nullptr, hud_flags | ImGuiWindowFlags_AlwaysAutoResize); + for (std::size_t i = 0; i < nutrient_names.size(); ++i) { + dot(nutrient_colors.at(i)); + ImGui::SameLine(0, ImGui::GetStyle().ItemInnerSpacing.x); + ImGui::TextUnformatted(nutrient_names.at(i)); + if (i % 2 == 0 && i + 1 < nutrient_names.size()) + ImGui::SameLine(px(130)); + } + if (ImGui::CollapsingHeader("Food in range")) { + const bool active = + v.cellular_play && v.cellular_play->fresh() && v.cellular_play->life() != 0; + ImGui::BeginDisabled(!active); + if (v.cellular_feed_target && ImGui::Button("Stop feeding", {-1, 0})) + a.stop_feeding = true; + if (const auto* p = v.cellular_perception) { + if (p->patches.empty()) + disabled_wrapped("No food is visible within sensor range."); for (const auto& patch : p->patches) { - const bool selected = v.cellular_feed_target == std::pair{patch.x_um, patch.y_um}; - if (selected != target_first) - continue; ImGui::PushID(static_cast(patch.x_um)); ImGui::PushID(static_cast(patch.y_um)); + const bool selected = v.cellular_feed_target == std::pair{patch.x_um, patch.y_um}; ImGui::Separator(); - ImGui::Text("Patch %u / %u um", patch.x_um, patch.y_um); - const bool has_matter = - std::ranges::any_of(patch.matter_fg, [](auto amount) { return amount != 0; }); - ImGui::TextColored(patch.energy_pj != 0 ? amber : green, "%s", - patch.energy_pj != 0 ? "E ENERGY AVAILABLE" - : has_matter ? "M MATTER ONLY / NO ENERGY" - : "EMPTY / DEPLETED"); - ImGui::Text("Energy stock: %llu pJ", - static_cast(patch.energy_pj)); - ImGui::TextWrapped("C %llu / N %llu / P %llu / other %llu fg", - static_cast(patch.matter_fg[0]), - static_cast(patch.matter_fg[1]), - static_cast(patch.matter_fg[2]), - static_cast(patch.matter_fg[3])); + ImGui::TextColored(nutrient(0), "%s", energy_text(patch.energy_pj).c_str()); + for (std::size_t i = 0; i < patch.matter_fg.size(); ++i) { + ImGui::SameLine(); + ImGui::TextColored(nutrient(i + 1), "%s", + mass_text(patch.matter_fg.at(i)).c_str()); + } if (selected) - ImGui::TextColored(green, "FEEDING TARGET"); - else if (ImGui::Button("Feed here", {-1, 0})) + ImGui::TextColored(lavender, "Feeding target"); + else if (ImGui::SmallButton("Feed here")) a.feed_patch = {patch.x_um, patch.y_um}; ImGui::PopID(); ImGui::PopID(); } } + ImGui::EndDisabled(); } + if (ImGui::CollapsingHeader("Steering")) { + ImGui::Checkbox("Slow near food", &form.cellular_controls.slow_near_food); + ImGui::Checkbox("Precision steering (20%)", &form.cellular_controls.precision); + ImGui::SetNextItemWidth(-1); + ImGui::SliderInt("##speed", &form.cellular_controls.speed_percent, 1, 100, "Speed: %d%%"); + } + if (ImGui::CollapsingHeader("Recent actions") && v.cellular_play) { + const auto& records = v.cellular_play->history(); + if (records.empty()) + disabled_wrapped("Your discrete action results appear here."); + for (auto it = records.rbegin(); it != records.rend(); ++it) + cell_record(*it); + } + if (ImGui::CollapsingHeader("Help")) { + if (v.bindings) + disabled_wrapped(controls_hint(*v.bindings).c_str()); + disabled_wrapped("E opens mutations. On disconnect your cell freezes but stays " + "vulnerable for 10 seconds before it is suspended."); + ImGui::Checkbox("Engineering panels", &form.engineering); + } + ImGui::End(); +} +// Upper right: a quiet callout while an offer waits; click it or press E. +void hud_callout(const PanelView& v, FormBuffers& form) { + const auto* play = v.cellular_play; + if (!play || play->life() == 0 || form.evolution_open) + return; + const auto& offer = play->offer(); + if (!offer) + return; + const auto& io = ImGui::GetIO(); + ImGui::SetNextWindowPos({io.DisplaySize.x - eyepiece_clearance(), px(64)}, ImGuiCond_Always, + {1, 0}); + ImGui::Begin("##mutation", nullptr, + ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | + ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings); + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{0.165F, 0.133F, 0.075F, 1.0F}); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4{0.24F, 0.19F, 0.10F, 1.0F}); + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{0.97F, 0.91F, 0.80F, 1.0F}); + const std::string label = + "Mutation ready - " + std::to_string(offer->candidates.size()) + " choices [E]"; + if (ImGui::Button(label.c_str(), {0, px(40)})) + form.evolution_open = true; + ImGui::PopStyleColor(3); + ImGui::End(); +} +constexpr std::array capability_names{"Energy conversion", "Membrane", "Movement", + "Ingestion", "Reproduction", "Size", + "Thermal tolerance"}; +constexpr std::array capability_kinds{"Metabolism", "Defense", "Movement", "Feeding", + "Reproduction", "Size", "Environment"}; +constexpr std::array effect_names{"Increase", "Decrease", "Acquire", "Shed"}; +constexpr std::array increase_text{"Convert more of what you eat into usable energy.", + "A thicker wall: prey must be much larger to engulf you.", + "Swim faster; each movement costs a little more.", + "Take food faster from every patch you touch.", + "Invest more of your body in each bud.", + "Grow toward a larger body: harder to engulf, slower to fill.", + "Tolerate a wider range of temperatures."}; +constexpr std::array decrease_text{"Convert less of what you eat into energy.", + "A thinner, cheaper wall that is easier to breach.", + "Swim slower and spend less on movement.", + "Take food more slowly from each patch.", + "Each bud takes less of your body: cheaper, smaller buds.", + "Grow toward a smaller body that is cheaper to keep.", + "Tolerate a narrower range of temperatures."}; +// A small before/after drawing of the cell for one candidate. +void candidate_glyph(const network::CellularOfferedCandidate& c, float width) { + const ImVec2 at = ImGui::GetCursorScreenPos(); + const float height = px(80); + auto& list = *ImGui::GetWindowDrawList(); + list.AddRectFilled(at, {at.x + width, at.y + height}, IM_COL32(14, 12, 18, 255), px(10)); + SceneCell before{ + at.x + width * 0.27F, at.y + height * 0.5F, px(16), px(2.5F), 2, 3, true, false, false, 7}; + SceneCell after = before; + after.x = at.x + width * 0.75F; + const bool up = c.effect == 0 || c.effect == 2; + switch (c.capability) { + case 1: + after.membrane = up ? px(5.5F) : px(1.2F); + break; + case 2: + after.flagella = c.effect == 3 ? 0 : up ? 4 : 1; + break; + case 5: + after.radius = up ? px(20) : px(12); + break; + case 0: + after.organelles = up ? 5 : 1; + break; + default: + break; + } + const auto time = static_cast(ImGui::GetTime()); + draw_cell(list, before, time); + draw_cell(list, after, time); + list.AddText({at.x + width * 0.5F - px(6), at.y + height * 0.5F - px(8)}, + IM_COL32(173, 164, 184, 255), "->"); + ImGui::Dummy({width, height}); +} +void offer_card(const PanelView& v, const network::CellularMutationOffer& offer, + const network::CellularOfferedCandidate& c, PanelActions& a) { + const auto* play = v.cellular_play; + const auto* d = diagnostics(v); + ImGui::TextDisabled("%s", capability_kinds.at(c.capability)); + const float width = ImGui::GetContentRegionAvail().x; + candidate_glyph(c, width); + ImGui::PushFont(nullptr, px(18)); + ImGui::TextWrapped("%s %s", effect_names.at(c.effect), capability_names.at(c.capability)); + ImGui::PopFont(); + disabled_wrapped(c.effect == 3 ? "Lose this capability entirely." + : c.effect == 2 ? "Gain this capability." + : c.effect == 0 ? increase_text.at(c.capability) + : decrease_text.at(c.capability)); + ImGui::TextDisabled("upkeep %s/s mass %s", energy_text(c.maintenance).c_str(), + mass_text(c.total_mass).c_str()); + // Cost against the reserve, per nutrient that the change needs. + bool affordable = d != nullptr; + std::string first_short; + const bool table = begin_nutrient_table("cost"); + for (std::size_t channel = 0; channel < 5; ++channel) { + const auto need = channel == 0 ? c.cost_energy_pj : c.cost_matter_fg.at(channel - 1); + if (need == 0) + continue; + const auto have = + d ? (channel == 0 ? d->reserve_energy_pj : d->reserve_matter_fg.at(channel - 1)) : 0; + if (have < need) { + affordable = false; + if (first_short.empty()) + first_short = (channel == 0 ? energy_text(need - have) : mass_text(need - have)) + + " more " + nutrient_names.at(channel); + } + if (table) + nutrient_row(channel, nutrient_names.at(channel), + static_cast(static_cast(have) / static_cast(need)), + channel == 0 ? energy_text(need) : mass_text(need)); + } + if (table) + ImGui::EndTable(); + if (c.cost_energy_pj == 0 && + std::ranges::all_of(c.cost_matter_fg, [](auto x) { return x == 0; })) + disabled_wrapped("Costs nothing: it only reshapes or sheds."); + const bool ready = + play && play->can_act() && v.remote && v.remote->server_tick > offer.offer_tick; + ImGui::BeginDisabled(!affordable || !ready); + const std::string choose = affordable ? std::string{"Choose"} : "Feed for " + first_short; + if (ImGui::Button(choose.c_str(), {-1, px(40)})) + a.mutation = + MutationChoice{offer.life_identity, offer.event_index, offer.offer_tick, c.operator_id}; ImGui::EndDisabled(); } -void cell_actions(const PanelView& v, PanelActions& a) { +// The mutation choice (while open) and the end-of-life screen (while no cell lives). +void evolution_window(const PanelView& v, FormBuffers& form, PanelActions& a, bool compact) { const auto* play = v.cellular_play; - ImGui::Separator(); - ImGui::TextColored(green, "ACT ONCE"); - ImGui::BeginDisabled(!play || !play->can_act()); - const float width = (ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x) / 2; - if (ImGui::Button("Engulf", {width, px(32)})) - a.cell_action = CellAction::engulf; - ImGui::SameLine(); - if (ImGui::Button("Bud", {width, px(32)})) - a.cell_action = CellAction::bud; - ImGui::EndDisabled(); - disabled_wrapped("Engulf attempts nearby prey. Bud funds an independent descendant; you keep " - "your cell. Automatic feeding resumes after the action tick."); - // ADR-0129 amendment: what a bud takes from the reserve once the cell is fully grown. - if (const auto* perception = v.cellular_perception; perception && perception->diagnostics) { - const auto& d = *perception->diagnostics; - const bool can_bud = d.bud_cost_energy_pj != 0 || - std::ranges::any_of(d.bud_cost_matter_fg, - [](std::uint64_t value) { return value != 0; }); - if (!can_bud) { - disabled_wrapped("This cell's genome cannot bud."); - } else { - ImGui::TextWrapped("Bud needs: %llu pJ\nC %llu / N %llu / P %llu / other %llu fg", - static_cast(d.bud_cost_energy_pj), - static_cast(d.bud_cost_matter_fg[0]), - static_cast(d.bud_cost_matter_fg[1]), - static_cast(d.bud_cost_matter_fg[2]), - static_cast(d.bud_cost_matter_fg[3])); - constexpr std::array names{"energy", "carbon", "nitrogen", "phosphorus", "other"}; - std::string missing; - const auto short_on = bud_shortfall(d); - for (std::size_t i = 0; i < short_on.size(); ++i) - if (short_on[i]) - missing += std::string{missing.empty() ? "" : ", "} + names.at(i); - if (!missing.empty()) - ImGui::TextColored(amber, "Short on %s", missing.c_str()); - disabled_wrapped("A bud also needs the cell fully grown and undamaged."); - } - } if (!play) return; - if (const auto& pending = play->pending(); pending) { - ImGui::Separator(); - cell_record(*pending); - if (pending->state == CellActionState::unresolved) { - disabled_wrapped("The reply was lost or is unavailable. Checking the original request; " - "no second action is created."); - if (ImGui::Button("Keep result as unknown", {-1, 0})) - a.keep_unknown = true; - } - } -} -void cell_evolution(const PanelView& v, PanelActions& a) { - const auto* play = v.cellular_play; - ImGui::TextColored(green, "LIFE & EVOLUTION"); - if (!play) + const bool no_life = play->life() == 0; + const auto& offer = play->offer(); + if (!no_life && (!form.evolution_open || !offer)) { + form.evolution_open = form.evolution_open && offer.has_value(); return; - if (play->life() == 0) { - ImGui::Separator(); + } + const auto& io = ImGui::GetIO(); + const float margin = compact ? px(12) : eyepiece_clearance(); + const float width = no_life ? std::min(px(460), io.DisplaySize.x - 2 * px(12)) + : std::min(px(1180), io.DisplaySize.x - 2 * margin); + ImGui::SetNextWindowPos({io.DisplaySize.x * 0.5F, io.DisplaySize.y * 0.5F}, ImGuiCond_Always, + {0.5F, 0.5F}); + ImGui::SetNextWindowSizeConstraints({width, 0}, {width, io.DisplaySize.y - 2 * px(40)}); + ImGui::Begin("Evolution", nullptr, + hud_flags | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize); + if (no_life) { if (const auto& ended = play->ended(); ended) { ImGui::TextColored(amber, "THIS LIFE HAS ENDED"); const auto cause = ended->cause; - ImGui::TextWrapped("%s", cause == network::CellularDeathReason::starved - ? "Your cell starved." - : cause == network::CellularDeathReason::engulfed - ? "Your cell was engulfed." - : "The cause was not recorded."); - if (cause == network::CellularDeathReason::starved) - disabled_wrapped("Your reserve could not pay upkeep before feeding. A patch can " - "still hold matter after its energy runs out; intake can also be " - "slower than your energy spending."); - ImGui::TextWrapped("Its history and descendants remain. Your next life begins as a new " + ImGui::PushFont(nullptr, px(22)); + ImGui::TextWrapped( + "%s", cause == network::CellularDeathReason::starved ? "Your cell starved" + : cause == network::CellularDeathReason::engulfed ? "Your cell was engulfed" + : "Your cell died"); + ImGui::PopFont(); + disabled_wrapped(cause == network::CellularDeathReason::starved + ? "Its reserve could not pay upkeep. Its body became food." + : "Its body became food for another cell."); + ImGui::TextWrapped("Your descendants live on as wildlife. You return as a new " "primitive cell."); } else { ImGui::TextWrapped("%s", play->birth_pending() ? "Establishing your cell..." : "No active cell is visible."); - disabled_wrapped("A missing view alone does not reveal a death cause. A suspended cell " - "may still be waiting for space to resume."); + disabled_wrapped("A missing view alone does not reveal a death. A suspended cell may " + "still be waiting for space to resume."); } ImGui::BeginDisabled(!play->can_restart()); - if (ImGui::Button("Start new life", {-1, px(38)})) + if (ImGui::Button("Begin a new life", {-1, px(44)})) a.restart_life = true; ImGui::EndDisabled(); if (play->birth_pending()) - disabled_wrapped( - "Waiting for the server. Rechecking this same birth request every " - "2 seconds. Reconnecting or creating an account cannot refill a nursery."); + disabled_wrapped("Waiting for the server; rechecking this birth request every 2 " + "seconds."); if (v.remote && !v.remote->cellular_action.empty()) ImGui::TextWrapped("%s", v.remote->cellular_action.c_str()); + ImGui::End(); return; } - const auto& offer = play->offer(); - if (!offer) { - ImGui::Separator(); - ImGui::TextWrapped("Feed. Adapt. Leave descendants."); - disabled_wrapped("Useful feeding earns mutation opportunities. When an offer arrives, " - "choose a tradeoff for this life."); - ImGui::Spacing(); - disabled_wrapped("No offer is available yet. Wildlife descendants inherit your genome and " - "live independently."); - return; + ImGui::TextColored(amber, "MUTATION OFFER - your cell keeps moving"); + ImGui::PushFont(nullptr, px(24)); + ImGui::TextUnformatted("Shape this life"); + ImGui::PopFont(); + disabled_wrapped("Your feeding earned one change. Each trades a capability against upkeep " + "and body mass. Buds inherit what you choose."); + const auto count = static_cast(offer->candidates.size()); + const int columns = compact ? 1 : std::max(1, count); + if (ImGui::BeginTable("offers", columns, ImGuiTableFlags_SizingStretchSame)) { + for (const auto& c : offer->candidates) { + ImGui::TableNextColumn(); + ImGui::PushID(static_cast(c.operator_id)); + ImGui::BeginChild("card", {0, 0}, + ImGuiChildFlags_Borders | ImGuiChildFlags_AutoResizeY | + ImGuiChildFlags_AlwaysUseWindowPadding); + offer_card(v, *offer, c, a); + ImGui::EndChild(); + ImGui::PopID(); + } + ImGui::EndTable(); } - ImGui::TextColored(amber, "MUTATION AVAILABLE"); - disabled_wrapped("Useful feeding earned this choice. Each change trades a capability against " - "upkeep and body mass. The server checks your reserve when it commits."); - // ADR-0120 amendment: declining consumes the offer and changes nothing; more feeding - // (or credit already earned) brings the next one. - ImGui::BeginDisabled(!play->can_act() || !v.remote || - v.remote->server_tick <= offer->offer_tick); - if (ImGui::Button("Decline this offer", {-1, px(28)})) + const bool ready = play->can_act() && v.remote && v.remote->server_tick > offer->offer_tick; + ImGui::BeginDisabled(!ready); + if (ImGui::Button("Decline all - keep my genome", {0, px(40)})) a.mutation = MutationChoice{offer->life_identity, offer->event_index, offer->offer_tick, 0}; ImGui::EndDisabled(); - disabled_wrapped("Declining keeps your genome; earned feeding brings the next offer."); - constexpr std::array capabilities{"Energy conversion", "Membrane", "Movement", - "Ingestion", "Reproduction", "Target size", - "Thermal tolerance"}; - constexpr std::array effects{"Increase", "Decrease", "Acquire", "Shed"}; - for (const auto& c : offer->candidates) { - ImGui::PushID(static_cast(c.operator_id)); - ImGui::Separator(); - ImGui::TextWrapped("%s %s", effects.at(c.effect), capabilities.at(c.capability)); - constexpr std::array increase{"Convert more intake into usable energy.", - "Build a thicker protective membrane.", - "Raise your maximum movement speed.", - "Raise how much food you can ingest per second.", - "Increase your reproduction capability.", - "Grow toward a larger target body mass.", - "Widen your temperature tolerance."}; - constexpr std::array decrease{"Reduce energy conversion capability.", - "Build a thinner membrane.", - "Lower your maximum movement speed.", - "Lower how much food you can ingest per second.", - "Reduce your reproduction capability.", - "Grow toward a smaller target body mass.", - "Narrow your temperature tolerance."}; - disabled_wrapped(c.effect == 3 ? "Remove this capability from your genome." - : c.effect == 2 ? "Add this capability to your genome." - : c.effect == 0 ? increase.at(c.capability) - : decrease.at(c.capability)); - constexpr std::array units{"per 1000", "um", "um/s", "fg/s", "per 1000", "fg", "mK"}; - ImGui::TextWrapped("Successor value %u %s", c.parameter, units.at(c.capability)); - ImGui::TextWrapped("Maintenance %llu pJ / s\nTotal mass %llu fg", - static_cast(c.maintenance), - static_cast(c.total_mass)); - const auto* perception = v.cellular_perception; - const bool affordable = - perception && perception->diagnostics && can_fund(c, *perception->diagnostics); - ImGui::TextWrapped("Cost: %llu pJ\nC %llu / N %llu / P %llu / other %llu fg", - static_cast(c.cost_energy_pj), - static_cast(c.cost_matter_fg[0]), - static_cast(c.cost_matter_fg[1]), - static_cast(c.cost_matter_fg[2]), - static_cast(c.cost_matter_fg[3])); - if (!affordable) - ImGui::TextColored(amber, "Need more reserves"); - ImGui::BeginDisabled(!affordable || !play->can_act() || !v.remote || - v.remote->server_tick <= offer->offer_tick); - if (ImGui::Button("Choose mutation", {-1, px(30)})) - a.mutation = MutationChoice{offer->life_identity, offer->event_index, offer->offer_tick, - c.operator_id}; - ImGui::EndDisabled(); - ImGui::PopID(); - } -} -void cell_log(const PanelView& v, FormBuffers& form) { - ImGui::TextColored(green, "ACTION RECORD"); - if (v.cellular_play) { - const auto& records = v.cellular_play->history(); - if (records.empty()) - disabled_wrapped("Your discrete action results will appear here."); - for (auto it = records.rbegin(); it != records.rend(); ++it) { - cell_record(*it); - ImGui::Separator(); - } - } - if (v.remote) { - ImGui::TextWrapped("Region %llu / tick %llu / grants %zu", - static_cast(v.remote->region), - static_cast(v.remote->server_tick), - v.remote->grants_left); - } - ImGui::Checkbox("Engineering panels", &form.engineering); - disabled_wrapped("On disconnect your biology freezes immediately, but the cell remains " - "vulnerable for the 10-second linger before suspension."); + ImGui::SameLine(); + if (ImGui::Button("Close [E]", {0, px(40)})) + form.evolution_open = false; + ImGui::SameLine(); + disabled_wrapped("Earned feeding brings the next offer."); + ImGui::End(); } void cellular(const PanelView& v, FormBuffers& form, PanelActions& a) { const auto& io = ImGui::GetIO(); - const float margin = px(12), top = px(58); const bool compact = io.DisplaySize.x < px(880); - const float height = std::max(px(80), io.DisplaySize.y - top - margin); - const float left_width = compact ? std::min(px(330), io.DisplaySize.x - 2 * margin) : px(280); - const auto flags = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | - ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings; - ImGui::SetNextWindowPos({margin, top}, ImGuiCond_Always); - ImGui::SetNextWindowSize({left_width, height}, ImGuiCond_Always); - ImGui::Begin("Cellular field journal", nullptr, flags); - if (ImGui::BeginTabBar("cell-tabs")) { - if (ImGui::BeginTabItem("Cell")) { - disabled_wrapped(form.cellular_controls.auto_feed ? "AUTO FEED ON / steering in Food" - : "MANUAL FEED / steering in Food"); - cell_vitals(v); - cell_actions(v, a); - if (v.bindings) { - ImGui::Separator(); - disabled_wrapped(controls_hint(*v.bindings).c_str()); - } - ImGui::EndTabItem(); - } - if (ImGui::BeginTabItem("Food")) { - cell_food(v, a, form); - ImGui::EndTabItem(); - } - if (compact && ImGui::BeginTabItem("Life")) { - cell_evolution(v, a); - ImGui::EndTabItem(); - } - if (ImGui::BeginTabItem("Log")) { - cell_log(v, form); - ImGui::EndTabItem(); - } - ImGui::EndTabBar(); - } - ImGui::End(); - if (!compact) { - ImGui::SetNextWindowPos({io.DisplaySize.x - margin, top}, ImGuiCond_Always, {1, 0}); - ImGui::SetNextWindowSize({px(300), height}, ImGuiCond_Always); - ImGui::Begin("Evolution", nullptr, flags); - cell_evolution(v, a); - ImGui::End(); + const auto* play = v.cellular_play; + if (play && play->offer() && !io.WantTextInput) { + if (ImGui::IsKeyPressed(ImGuiKey_E, false)) + form.evolution_open = !form.evolution_open; + if (ImGui::IsKeyPressed(ImGuiKey_Escape, false)) + form.evolution_open = false; } + hud_status(v, a); + hud_notes(v, form, a, compact); + hud_vitals(v, compact); + hud_dock(v, form, a, compact); + hud_callout(v, form); + evolution_window(v, form, a, compact); } // Newest at the bottom right. Each notice wraps its text beside a reserved close @@ -1049,9 +1412,12 @@ PanelActions draw_panels(const PanelView& view, FormBuffers& form, if (view.mode == Mode::launcher) { launcher(view, form, actions); } else { - banner(view, actions); - if (view.remote && view.remote->cellular_trial) + if (view.remote && view.remote->cellular_trial) { + draw_scene(view); cellular(view, form, actions); + } else { + banner(view, actions); + } if (!view.remote || !view.remote->cellular_trial || form.engineering) { legend(view, display); inspector(view); diff --git a/apps/evo-client/panels.hpp b/apps/evo-client/panels.hpp index 25fe774..9ac1d86 100644 --- a/apps/evo-client/panels.hpp +++ b/apps/evo-client/panels.hpp @@ -16,15 +16,38 @@ #include #include #include +#include namespace evo::client_app { enum class Mode : std::uint8_t { launcher, fixture, remote }; +// The cellular microscope view (2026-10-16 UI), in logical window coordinates. The client +// loop builds it from copied presentations each frame; the panels draw it with the +// toolkit, since membranes, flagella and granules are not rectangles. Appearance comes +// from the phenotype only: size from extent, flagella from movement speed, wall +// thickness from membrane mass, organelles from energy conversion. +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. +}; +struct ScenePatch { + float x{}, y{}, half{}; // Centre and half side of the 1 mm contact footprint. + std::array stock{}; // Energy pJ, then C, N, P, other fg. + bool target{}, stale{}; + std::uint64_t seed{}; +}; +struct CellularScene { + std::vector patches; + std::vector cells; +}; // Notice layout (logical pixels); the window name is the prefix plus the notice id. inline constexpr float notice_width = 320, notice_close_width = 22; inline constexpr const char* notice_window_prefix = "##notice"; // Text-field storage for the connect form (bounded; never persisted). struct FormBuffers { bool engineering{}; + bool evolution_open{}; // The mutation window (E or the callout opens it). CellularControls cellular_controls; std::array endpoint{}, server_name{}, authority{}, grants{}; void load(const client::ConnectForm& form); @@ -50,6 +73,7 @@ struct PanelView { std::optional remote; const network::CellularPerception* cellular_perception{}; const CellularPlay* cellular_play{}; + const CellularScene* cellular_scene{}; // Drawn under the panels when present. std::optional> cellular_feed_target; const client::OutcomeLog* outcomes{}; int visible_organisms{-1}; // -1 when unknown. diff --git a/deploy/kubernetes/region/dev-session-route/listener.yaml b/deploy/kubernetes/region/dev-session-route/listener.yaml index 18953c5..086140d 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-20261016T123415-16196:1792164855"} + - {name: REGION_SESSION_WINDOW, value: "dev-20261016T125355-89029:1792166035"} - {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"} ports: # QUIC (ADR-0090): UDP only; nothing listens on TCP 7400. diff --git a/docs/engineering/CLIENT.md b/docs/engineering/CLIENT.md index f76381c..cfa16dc 100644 --- a/docs/engineering/CLIENT.md +++ b/docs/engineering/CLIENT.md @@ -27,6 +27,22 @@ watermark, grants left, the snapshot, interest and snapshot bytes, and the last intentions with their outcome (sent, admitted, rejected, simulated, unknown; M10.5c). That list is the record; short notifications expire and can be dismissed. +**Microscope view** (2026-10-16, cellular play): the world sits inside a rounded eyepiece +with a vignette. Cells are drawn from their phenotype: a membrane whose wall thickens +with membrane mass, one flagellum per 150 um/s of speed, coral organelles by energy +conversion, a torn membrane when dead. Food patches are granules coloured by nutrient +(energy gold, carbon umber, nitrogen blue, phosphorus rose, other grey); a nutrient +that runs out loses its colour. The HUD: +- a status pill; +- Field notes (legend, food in range, steering, recent actions, help); +- Vitals (energy and matter in readable units, bars toward the next bud); +- an action dock (feed, engulf, bud, last result); +- a "Mutation ready [E]" callout opening the evolution window (cards with before/after + drawings and per-nutrient costs, Choose, Decline all), which also shows the end of + a life. + +The toolkit draws these shapes; the rectangle renderer still draws everything else. + **Sign in / Register** (Windows, ADR-0131) opens the system browser for Keycloak. After sign-in the client fetches a 10-minute grant from `grants.aeternalisgames.com` and connects to the cellular DEV region. It renews the grant before expiry and after a diff --git a/docs/engineering/VALIDATION.md b/docs/engineering/VALIDATION.md index 59f06b0..a2c3359 100644 --- a/docs/engineering/VALIDATION.md +++ b/docs/engineering/VALIDATION.md @@ -7831,3 +7831,27 @@ Executed locally: WSL `m97-postgres` 79/79 CTests; `postgres-check.sh --full`, including the v41 upgrade and drift drills; clang-tidy-19 on the changed sources; WSL client 14/14 with clang-tidy plus the Xvfb check; MSVC `client-package` 18/18; clang-format 19. + +## 2026-10-16 — cellular microscope UI (CI pending) + +Client-only redesign from the maintainer's design review (concept canvas A, C and E): +- **Palette:** an ink and lavender theme with amber for shortages. +- **Eyepiece:** a rounded viewport with a vignette. +- **Cells and food:** cells drawn from the phenotype (wall thickness, flagella, + organelles, torn when dead); food patches as nutrient-coloured granules. +- **HUD:** a status pill, Field notes, Vitals in readable units, and an action dock. +- **Evolution window:** a "Mutation ready [E]" callout opens it, with before/after + drawings and per-nutrient costs; it also shows the end of a life. + +No protocol, server or simulation change. Per-candidate discard waits for rules 7 +(ADR-0135). + +Tests: `client-panels` now checks that each HUD window (Vitals, Actions, status, +callout, Field notes) fits the viewport at 640, 960 and 1280. It draws a scene with +patches, a live cell and a dead cell. E opens the evolution window. An unaffordable +candidate cannot be chosen, and Decline all sends operator 0. Bud from the dock +works, and Begin a new life works. + +Executed locally: WSL clang-19 `client-probe` with clang-tidy 14/14 plus the Xvfb +X11 lifecycle check; MSVC `client-package` 18/18; clang-format 19. Screenshots of +the HUD at three sizes, the evolution window and the end of a life were reviewed. diff --git a/src/client/platform/application.cpp b/src/client/platform/application.cpp index 37c6058..795f320 100644 --- a/src/client/platform/application.cpp +++ b/src/client/platform/application.cpp @@ -56,26 +56,26 @@ struct Toolkit { style.FramePadding = {10, 6}; style.ItemSpacing = {8, 9}; auto* colors = style.Colors; - colors[ImGuiCol_WindowBg] = {0.035F, 0.065F, 0.085F, 0.97F}; - colors[ImGuiCol_ChildBg] = {0.055F, 0.095F, 0.12F, 0.9F}; - colors[ImGuiCol_PopupBg] = {0.045F, 0.08F, 0.10F, 1.0F}; - colors[ImGuiCol_Border] = {0.18F, 0.31F, 0.34F, 0.65F}; - colors[ImGuiCol_Text] = {0.88F, 0.94F, 0.93F, 1.0F}; - colors[ImGuiCol_TextDisabled] = {0.52F, 0.66F, 0.68F, 1.0F}; - colors[ImGuiCol_FrameBg] = {0.10F, 0.18F, 0.21F, 1.0F}; - colors[ImGuiCol_FrameBgHovered] = {0.15F, 0.28F, 0.31F, 1.0F}; - colors[ImGuiCol_FrameBgActive] = {0.18F, 0.35F, 0.36F, 1.0F}; - colors[ImGuiCol_Button] = {0.10F, 0.30F, 0.28F, 1.0F}; - colors[ImGuiCol_ButtonHovered] = {0.16F, 0.45F, 0.38F, 1.0F}; - colors[ImGuiCol_ButtonActive] = {0.20F, 0.55F, 0.44F, 1.0F}; - colors[ImGuiCol_Header] = {0.10F, 0.26F, 0.28F, 1.0F}; + colors[ImGuiCol_WindowBg] = {0.090F, 0.078F, 0.114F, 0.94F}; // Ink (2026-10-16 palette). + colors[ImGuiCol_ChildBg] = {0.114F, 0.098F, 0.141F, 0.9F}; + colors[ImGuiCol_PopupBg] = {0.090F, 0.078F, 0.114F, 1.0F}; + colors[ImGuiCol_Border] = {0.165F, 0.141F, 0.200F, 0.9F}; + colors[ImGuiCol_Text] = {0.945F, 0.925F, 0.902F, 1.0F}; + colors[ImGuiCol_TextDisabled] = {0.678F, 0.643F, 0.722F, 1.0F}; + colors[ImGuiCol_FrameBg] = {0.125F, 0.106F, 0.157F, 1.0F}; + colors[ImGuiCol_FrameBgHovered] = {0.165F, 0.141F, 0.200F, 1.0F}; + colors[ImGuiCol_FrameBgActive] = {0.227F, 0.196F, 0.271F, 1.0F}; + colors[ImGuiCol_Button] = {0.165F, 0.137F, 0.278F, 1.0F}; + colors[ImGuiCol_ButtonHovered] = {0.239F, 0.204F, 0.400F, 1.0F}; + colors[ImGuiCol_ButtonActive] = {0.294F, 0.247F, 0.561F, 1.0F}; + colors[ImGuiCol_Header] = {0.165F, 0.137F, 0.278F, 1.0F}; colors[ImGuiCol_HeaderHovered] = colors[ImGuiCol_ButtonHovered]; colors[ImGuiCol_HeaderActive] = colors[ImGuiCol_ButtonActive]; - colors[ImGuiCol_TitleBg] = {0.04F, 0.09F, 0.12F, 1.0F}; - colors[ImGuiCol_TitleBgActive] = {0.08F, 0.20F, 0.22F, 1.0F}; - colors[ImGuiCol_CheckMark] = {0.40F, 0.88F, 0.68F, 1.0F}; - colors[ImGuiCol_Tab] = {0.08F, 0.17F, 0.20F, 1.0F}; - colors[ImGuiCol_TabSelected] = {0.12F, 0.32F, 0.31F, 1.0F}; + colors[ImGuiCol_TitleBg] = {0.078F, 0.067F, 0.098F, 1.0F}; + colors[ImGuiCol_TitleBgActive] = {0.125F, 0.106F, 0.157F, 1.0F}; + colors[ImGuiCol_CheckMark] = {0.663F, 0.608F, 1.0F, 1.0F}; + colors[ImGuiCol_Tab] = {0.114F, 0.098F, 0.141F, 1.0F}; + colors[ImGuiCol_TabSelected] = {0.165F, 0.137F, 0.278F, 1.0F}; colors[ImGuiCol_TabHovered] = colors[ImGuiCol_ButtonHovered]; base_style = ImGui::GetStyle(); platform = ImGui_ImplSDL3_InitForSDLRenderer(window, target); diff --git a/tests/client_panels.cpp b/tests/client_panels.cpp index 0a3853e..0d19c06 100644 --- a/tests/client_panels.cpp +++ b/tests/client_panels.cpp @@ -447,6 +447,13 @@ void cellular_panels(const std::filesystem::path& review) { view.remote->cellular_trial = true; view.remote->server_tick = 102; view.remote->region = 4; + // 2026-10-16 microscope view: patches as granules and cells, drawn under the HUD. + CellularScene scene; + scene.patches.push_back({200, 200, 60, {50000, 100, 20, 10, 40}, false, false, 1}); + scene.patches.push_back({400, 260, 60, {0, 90, 0, 8, 0}, true, false, 2}); + scene.cells.push_back({300, 300, 24, 2.5F, 2, 3, true, false, false, 901}); + scene.cells.push_back({500, 220, 14, 4.0F, 0, 2, false, true, false, 77}); + view.cellular_scene = &scene; PanelActions action; app->set_overlay([&] { action = draw_panels(view, form, display); }); const auto draw = [&] { @@ -454,11 +461,18 @@ void cellular_panels(const std::filesystem::path& review) { }; for (int i = 0; i < 3; ++i) draw(); - auto* journal = ImGui::FindWindowByName("Cellular field journal"); - CHECK(journal && journal->Active && journal->ScrollMax.x == 0); - CHECK(journal->Pos.x >= 0 && journal->Pos.y >= 0 && - journal->Pos.x + journal->Size.x <= static_cast(width) && - journal->Pos.y + journal->Size.y <= static_cast(height)); + // Every HUD window fits the viewport without sideways scrolling. + const auto fits = [&](const ImGuiWindow* w) { + return w && w->Active && w->ScrollMax.x == 0 && w->Pos.x >= 0 && w->Pos.y >= 0 && + w->Pos.x + w->Size.x <= static_cast(width) && + w->Pos.y + w->Size.y <= static_cast(height); + }; + auto* vitals = ImGui::FindWindowByName("Vitals"); + auto* dock = ImGui::FindWindowByName("Actions"); + CHECK(fits(vitals) && fits(dock) && fits(ImGui::FindWindowByName("##mode"))); + CHECK(fits(ImGui::FindWindowByName("##mutation"))); // The offer callout. + if (width >= 880) + CHECK(fits(ImGui::FindWindowByName("Field notes"))); if (!review.empty()) { std::filesystem::create_directories(review); auto later = perception; @@ -469,31 +483,6 @@ void cellular_panels(const std::filesystem::path& review) { CHECK(app->request_screenshot( (review / ("cellular-" + std::to_string(width) + ".bmp")).string())); draw(); - auto* tabs = GImGui->TabBars.GetByKey(journal->GetID("cell-tabs")); - CHECK(tabs); - const auto choose_tab = [&](const char* name) { - for (auto& tab : tabs->Tabs) - if (std::string_view{ImGui::TabBarGetTabName(tabs, &tab)} == name) { - const float x = tabs->BarRect.Min.x + tab.Offset + tab.Width / 2; - const float y = tabs->BarRect.GetCenter().y; - mouse(id, SDL_EVENT_MOUSE_MOTION, x, y); - draw(); - mouse(id, SDL_EVENT_MOUSE_BUTTON_DOWN, x, y); - draw(); - mouse(id, SDL_EVENT_MOUSE_BUTTON_UP, x, y); - for (int i = 0; i < 3; ++i) - draw(); - CHECK(tabs->SelectedTabId == tab.ID); - return; - } - CHECK(false); - }; - choose_tab("Food"); - CHECK(journal->ScrollMax.x == 0); - CHECK(app->request_screenshot( - (review / ("cellular-food-" + std::to_string(width) + ".bmp")).string())); - draw(); - choose_tab("Cell"); const auto saved_offer = play.offer(); play.disconnected(); play.connected(); @@ -506,17 +495,35 @@ void cellular_panels(const std::filesystem::path& review) { } if (width != 960) continue; + // E opens the mutation window over the world. + SDL_Event e_key{}; + e_key.type = SDL_EVENT_KEY_DOWN; + e_key.key.windowID = id; + e_key.key.scancode = SDL_SCANCODE_E; + e_key.key.key = SDLK_E; + e_key.key.down = true; + CHECK(SDL_PushEvent(&e_key)); + draw(); + auto e_up = e_key; + e_up.type = SDL_EVENT_KEY_UP; + e_up.key.down = false; + CHECK(SDL_PushEvent(&e_up)); + for (int i = 0; i < 3; ++i) + draw(); + CHECK(form.evolution_open); const auto* evolution = ImGui::FindWindowByName("Evolution"); - CHECK(evolution && evolution->Active && evolution->ScrollMax.x == 0); - CHECK(evolution->Pos.x >= journal->Pos.x + journal->Size.x && - evolution->Pos.x + evolution->Size.x <= static_cast(width)); + CHECK(fits(evolution)); + if (!review.empty()) { + CHECK(app->request_screenshot((review / "cellular-evolution.bmp").string())); + draw(); + } // 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; // Every button is at least a frame high. Half-frame spacing still hits // each button, including disabled ones, without rendering every five pixels. const int stride = std::max(1, static_cast(ImGui::GetFrameHeight() / 2)); - for (int offset = 90; static_cast(offset) < panel->Size.y - 10; + for (int offset = 8; static_cast(offset) < panel->Size.y - 10; offset += stride) { const float y = panel->Pos.y + static_cast(offset); mouse(id, SDL_EVENT_MOUSE_MOTION, x, y); @@ -539,22 +546,25 @@ void cellular_panels(const std::filesystem::path& review) { const auto chose_candidate = [&] { return action.mutation.has_value() && action.mutation->operator_id != 0; }; - CHECK(!probe(evolution, 0.5F, chose_candidate)); + CHECK(!probe(evolution, 0.17F, chose_candidate)); action.mutation.reset(); - CHECK(probe(evolution, 0.5F, [&] { return action.mutation.has_value(); })); + CHECK(probe(evolution, 0.17F, [&] { return action.mutation.has_value(); })); CHECK(action.mutation == MutationChoice{901, 1, 100, 0}); action.mutation.reset(); perception.diagnostics = diagnostics; draw(); - CHECK(probe(evolution, 0.5F, chose_candidate)); + CHECK(probe(evolution, 0.17F, chose_candidate)); CHECK(action.mutation == MutationChoice{901, 1, 100, 3}); CHECK(play.queue(CellAction::mutation, 102, required(action.mutation))); const auto mutation_id = required(play.pending()).id; draw(); - CHECK(!probe(evolution, 0.5F, [&] { return action.mutation.has_value(); })); + CHECK(!probe(evolution, 0.17F, [&] { return action.mutation.has_value(); })); play.outcome({mutation_id, network::ActionResult::committed, 103, 5}); draw(); - CHECK(probe(journal, 0.75F, [&] { return action.cell_action == CellAction::bud; })); + bool budded = false; + for (float fraction = 0.1F; fraction < 1.0F && !budded; fraction += 0.1F) + budded = probe(dock, fraction, [&] { return action.cell_action == CellAction::bud; }); + CHECK(budded); play.observe_end({104, 901, network::CellularDeathReason::engulfed}); perception = {104, 0, {}, {}}; play.observe(perception); @@ -563,10 +573,10 @@ void cellular_panels(const std::filesystem::path& review) { CHECK(app->request_screenshot((review / "cellular-death.bmp").string())); draw(); } - CHECK(probe(evolution, 0.5F, [&] { return action.restart_life; })); + CHECK(probe(evolution, 0.17F, [&] { return action.restart_life; })); CHECK(play.restart()); draw(); - CHECK(!probe(evolution, 0.5F, [&] { return action.restart_life; })); + CHECK(!probe(evolution, 0.17F, [&] { return action.restart_life; })); } } } // namespace