Add M9.8c launcher, legend, labelled inspector and click selection
Toolkit-independent launcher, selection, label and outcome-log models with bounded inputs and fixed error text; Dear ImGui overlay in the native adapter with toolkit-first event routing and capture; engineering panels for fixture vs dev region, legend, inspector, session outcomes, notices and dialog. Additive SessionClient::unreachable_attempts() bounds unreachable connects. Docs, CI targets and validation evidence updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+241
-65
@@ -1,7 +1,10 @@
|
||||
#include "evo/client/application.hpp"
|
||||
#include "evo/client/organism_inspector.hpp"
|
||||
#include "evo/client/launcher.hpp"
|
||||
#include "evo/client/selection.hpp"
|
||||
#include "evo/client/ui_state.hpp"
|
||||
#include "evo/render/environment.hpp"
|
||||
#include "evo/render/organism.hpp"
|
||||
#include "panels.hpp"
|
||||
#include "remote_session.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
@@ -24,12 +27,11 @@ constexpr std::int64_t fixture_z = -16000;
|
||||
// incident energy (never opened: missing). Unrequested fields draw hollow outlines.
|
||||
constexpr std::uint32_t fixture_mask = (1U << 0) | (1U << 1) | (1U << 2) | (1U << 7) | (1U << 8);
|
||||
constexpr unsigned frames_per_authority_tick = 60;
|
||||
// Frame composition: environment bound + organisms + inspector + 5 host UI rectangles
|
||||
// (capture bar, intention dot, and in remote mode the connection and intent chips).
|
||||
constexpr std::size_t host_ui_rectangles = 5;
|
||||
constexpr std::size_t organism_budget = evo::render::max_rectangles -
|
||||
evo::render::max_environment_rectangles -
|
||||
evo::client::inspector_rectangles - host_ui_rectangles;
|
||||
// Frame composition: environment bound + organisms + 6 host rectangles (capture bar,
|
||||
// intention dot, 4-sided selection highlight). Text and panels are the toolkit overlay.
|
||||
constexpr std::size_t host_rectangles = 6;
|
||||
constexpr std::size_t organism_budget =
|
||||
evo::render::max_rectangles - evo::render::max_environment_rectangles - host_rectangles;
|
||||
// Local in-memory stand-in for authoritative region views until M9.7. It is never
|
||||
// persisted or published; the client presentation only copies its read-only views.
|
||||
struct FixtureAuthority {
|
||||
@@ -171,28 +173,64 @@ bool parse_count(std::string_view value, unsigned limit, unsigned& out) {
|
||||
const auto [end, error] = std::from_chars(value.data(), value.data() + value.size(), out);
|
||||
return error == std::errc{} && end == value.data() + value.size() && out != 0 && out <= limit;
|
||||
}
|
||||
std::optional<evo::client::ScreenPoint> parse_point(std::string_view value) {
|
||||
const auto comma = value.find(',');
|
||||
unsigned x = 0, y = 0;
|
||||
if (comma == std::string_view::npos || !parse_count(value.substr(0, comma), 32768, x) ||
|
||||
!parse_count(value.substr(comma + 1), 32768, y))
|
||||
return std::nullopt;
|
||||
return evo::client::ScreenPoint{static_cast<double>(x), static_cast<double>(y)};
|
||||
}
|
||||
void outline(std::vector<evo::render::Rectangle>& out, double l, double t, double r, double b,
|
||||
double width, double height) {
|
||||
const auto rect = [&](double x0, double y0, double x1, double y1) {
|
||||
x0 = std::max(x0, 0.0);
|
||||
y0 = std::max(y0, 0.0);
|
||||
x1 = std::min(x1, width);
|
||||
y1 = std::min(y1, height);
|
||||
if (x1 > x0 && y1 > y0)
|
||||
out.push_back({static_cast<float>(x0),
|
||||
static_cast<float>(y0),
|
||||
static_cast<float>(x1 - x0),
|
||||
static_cast<float>(y1 - y0),
|
||||
{255, 255, 255, 255}});
|
||||
};
|
||||
rect(l, t, r, t + 2);
|
||||
rect(l, b - 2, r, b);
|
||||
rect(l, t + 2, l + 2, b - 2);
|
||||
rect(r - 2, t + 2, r, b - 2);
|
||||
}
|
||||
std::uint64_t milliseconds(std::chrono::steady_clock::time_point t) {
|
||||
return static_cast<std::uint64_t>(
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(t.time_since_epoch()).count());
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) try {
|
||||
using evo::client_app::Mode;
|
||||
evo::client::Config config;
|
||||
unsigned frames = 0, refresh_every = 1;
|
||||
bool inspect = false;
|
||||
bool start_fixture = false;
|
||||
std::optional<evo::client::ScreenPoint> scripted_pick;
|
||||
std::string screenshot;
|
||||
evo::render::EnvironmentDisplay display;
|
||||
evo::client_app::RemoteOptions remote_options;
|
||||
evo::client::ConnectForm form;
|
||||
bool connect_now = false;
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
const std::string_view arg{argv[i]};
|
||||
if (arg == "--hidden")
|
||||
config.hidden = true;
|
||||
else if (arg == "--inspect")
|
||||
inspect = true;
|
||||
else if (arg == "--connect" && i + 1 < argc)
|
||||
remote_options.connect = argv[++i];
|
||||
else if (arg == "--server-name" && i + 1 < argc)
|
||||
remote_options.server_name = argv[++i];
|
||||
else if (arg == "--fixture")
|
||||
start_fixture = true;
|
||||
else if (arg == "--connect" && i + 1 < argc) {
|
||||
form.endpoint = argv[++i];
|
||||
connect_now = true;
|
||||
} else if (arg == "--server-name" && i + 1 < argc)
|
||||
form.server_name = argv[++i];
|
||||
else if (arg == "--ca" && i + 1 < argc)
|
||||
remote_options.authority = argv[++i];
|
||||
form.authority_path = argv[++i];
|
||||
else if (arg == "--grants" && i + 1 < argc)
|
||||
remote_options.grants = argv[++i];
|
||||
form.grants_path = argv[++i];
|
||||
else if (arg == "--renderer" && i + 1 < argc)
|
||||
config.renderer = argv[++i];
|
||||
else if (arg == "--frames" && i + 1 < argc) {
|
||||
@@ -206,42 +244,80 @@ int main(int argc, char** argv) try {
|
||||
if (!layer)
|
||||
return 2;
|
||||
display = *layer;
|
||||
} else if (arg == "--pick" && i + 1 < argc) { // Engineering automation only.
|
||||
scripted_pick = parse_point(argv[++i]);
|
||||
if (!scripted_pick)
|
||||
return 2;
|
||||
} else if (arg == "--screenshot" && i + 1 < argc) { // Last frame, as BMP.
|
||||
screenshot = argv[++i];
|
||||
} else {
|
||||
std::fputs("usage: evo-client [--renderer NAME] [--hidden] [--frames 1..100000]\n"
|
||||
" [--fixture | --connect HOST:PORT --server-name NAME "
|
||||
"--ca FILE --grants FILE]\n"
|
||||
" [--layer water|nitrogen|...|heat|moisture]\n"
|
||||
" [--refresh-every 1..1000] [--inspect]\n"
|
||||
" [--connect HOST:PORT --server-name NAME --ca FILE "
|
||||
"--grants FILE]\n",
|
||||
" [--refresh-every 1..1000] [--pick X,Y] "
|
||||
"[--screenshot FILE.bmp --frames N]\n"
|
||||
"Without --fixture or --connect the launcher opens.\n",
|
||||
stderr);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
// Remote mode (M9.7): views and intentions go through a dev session; the local
|
||||
// fixture authority is not created at all.
|
||||
if ((start_fixture && connect_now) || (!screenshot.empty() && frames == 0))
|
||||
return 2;
|
||||
evo::client::Launcher launcher;
|
||||
evo::client::UiState ui;
|
||||
evo::client::Selection selection;
|
||||
evo::client_app::FormBuffers buffers;
|
||||
buffers.load(form);
|
||||
std::optional<evo::client::LaunchError> form_error;
|
||||
std::optional<evo::client_app::RemoteSession> remote;
|
||||
if (remote_options.any()) {
|
||||
if (!evo::client_app::remote_available || !remote_options.complete()) {
|
||||
std::fputs("remote mode needs --connect, --server-name, --ca and --grants "
|
||||
"(and a build with EVO_BUILD_NETWORK)\n",
|
||||
stderr);
|
||||
return 2;
|
||||
}
|
||||
remote = evo::client_app::RemoteSession::open(remote_options);
|
||||
if (!remote) {
|
||||
std::fputs("client session configuration error\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
std::optional<FixtureAuthority> authority;
|
||||
if (!remote) {
|
||||
authority = make_authority();
|
||||
if (!authority) {
|
||||
std::fputs("client environment fixture error\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
evo::client::EnvironmentLayer environment;
|
||||
evo::client::OrganismLayer population;
|
||||
std::optional<std::uint64_t> disconnect_dialog;
|
||||
// Validates the form and opens a fresh session; errors stay in the launcher.
|
||||
const auto connect = [&](const evo::client::ConnectForm& f) {
|
||||
form_error.reset();
|
||||
if constexpr (!evo::client_app::remote_available) {
|
||||
form_error = evo::client::LaunchError::no_session;
|
||||
return false;
|
||||
} else {
|
||||
const auto material = evo::client::load_connect(f);
|
||||
if (!material) {
|
||||
form_error = material.error();
|
||||
return false;
|
||||
}
|
||||
remote = evo::client_app::RemoteSession::open(*material);
|
||||
if (!remote) {
|
||||
form_error = evo::client::LaunchError::endpoint;
|
||||
return false;
|
||||
}
|
||||
return launcher.begin_connect();
|
||||
}
|
||||
};
|
||||
const auto enter_fixture = [&] {
|
||||
if (!authority) {
|
||||
authority = make_authority();
|
||||
if (!authority)
|
||||
return false;
|
||||
}
|
||||
environment.reset();
|
||||
population.reset();
|
||||
selection.clear();
|
||||
launcher.start_fixture();
|
||||
return true;
|
||||
};
|
||||
if (start_fixture && !enter_fixture()) {
|
||||
std::fputs("client environment fixture error\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
if (connect_now && !connect(form)) {
|
||||
std::fprintf(stderr, "client session configuration error: %s\n",
|
||||
std::string{evo::client::launch_error_text(
|
||||
form_error.value_or(evo::client::LaunchError::no_session))}
|
||||
.c_str());
|
||||
return 1;
|
||||
}
|
||||
auto app = evo::client::Application::open(config);
|
||||
if (!app) {
|
||||
std::fprintf(stderr, "client initialization error=%d\n", static_cast<int>(app.error()));
|
||||
@@ -253,9 +329,48 @@ int main(int argc, char** argv) try {
|
||||
{config.width, config.height, config.width, config.height}, {}, 0.05);
|
||||
if (!camera)
|
||||
return 1;
|
||||
std::puts("Arrows: pan | wheel: zoom | WASD: intention indicator | Tab: UI capture (orange)");
|
||||
std::puts("Status chips (environment, organisms): green current | amber stale | red none;"
|
||||
" magenta marker: organisms truncated");
|
||||
const auto mode = [&] {
|
||||
const auto phase = launcher.phase();
|
||||
if (phase == evo::client::LaunchPhase::fixture)
|
||||
return Mode::fixture;
|
||||
if (phase == evo::client::LaunchPhase::connected ||
|
||||
(phase == evo::client::LaunchPhase::connecting && launcher.ever_connected()))
|
||||
return Mode::remote;
|
||||
return Mode::launcher; // Choosing, failed, or the first connection attempt.
|
||||
};
|
||||
const auto shown_environment = [&]() -> const evo::client::EnvironmentLayer* {
|
||||
if (mode() == Mode::fixture)
|
||||
return &environment;
|
||||
if (mode() == Mode::remote && remote)
|
||||
return &remote->environment();
|
||||
return nullptr;
|
||||
};
|
||||
const auto shown_organisms = [&]() -> const evo::client::OrganismLayer* {
|
||||
if (mode() == Mode::fixture)
|
||||
return &population;
|
||||
if (mode() == Mode::remote && remote)
|
||||
return &remote->organisms();
|
||||
return nullptr;
|
||||
};
|
||||
int drawn_organisms = -1;
|
||||
evo::client_app::PanelActions actions;
|
||||
(*app)->set_overlay([&] {
|
||||
evo::client_app::PanelView view;
|
||||
view.mode = mode();
|
||||
view.launcher = &launcher;
|
||||
view.form_error = form_error;
|
||||
view.remote_available = evo::client_app::remote_available;
|
||||
view.environment = shown_environment();
|
||||
view.organisms = shown_organisms();
|
||||
view.selection = &selection;
|
||||
view.ui = &ui;
|
||||
if (remote && view.mode == Mode::remote) {
|
||||
view.remote = remote->status();
|
||||
view.outcomes = &remote->outcomes();
|
||||
}
|
||||
view.visible_organisms = drawn_organisms;
|
||||
actions = evo::client_app::draw_panels(view, buffers, display);
|
||||
});
|
||||
std::vector<evo::render::Rectangle> boxes;
|
||||
std::uint64_t count = 0;
|
||||
auto previous = std::chrono::steady_clock::now();
|
||||
@@ -268,19 +383,50 @@ int main(int argc, char** argv) try {
|
||||
if (state.closed)
|
||||
break;
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
static_cast<void>(ui.advance(milliseconds(now)).has_value()); // Monotonic clock.
|
||||
const double seconds =
|
||||
std::clamp(std::chrono::duration<double>(now - previous).count(), 0.0, 0.1);
|
||||
previous = now;
|
||||
// Panel actions from the previous rendered frame.
|
||||
if (actions.fixture && !enter_fixture())
|
||||
return 1;
|
||||
if ((actions.connect || actions.retry) && connect(buffers.form())) {
|
||||
selection.clear();
|
||||
}
|
||||
if (actions.cancel || actions.back) {
|
||||
remote.reset(); // Drops the connection; its unresolved outcomes are unknown.
|
||||
launcher.cancel();
|
||||
selection.clear();
|
||||
}
|
||||
if (actions.ask_disconnect && !disconnect_dialog)
|
||||
if (const auto id = ui.open_dialog("Disconnect from the dev region?",
|
||||
"Intentions without a final outcome will be "
|
||||
"unknown. Views stop updating."))
|
||||
disconnect_dialog = *id;
|
||||
if (actions.confirm_dialog && actions.confirm_dialog == disconnect_dialog &&
|
||||
ui.close_dialog(*actions.confirm_dialog)) {
|
||||
disconnect_dialog.reset();
|
||||
remote.reset();
|
||||
launcher.cancel();
|
||||
selection.clear();
|
||||
}
|
||||
if (actions.cancel_dialog && ui.close_dialog(*actions.cancel_dialog))
|
||||
disconnect_dialog.reset();
|
||||
if (actions.dismiss_notice)
|
||||
static_cast<void>(ui.dismiss(*actions.dismiss_notice));
|
||||
actions = {};
|
||||
// The launcher and modal dialogs own input: no world movement or selection.
|
||||
(*app)->set_ui_capture(mode() == Mode::launcher || ui.dialog().has_value());
|
||||
const auto navigation = (*app)->take_navigation();
|
||||
// Local input counter; in remote mode the session sets the server tick.
|
||||
const auto intention = (*app)->sample_intention(count);
|
||||
if (!intention)
|
||||
return 1;
|
||||
if (remote)
|
||||
remote->step(now, *intention);
|
||||
if (remote && launcher.phase() != evo::client::LaunchPhase::failed)
|
||||
remote->step(now, *intention, ui, launcher);
|
||||
// The fixture authority advances at its own cadence. Presentations refresh
|
||||
// every N authority ticks; in between the advanced watermark shows as stale.
|
||||
if (!remote && count % frames_per_authority_tick == 0) {
|
||||
if (mode() == Mode::fixture && count % frames_per_authority_tick == 0) {
|
||||
if (count != 0 && !advance(*authority))
|
||||
return 1;
|
||||
if ((authority->tick - 1) % refresh_every == 0) {
|
||||
@@ -295,6 +441,19 @@ int main(int argc, char** argv) try {
|
||||
!population.observe({fixture_identity, authority->tick, 1}))
|
||||
return 1;
|
||||
}
|
||||
const auto* env_layer = shown_environment();
|
||||
const auto* org_layer = shown_organisms();
|
||||
const auto* env = env_layer ? env_layer->current() : nullptr;
|
||||
const auto* orgs = org_layer ? org_layer->current() : nullptr;
|
||||
const auto change = selection.refresh(env, orgs);
|
||||
if (change == evo::client::Selection::Change::organism_gone)
|
||||
static_cast<void>(ui.notify("The selected organism is no longer present.",
|
||||
evo::client::NoticeLevel::info)
|
||||
.has_value());
|
||||
else if (change == evo::client::Selection::Change::cell_gone)
|
||||
static_cast<void>(ui.notify("The selected habitat cell is no longer in view.",
|
||||
evo::client::NoticeLevel::info)
|
||||
.has_value());
|
||||
boxes.clear();
|
||||
if (state.logical_width > 0 && state.logical_height > 0 && state.pixel_width > 0 &&
|
||||
state.pixel_height > 0) {
|
||||
@@ -311,35 +470,52 @@ int main(int argc, char** argv) try {
|
||||
if (auto result = camera->zoom(std::exp2(navigation.wheel / 4), anchor);
|
||||
!result && result.error() != evo::client::CameraError::out_of_range)
|
||||
return 1;
|
||||
const auto& shown_environment = remote ? remote->environment() : environment;
|
||||
const auto& shown_organisms = remote ? remote->organisms() : population;
|
||||
if (navigation.click)
|
||||
selection.pick(*navigation.click, env, orgs, *camera);
|
||||
if (scripted_pick && env != nullptr) {
|
||||
selection.pick(*scripted_pick, env, orgs, *camera);
|
||||
scripted_pick.reset();
|
||||
}
|
||||
// Copied presentation only; clipped to the viewport before float conversion.
|
||||
if (!evo::render::build_environment(boxes, shown_environment.current(),
|
||||
shown_environment.freshness(), *camera, display) ||
|
||||
!evo::render::append_organisms(boxes, organism_budget, shown_organisms.current(),
|
||||
shown_organisms.freshness(), *camera))
|
||||
if (!evo::render::build_environment(
|
||||
boxes, env, env_layer ? env_layer->freshness() : evo::client::Freshness::none,
|
||||
*camera, display))
|
||||
return 1;
|
||||
// Engineering inspector: biology gauges for the hovered organism only.
|
||||
if (const auto* shown = shown_organisms.current(); inspect && shown != nullptr)
|
||||
if (const auto index =
|
||||
evo::client::pick_organism(*shown, *camera, navigation.pointer))
|
||||
if (!evo::client::append_inspector(boxes, evo::client::inspector_rectangles,
|
||||
shown->cells()[*index], *camera))
|
||||
return 1;
|
||||
const auto report = evo::render::append_organisms(
|
||||
boxes, organism_budget, orgs,
|
||||
org_layer ? org_layer->freshness() : evo::client::Freshness::none, *camera);
|
||||
if (!report)
|
||||
return 1;
|
||||
drawn_organisms = static_cast<int>(report->drawn);
|
||||
const double width = state.logical_width, height = state.logical_height;
|
||||
if (const auto* o = selection.organism(orgs)) {
|
||||
const auto b = evo::render::organism_bounds(*o, *camera);
|
||||
outline(boxes, b.left - 3, b.top - 3, b.right + 3, b.bottom + 3, width, height);
|
||||
} else if (const auto* c = selection.cell(env)) {
|
||||
const double pitch = evo::world::cell_pitch_mm;
|
||||
const auto low = camera->world_to_screen({static_cast<double>(c->voxel.x) * pitch,
|
||||
static_cast<double>(c->voxel.y) * pitch});
|
||||
const auto high =
|
||||
camera->world_to_screen({static_cast<double>(c->voxel.x + 1) * pitch,
|
||||
static_cast<double>(c->voxel.y + 1) * pitch});
|
||||
if (low && high)
|
||||
outline(boxes, low->x, high->y, high->x, low->y, width, height);
|
||||
}
|
||||
}
|
||||
boxes.push_back({8, 8, 64, 8,
|
||||
boxes.push_back({8, static_cast<float>(std::max(state.logical_height - 20, 0)), 64, 8,
|
||||
(*app)->ui_captured() ? evo::render::Color{240, 140, 32, 255}
|
||||
: evo::render::Color{64, 180, 140, 255}});
|
||||
boxes.push_back({36 + static_cast<float>(intention->move_x) / 50,
|
||||
48 - static_cast<float>(intention->move_y) / 50,
|
||||
static_cast<float>(std::max(state.logical_height - 48, 0)) -
|
||||
static_cast<float>(intention->move_y) / 50,
|
||||
8,
|
||||
8,
|
||||
{240, 240, 240, 255}});
|
||||
if (remote)
|
||||
remote->status(boxes);
|
||||
const auto frame = evo::render::Frame::create(boxes, {16, 20, 28, 255});
|
||||
if (!frame)
|
||||
return 1;
|
||||
if (!screenshot.empty() && count + 1 == frames && !(*app)->request_screenshot(screenshot))
|
||||
return 2;
|
||||
const auto result = (*app)->present(*frame);
|
||||
if (!result) {
|
||||
std::fprintf(stderr, "client frame error=%d\n", static_cast<int>(result.error()));
|
||||
|
||||
Reference in New Issue
Block a user