Add M9.8d rebindable engineering controls

SDL-free action/HID-key bindings with conflict validation, a staging editor and
a versioned all-or-nothing controls file (ADR-0085). The adapter maps keys
through the bindings, releases and drains on rebinding, and captures the chosen
key ahead of the toolkit and world. The client adds a Controls panel, key hints,
startup loading with a bounded rejection notice, and --controls/--show-controls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-02 11:30:17 -04:00
co-authored by Claude Opus 5.5
parent bb8c2fc359
commit 5cf8709912
23 changed files with 1292 additions and 45 deletions
+94 -1
View File
@@ -14,6 +14,7 @@
#include <cmath>
#include <cstdio>
#include <exception>
#include <filesystem>
#include <memory>
#include <optional>
#include <string_view>
@@ -214,6 +215,8 @@ int main(int argc, char** argv) try {
bool start_fixture = false;
std::optional<evo::client::ScreenPoint> scripted_pick;
std::string screenshot;
std::filesystem::path controls_path; // Empty: per-user settings directory.
bool show_controls = false;
evo::render::EnvironmentDisplay display;
evo::client::ConnectForm form;
bool connect_now = false;
@@ -251,6 +254,12 @@ int main(int argc, char** argv) try {
return 2;
} else if (arg == "--screenshot" && i + 1 < argc) { // Last frame, as BMP.
screenshot = argv[++i];
} else if (arg == "--controls" && i + 1 < argc) {
controls_path = argv[++i];
if (controls_path.empty())
return 2;
} else if (arg == "--show-controls") { // Engineering review: open the panel.
show_controls = true;
} else {
std::fputs("usage: evo-client [--renderer NAME] [--hidden] [--frames 1..100000]\n"
" [--fixture | --connect HOST:PORT --server-name NAME "
@@ -258,6 +267,7 @@ int main(int argc, char** argv) try {
" [--layer water|nitrogen|...|heat|moisture]\n"
" [--refresh-every 1..1000] [--pick X,Y] "
"[--screenshot FILE.bmp --frames N]\n"
" [--controls FILE] [--show-controls]\n"
"Without --fixture or --connect the launcher opens.\n",
stderr);
return 2;
@@ -327,6 +337,29 @@ int main(int argc, char** argv) try {
}
// A minimized native window may start with no drawable area. Adopt the
// native viewport before projecting; until then use the requested size.
// Controls (ADR-0085): an invalid file is reported and left untouched; defaults
// apply until the user saves new bindings.
if (controls_path.empty())
if (const auto dir = evo::client::Application::settings_directory())
controls_path = *dir / "controls-v1.txt";
if (std::error_code missing;
!controls_path.empty() && std::filesystem::exists(controls_path, missing)) {
// Notices expire on the same monotonic clock the loop uses.
static_cast<void>(ui.advance(milliseconds(std::chrono::steady_clock::now())).has_value());
if (const auto loaded = evo::client::load_bindings(controls_path))
(*app)->set_bindings(*loaded);
else
static_cast<void>(
ui.notify("Saved controls rejected: " + evo::client::describe(loaded.error()) +
" Default controls are in use; the file was not changed.",
evo::client::NoticeLevel::warning, 15000)
.has_value());
}
std::optional<evo::client::BindingEditor> editor;
std::optional<evo::client_app::ControlSlot> capturing;
std::optional<evo::client::BindingProblem> controls_problem;
if (show_controls)
editor.emplace((*app)->bindings());
auto camera = evo::client::Camera::create(
{config.width, config.height, config.width, config.height}, {}, 0.05);
if (!camera)
@@ -371,6 +404,10 @@ int main(int argc, char** argv) try {
view.outcomes = &remote->outcomes();
}
view.visible_organisms = drawn_organisms;
view.bindings = &(*app)->bindings();
view.controls = editor ? &*editor : nullptr;
view.capturing = capturing;
view.controls_problem = controls_problem;
actions = evo::client_app::draw_panels(view, buffers, display);
});
std::vector<evo::render::Rectangle> boxes;
@@ -414,9 +451,65 @@ int main(int argc, char** argv) try {
disconnect_dialog.reset();
if (actions.dismiss_notice)
static_cast<void>(ui.dismiss(*actions.dismiss_notice));
if (actions.open_controls && !editor) {
editor.emplace((*app)->bindings());
controls_problem.reset();
}
if (editor) {
if (actions.capture_key && !capturing) {
capturing = actions.capture_key;
controls_problem.reset();
(*app)->begin_key_capture();
}
if (actions.cancel_capture && capturing) {
(*app)->cancel_key_capture();
capturing.reset();
}
if (actions.clear_secondary)
editor->clear_secondary(*actions.clear_secondary);
if (actions.reset_controls) {
editor->reset_defaults();
controls_problem.reset();
}
if (actions.apply_controls) {
if (const auto applied = editor->apply(); !applied) {
controls_problem = applied.error();
} else {
(*app)->set_bindings(*applied); // Releases held actions.
const bool saved = !controls_path.empty() &&
evo::client::save_bindings(*applied, controls_path);
static_cast<void>(
ui.notify(saved ? "Controls saved."
: "Controls apply to this session but could not be saved.",
saved ? evo::client::NoticeLevel::info
: evo::client::NoticeLevel::warning)
.has_value());
editor.reset();
}
}
if (actions.close_controls) {
editor.reset();
controls_problem.reset();
}
if (!editor && capturing) {
(*app)->cancel_key_capture();
capturing.reset();
}
}
// A finished capture (key, Escape or focus loss) updates the draft only.
if (capturing && editor && !(*app)->key_capture_active()) {
if (const auto key = (*app)->take_captured_key();
key && *key != evo::client::escape_key) {
if (auto assigned = editor->assign(capturing->action, capturing->secondary, *key);
!assigned)
controls_problem = assigned.error();
}
capturing.reset();
}
actions = {};
// The launcher and modal dialogs own input: no world movement or selection.
(*app)->set_ui_capture(mode() == Mode::launcher || ui.dialog().has_value());
(*app)->set_ui_capture(mode() == Mode::launcher || ui.dialog().has_value() ||
editor.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);