Files
aevolution/apps/evo-client/panels.cpp
T
dingoandClaude Opus 5.5 feac7aac4e
Foundation / checks (ecs) (push) Successful in 4m39s
Foundation / checks (tsan) (push) Successful in 11m8s
Foundation / checks (deploy) (push) Failing after 16m14s
Foundation / checks (checks) (push) Failing after 16m15s
Foundation / checks (network) (push) Successful in 19m51s
Foundation / checks (client) (push) Successful in 20m58s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 39m38s
Inspect cells by hovering them in the microscope view
Hovering a cell outside the HUD rings it in amber and shows a card from its replicated
phenotype: size across and mass, how grown, swimming speed, membrane share of the body,
intake rate and energy conversion. A dead cell is labelled as food. Only what the
replication view already carries is shown; nothing hidden is revealed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 22:02:16 -04:00

1478 lines
72 KiB
C++

#include "panels.hpp"
#include "evo/client/labels.hpp"
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <imgui.h>
#include <string>
#include <string_view>
namespace evo::client_app {
namespace {
using client::LaunchPhase;
// Logical sizes at the current UI scale (window height and Ctrl+= / Ctrl+-).
float px(float v) {
return v * ImGui::GetStyle().FontScaleMain;
}
// A panel placed once (the user may move or resize it), and again at each new UI scale.
ImGuiCond placed(float& seen) {
const float scale = ImGui::GetStyle().FontScaleMain;
if (scale == seen)
return ImGuiCond_FirstUseEver;
seen = scale;
return ImGuiCond_Always;
}
ImVec4 color(render::Color c) {
return {static_cast<float>(c.red) / 255.0F, static_cast<float>(c.green) / 255.0F,
static_cast<float>(c.blue) / 255.0F, static_cast<float>(c.alpha) / 255.0F};
}
void copy(std::array<char, client::max_field_bytes>& out, const std::string& in) {
out.fill('\0');
std::memcpy(out.data(), in.data(), std::min(in.size(), out.size() - 1));
}
std::string text(const std::array<char, client::max_field_bytes>& in) {
return {in.begin(), std::find(in.begin(), in.end(), '\0')};
}
void row(const char* label, const std::string& value, const std::string& unit = {}) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::TextUnformatted(label);
ImGui::TableNextColumn();
ImGui::TextUnformatted(value.c_str());
ImGui::TableNextColumn();
ImGui::TextUnformatted(unit.c_str());
}
void swatch(const char* id, render::Color c, const char* label) {
ImGui::ColorButton(id, color(c), ImGuiColorEditFlags_NoTooltip | ImGuiColorEditFlags_NoAlpha,
{px(14), px(14)});
ImGui::SameLine();
ImGui::TextUnformatted(label);
}
// 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;
}
const char* outcome_name(client::OutcomeState s) {
switch (s) {
case client::OutcomeState::sent:
return "sent (no reply yet)";
case client::OutcomeState::admitted:
return "admitted (not yet durable)";
case client::OutcomeState::rejected:
return "rejected";
case client::OutcomeState::durable:
return "durable, no effect";
case client::OutcomeState::not_committed:
return "not committed";
case client::OutcomeState::unknown:
return "UNKNOWN (connection lost)";
case client::OutcomeState::simulated:
return "simulated (not durable)";
}
return "?";
}
void disabled_wrapped(const char* text) {
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled));
ImGui::TextWrapped("%s", text);
ImGui::PopStyleColor();
}
std::string key_label(client::KeyCode key) {
return key == client::no_key ? std::string{"-"} : std::string{client::key_name(key)};
}
std::string controls_hint(const client::Bindings& b) {
using client::Action;
const auto k = [&](Action action) { return key_label(b.slot(action).primary); };
return "Click selects, wheel zooms. Move " + k(Action::move_up) + " " + k(Action::move_left) +
" " + k(Action::move_down) + " " + k(Action::move_right) + "; pan " + k(Action::pan_up) +
" " + k(Action::pan_left) + " " + k(Action::pan_down) + " " + k(Action::pan_right) +
"; UI capture " + k(Action::toggle_capture) + ".";
}
// Fixed wording only (never echoes paths or file bytes); wraps inside the launcher.
void error_text(client::LaunchError error) {
ImGui::PushStyleColor(ImGuiCol_Text, red);
ImGui::TextWrapped("%s", std::string{client::launch_error_text(error)}.c_str());
ImGui::PopStyleColor();
}
constexpr std::array<const char*, world::field_count + 1> layer_names{
"Water", "Dissolved nitrogen", "Dissolved phosphorus",
"Organic carbon", "Organic nitrogen", "Organic phosphorus",
"Organic other", "Organic energy", "Incident energy",
"Heat", "Moisture (saturation)"};
void launcher(const PanelView& v, FormBuffers& form, PanelActions& a) {
const auto phase = v.launcher->phase();
const auto& io = ImGui::GetIO();
ImGui::SetNextWindowPos({io.DisplaySize.x * 0.5F, io.DisplaySize.y * 0.5F}, ImGuiCond_Always,
{0.5F, 0.5F});
ImGui::SetNextWindowSize({std::min(px(520), io.DisplaySize.x - px(16)), 0}, ImGuiCond_Always);
ImGui::Begin("Aeternalis Evolution - engineering client", nullptr,
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
ImGui::TextColored(green, "AETERNALIS / EVOLUTION");
ImGui::TextWrapped("Begin a cellular life in the shared dev ecosystem, or explore the local "
"engineering fixture.");
if (ImGui::SmallButton("Controls..."))
a.open_controls = true;
ImGui::Separator();
if (ImGui::Button("Local fixture", {px(160), 0}))
a.fixture = true;
ImGui::SameLine();
ImGui::TextWrapped("In-memory stand-in: environment changes and static organisms. Not a "
"server, not an ecosystem, not authoritative.");
ImGui::Separator();
ImGui::TextUnformatted("Connect to a dev region");
ImGui::InputText("Region CA file", form.authority.data(), form.authority.size());
ImGui::BeginDisabled(!v.remote_available || !v.auth.supported || v.auth.busy ||
phase == LaunchPhase::connecting);
if (ImGui::Button(v.auth.signed_in ? "Play in DEV" : "Sign in / Register", {-1, px(34)})) {
a.sign_in = !v.auth.signed_in;
a.auth_connect = v.auth.signed_in;
}
ImGui::EndDisabled();
if (v.auth.busy) {
ImGui::TextWrapped(
"%s",
v.auth.phase == client::AuthPhase::signing_out ? "Signing out..."
: v.auth.phase == client::AuthPhase::renewing
? "Renewing your connection..."
: "Complete sign-in in your browser, then return here. Connecting is automatic.");
if (v.auth.phase == client::AuthPhase::signing_in && ImGui::Button("Cancel sign-in"))
a.cancel_sign_in = true;
} else if (v.auth.signed_in && ImGui::SmallButton("Sign out"))
a.sign_out = true;
if (v.auth.error) {
ImGui::PushStyleColor(ImGuiCol_Text, amber);
const auto text = client::auth_error_text(*v.auth.error);
ImGui::PushTextWrapPos(0.0F);
ImGui::TextUnformatted(text.data(), text.data() + text.size());
ImGui::PopTextWrapPos();
ImGui::PopStyleColor();
}
ImGui::TextWrapped(
"Your password stays in the system browser. Windows Credential Manager stores your login.");
if (ImGui::CollapsingHeader("Manual connection (developer grants)")) {
ImGui::BeginDisabled(!v.remote_available || phase == LaunchPhase::connecting);
ImGui::InputText("Endpoint (host:port)", form.endpoint.data(), form.endpoint.size());
ImGui::InputText("Server name", form.server_name.data(), form.server_name.size());
ImGui::InputText("Grant bundle file", form.grants.data(), form.grants.size());
bool cellular_trial = v.cellular_trial;
if (ImGui::Checkbox("Cellular play (v10)", &cellular_trial))
a.cellular_trial = cellular_trial;
const bool start = phase == LaunchPhase::choosing && ImGui::Button("Connect", {px(160), 0});
ImGui::EndDisabled();
if (start)
a.connect = true;
}
if (!v.remote_available)
ImGui::TextColored(amber, "Remote mode needs a build with EVO_BUILD_NETWORK.");
if (v.form_error)
error_text(*v.form_error);
if (phase == LaunchPhase::connecting) {
ImGui::TextColored(amber, "Connecting (TLS handshake and grant check)...");
if (ImGui::Button("Cancel", {px(120), 0}))
a.cancel = true;
}
if (phase == LaunchPhase::failed) {
error_text(v.launcher->error());
if (ImGui::Button("Retry", {px(120), 0}))
a.retry = true;
ImGui::SameLine();
if (ImGui::Button("Cancel", {px(120), 0}))
a.cancel = true;
}
ImGui::TextWrapped("The region CA is still required to verify the game server. Manual grant "
"files are only read when connecting.");
ImGui::End();
}
void banner(const PanelView& v, PanelActions& a) {
const auto& io = ImGui::GetIO();
ImGui::SetNextWindowPos({io.DisplaySize.x * 0.5F, px(4)}, ImGuiCond_Always, {0.5F, 0});
ImGui::Begin("##mode", nullptr,
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings);
if (v.mode == Mode::fixture) {
ImGui::TextColored(amber, "LOCAL FIXTURE - in-memory stand-in, not authoritative");
ImGui::SameLine();
if (ImGui::SmallButton("Launcher"))
a.back = true;
ImGui::SameLine();
if (ImGui::SmallButton("Controls"))
a.open_controls = true;
if (v.auth.signed_in) {
ImGui::SameLine();
ImGui::BeginDisabled(v.auth.busy);
if (ImGui::SmallButton("Sign out"))
a.sign_out = true;
ImGui::EndDisabled();
}
} else {
ImGui::TextColored(v.remote && v.remote->phase == "connected" ? green : amber,
"DEV REGION - %s%s", v.remote ? v.remote->phase.c_str() : "?",
v.remote && v.remote->stale_view ? " - STALE (last view, frozen)" : "");
ImGui::SameLine();
if (ImGui::SmallButton("Disconnect"))
a.ask_disconnect = true;
ImGui::SameLine();
if (ImGui::SmallButton("Controls"))
a.open_controls = true;
}
ImGui::End();
}
void legend(const PanelView& v, render::EnvironmentDisplay& display) {
static float seen = 0;
const auto when = placed(seen);
ImGui::SetNextWindowPos({px(8), px(40)}, when);
ImGui::SetNextWindowSize({px(300), 0}, when);
ImGui::Begin("Legend");
int current = display.mode == render::EnvironmentDisplay::Mode::moisture
? static_cast<int>(world::field_count)
: static_cast<int>(display.field);
if (ImGui::Combo("Layer", &current, layer_names.data(), static_cast<int>(layer_names.size()))) {
display = current == static_cast<int>(world::field_count)
? render::EnvironmentDisplay{render::EnvironmentDisplay::Mode::moisture}
: render::EnvironmentDisplay{render::EnvironmentDisplay::Mode::field,
static_cast<world::Field>(current)};
}
if (display.mode == render::EnvironmentDisplay::Mode::moisture)
ImGui::TextWrapped("Water saturation, linear from 0 %% (low) to 100 %% (high).");
else
ImGui::TextWrapped("%s", client::density_scale(display.field).c_str());
swatch("##low", render::ramp(0), "Present: low");
ImGui::SameLine();
swatch("##mid", render::ramp(0.5), "mid");
ImGui::SameLine();
swatch("##high", render::ramp(1), "high");
swatch("##zero", render::palette::present_zero, "Present zero (black)");
swatch("##missing", render::palette::missing_a, "Missing: checkerboard");
swatch("##notreq", render::palette::not_requested, "Not requested: hollow outline");
swatch("##undef", render::palette::undefined, "Undefined moisture (no capacity)");
swatch("##stale", render::palette::stale_outline, "Stale: dimmed, amber outlines");
ImGui::Separator();
const auto env = v.environment ? v.environment->freshness() : client::Freshness::none;
const auto org = v.organisms ? v.organisms->freshness() : client::Freshness::none;
ImGui::TextColored(freshness_color(env), "Environment: %s",
std::string{client::freshness_name(env)}.c_str());
ImGui::TextColored(freshness_color(org), "Organisms: %s",
std::string{client::freshness_name(org)}.c_str());
if (v.mode == Mode::remote && v.organisms && v.organisms->current() &&
v.organisms->current()->cells().empty())
ImGui::TextWrapped("No individual organisms: this region reports pooled inventories only.");
if (v.mode == Mode::fixture)
ImGui::TextWrapped("Fixture organisms are static presentation data built from genomes.");
if (v.visible_organisms >= 0)
ImGui::Text("Organisms drawn: %d", v.visible_organisms);
if (v.bindings != nullptr)
disabled_wrapped(controls_hint(*v.bindings).c_str());
ImGui::End();
}
void inspector(const PanelView& v) {
const auto& io = ImGui::GetIO();
static float seen = 0;
const auto when = placed(seen);
ImGui::SetNextWindowPos({io.DisplaySize.x - px(8), px(40)}, when, {1, 0});
ImGui::SetNextWindowSize({px(420), 0}, when);
ImGui::Begin("Inspector");
const auto* env = v.environment ? v.environment->current() : nullptr;
const auto* orgs = v.organisms ? v.organisms->current() : nullptr;
const auto* organism = v.selection->organism(orgs);
const auto* cell = v.selection->cell(env);
if (organism == nullptr && cell == nullptr) {
ImGui::TextWrapped("Click an organism or habitat cell to inspect it.");
ImGui::End();
return;
}
const auto freshness = organism ? v.organisms->freshness() : v.environment->freshness();
if (freshness == client::Freshness::stale)
ImGui::TextColored(amber, "STALE: values are from an older revision.");
if (ImGui::BeginTable("rows", 3, ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit)) {
for (const auto& r : organism ? client::organism_rows(*organism) : client::cell_rows(*cell))
row(r.label.c_str(), r.value, r.unit);
ImGui::EndTable();
}
if (cell != nullptr && ImGui::BeginTable("fields", 2, ImGuiTableFlags_RowBg)) {
// Values wrap inside the column so missing/not-requested explanations stay readable.
ImGui::TableSetupColumn("field", ImGuiTableColumnFlags_WidthFixed, px(150));
ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthStretch);
for (std::size_t k = 0; k < world::field_count; ++k) {
const auto field = static_cast<world::Field>(k);
const auto value = client::describe_field(*cell, field);
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::TextUnformatted(std::string{client::field_name(field)}.c_str());
ImGui::TableNextColumn();
const bool tinted = value.kind == client::ValueKind::missing ||
value.kind == client::ValueKind::not_requested;
if (tinted)
ImGui::PushStyleColor(ImGuiCol_Text,
value.kind == client::ValueKind::missing
? red
: ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled));
ImGui::TextWrapped("%s", value.text.c_str());
if (tinted)
ImGui::PopStyleColor();
}
const auto moisture = client::describe_moisture(*cell);
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::TextUnformatted("Moisture");
ImGui::TableNextColumn();
ImGui::TextWrapped("%s", moisture.text.c_str());
ImGui::EndTable();
}
ImGui::End();
}
// Rebinding: each slot button arms key capture for that slot; the panel holds UI
// capture, so no key or click reaches the world while it is open (ADR-0085).
void controls(const PanelView& v, PanelActions& a) {
if (v.controls == nullptr)
return;
const auto& io = ImGui::GetIO();
ImGui::SetNextWindowPos({io.DisplaySize.x * 0.5F, io.DisplaySize.y * 0.5F}, ImGuiCond_Always,
{0.5F, 0.5F});
ImGui::SetNextWindowSize({std::min(px(460), io.DisplaySize.x - px(16)), 0}, ImGuiCond_Always);
ImGui::Begin("Controls", nullptr,
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse |
ImGuiWindowFlags_NoSavedSettings);
disabled_wrapped("Keys are named by their US-layout position. Mouse click (select) and "
"wheel (zoom) are fixed. Escape cancels a key capture.");
if (ImGui::BeginTable("bindings", 3, ImGuiTableFlags_RowBg)) {
ImGui::TableSetupColumn("Action", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("Primary", ImGuiTableColumnFlags_WidthFixed, px(120));
ImGui::TableSetupColumn("Secondary", ImGuiTableColumnFlags_WidthFixed, px(150));
ImGui::TableHeadersRow();
for (std::size_t k = 0; k < client::action_count; ++k) {
const auto action = static_cast<client::Action>(k);
const auto& slot = v.controls->draft()[k];
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::TextUnformatted(std::string{client::action_name(action)}.c_str());
for (const bool secondary : {false, true}) {
ImGui::TableNextColumn();
const ControlSlot here{action, secondary};
const auto key = secondary ? slot.secondary : slot.primary;
const std::string label =
(v.capturing == here ? std::string{"Press a key"} : key_label(key)) + "##" +
std::to_string(k) + (secondary ? "s" : "p");
ImGui::BeginDisabled(v.capturing.has_value());
if (ImGui::Button(label.c_str(), {px(100), 0}))
a.capture_key = here;
if (secondary && key != client::no_key) {
ImGui::SameLine();
if (ImGui::SmallButton(("x##clear" + std::to_string(k)).c_str()))
a.clear_secondary = action;
}
ImGui::EndDisabled();
}
}
ImGui::EndTable();
}
if (v.capturing) {
ImGui::TextColored(amber, "Press a key for %s (Escape cancels).",
std::string{client::action_name(v.capturing->action)}.c_str());
if (ImGui::Button("Cancel capture", {px(140), 0}))
a.cancel_capture = true;
}
if (v.controls_problem) {
ImGui::PushStyleColor(ImGuiCol_Text, red);
ImGui::TextWrapped("%s", client::describe(*v.controls_problem).c_str());
ImGui::PopStyleColor();
}
ImGui::BeginDisabled(v.capturing.has_value());
if (ImGui::Button("Apply", {px(100), 0}))
a.apply_controls = true;
ImGui::SameLine();
if (ImGui::Button("Reset defaults", {px(130), 0}))
a.reset_controls = true;
ImGui::SameLine();
if (ImGui::Button("Cancel", {px(100), 0}))
a.close_controls = true;
ImGui::EndDisabled();
ImGui::End();
}
void session(const PanelView& v, PanelActions& a) {
if (!v.remote)
return;
const auto& io = ImGui::GetIO();
static float seen = 0;
const auto when = placed(seen);
ImGui::SetNextWindowPos({px(8), io.DisplaySize.y - px(8)}, when, {0, 1});
ImGui::SetNextWindowSize({px(360), 0}, when);
ImGui::Begin("Session");
const auto& s = *v.remote;
if (s.cellular_trial)
ImGui::TextColored(amber, "CELLULAR TRIAL - exploratory server-authoritative play");
if (ImGui::BeginTable("status", 3, ImGuiTableFlags_SizingFixedFit)) {
row("Connection", s.phase);
row("Session / epoch", std::to_string(s.session) + " / " + std::to_string(s.epoch));
row("Region", std::to_string(s.region) + " (" + std::to_string(s.handoffs) + " crossings)");
row("Server tick", std::to_string(s.server_tick));
row("Simulated through", std::to_string(s.simulated_tick));
row("Grants left", std::to_string(s.grants_left));
row("Snapshot", s.snapshot_tick == 0 ? std::string{"none yet"}
: "tick " + std::to_string(s.snapshot_tick) + ", " +
std::to_string(s.cells) + " cells, " +
std::to_string(s.organisms) + " organisms");
if (s.focused)
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");
char delay[48];
std::snprintf(delay, sizeof delay, "%zu, %.1f ticks behind, %zu stale", s.other_markers,
s.interpolation_delay, s.stale_markers);
row("Other markers", delay);
}
ImGui::EndTable();
}
if (s.cellular_trial) {
ImGui::Separator();
ImGui::TextUnformatted("Nearby food patches (server sensor view)");
if (!s.cellular_action.empty())
ImGui::TextWrapped("%s", s.cellular_action.c_str());
if (!v.cellular_perception) {
ImGui::TextDisabled("Waiting for the first cell view...");
} else if (v.cellular_perception->life_identity == 0) {
ImGui::TextColored(amber, "No living cell is currently bound to this account.");
} else {
ImGui::Text("Life %llu, tick %llu",
static_cast<unsigned long long>(v.cellular_perception->life_identity),
static_cast<unsigned long long>(v.cellular_perception->tick));
if (const auto& diagnostics = v.cellular_perception->diagnostics) {
const auto& matter = diagnostics->reserve_matter_fg;
ImGui::TextWrapped("Reserve %llu pJ | C %llu N %llu P %llu O %llu fg",
static_cast<unsigned long long>(diagnostics->reserve_energy_pj),
static_cast<unsigned long long>(matter[0]),
static_cast<unsigned long long>(matter[1]),
static_cast<unsigned long long>(matter[2]),
static_cast<unsigned long long>(matter[3]));
const auto movement_name = [&] {
switch (diagnostics->movement) {
case network::CellularMovementResult::not_reported:
return "unavailable";
case network::CellularMovementResult::no_movement:
return "no movement";
case network::CellularMovementResult::moved:
return "moved";
case network::CellularMovementResult::blocked:
return "blocked";
case network::CellularMovementResult::insufficient_energy:
return "insufficient reserve";
}
return "unknown";
};
const auto intake_name = [&] {
switch (diagnostics->intake) {
case network::CellularIntakeResult::not_reported:
return "unavailable";
case network::CellularIntakeResult::not_requested:
return "not feeding";
case network::CellularIntakeResult::acquired:
return "acquired";
case network::CellularIntakeResult::missing_patch:
return "patch missing";
case network::CellularIntakeResult::out_of_contact:
return "out of contact";
}
return "unknown";
};
ImGui::TextWrapped(
"Last tick: maintenance %llu pJ, movement %llu pJ; %s; feeding %s",
static_cast<unsigned long long>(diagnostics->maintenance_cost_pj),
static_cast<unsigned long long>(diagnostics->movement_cost_pj), movement_name(),
intake_name());
if (!diagnostics->has_tick_effects)
ImGui::TextDisabled("Tick effects unavailable after recovery.");
}
ImGui::TextDisabled("Steer with movement keys. Feeding continues until stopped.");
if (v.cellular_feed_target && ImGui::SmallButton("Stop feeding"))
a.stop_feeding = true;
if (ImGui::BeginChild("cellular-patches", {0, px(142)}, true)) {
const auto& patches = v.cellular_perception->patches;
if (patches.empty())
ImGui::TextDisabled("No provisioned food within sensor range.");
for (std::size_t i = 0; i < patches.size(); ++i) {
const auto& patch = patches[i];
ImGui::PushID(static_cast<int>(i));
ImGui::Text("Patch (%u, %u) um", patch.x_um, patch.y_um);
ImGui::TextWrapped("Energy %llu pJ | C %llu N %llu P %llu O %llu fg",
static_cast<unsigned long long>(patch.energy_pj),
static_cast<unsigned long long>(patch.matter_fg[0]),
static_cast<unsigned long long>(patch.matter_fg[1]),
static_cast<unsigned long long>(patch.matter_fg[2]),
static_cast<unsigned long long>(patch.matter_fg[3]));
const bool active = v.cellular_feed_target &&
v.cellular_feed_target->first == patch.x_um &&
v.cellular_feed_target->second == patch.y_um;
if (active)
ImGui::TextColored(green, "Feeding target");
else if (ImGui::SmallButton("Feed this patch"))
a.feed_patch = {patch.x_um, patch.y_um};
ImGui::Separator();
ImGui::PopID();
}
}
ImGui::EndChild();
}
}
disabled_wrapped("Intentions (newest first; this is the record, toasts expire):");
if (v.outcomes &&
ImGui::BeginTable("outcomes", 3, ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit)) {
const auto& entries = v.outcomes->entries();
int shown = 0;
for (auto it = entries.rbegin(); it != entries.rend() && shown < 10; ++it, ++shown) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("#%llu", static_cast<unsigned long long>(it->sequence));
ImGui::TableNextColumn();
ImGui::TextUnformatted(outcome_name(it->state));
ImGui::TableNextColumn();
if (it->state == client::OutcomeState::durable)
ImGui::Text("tick %llu, commit %llu", static_cast<unsigned long long>(it->tick),
static_cast<unsigned long long>(it->commit_sequence));
else if (it->state == client::OutcomeState::rejected)
ImGui::Text("status %u", static_cast<unsigned>(it->detail));
else if (it->tick != 0)
ImGui::Text("tick %llu", static_cast<unsigned long long>(it->tick));
}
ImGui::EndTable();
}
ImGui::End();
}
const char* cell_action_name(CellAction kind) {
switch (kind) {
case CellAction::engulf:
return "Engulf";
case CellAction::bud:
return "Bud";
case CellAction::mutation:
return "Mutation";
}
return "Action";
}
const char* cell_action_state(CellActionState state) {
switch (state) {
case CellActionState::queued:
return "Queued";
case CellActionState::sent:
return "Sent / awaiting admission";
case CellActionState::admitted:
return "Accepted / awaiting commit";
case CellActionState::unresolved:
return "Unresolved / outcome unknown";
case CellActionState::committed:
return "Committed";
case CellActionState::no_effect:
return "Committed / no effect";
case CellActionState::refused:
return "Refused / no new action";
}
return "Unknown";
}
void cell_record(const CellActionRecord& record) {
ImGui::TextColored(record.state == CellActionState::committed ? green : amber, "%s",
cell_action_name(record.kind));
ImGui::TextWrapped("%s", cell_action_state(record.state));
if (record.state == CellActionState::refused &&
record.refusal != network::AdmitStatus::admitted)
disabled_wrapped(std::string{cellular_admission_message(record.refusal)}.c_str());
}
// 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<ImU32, 5> 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<const char*, 5> 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<const char*, 4>& units) {
double v = static_cast<double>(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<char, 32> 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<float>(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 = c.facing ? c.heading : static_cast<float>(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<int>(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<float>(i) / static_cast<float>(c.flagella - 1) - 0.5F) * 1.1F;
const float wave = std::sin(time * 6.0F + static_cast<float>(i) * 1.7F +
static_cast<float>(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;
}
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<std::uint64_t>(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);
}
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<int>(2.0 + 2.5 * std::log10(static_cast<double>(amount) / 1.0e5)), 1, 18);
for (int i = 0; i < count; ++i) {
const auto key = p.seed * 131U + channel * 977U + static_cast<std::uint64_t>(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<float>(i) * step;
const auto alpha = static_cast<int>(60.0F * (1.0F - static_cast<float>(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);
}
}
// Hovering a cell (not over the HUD) rings it and shows what its phenotype says.
void inspect_cell(ImDrawList& list, const SceneCell& c) {
const float r = std::max(c.radius, 5.0F);
list.AddCircle({c.x, c.y}, r * 1.6F + 6.0F, IM_COL32(245, 181, 68, 200), 0, 2.0F);
ImGui::BeginTooltip();
ImGui::TextColored(lavender, "%s",
c.own ? "YOUR CELL"
: c.dead ? "DEAD CELL - FOOD"
: "ANOTHER CELL");
ImGui::Text("Size %u µm across, %s", c.extent_um, mass_text(c.mass_fg).c_str());
if (!c.dead) {
ImGui::Text("Grown %u%%", c.grown_per_thousand / 10);
if (c.speed_um_s == 0)
ImGui::TextUnformatted("Speed cannot swim");
else
ImGui::Text("Speed %u µm/s", c.speed_um_s);
ImGui::Text("Membrane %s (%u%% of body)", mass_text(c.membrane_fg).c_str(),
c.mass_fg == 0 ? 0U : static_cast<unsigned>(c.membrane_fg * 100 / c.mass_fg));
ImGui::Text("Intake %s/s", mass_text(c.ingestion_fg_s).c_str());
ImGui::Text("Converts %u%% of food energy", c.conversion_per_thousand / 10);
}
ImGui::EndTooltip();
}
void draw_scene(const PanelView& v) {
if (!v.cellular_scene)
return;
auto& list = *ImGui::GetBackgroundDrawList();
const auto time = static_cast<float>(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);
const auto& io = ImGui::GetIO();
if (io.WantCaptureMouse || !ImGui::IsMousePosValid())
return;
const SceneCell* hovered = nullptr;
float best = 0;
for (const auto& cell : v.cellular_scene->cells) {
const float dx = io.MousePos.x - cell.x, dy = io.MousePos.y - cell.y;
const float reach = std::max(cell.radius, 5.0F) * 1.4F + 6.0F;
const float distance = dx * dx + dy * dy;
if (distance <= reach * reach && (!hovered || distance < best)) {
hovered = &cell;
best = distance;
}
}
if (hovered)
inspect_cell(list, *hovered);
}
// 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<unsigned long long>(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<unsigned long long>(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 != patches.end() && patch->energy_pj == 0)
ImGui::TextColored(amber, "Feed target has no energy left");
}
ImGui::Separator();
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<float>(static_cast<double>(have) / static_cast<double>(need))
: 1.0F;
nutrient_row(i + 1, nutrient_names.at(i + 1), share, mass_text(have));
}
ImGui::EndTable();
}
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<std::size_t>(d->movement)),
intake.at(static_cast<std::size_t>(d->intake)),
energy_text(d->maintenance_cost_pj).c_str());
}
ImGui::End();
}
// 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 (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<std::size_t>(f->second))}.empty())
ImGui::TextWrapped("%s", engulf.at(static_cast<std::size_t>(f->second)));
if (const auto& f = play->bud_feedback();
f && !std::string_view{bud.at(static_cast<std::size_t>(f->second))}.empty())
ImGui::TextWrapped("%s", bud.at(static_cast<std::size_t>(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) {
ImGui::PushID(static_cast<int>(patch.x_um));
ImGui::PushID(static_cast<int>(patch.y_um));
const bool selected = v.cellular_feed_target == std::pair{patch.x_um, patch.y_um};
ImGui::Separator();
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(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<float>(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<float>(static_cast<double>(have) / static_cast<double>(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();
}
// 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;
if (!play)
return;
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;
}
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::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. A suspended cell may "
"still be waiting for space to resume.");
}
ImGui::BeginDisabled(!play->can_restart());
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 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;
}
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<int>(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<int>(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();
}
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();
ImGui::SameLine();
if (ImGui::Button("Close [E]", {0, px(40)}))
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) {
const auto& io = ImGui::GetIO();
const bool compact = io.DisplaySize.x < px(880);
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
// column, so the button is always visible; the stack stops at 60 % of the viewport
// height and counts what it could not show (those still expire or can be dismissed
// once space frees). Notices are not the outcome record (Session panel is).
void notices(const PanelView& v, PanelActions& a) {
const auto& io = ImGui::GetIO();
const float width = std::min(px(notice_width), io.DisplaySize.x - px(16));
const float top = io.DisplaySize.y * 0.4F;
float y = io.DisplaySize.y - px(8);
const auto list = v.ui->notices();
std::size_t hidden = 0;
for (auto it = list.rbegin(); it != list.rend(); ++it) {
const auto& n = *it;
if (y < top || width < 120) {
++hidden;
continue;
}
ImGui::SetNextWindowPos({io.DisplaySize.x - px(8), y}, ImGuiCond_Always, {1, 1});
ImGui::SetNextWindowSize({width, 0}, ImGuiCond_Always);
const std::string id = notice_window_prefix + std::to_string(n.id);
ImGui::Begin(id.c_str(), nullptr,
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing);
if (ImGui::BeginTable("notice", 2)) {
ImGui::TableSetupColumn("text", ImGuiTableColumnFlags_WidthStretch);
ImGui::TableSetupColumn("close", ImGuiTableColumnFlags_WidthFixed,
px(notice_close_width));
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::PushStyleColor(ImGuiCol_Text, n.level == client::NoticeLevel::error ? red
: n.level == client::NoticeLevel::warning ? amber
: green);
ImGui::TextWrapped("%s", n.text.c_str());
ImGui::PopStyleColor();
ImGui::TableNextColumn();
if (ImGui::Button(("x" + id).c_str(), {px(notice_close_width), 0}))
a.dismiss_notice = n.id;
ImGui::EndTable();
}
y -= ImGui::GetWindowHeight() + px(4);
ImGui::End();
}
if (v.ui->evicted_notices() > 0 || hidden > 0) {
ImGui::SetNextWindowPos({io.DisplaySize.x - px(8), y}, ImGuiCond_Always, {1, 1});
ImGui::Begin("##evicted", nullptr,
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize |
ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing);
if (hidden > 0)
ImGui::TextDisabled("%zu more notices (dismiss to show)", hidden);
if (v.ui->evicted_notices() > 0)
ImGui::TextDisabled("%llu older notices discarded",
static_cast<unsigned long long>(v.ui->evicted_notices()));
ImGui::End();
}
}
void dialog(const PanelView& v, PanelActions& a) {
const auto& d = v.ui->dialog();
if (!d)
return;
const std::string id = d->title + "##dialog" + std::to_string(d->id);
ImGui::OpenPopup(id.c_str());
if (ImGui::BeginPopupModal(id.c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::TextWrapped("%s", d->body.c_str());
if (ImGui::Button("Confirm", {px(120), 0}))
a.confirm_dialog = d->id;
ImGui::SameLine();
if (ImGui::Button("Cancel", {px(120), 0}))
a.cancel_dialog = d->id;
ImGui::EndPopup();
}
}
} // namespace
void FormBuffers::load(const client::ConnectForm& f) {
copy(endpoint, f.endpoint);
copy(server_name, f.server_name);
copy(authority, f.authority_path);
copy(grants, f.grants_path);
}
client::ConnectForm FormBuffers::form() const {
return {text(endpoint), text(server_name), text(authority), text(grants)};
}
PanelActions draw_panels(const PanelView& view, FormBuffers& form,
render::EnvironmentDisplay& display) {
PanelActions actions;
if (view.mode == Mode::launcher) {
launcher(view, form, actions);
} else {
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);
session(view, actions);
}
}
controls(view, actions);
notices(view, actions);
dialog(view, actions);
return actions;
}
} // namespace evo::client_app