Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m29s
Foundation / postgres-tools (push) Successful in 29s
Foundation / server-image (push) Successful in 4m24s
Foundation / image (push) Successful in 4m58s
From the first rules-13 playtest: - An earned offer waits until a single cell can split (keeping its count), so choices are no longer refused one after another. - The client draws the region's walls (dimming outside), names the edge when the cell is against it, shows the region's cell count, and says when upkeep is burning kept matter because no energy is left. - Mixed bubbles hold every nutrient at once (--mixed-motes; none leaves the scatter stream unchanged) and are drawn as small pools of their nutrients. With intake split by the body's recipe, single-nutrient phosphorus bubbles fed slowly; mixed ones carry it with everything else. - Liquid openings move each pool out of the currents to the nearest still water (cellular_still_centre). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2033 lines
103 KiB
C++
2033 lines
103 KiB
C++
#include "panels.hpp"
|
|
#include "evo/biology/cellular_catalog.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) +
|
|
"; brake " + k(Action::brake) + "; 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", ¤t, 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";
|
|
case CellAction::emerge:
|
|
return "Emerge";
|
|
}
|
|
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";
|
|
}
|
|
// What the region did with an engulf or bud, as its tick's view reports it ("" when none).
|
|
const char* engulf_text(network::CellularEngulfResult result) {
|
|
constexpr std::array text{"",
|
|
"",
|
|
"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"};
|
|
const auto index = static_cast<std::size_t>(result);
|
|
return index < text.size() ? text.at(index) : "";
|
|
}
|
|
const char* bud_text(network::CellularBudOutcome outcome) {
|
|
constexpr std::array text{"",
|
|
"",
|
|
"Bud created: a descendant split off",
|
|
"Bud failed: not fully grown",
|
|
"Bud failed: not enough resources",
|
|
"Bud failed: no space beside you"};
|
|
const auto index = static_cast<std::size_t>(outcome);
|
|
return index < text.size() ? text.at(index) : "";
|
|
}
|
|
void cell_record(const CellActionRecord& record) {
|
|
const char* effect = record.engulf ? engulf_text(*record.engulf)
|
|
: record.bud ? bud_text(*record.bud)
|
|
: "";
|
|
const bool succeeded =
|
|
record.state == CellActionState::committed &&
|
|
(!record.engulf || *record.engulf == network::CellularEngulfResult::engulfed) &&
|
|
(!record.bud || *record.bud == network::CellularBudOutcome::budded);
|
|
ImGui::TextColored(succeeded ? green : amber, "%s (tick %llu)", cell_action_name(record.kind),
|
|
static_cast<unsigned long long>(record.tick));
|
|
ImGui::TextWrapped("%s", *effect != '\0' ? effect : 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};
|
|
}
|
|
ImU32 opacity(ImU32 c, unsigned alpha) {
|
|
return (c & ~IM_COL32_A_MASK) | (alpha << IM_COL32_A_SHIFT);
|
|
}
|
|
// Shared nutrient silhouettes at every scale: lipid-like energy lobes, carbon facets,
|
|
// nitrogen vesicles, phosphorus rosettes and angular detritus. These are visual symbols,
|
|
// not a claim about chemical species. Zero stock never emits a glyph.
|
|
void draw_food(ImDrawList& list, ImVec2 at, float r, std::size_t channel, bool stale,
|
|
std::uint64_t seed) {
|
|
const auto c = nutrient_colors.at(channel);
|
|
const unsigned alpha = stale ? 90U : 225U;
|
|
if (r < 3.5F) {
|
|
list.AddNgonFilled(at, r, opacity(c, alpha), channel == 1 || channel == 4 ? 4 : 6);
|
|
return;
|
|
}
|
|
list.AddCircleFilled(at, r * 1.35F, opacity(c, stale ? 8U : 18U), 16);
|
|
if (channel == 0 || channel == 2) {
|
|
const int count = channel == 0 ? 3 : 4;
|
|
for (int i = 0; i < count; ++i) {
|
|
const float a = static_cast<float>(i) * 6.2832F / static_cast<float>(count);
|
|
const auto p = add(at, {std::cos(a) * r * 0.38F, std::sin(a) * r * 0.38F});
|
|
list.AddCircleFilled(p, r * 0.6F, opacity(c, alpha / 2), 12);
|
|
list.AddCircle(p, r * 0.6F, opacity(c, alpha), 12, 1.0F);
|
|
}
|
|
} else {
|
|
const int count = channel == 3 ? 10 : 6;
|
|
const float angle = unit_of(seed) * 6.2832F;
|
|
std::array<ImVec2, 10> points{};
|
|
for (int i = 0; i < count; ++i) {
|
|
const float a = angle + static_cast<float>(i) * 6.2832F / static_cast<float>(count);
|
|
const float radius = r * (channel == 3 && i % 2 != 0 ? 0.65F : 1.0F);
|
|
points.at(static_cast<std::size_t>(i)) =
|
|
add(at, {std::cos(a) * radius, std::sin(a) * radius});
|
|
}
|
|
// A triangle fan also handles the concave rosette correctly.
|
|
for (int i = 0; i < count; ++i)
|
|
list.AddTriangleFilled(at, points.at(static_cast<std::size_t>(i)),
|
|
points.at(static_cast<std::size_t>((i + 1) % count)),
|
|
opacity(c, alpha / 2));
|
|
list.AddPolyline(points.data(), count, opacity(c, alpha), ImDrawFlags_Closed, 1.0F);
|
|
list.AddLine(points[0], points[3], opacity(c, alpha / 2), 1.0F);
|
|
}
|
|
list.AddCircleFilled({at.x - r * 0.23F, at.y - r * 0.26F}, std::max(0.8F, r * 0.15F),
|
|
IM_COL32(240, 253, 255, stale ? 60 : 210), 8);
|
|
}
|
|
// 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) : IM_COL32(157, 226, 241, alpha);
|
|
const ImU32 body = IM_COL32(67, 154, 182, alpha / 4);
|
|
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));
|
|
list.AddEllipse(centre, times(radius, 0.87F), IM_COL32(116, 174, 238, alpha / 2), angle, 0,
|
|
1.0F);
|
|
// Interior highlights give the cytoplasm depth without introducing extra capabilities.
|
|
if (r >= 12) {
|
|
list.AddEllipseFilled(add(centre, times(normal, -r * 0.26F)), {r * 0.65F, r * 0.19F},
|
|
IM_COL32(186, 246, 239, alpha / 8), angle);
|
|
for (int k = 0; k < 9; ++k) {
|
|
const auto key = c.seed * 19U + static_cast<std::uint64_t>(k);
|
|
const auto at = add(add(centre, times(axis, (unit_of(key) - 0.5F) * r * 1.7F)),
|
|
times(normal, (unit_of(key + 3) - 0.5F) * r));
|
|
list.AddCircleFilled(at, std::max(0.7F, r * 0.025F), IM_COL32(180, 240, 245, alpha / 2),
|
|
6);
|
|
}
|
|
}
|
|
const ImU32 organelle = IM_COL32(255, 176, 94, alpha);
|
|
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;
|
|
const auto at =
|
|
add(add(centre, times(axis, u * radius.x * 1.1F)), times(normal, v * radius.y * 0.9F));
|
|
list.AddEllipseFilled(at, {std::max(1.5F, r * 0.19F), std::max(1.0F, r * 0.12F)}, organelle,
|
|
angle);
|
|
if (r >= 18)
|
|
list.AddLine(add(at, times(axis, -r * 0.1F)), add(at, times(axis, r * 0.1F)),
|
|
IM_COL32(124, 75, 62, alpha), 1.0F);
|
|
}
|
|
// Producers (ADR-0176): chloroplasts, more of them for more efficient cells.
|
|
for (int k = 0; k < c.chloroplasts; ++k) {
|
|
const auto key = c.seed * 53U + 11U + static_cast<std::uint64_t>(k);
|
|
const float u = unit_of(key) - 0.55F, v = unit_of(key + 5U) - 0.5F;
|
|
const ImVec2 at =
|
|
add(add(centre, times(axis, u * radius.x * 1.1F)), times(normal, v * radius.y * 0.9F));
|
|
list.AddCircleFilled(at, std::max(1.8F, r * 0.18F), IM_COL32(64, 168, 84, alpha));
|
|
list.AddCircleFilled(at, std::max(0.8F, r * 0.08F), IM_COL32(150, 222, 128, alpha));
|
|
}
|
|
const ImVec2 nucleus = add(centre, times(axis, radius.x * 0.42F));
|
|
list.AddCircleFilled(nucleus, std::max(2.0F, r * 0.35F), IM_COL32(166, 100, 217, alpha / 2));
|
|
list.AddCircle(nucleus, std::max(2.0F, r * 0.3F), IM_COL32(222, 175, 250, alpha), 20, 1.0F);
|
|
list.AddCircleFilled(nucleus, std::max(1.0F, r * 0.14F), IM_COL32(245, 190, 245, alpha));
|
|
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;
|
|
draw_food(list, {p.x + std::cos(a) * d, p.y + std::sin(a) * d},
|
|
grain * (0.7F + 0.6F * unit_of(key + 5U)), channel, p.stale, key);
|
|
}
|
|
}
|
|
}
|
|
// The channel a deposit mostly holds (by its share of the largest amount): its colour.
|
|
std::size_t dominant_channel(const std::array<std::uint64_t, 5>& stock) {
|
|
std::size_t best = 0;
|
|
for (std::size_t c = 1; c < stock.size(); ++c)
|
|
if (stock.at(c) > stock.at(best))
|
|
best = c;
|
|
return best;
|
|
}
|
|
// ADR-0136: a bubble is a translucent circle in its nutrient's colour, sized by what it
|
|
// holds (never below its contact disc). While something eats it, a soft glow of its own
|
|
// colour fades in and out around it; the bubble itself keeps its size.
|
|
void draw_pool(ImDrawList& list, const SceneDeposit& d, float time);
|
|
void draw_bubble(ImDrawList& list, const SceneDeposit& d, float time) {
|
|
// A bubble holding more than one nutrient looks like a little pool of all of them.
|
|
if (std::ranges::count_if(d.stock, [](std::uint64_t amount) { return amount != 0; }) > 1) {
|
|
std::uint64_t total{};
|
|
for (const auto amount : d.stock)
|
|
total += amount;
|
|
auto small = d;
|
|
small.radius = std::max(
|
|
d.radius *
|
|
std::clamp(0.7F + 0.12F * static_cast<float>(std::log10(static_cast<double>(
|
|
std::max<std::uint64_t>(1, total)))),
|
|
0.8F, 2.2F) *
|
|
0.6F,
|
|
6.0F);
|
|
draw_pool(list, small, time);
|
|
return;
|
|
}
|
|
const auto channel = dominant_channel(d.stock);
|
|
const auto total = static_cast<double>(std::max<std::uint64_t>(1, d.stock.at(channel)));
|
|
const float scale =
|
|
std::clamp(0.7F + 0.12F * static_cast<float>(std::log10(total)), 0.8F, 2.2F);
|
|
const float r = std::max(d.radius * scale * 0.5F, 2.5F);
|
|
auto color = nutrient_colors.at(channel);
|
|
if (d.drained && !d.stale) {
|
|
// About 1.5 glows a second, eased: a breathing light, not a shock wave.
|
|
const float phase = 0.5F - 0.5F * std::cos(time * 9.0F + static_cast<float>(d.seed % 7U));
|
|
for (int ring = 3; ring >= 1; --ring) {
|
|
const auto glow = static_cast<unsigned>(phase * 34.0F / static_cast<float>(ring));
|
|
list.AddCircleFilled({d.x, d.y}, r * (1.0F + 0.45F * static_cast<float>(ring)),
|
|
(color & 0x00FFFFFFU) | (glow << IM_COL32_A_SHIFT));
|
|
}
|
|
}
|
|
if (d.stock.at(channel) != 0)
|
|
draw_food(list, {d.x, d.y}, r, channel, d.stale, d.seed);
|
|
}
|
|
// A thin enclosing membrane follows the contact disc. Its contents are the same nutrient
|
|
// glyphs as free food, never extra resource identities or additional collision shapes.
|
|
void draw_pool(ImDrawList& list, const SceneDeposit& d, float time) {
|
|
const float r = std::max(d.radius, 8.0F);
|
|
const ImVec2 centre{d.x, d.y};
|
|
const int alpha = d.stale ? 65 : 170;
|
|
list.AddCircleFilled(centre, r, IM_COL32(84, 177, 163, d.stale ? 12 : 25), 64);
|
|
list.AddCircle(centre, r, IM_COL32(166, 220, 199, alpha), 64, 1.25F);
|
|
list.AddCircle(centre, r - 3, IM_COL32(116, 190, 188, alpha / 3), 64, 1.0F);
|
|
list.PathArcTo(centre, r - 1, 3.5F, 4.8F, 16);
|
|
list.PathStroke(IM_COL32(220, 249, 219, alpha), 0, 2.0F);
|
|
if (d.drained && !d.stale)
|
|
list.AddCircle(centre, r + 2,
|
|
IM_COL32(178, 240, 218, static_cast<int>(50 + 30 * std::sin(time * 6))), 64,
|
|
2.0F);
|
|
const float grain = std::clamp(r * 0.09F, 2.0F, 11.0F);
|
|
for (std::size_t channel = 0; channel < d.stock.size(); ++channel) {
|
|
const auto amount = d.stock.at(channel);
|
|
if (amount == 0)
|
|
continue;
|
|
const auto count = std::clamp(
|
|
static_cast<int>(2.0 + 3.0 * std::log10(static_cast<double>(amount) / 1.0e5)), 1, 18);
|
|
for (int i = 0; i < count; ++i) {
|
|
const auto key = d.seed * 131U + channel * 977U + static_cast<std::uint64_t>(i);
|
|
const float a = unit_of(key) * 6.2832F, dist = std::sqrt(unit_of(key + 3U)) * r * 0.75F;
|
|
draw_food(list, {d.x + std::cos(a) * dist, d.y + std::sin(a) * dist},
|
|
grain * (0.7F + 0.6F * unit_of(key + 5U)), channel, d.stale, key);
|
|
}
|
|
}
|
|
}
|
|
// A bubble that ran out: its glow shrinks and fades away where it was.
|
|
void draw_pop(ImDrawList& list, const ScenePop& p) {
|
|
const float t = std::clamp(p.age, 0.0F, 1.0F);
|
|
const auto base =
|
|
nutrient_colors.at(static_cast<std::size_t>(std::clamp(p.channel, 0, 4))) & 0x00FFFFFFU;
|
|
const float r = std::max(p.radius * 0.5F, 2.5F) * (1.0F - 0.7F * t);
|
|
list.AddCircleFilled({p.x, p.y}, r * 1.6F,
|
|
base | (static_cast<unsigned>(40.0F * (1.0F - t)) << IM_COL32_A_SHIFT));
|
|
list.AddCircleFilled({p.x, p.y}, r,
|
|
base | (static_cast<unsigned>(160.0F * (1.0F - t)) << IM_COL32_A_SHIFT));
|
|
}
|
|
// 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);
|
|
if (c.photosynthesis_per_thousand != 0)
|
|
ImGui::Text("Light %u%% photosynthesis", c.photosynthesis_per_thousand / 10);
|
|
}
|
|
ImGui::EndTooltip();
|
|
}
|
|
// Optical depth and caustics: decorative illumination, never temperature or hidden food.
|
|
// The fixed 24 x 16 mesh bounds cost independently of resolution and camera zoom.
|
|
void draw_liquid(ImDrawList& list, ImVec2 size, float time) {
|
|
constexpr int columns = 24, rows = 16;
|
|
const auto tint = [&](int x, int y) {
|
|
const float u = static_cast<float>(x) / columns, v = static_cast<float>(y) / rows;
|
|
const float wave = 0.5F + 0.5F * std::sin(u * 8 + v * 5 + std::sin(v * 9 + time * 0.08F));
|
|
const float light = std::pow(wave, 7.0F);
|
|
return IM_COL32(static_cast<int>(12 + 9 * wave),
|
|
static_cast<int>(37 + 24 * wave + 10 * light),
|
|
static_cast<int>(55 + 23 * wave + 14 * light), 255);
|
|
};
|
|
for (int y = 0; y < rows; ++y)
|
|
for (int x = 0; x < columns; ++x) {
|
|
list.AddRectFilledMultiColor(
|
|
{static_cast<float>(x) * size.x / columns, static_cast<float>(y) * size.y / rows},
|
|
{static_cast<float>(x + 1) * size.x / columns,
|
|
static_cast<float>(y + 1) * size.y / rows},
|
|
tint(x, y), tint(x + 1, y), tint(x + 1, y + 1), tint(x, y + 1));
|
|
}
|
|
}
|
|
// Rules 12: translucent ribbons follow the sampled local current. Their travelling
|
|
// highlights move along that direction; width/brightness encode speed, never temperature.
|
|
void draw_flows(ImDrawList& list, const std::vector<SceneFlow>& flows, float time) {
|
|
for (const auto& f : flows) {
|
|
const float phase = std::fmod(time * 0.5F + static_cast<float>(f.seed % 97U) / 97.0F, 1.0F);
|
|
const float fade = std::sin(phase * 3.14159265F);
|
|
const auto alpha = static_cast<unsigned>((24.0F + 80.0F * f.strength) * fade);
|
|
const ImVec2 from{f.x + f.dx * (phase - 0.5F), f.y + f.dy * (phase - 0.5F)};
|
|
const ImVec2 to{from.x + f.dx * 0.6F, from.y + f.dy * 0.6F};
|
|
const ImVec2 start{f.x - f.dx, f.y - f.dy}, end{f.x + f.dx, f.y + f.dy};
|
|
const ImVec2 bend{-f.dy * 0.16F, f.dx * 0.16F};
|
|
const ImVec2 middle{f.x, f.y};
|
|
list.AddTriangleFilled(start, add(middle, bend), add(middle, times(bend, -1)),
|
|
IM_COL32(67, 180, 217, 8));
|
|
list.AddTriangleFilled(end, add(middle, bend), add(middle, times(bend, -1)),
|
|
IM_COL32(67, 180, 217, 8));
|
|
list.AddLine(from, to, IM_COL32(125, 213, 239, alpha / 3), 5.0F);
|
|
list.AddLine(from, to, IM_COL32(172, 234, 248, alpha), 1.2F);
|
|
}
|
|
}
|
|
void draw_scene(const PanelView& v) {
|
|
if (!v.cellular_scene)
|
|
return;
|
|
auto& list = *ImGui::GetBackgroundDrawList();
|
|
const auto time = v.cellular_scene->stale ? 0.0F : static_cast<float>(ImGui::GetTime());
|
|
draw_liquid(list, ImGui::GetIO().DisplaySize, time);
|
|
draw_flows(list, v.cellular_scene->flows, time);
|
|
if (const auto& s = *v.cellular_scene; s.region) {
|
|
const auto size = ImGui::GetIO().DisplaySize;
|
|
const auto outside = IM_COL32(4, 3, 6, 200);
|
|
list.AddRectFilled({0, 0}, {size.x, s.region_top}, outside);
|
|
list.AddRectFilled({0, s.region_bottom}, {size.x, size.y}, outside);
|
|
list.AddRectFilled({0, s.region_top}, {s.region_left, s.region_bottom}, outside);
|
|
list.AddRectFilled({s.region_right, s.region_top}, {size.x, s.region_bottom}, outside);
|
|
list.AddRect({s.region_left, s.region_top}, {s.region_right, s.region_bottom},
|
|
s.at_edge ? IM_COL32(243, 176, 77, 230) : IM_COL32(166, 220, 199, 140), 0, 0,
|
|
s.at_edge ? 3.0F : 1.5F);
|
|
}
|
|
for (const auto& patch : v.cellular_scene->patches)
|
|
draw_patch(list, patch);
|
|
const auto visible = [&](const SceneDeposit& d) {
|
|
const float reach = std::max(d.radius * 3, 12.0F);
|
|
const auto size = ImGui::GetIO().DisplaySize;
|
|
return d.x + reach >= 0 && d.y + reach >= 0 && d.x - reach <= size.x &&
|
|
d.y - reach <= size.y;
|
|
};
|
|
for (const auto& deposit : v.cellular_scene->deposits)
|
|
if (deposit.pool && visible(deposit))
|
|
draw_pool(list, deposit, time);
|
|
for (const auto& deposit : v.cellular_scene->deposits)
|
|
if (!deposit.pool && visible(deposit))
|
|
draw_bubble(list, deposit, time);
|
|
for (const auto& pop : v.cellular_scene->pops)
|
|
draw_pop(list, pop);
|
|
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; });
|
|
}
|
|
// One control standard: rounded, bordered, full label, visible hover/pressed/disabled.
|
|
// Accent denotes action family, never funding or whether the server accepted it.
|
|
bool action_button(const char* label, ImVec2 size, ImVec4 accent) {
|
|
ImGui::PushStyleColor(ImGuiCol_Button,
|
|
{accent.x * 0.23F, accent.y * 0.23F, accent.z * 0.23F, 1});
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonHovered,
|
|
{accent.x * 0.38F, accent.y * 0.38F, accent.z * 0.38F, 1});
|
|
ImGui::PushStyleColor(ImGuiCol_ButtonActive,
|
|
{accent.x * 0.5F, accent.y * 0.5F, accent.z * 0.5F, 1});
|
|
ImGui::PushStyleColor(ImGuiCol_Border, {accent.x, accent.y, accent.z, 0.7F});
|
|
const bool pressed = ImGui::Button(label, size);
|
|
ImGui::PopStyleColor(4);
|
|
return pressed;
|
|
}
|
|
void panel_heading(const char* title, bool& minimized) {
|
|
ImGui::PushID(title);
|
|
const float right = ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x;
|
|
ImGui::AlignTextToFramePadding();
|
|
ImGui::TextUnformatted(title);
|
|
ImGui::SameLine();
|
|
ImGui::SetCursorPosX(right - ImGui::CalcTextSize(" + ").x -
|
|
2 * ImGui::GetStyle().FramePadding.x);
|
|
if (ImGui::SmallButton(minimized ? " + " : " - "))
|
|
minimized = !minimized;
|
|
if (ImGui::IsItemHovered())
|
|
ImGui::SetTooltip("%s %s", minimized ? "Expand" : "Minimize", title);
|
|
ImGui::PopID();
|
|
}
|
|
// 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, FormBuffers& form, 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.
|
|
const float max_height =
|
|
compact ? std::max(px(120), io.DisplaySize.y - px(220)) : io.DisplaySize.y * 0.43F;
|
|
ImGui::SetNextWindowSizeConstraints({width, 0}, {width, max_height});
|
|
ImGui::Begin("Vitals", nullptr,
|
|
hud_flags | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize);
|
|
panel_heading("Your cell", form.vitals_minimized);
|
|
if (form.vitals_minimized) {
|
|
if (d)
|
|
ImGui::Text("Energy %s", energy_text(d->reserve_energy_pj).c_str());
|
|
ImGui::End();
|
|
return;
|
|
}
|
|
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;
|
|
}
|
|
ImGui::TextDisabled("Body -- Water --");
|
|
if (ImGui::IsItemHovered())
|
|
ImGui::SetTooltip("Temperatures are not reported by this session.\nThermal gradients are "
|
|
"not yet available.");
|
|
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());
|
|
if (d->light_pj != 0)
|
|
ImGui::TextDisabled("Sunlight +%s", energy_text(d->light_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 (action_button(form.cellular_controls.auto_feed ? "Feed: auto" : "Feed: manual",
|
|
{each, px(44)}, {0.32F, 0.90F, 0.73F, 1}))
|
|
form.cellular_controls.auto_feed = !form.cellular_controls.auto_feed;
|
|
ImGui::EndDisabled();
|
|
ImGui::SameLine();
|
|
ImGui::BeginDisabled(!play || !play->can_act());
|
|
if (action_button("Engulf", {each, px(44)}, {0.38F, 0.68F, 1.0F, 1}))
|
|
a.cell_action = CellAction::engulf;
|
|
ImGui::SameLine();
|
|
if (action_button("Bud", {each, px(44)}, {0.82F, 0.53F, 0.96F, 1})) {
|
|
a.cell_action = CellAction::bud;
|
|
a.cell_become = form.bud_become && d && d->members == 1;
|
|
}
|
|
ImGui::EndDisabled();
|
|
// Rules 13 (v14): continue as the bud, or grow the organism toward Emerge.
|
|
if (d && d->members != 0 && play && play->life() != 0) {
|
|
if (d->members == 1) {
|
|
ImGui::Checkbox("Continue as the bud", &form.bud_become);
|
|
} else {
|
|
ImGui::TextColored(lavender, "Organism of %u cells (Emerge at %u)",
|
|
static_cast<unsigned>(d->members),
|
|
static_cast<unsigned>(d->emerge_members));
|
|
ImGui::BeginDisabled(!play->can_act() || !d->can_emerge);
|
|
if (action_button("Emerge", {-1, px(40)}, {0.98F, 0.82F, 0.35F, 1}))
|
|
a.cell_action = CellAction::emerge;
|
|
ImGui::EndDisabled();
|
|
if (!d->can_emerge)
|
|
disabled_wrapped("Emerge opens at the threshold of cells, mass and reserve. Buds "
|
|
"add cells to the organism.");
|
|
}
|
|
}
|
|
// 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 (const auto* s = v.cellular_scene; s && s->at_edge && play && play->life() != 0)
|
|
ImGui::TextColored(amber, "At the region edge: nothing lies beyond. Swim back in; "
|
|
"pushing on the wall still costs energy.");
|
|
if (play) {
|
|
if (const auto& f = play->engulf_feedback(); f && *engulf_text(f->second) != '\0')
|
|
ImGui::TextWrapped("%s", engulf_text(f->second));
|
|
if (const auto& f = play->bud_feedback(); f && *bud_text(f->second) != '\0')
|
|
ImGui::TextWrapped("%s", bud_text(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.41F)});
|
|
ImGui::Begin("Field notes", nullptr,
|
|
hud_flags | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize);
|
|
panel_heading("Field notes", form.notes_minimized);
|
|
if (form.notes_minimized) {
|
|
ImGui::End();
|
|
return;
|
|
}
|
|
for (std::size_t i = 0; i < nutrient_names.size(); ++i) {
|
|
const float glyph_size = ImGui::GetTextLineHeight();
|
|
const auto at = ImGui::GetCursorScreenPos();
|
|
draw_food(*ImGui::GetWindowDrawList(), {at.x + glyph_size / 2, at.y + glyph_size / 2},
|
|
glyph_size * 0.36F, i, false, i);
|
|
ImGui::Dummy({glyph_size, glyph_size});
|
|
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* seen = v.cellular_perception; seen && !seen->deposits.empty()) {
|
|
// ADR-0136: pools and bubbles feed on contact; a summary, not a target list.
|
|
std::size_t pools = 0;
|
|
std::array<std::uint64_t, 5> totals{};
|
|
for (const auto& d : seen->deposits) {
|
|
pools += d.shape == network::CellularDepositShape::pool ? 1 : 0;
|
|
for (std::size_t c = 0; c < totals.size(); ++c)
|
|
totals.at(c) += network::deposit_amount_value(d.amount_codes.at(c));
|
|
}
|
|
ImGui::Text("%zu bubbles, %zu pools in range", seen->deposits.size() - pools, pools);
|
|
ImGui::TextColored(nutrient(0), "%s", energy_text(totals[0]).c_str());
|
|
for (std::size_t c = 1; c < totals.size(); ++c) {
|
|
ImGui::SameLine();
|
|
ImGui::TextColored(nutrient(c), "%s", mass_text(totals.at(c)).c_str());
|
|
}
|
|
disabled_wrapped("Swim through bubbles to collect them; pools feed slowly.");
|
|
} else 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();
|
|
}
|
|
// Rules 13 (v14): which reserve matter may stand in for energy, and the heritable body.
|
|
if (const auto* d = diagnostics(v); d && d->members != 0) {
|
|
if (ImGui::CollapsingHeader("Burning reserve matter")) {
|
|
for (std::size_t c = 0; c < 4; ++c) {
|
|
const auto bit = static_cast<std::uint8_t>(1U << c);
|
|
bool keep = (form.cellular_controls.exclude & bit) != 0;
|
|
const std::string label = std::string{"Keep "} + nutrient_names.at(c + 1);
|
|
if (ImGui::Checkbox(label.c_str(), &keep))
|
|
form.cellular_controls.exclude =
|
|
static_cast<std::uint8_t>(keep ? form.cellular_controls.exclude | bit
|
|
: form.cellular_controls.exclude & ~bit);
|
|
}
|
|
ImGui::TextDisabled("Can pay %s now", energy_text(d->payable_energy_pj).c_str());
|
|
if (form.cellular_controls.exclude != 0 && d->has_tick_effects &&
|
|
d->reserve_energy_pj < d->maintenance_cost_pj)
|
|
ImGui::TextColored(amber, "No energy left: upkeep is burning kept matter.");
|
|
disabled_wrapped("Matter you keep is never burned for movement or mutations; upkeep "
|
|
"still burns it when nothing else can pay.");
|
|
}
|
|
if (ImGui::CollapsingHeader("Body")) {
|
|
const auto& t = d->traits;
|
|
ImGui::Text("Mass %s Grown %u%%", mass_text(d->total_mass_fg).c_str(),
|
|
static_cast<unsigned>(d->growth_per_thousand / 10));
|
|
ImGui::TextDisabled("Density %u Upkeep efficiency %u Growth %u", unsigned{t[0]},
|
|
unsigned{t[1]}, unsigned{t[2]});
|
|
ImGui::TextDisabled("Engulf capacity %u Kill absorption %u", unsigned{t[12]},
|
|
unsigned{t[13]});
|
|
ImGui::TextDisabled("Litter %u Recipe C%u N%u P%u O%u", unsigned{t[14]},
|
|
unsigned{t[15]}, unsigned{t[16]}, unsigned{t[17]}, unsigned{t[18]});
|
|
if (t[19] != 0)
|
|
ImGui::TextColored(lavender, "Adhesive: a multicellular organism");
|
|
}
|
|
}
|
|
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});
|
|
// 2026-10-16: offers come often, so the callout is a small pill (E or a click opens it).
|
|
const std::string label = "Mutation [E]";
|
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {px(10), px(3)});
|
|
if (ImGui::Button(label.c_str(), {0, px(24)}))
|
|
form.evolution_open = true;
|
|
ImGui::PopStyleVar();
|
|
ImGui::PopStyleColor(3);
|
|
ImGui::End();
|
|
}
|
|
constexpr std::array capability_names{"Energy conversion", "Membrane", "Movement",
|
|
"Ingestion", "Reproduction", "Size",
|
|
"Thermal tolerance", "Photosynthesis"};
|
|
constexpr std::array capability_kinds{"Metabolism", "Defense", "Movement", "Feeding",
|
|
"Reproduction", "Size", "Environment", "Producer"};
|
|
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 10% faster; each movement costs a little more.",
|
|
"Take food faster from every patch you touch.",
|
|
"Better at budding: cheaper buds, more twins (+10%).",
|
|
"Grow toward a larger body: harder to engulf, slower to fill.",
|
|
"Tolerate a wider range of temperatures.",
|
|
"Capture 10% more light while still; heavier and slower."};
|
|
constexpr std::array decrease_text{"Convert less of what you eat into energy.",
|
|
"A thinner, cheaper wall that is easier to breach.",
|
|
"Swim 10% slower and spend less on movement.",
|
|
"Take food more slowly from each patch.",
|
|
"Worse at budding: dearer buds, fewer twins (-10%).",
|
|
"Grow toward a smaller body that is cheaper to keep.",
|
|
"Tolerate a narrower range of temperatures.",
|
|
"Capture 10% less light; lighter and a little faster."};
|
|
// 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;
|
|
case 7:
|
|
after.chloroplasts = c.effect == 3 ? 0 : up ? 5 : 2;
|
|
before.chloroplasts = c.effect == 2 ? 0 : 3;
|
|
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});
|
|
}
|
|
// Rules 13 (v14): a named catalog mutation, with its pro, con, chance and tuned cost. The
|
|
// choice splits a single cell (stay as the founder or become the offspring that expresses it);
|
|
// an organism expresses it as a whole.
|
|
const biology::CellularMutationSpec* named_mutation(const network::CellularLifeDiagnostics* d,
|
|
const network::CellularOfferedCandidate& c) {
|
|
if (!d || d->members == 0 || c.capability != 0 || c.effect != 0)
|
|
return nullptr;
|
|
return biology::cellular_mutation(c.operator_id);
|
|
}
|
|
void named_offer_card(const PanelView& v, const network::CellularMutationOffer& offer,
|
|
const network::CellularOfferedCandidate& c,
|
|
const biology::CellularMutationSpec& spec, PanelActions& a) {
|
|
const auto* play = v.cellular_play;
|
|
const auto* d = diagnostics(v);
|
|
ImGui::TextDisabled("%.1f%% chance", static_cast<double>(c.parameter) / 10'000.0);
|
|
ImGui::PushFont(nullptr, px(18));
|
|
ImGui::TextWrapped("%.*s", static_cast<int>(spec.name.size()), spec.name.data());
|
|
ImGui::PopFont();
|
|
ImGui::TextColored({0.32F, 0.90F, 0.73F, 1}, "+ %.*s", static_cast<int>(spec.pro.size()),
|
|
spec.pro.data());
|
|
ImGui::TextColored(amber, "- %.*s", static_cast<int>(spec.con.size()), spec.con.data());
|
|
bool affordable = d != nullptr;
|
|
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;
|
|
// Energy may be paid with burnable matter standing in.
|
|
const auto have =
|
|
d ? (channel == 0 ? d->payable_energy_pj : d->reserve_matter_fg.at(channel - 1)) : 0;
|
|
affordable = affordable && have >= need;
|
|
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();
|
|
const bool organism = d && d->members > 1;
|
|
const bool adhesion = spec.effect == biology::CellularEffect::acquire_adhesion;
|
|
// A choice that splits the cell waits until it has grown enough (the offer waits too).
|
|
const bool splits = !organism && !adhesion;
|
|
const bool grown = !splits || (d && d->split_ready);
|
|
if (adhesion)
|
|
disabled_wrapped("Your cell and its split-off offspring stay joined: one organism with "
|
|
"one genome and one reserve, growing toward Emerge.");
|
|
else if (organism)
|
|
disabled_wrapped("Your whole organism changes, paid from its reserve.");
|
|
else
|
|
disabled_wrapped("Your cell splits: both keep the change in their plan; only the "
|
|
"offspring expresses it.");
|
|
if (!grown)
|
|
ImGui::TextColored(amber, "Grow to split (now %u%%). Feed; the offer waits.",
|
|
d ? static_cast<unsigned>(d->growth_per_thousand / 10) : 0U);
|
|
const bool ready =
|
|
play && play->can_act() && v.remote && v.remote->server_tick > offer.offer_tick;
|
|
ImGui::BeginDisabled(!affordable || !ready || !grown);
|
|
const MutationChoice stay{offer.life_identity, offer.event_index, offer.offer_tick,
|
|
c.operator_id, false};
|
|
if (organism || adhesion) {
|
|
if (ImGui::Button(affordable ? "Choose" : "Feed first", {-1, px(40)}))
|
|
a.mutation = stay;
|
|
} else {
|
|
const float half = (ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x) / 2;
|
|
if (ImGui::Button(affordable ? "Stay" : "Feed first", {half, px(40)}))
|
|
a.mutation = stay;
|
|
ImGui::SameLine();
|
|
if (ImGui::Button("Become offspring", {half, px(40)})) {
|
|
auto become = stay;
|
|
become.become = true;
|
|
a.mutation = become;
|
|
}
|
|
}
|
|
ImGui::EndDisabled();
|
|
}
|
|
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);
|
|
if (const auto* spec = named_mutation(d, c)) {
|
|
named_offer_card(v, offer, c, *spec, a);
|
|
return;
|
|
}
|
|
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"
|
|
: cause == network::CellularDeathReason::emerged ? "Your organism emerged"
|
|
: "Your cell died");
|
|
ImGui::PopFont();
|
|
disabled_wrapped(cause == network::CellularDeathReason::starved
|
|
? "Its reserve could not pay upkeep. Its body became food."
|
|
: cause == network::CellularDeathReason::emerged
|
|
? "It left the cellular region for the world, taking all its "
|
|
"matter with it. This cellular life is complete."
|
|
: "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();
|
|
const bool named = !offer->candidates.empty() &&
|
|
named_mutation(diagnostics(v), offer->candidates.front()) != nullptr;
|
|
disabled_wrapped(named ? "Your play earned one change. Each has a benefit and a cost; what "
|
|
"you do makes some more likely to appear."
|
|
: "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 hud_map(const PanelView& v, FormBuffers& form, bool compact) {
|
|
if (!v.cellular_scene)
|
|
return;
|
|
const auto& scene = *v.cellular_scene;
|
|
const auto& io = ImGui::GetIO();
|
|
const float width = px(compact ? 184.0F : 210.0F);
|
|
ImGui::SetNextWindowPos({io.DisplaySize.x - (compact ? px(12) : eyepiece_clearance()), px(126)},
|
|
ImGuiCond_Always, {1, 0});
|
|
ImGui::SetNextWindowSizeConstraints({width, 0}, {width, io.DisplaySize.y - px(200)});
|
|
ImGui::Begin("Nearby", nullptr,
|
|
hud_flags | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize);
|
|
panel_heading("Nearby", form.map_minimized);
|
|
if (form.map_minimized) {
|
|
ImGui::End();
|
|
return;
|
|
}
|
|
if (const auto* s = v.cellular_scene; s && s->region_cells != 0)
|
|
ImGui::TextDisabled("%zu cells in this region", s->region_cells);
|
|
auto at = ImGui::GetCursorScreenPos();
|
|
const float available = ImGui::GetContentRegionAvail().x;
|
|
const float side = std::min(available, px(compact ? 96.0F : 178.0F));
|
|
at.x += (available - side) / 2;
|
|
const ImVec2 centre{at.x + side / 2, at.y + side / 2};
|
|
const float r = side * 0.39F;
|
|
auto& list = *ImGui::GetWindowDrawList();
|
|
list.AddCircleFilled(centre, r, IM_COL32(13, 39, 48, 255), 48);
|
|
list.AddCircle(centre, r, IM_COL32(110, 180, 192, 180), 48, 1.0F);
|
|
list.AddCircle(centre, r / 2, IM_COL32(110, 180, 192, 35), 32, 1.0F);
|
|
list.AddLine({centre.x - r, centre.y}, {centre.x + r, centre.y}, IM_COL32(110, 180, 192, 35));
|
|
list.AddLine({centre.x, centre.y - r}, {centre.x, centre.y + r}, IM_COL32(110, 180, 192, 35));
|
|
const auto label = [&](ImVec2 p, const char* text) {
|
|
const auto size = ImGui::CalcTextSize(text);
|
|
list.AddText({p.x - size.x / 2, p.y - size.y / 2}, IM_COL32(196, 224, 238, 255), text);
|
|
};
|
|
label({centre.x, at.y + px(6)}, "+Y");
|
|
label({centre.x, at.y + side - px(6)}, "-Y");
|
|
label({at.x + px(7), centre.y}, "-X");
|
|
label({at.x + side - px(7), centre.y}, "+X");
|
|
// Fixed six millimetre radius, camera centred. Only replicated observations enter.
|
|
const auto marker = [&](double x, double y, ImU32 color, bool pool, bool cell, bool own) {
|
|
const float dx = static_cast<float>((x - scene.camera_centre.x_mm) / 6.0);
|
|
const float dy = static_cast<float>((scene.camera_centre.y_mm - y) / 6.0);
|
|
if (dx * dx + dy * dy > 0.94F * 0.94F)
|
|
return;
|
|
const ImVec2 p{centre.x + dx * r, centre.y + dy * r};
|
|
if (scene.stale)
|
|
color = opacity(color, 85);
|
|
if (pool)
|
|
list.AddCircle(p, px(4), color, 12, 1.0F);
|
|
else if (cell)
|
|
list.AddTriangleFilled({p.x, p.y - px(3)}, {p.x - px(3), p.y + px(3)},
|
|
{p.x + px(3), p.y + px(3)}, color);
|
|
else
|
|
list.AddCircleFilled(p, px(1.6F), color, 6);
|
|
if (own)
|
|
list.AddCircle(p, px(6), color, 12, 1.0F);
|
|
};
|
|
if (const auto* seen = v.cellular_perception) {
|
|
for (const auto& d : seen->deposits) {
|
|
const auto channel = static_cast<std::size_t>(
|
|
std::distance(d.amount_codes.begin(),
|
|
std::max_element(d.amount_codes.begin(), d.amount_codes.end())));
|
|
if (d.amount_codes.at(channel) != 0)
|
|
marker(d.x_um / 1000.0, d.y_um / 1000.0, nutrient_colors.at(channel),
|
|
d.shape == network::CellularDepositShape::pool, false, false);
|
|
}
|
|
for (const auto& p : seen->patches)
|
|
if (p.energy_pj != 0 ||
|
|
std::ranges::any_of(p.matter_fg, [](auto amount) { return amount != 0; }))
|
|
marker(p.x_um / 1000.0 + 0.5, p.y_um / 1000.0 + 0.5, nutrient_colors[0], true,
|
|
false, false);
|
|
}
|
|
if (v.organisms && v.organisms->current())
|
|
for (const auto& cell : v.organisms->current()->cells())
|
|
marker(static_cast<double>(cell.voxel.x) * static_cast<double>(world::cell_pitch_mm) +
|
|
static_cast<double>(cell.x.value) / 1000.0,
|
|
static_cast<double>(cell.voxel.y) * static_cast<double>(world::cell_pitch_mm) +
|
|
static_cast<double>(cell.y.value) / 1000.0,
|
|
IM_COL32(181, 232, 242, 255), false, true,
|
|
v.cellular_play && cell.id == v.cellular_play->life());
|
|
ImGui::Dummy({side, side});
|
|
disabled_wrapped(compact ? "6 mm / local axes" : "6 mm radius / local axes");
|
|
if (scene.stale)
|
|
ImGui::TextColored(amber, "Last observation - stale");
|
|
else
|
|
disabled_wrapped(compact ? "Received view" : "Observed food and cells");
|
|
if (ImGui::IsWindowHovered())
|
|
ImGui::SetTooltip(
|
|
"Camera-centred local map. Unseen space is unknown.\nRings: pools. Dots: nutrients. "
|
|
"Triangles: cells.\nLocal +Y is up; planetary north is not defined.");
|
|
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, form, compact);
|
|
hud_map(v, form, 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
|