Files
aevolution/tests/client_panels.cpp
T
dingoandClaude Opus 5.5 521372607a
Foundation / checks (checks) (push) Successful in 45m19s
Foundation / checks (deploy) (push) Successful in 3m45s
Foundation / checks (ecs) (push) Successful in 2m16s
Foundation / checks (network) (push) Successful in 19m17s
Foundation / checks (postgres) (push) Successful in 43m23s
Foundation / checks (tsan) (push) Successful in 11m39s
Foundation / checks (client) (push) Successful in 17m3s
Foundation / postgres-tools (push) Successful in 29s
Foundation / server-image (push) Successful in 3m8s
Foundation / image (push) Successful in 3m25s
Cells face where they move; a click outside closes the evolution window
The microscope view orients each cell along its last movement of at least 20 um, with
the flagella trailing, easing into turns. The heading is projected with the current
camera, so panning never turns a cell; a cell that has not moved keeps its seeded
orientation. A left click outside the evolution window closes it (the offer stays;
E or the callout reopens it), except on the frame it opens.

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

611 lines
27 KiB
C++

// M9.8c: the production engineering panels through the real adapter (dummy driver,
// software renderer, pinned toolkit). Notices fit their fixed-width window with a
// visible close button; clicking it (move + press + release in one batch, no settling
// frame) dismisses exactly that notice and never reaches the world.
#include "cellular_scene.hpp"
#include "controls_flow.hpp"
#include "evo/client/application.hpp"
#include "evo/render/organism.hpp"
#include "panels.hpp"
#include <SDL3/SDL.h>
#include <array>
#include <cstdio>
#include <filesystem>
#include <imgui.h>
#include <imgui_internal.h>
#include <source_location>
#include <stdexcept>
#include <string>
#include <vector>
namespace {
using namespace evo;
using namespace evo::client;
using namespace evo::client_app;
void check(bool ok, std::source_location at = std::source_location::current()) {
if (!ok)
throw std::runtime_error("client panels line " + std::to_string(at.line()));
}
#define CHECK(...) check(static_cast<bool>(__VA_ARGS__))
template <class T> const T& required(const std::optional<T>& value) {
if (!value)
throw std::runtime_error("missing panel test value");
return *value;
}
SDL_Window* window() {
int count{};
SDL_Window** windows = SDL_GetWindows(&count);
SDL_Window* result = count == 1 ? windows[0] : nullptr;
SDL_free(static_cast<void*>(windows));
CHECK(result);
return result;
}
void mouse(SDL_WindowID id, SDL_EventType type, float x, float y) {
SDL_Event event{};
event.type = type;
if (type == SDL_EVENT_MOUSE_MOTION) {
event.motion.windowID = id;
event.motion.x = x;
event.motion.y = y;
} else {
event.button.windowID = id;
event.button.button = SDL_BUTTON_LEFT;
event.button.down = type == SDL_EVENT_MOUSE_BUTTON_DOWN;
event.button.clicks = 1;
event.button.x = x;
event.button.y = y;
}
CHECK(SDL_PushEvent(&event));
}
ImGuiWindow* notice_window(std::uint64_t id) {
return ImGui::FindWindowByName((notice_window_prefix + std::to_string(id)).c_str());
}
void notices() {
const std::array<render::Rectangle, 1> boxes{{{0, 0, 32, 32, {40, 40, 40, 255}}}};
auto frame = render::Frame::create(boxes);
CHECK(frame);
auto opened = Application::open({960, 640, false, "software"});
CHECK(opened);
auto app = std::move(*opened);
const auto id = SDL_GetWindowID(window());
SDL_Event focus{};
focus.type = SDL_EVENT_WINDOW_FOCUS_GAINED;
focus.window.windowID = id;
CHECK(SDL_PushEvent(&focus) && app->poll_events());
UiState ui;
EnvironmentLayer environment;
OrganismLayer organisms;
Selection selection;
Launcher launcher;
FormBuffers form;
render::EnvironmentDisplay display;
PanelView view;
view.mode = Mode::fixture;
view.launcher = &launcher;
view.environment = &environment;
view.organisms = &organisms;
view.selection = &selection;
view.ui = &ui;
std::optional<std::uint64_t> dismissed;
app->set_overlay([&] {
if (const auto a = draw_panels(view, form, display); a.dismiss_notice)
dismissed = a.dismiss_notice;
});
// The application's real notices plus a maximal 240-byte message of wide glyphs.
const std::string longest(UiState::max_text, 'W');
std::vector<std::uint64_t> ids;
for (const auto* text :
{"Connected to the dev region (fresh baseline).", "Connection lost; views are stale.",
"Session event backlog; reconnecting after draining.", longest.c_str()}) {
const auto made = ui.notify(text, NoticeLevel::warning, 600000);
CHECK(made);
ids.push_back(*made);
}
for (int i = 0; i < 2; ++i)
CHECK(app->poll_events() && app->present(*frame) == Step::rendered);
const auto& style = ImGui::GetStyle();
for (const auto n : ids) {
const auto* w = notice_window(n);
CHECK(w != nullptr && w->Active);
// Nothing wider than the window: no clipped text, no horizontal scrolling.
CHECK(w->ContentSize.x <= w->Size.x - (2 * style.WindowPadding.x) + 0.5F);
CHECK(w->ScrollMax.x == 0 && w->Pos.x >= 0 && w->Pos.x + w->Size.x <= 960);
CHECK(w->Pos.y >= 0 && w->Pos.y + w->Size.y <= 640);
}
// Close the longest notice: pointer last over the world, then one batch.
const auto* target = notice_window(ids.back());
const float x = target->Pos.x + target->Size.x - style.WindowPadding.x - style.CellPadding.x -
(notice_close_width / 2);
const float y = target->Pos.y + style.WindowPadding.y + style.CellPadding.y +
style.FramePadding.y + (ImGui::GetFontSize() / 2);
mouse(id, SDL_EVENT_MOUSE_MOTION, 480, 320);
CHECK(app->poll_events() && app->present(*frame) == Step::rendered);
static_cast<void>(app->take_navigation());
mouse(id, SDL_EVENT_MOUSE_MOTION, x, y);
mouse(id, SDL_EVENT_MOUSE_BUTTON_DOWN, x, y);
mouse(id, SDL_EVENT_MOUSE_BUTTON_UP, x, y);
CHECK(app->poll_events() && !app->take_navigation().click);
for (int i = 0; i < 5 && !dismissed; ++i)
CHECK(app->present(*frame) == Step::rendered && app->poll_events());
CHECK(dismissed == ids.back() && ui.dismiss(*dismissed) && ui.notices().size() == 3);
CHECK(!app->take_navigation().click);
CHECK(app->present(*frame) == Step::rendered && app->poll_events());
const auto* gone = notice_window(ids.back());
CHECK(gone == nullptr || !gone->Active);
for (std::size_t k = 0; k + 1 < ids.size(); ++k)
CHECK(notice_window(ids[k])->Active);
// A full stack stays inside the lower part of the viewport and counts the rest.
for (int k = 0; k < 8; ++k)
CHECK(ui.notify(longest, NoticeLevel::info, 600000));
for (int i = 0; i < 2; ++i)
CHECK(app->present(*frame) == Step::rendered && app->poll_events());
for (const auto& n : ui.notices())
if (const auto* w = notice_window(n.id); w != nullptr && w->Active)
CHECK(w->Pos.y >= 0 && w->Pos.y + w->Size.y <= 640);
const auto* more = ImGui::FindWindowByName("##evicted");
CHECK(more != nullptr && more->Active && more->Pos.y >= 0);
}
// M9.8d controls panel: fits the viewport, a slot button requests key capture for that
// slot without a world click, and the chosen key reaches neither toolkit nor world.
void controls_panel() {
const std::array<render::Rectangle, 1> boxes{{{0, 0, 32, 32, {40, 40, 40, 255}}}};
auto frame = render::Frame::create(boxes);
CHECK(frame);
auto opened = Application::open({960, 640, false, "software"});
CHECK(opened);
auto app = std::move(*opened);
const auto id = SDL_GetWindowID(window());
SDL_Event focus{};
focus.type = SDL_EVENT_WINDOW_FOCUS_GAINED;
focus.window.windowID = id;
CHECK(SDL_PushEvent(&focus) && app->poll_events());
UiState ui;
EnvironmentLayer environment;
OrganismLayer organisms;
Selection selection;
Launcher launcher;
FormBuffers form;
render::EnvironmentDisplay display;
BindingEditor editor{app->bindings()};
PanelView view;
view.mode = Mode::fixture;
view.launcher = &launcher;
view.environment = &environment;
view.organisms = &organisms;
view.selection = &selection;
view.ui = &ui;
view.bindings = &app->bindings();
view.controls = &editor;
PanelActions last;
app->set_overlay([&] {
const auto a = draw_panels(view, form, display);
if (a.capture_key)
last.capture_key = a.capture_key;
last.apply_controls = last.apply_controls || a.apply_controls;
});
app->set_ui_capture(true); // As the host does while the panel is open.
for (int i = 0; i < 2; ++i)
CHECK(app->poll_events() && app->present(*frame) == Step::rendered);
const auto* w = ImGui::FindWindowByName("Controls");
CHECK(w != nullptr && w->Active);
const auto& style = ImGui::GetStyle();
CHECK(w->ContentSize.x <= w->Size.x - (2 * style.WindowPadding.x) + 0.5F);
CHECK(w->Pos.x >= 0 && w->Pos.y >= 0 && w->Pos.x + w->Size.x <= 960 &&
w->Pos.y + w->Size.y <= 640);
// Probe down the primary column until a slot button answers: the first row is
// Move left. Every probe is one batch (move, press, release).
const float x =
w->Pos.x + w->Size.x - style.WindowPadding.x - 150 - (2 * style.CellPadding.x) - 50;
for (float y = w->Pos.y + 20; y < w->Pos.y + w->Size.y && !last.capture_key; y += 4) {
mouse(id, SDL_EVENT_MOUSE_MOTION, x, y);
mouse(id, SDL_EVENT_MOUSE_BUTTON_DOWN, x, y);
mouse(id, SDL_EVENT_MOUSE_BUTTON_UP, x, y);
CHECK(app->poll_events() && !app->take_navigation().click);
for (int i = 0; i < 3 && !last.capture_key; ++i)
CHECK(app->present(*frame) == Step::rendered && app->poll_events());
}
CHECK(last.capture_key == ControlSlot{Action::move_left, false} && !last.apply_controls);
// The host arms capture; the chosen key is consumed before the toolkit.
view.capturing = last.capture_key;
app->begin_key_capture();
SDL_Event key{};
key.type = SDL_EVENT_KEY_DOWN;
key.key.windowID = id;
key.key.scancode = SDL_SCANCODE_J;
key.key.key = SDL_GetKeyFromScancode(SDL_SCANCODE_J, SDL_KMOD_NONE, false);
key.key.down = true;
CHECK(SDL_PushEvent(&key) && app->poll_events());
CHECK(app->take_captured_key() == KeyCode{SDL_SCANCODE_J});
CHECK(editor.assign(Action::move_left, false, SDL_SCANCODE_J));
view.capturing.reset();
CHECK(app->present(*frame) == Step::rendered && !ImGui::IsKeyDown(ImGuiKey_J));
CHECK(editor.apply() && editor.apply()->action(SDL_SCANCODE_J) == Action::move_left);
CHECK(!app->take_navigation().click);
}
// M9.8d review: host rehearsal through the real adapter, production panels and the
// host's ControlsFlow: click a slot, a conflicting key is refused, choose J, Apply
// writes the file; a restarted application loads it and J moves left.
SDL_Event key_event(SDL_WindowID id, SDL_Scancode scancode, bool down) {
SDL_Event event{};
event.type = down ? SDL_EVENT_KEY_DOWN : SDL_EVENT_KEY_UP;
event.key.windowID = id;
event.key.scancode = scancode;
event.key.key = SDL_GetKeyFromScancode(scancode, SDL_KMOD_NONE, false);
event.key.down = down;
return event;
}
void apply_save_restart() {
const auto dir = std::filesystem::temp_directory_path() / "evo-controls-rehearsal";
std::filesystem::remove_all(dir);
std::filesystem::create_directories(dir);
const auto file = dir / "controls-v1.txt";
const std::array<render::Rectangle, 1> boxes{{{0, 0, 32, 32, {40, 40, 40, 255}}}};
auto frame = render::Frame::create(boxes);
CHECK(frame);
{
auto opened = Application::open({960, 640, false, "software"});
CHECK(opened);
auto app = std::move(*opened);
const auto id = SDL_GetWindowID(window());
SDL_Event focus{};
focus.type = SDL_EVENT_WINDOW_FOCUS_GAINED;
focus.window.windowID = id;
CHECK(SDL_PushEvent(&focus) && app->poll_events());
UiState ui;
EnvironmentLayer environment;
OrganismLayer organisms;
Selection selection;
Launcher launcher;
FormBuffers form;
render::EnvironmentDisplay display;
ControlsFlow flow{file};
flow.load(*app, ui); // No file yet: defaults.
CHECK(app->bindings() == Bindings::defaults());
flow.show(*app);
PanelActions pending;
app->set_overlay([&] {
PanelView view;
view.mode = Mode::fixture;
view.launcher = &launcher;
view.environment = &environment;
view.organisms = &organisms;
view.selection = &selection;
view.ui = &ui;
view.bindings = &app->bindings();
flow.fill(view);
pending = draw_panels(view, form, display);
});
// The host's frame order: poll, panel actions of the last frame, capture, draw.
const auto host_frame = [&] {
CHECK(app->poll_events());
flow.step(pending, *app, ui);
pending = {};
app->set_ui_capture(flow.open());
CHECK(!app->take_navigation().click && app->present(*frame) == Step::rendered);
};
for (int i = 0; i < 2; ++i)
host_frame();
const auto* w = ImGui::FindWindowByName("Controls");
CHECK(w != nullptr && w->Active);
const auto& style = ImGui::GetStyle();
// Probe one-batch clicks until `done` reports the intended widget answered.
const auto probe = [&](float x, float y0, float y1, float dy, const auto& done) {
for (float y = y0; (dy > 0 ? y < y1 : y > y1); y += dy) {
mouse(id, SDL_EVENT_MOUSE_MOTION, x, y);
mouse(id, SDL_EVENT_MOUSE_BUTTON_DOWN, x, y);
mouse(id, SDL_EVENT_MOUSE_BUTTON_UP, x, y);
for (int i = 0; i < 3; ++i) {
host_frame();
if (done())
return true;
}
}
return false;
};
const float primary_x =
w->Pos.x + w->Size.x - style.WindowPadding.x - 150 - (2 * style.CellPadding.x) - 50;
CHECK(probe(primary_x, w->Pos.y + 20, w->Pos.y + w->Size.y, 4,
[&] { return app->key_capture_active(); }));
// Up is Pan up's key: refused, the draft keeps A. Then arm again and choose J.
auto up = key_event(id, SDL_SCANCODE_UP, true);
CHECK(SDL_PushEvent(&up));
host_frame();
CHECK(!app->key_capture_active());
PanelView shown;
flow.fill(shown);
CHECK(shown.controls != nullptr && shown.controls->draft()[0].primary == SDL_SCANCODE_A);
CHECK(shown.controls_problem && shown.controls_problem->error == BindingError::conflict &&
shown.controls_problem->other == Action::pan_up);
auto up_release = key_event(id, SDL_SCANCODE_UP, false);
CHECK(SDL_PushEvent(&up_release));
host_frame();
CHECK(probe(primary_x, w->Pos.y + 20, w->Pos.y + w->Size.y, 4,
[&] { return app->key_capture_active(); }));
auto j = key_event(id, SDL_SCANCODE_J, true);
auto j_release = key_event(id, SDL_SCANCODE_J, false);
CHECK(SDL_PushEvent(&j) && SDL_PushEvent(&j_release));
host_frame();
CHECK(!app->key_capture_active() && flow.open() && !std::filesystem::exists(file));
// Apply sits at the bottom left of the panel.
CHECK(probe(w->Pos.x + style.WindowPadding.x + 40, w->Pos.y + w->Size.y - 6, w->Pos.y, -4,
[&] { return !flow.open(); }));
CHECK(app->bindings().action(SDL_SCANCODE_J) == Action::move_left);
CHECK(!app->bindings().action(SDL_SCANCODE_A));
CHECK(std::filesystem::exists(file) && !ui.notices().empty() &&
ui.notices().back().text == "Controls saved.");
}
// Restart: a new application loads the saved file; J moves left after a press.
auto opened = Application::open({320, 240, false, "software"});
CHECK(opened);
auto app = std::move(*opened);
const auto id = SDL_GetWindowID(window());
UiState ui;
ControlsFlow{file}.load(*app, ui);
CHECK(ui.notices().empty() && app->bindings().action(SDL_SCANCODE_J) == Action::move_left);
SDL_Event focus{};
focus.type = SDL_EVENT_WINDOW_FOCUS_GAINED;
focus.window.windowID = id;
CHECK(SDL_PushEvent(&focus) && app->poll_events() && app->poll_events());
auto j = key_event(id, SDL_SCANCODE_J, true);
CHECK(SDL_PushEvent(&j) && app->poll_events());
const auto intention = app->sample_intention(1);
CHECK(intention && intention->move_x == -1000);
std::filesystem::remove_all(dir);
}
void cellular_panels(const std::filesystem::path& review) {
for (const auto size : {std::pair{960, 640}, std::pair{1280, 800}, std::pair{640, 480}}) {
const auto [width, height] = size;
auto opened = Application::open({width, height, false, "software"});
CHECK(opened);
auto app = std::move(*opened);
const auto id = SDL_GetWindowID(window());
SDL_Event focus{};
focus.type = SDL_EVENT_WINDOW_FOCUS_GAINED;
focus.window.windowID = id;
CHECK(SDL_PushEvent(&focus) && app->poll_events());
std::vector<render::Rectangle> boxes{
{0, 0, static_cast<float>(width), static_cast<float>(height), {8, 19, 25, 255}}};
const auto camera =
Camera::create({width, height, width, height}, {width < 880 ? 0.29 : 2.1, 3.29}, 100);
CHECK(camera);
for (int x = 0; x < 5; ++x)
for (int y = 0; y < 6; ++y) {
const auto low =
camera->world_to_screen({static_cast<double>(x), static_cast<double>(y)});
const auto high = camera->world_to_screen({x + 1.0, y + 1.0});
CHECK(low && high);
patch_box(boxes, *low, *high, (x + y) % 4 != 0 && !(x == 2 && y == 3),
(x + y) % 3 != 0, x == 2 && y == 3, width, height);
}
OrganismCell organism;
organism.id = 901;
organism.x = {2200};
organism.y = {3200};
organism.phenotype.extent = 300;
organism.phenotype.total_mass = 10000;
organism.phenotype.structural_mass = 9000;
organism.phenotype.membrane_mass = 1000;
organism.phenotype.conversion_per_thousand = 650;
organism.phenotype.movement_speed = 500;
organism.phenotype.ingestion_rate = 400;
organism.growth.realized_per_thousand = 1000;
const auto population =
OrganismPresentation::create({{100, 1}, 102, 1}, 0, std::array{organism});
CHECK(population);
CHECK(render::append_organisms(boxes, 100, &*population, Freshness::current, *camera));
const auto frame = render::Frame::create(boxes);
CHECK(frame);
UiState ui;
Launcher launch;
Selection selection;
EnvironmentLayer environment;
OrganismLayer organisms;
CellularPlay play;
play.initialize(100);
play.connected();
network::CellularLifeDiagnostics diagnostics;
diagnostics.reserve_energy_pj = 248000;
diagnostics.reserve_matter_fg = {15000, 2400, 800, 6000};
diagnostics.has_tick_effects = true;
diagnostics.maintenance_cost_pj = 80;
diagnostics.movement_cost_pj = 20;
diagnostics.movement = network::CellularMovementResult::moved;
diagnostics.intake = network::CellularIntakeResult::acquired;
diagnostics.engulf = network::CellularEngulfResult::membrane_too_thick;
network::CellularPerception perception{
102,
901,
{{1000, 2000, 50000, {100, 20, 10, 40}}, {2000, 3000, 0, {90, 20, 8, 30}}},
diagnostics};
play.observe(perception);
play.observe_offer(network::CellularMutationOffer{
102,
901,
1,
100,
{{3, 2, 0, 500, 1600, 22000, 1200, {100, 20, 10, 40}},
{5, 1, 0, 2, 2000, 26000, 5000, {500, 80, 20, 120}},
{8, 3, 0, 400, 1800, 24000, 300000, {400, 60, 20, 100}}}});
FormBuffers form;
render::EnvironmentDisplay display;
PanelView view;
view.mode = Mode::remote;
view.launcher = &launch;
view.environment = &environment;
view.organisms = &organisms;
view.selection = &selection;
view.ui = &ui;
view.bindings = &app->bindings();
view.cellular_perception = &perception;
view.cellular_play = &play;
view.remote.emplace();
view.remote->phase = "connected";
view.remote->cellular_trial = true;
view.remote->server_tick = 102;
view.remote->region = 4;
// 2026-10-16 microscope view: patches as granules and cells, drawn under the HUD.
CellularScene scene;
scene.patches.push_back({200, 200, 60, {50000, 100, 20, 10, 40}, false, false, 1});
scene.patches.push_back({400, 260, 60, {0, 90, 0, 8, 0}, true, false, 2});
scene.cells.push_back({300, 300, 24, 2.5F, 2, 3, true, false, false, 901});
scene.cells.push_back({500, 220, 14, 4.0F, 0, 2, false, true, false, 77});
view.cellular_scene = &scene;
PanelActions action;
app->set_overlay([&] { action = draw_panels(view, form, display); });
const auto draw = [&] {
CHECK(app->poll_events() && app->present(*frame) == Step::rendered);
};
for (int i = 0; i < 3; ++i)
draw();
// Every HUD window fits the viewport without sideways scrolling.
const auto fits = [&](const ImGuiWindow* w) {
return w && w->Active && w->ScrollMax.x == 0 && w->Pos.x >= 0 && w->Pos.y >= 0 &&
w->Pos.x + w->Size.x <= static_cast<float>(width) &&
w->Pos.y + w->Size.y <= static_cast<float>(height);
};
auto* vitals = ImGui::FindWindowByName("Vitals");
auto* dock = ImGui::FindWindowByName("Actions");
CHECK(fits(vitals) && fits(dock) && fits(ImGui::FindWindowByName("##mode")));
CHECK(fits(ImGui::FindWindowByName("##mutation"))); // The offer callout.
if (width >= 880)
CHECK(fits(ImGui::FindWindowByName("Field notes")));
if (!review.empty()) {
std::filesystem::create_directories(review);
auto later = perception;
++later.tick;
later.diagnostics->reserve_energy_pj -= 50;
play.observe(later);
view.cellular_feed_target = {{2000, 3000}};
CHECK(app->request_screenshot(
(review / ("cellular-" + std::to_string(width) + ".bmp")).string()));
draw();
const auto saved_offer = play.offer();
play.disconnected();
play.connected();
++perception.tick;
play.observe(perception);
play.observe_offer(saved_offer);
view.cellular_feed_target.reset();
for (int i = 0; i < 3; ++i)
draw();
}
if (width != 960)
continue;
// E opens the mutation window over the world.
SDL_Event e_key{};
e_key.type = SDL_EVENT_KEY_DOWN;
e_key.key.windowID = id;
e_key.key.scancode = SDL_SCANCODE_E;
e_key.key.key = SDLK_E;
e_key.key.down = true;
CHECK(SDL_PushEvent(&e_key));
draw();
auto e_up = e_key;
e_up.type = SDL_EVENT_KEY_UP;
e_up.key.down = false;
CHECK(SDL_PushEvent(&e_up));
for (int i = 0; i < 3; ++i)
draw();
CHECK(form.evolution_open);
const auto* evolution = ImGui::FindWindowByName("Evolution");
CHECK(fits(evolution));
if (!review.empty()) {
CHECK(app->request_screenshot((review / "cellular-evolution.bmp").string()));
draw();
}
// A click outside closes it; E opens it again.
const float outside_x = evolution->Pos.x / 2;
const float outside_y = evolution->Pos.y + evolution->Size.y / 2;
mouse(id, SDL_EVENT_MOUSE_MOTION, outside_x, outside_y);
mouse(id, SDL_EVENT_MOUSE_BUTTON_DOWN, outside_x, outside_y);
mouse(id, SDL_EVENT_MOUSE_BUTTON_UP, outside_x, outside_y);
for (int i = 0; i < 3; ++i)
draw();
CHECK(!form.evolution_open);
(void)app->take_navigation();
CHECK(SDL_PushEvent(&e_key));
draw();
CHECK(SDL_PushEvent(&e_up));
for (int i = 0; i < 3; ++i)
draw();
CHECK(form.evolution_open);
// Click the first production choice. Pointer ownership prevents world selection.
const auto probe = [&](const ImGuiWindow* panel, float x_fraction, const auto& done) {
const float x = panel->Pos.x + panel->Size.x * x_fraction;
// Every button is at least a frame high. Half-frame spacing still hits
// each button, including disabled ones, without rendering every five pixels.
const int stride = std::max(1, static_cast<int>(ImGui::GetFrameHeight() / 2));
for (int offset = 8; static_cast<float>(offset) < panel->Size.y - 10;
offset += stride) {
const float y = panel->Pos.y + static_cast<float>(offset);
mouse(id, SDL_EVENT_MOUSE_MOTION, x, y);
mouse(id, SDL_EVENT_MOUSE_BUTTON_DOWN, x, y);
mouse(id, SDL_EVENT_MOUSE_BUTTON_UP, x, y);
CHECK(app->poll_events() && !app->take_navigation().click);
for (int i = 0; i < 3; ++i) {
CHECK(app->present(*frame) == Step::rendered && app->poll_events());
if (done())
return true;
}
}
return false;
};
auto depleted = diagnostics;
depleted.reserve_energy_pj = 0;
perception.diagnostics = depleted;
draw();
// An unaffordable candidate cannot be chosen; declining (operator 0) still can.
const auto chose_candidate = [&] {
return action.mutation.has_value() && action.mutation->operator_id != 0;
};
CHECK(!probe(evolution, 0.17F, chose_candidate));
action.mutation.reset();
CHECK(probe(evolution, 0.17F, [&] { return action.mutation.has_value(); }));
CHECK(action.mutation == MutationChoice{901, 1, 100, 0});
action.mutation.reset();
perception.diagnostics = diagnostics;
draw();
CHECK(probe(evolution, 0.17F, chose_candidate));
CHECK(action.mutation == MutationChoice{901, 1, 100, 3});
CHECK(play.queue(CellAction::mutation, 102, required(action.mutation)));
const auto mutation_id = required(play.pending()).id;
draw();
CHECK(!probe(evolution, 0.17F, [&] { return action.mutation.has_value(); }));
play.outcome({mutation_id, network::ActionResult::committed, 103, 5});
draw();
bool budded = false;
for (float fraction = 0.1F; fraction < 1.0F && !budded; fraction += 0.1F)
budded = probe(dock, fraction, [&] { return action.cell_action == CellAction::bud; });
CHECK(budded);
play.observe_end({104, 901, network::CellularDeathReason::engulfed});
perception = {104, 0, {}, {}};
play.observe(perception);
draw();
if (!review.empty()) {
CHECK(app->request_screenshot((review / "cellular-death.bmp").string()));
draw();
}
CHECK(probe(evolution, 0.17F, [&] { return action.restart_life; }));
CHECK(play.restart());
draw();
CHECK(!probe(evolution, 0.17F, [&] { return action.restart_life; }));
}
}
} // namespace
int main(int argc, char** argv) try {
notices();
controls_panel();
apply_save_restart();
cellular_panels(argc == 2 ? std::filesystem::path{argv[1]} : std::filesystem::path{});
std::puts("client panel tests passed");
return 0;
} catch (const std::exception& e) {
std::fprintf(stderr, "%s: %s\n", e.what(), SDL_GetError());
return 1;
}