Upgrade cellular client to v10 with readable play and assisted steering
This commit is contained in:
+50
-41
@@ -1,3 +1,4 @@
|
||||
#include "cellular_scene.hpp"
|
||||
#include "controls_flow.hpp"
|
||||
#include "evo/client/application.hpp"
|
||||
#include "evo/client/launcher.hpp"
|
||||
@@ -33,10 +34,11 @@ constexpr std::uint32_t fixture_mask = (1U << 0) | (1U << 1) | (1U << 2) | (1U <
|
||||
constexpr unsigned frames_per_authority_tick = 60;
|
||||
// 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 + evo::network::max_cellular_perceived_patches;
|
||||
constexpr std::size_t host_rectangles =
|
||||
6 + evo::client_app::patch_rectangles * evo::network::max_cellular_perceived_patches;
|
||||
// M11.3: the cellular arena is millimetres across, far below the metre-scale default
|
||||
// camera; the first view frames this much of it around the own cell.
|
||||
constexpr double cellular_view_mm = 12;
|
||||
constexpr double cellular_view_mm = 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
|
||||
@@ -204,28 +206,6 @@ void marker_box(std::vector<evo::render::Rectangle>& out, double x, double y, bo
|
||||
: own ? evo::render::Color{250, 190, 40, 255}
|
||||
: evo::render::Color{90, 170, 250, 255}});
|
||||
}
|
||||
// A cellular food patch over its true 1 mm footprint (contact means overlapping it), dim so
|
||||
// the cell stays visible on top; zoomed far out it shrinks to a bright marker instead.
|
||||
void patch_box(std::vector<evo::render::Rectangle>& out, evo::client::ScreenPoint low,
|
||||
evo::client::ScreenPoint high, bool stocked, bool selected, double width,
|
||||
double height) {
|
||||
const double minimum = selected ? 5 : 3;
|
||||
const double half_x = std::max((high.x - low.x) / 2, minimum);
|
||||
const double half_y = std::max((low.y - high.y) / 2, minimum);
|
||||
const bool footprint = half_x > 6 && half_y > 6;
|
||||
const double x = (low.x + high.x) / 2, y = (low.y + high.y) / 2;
|
||||
const double x0 = std::max(x - half_x, 0.0), y0 = std::max(y - half_y, 0.0);
|
||||
const double x1 = std::min(x + half_x, width), y1 = std::min(y + half_y, 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),
|
||||
selected ? (footprint ? evo::render::Color{120, 92, 24, 255}
|
||||
: evo::render::Color{250, 190, 40, 255})
|
||||
: stocked ? (footprint ? evo::render::Color{32, 100, 60, 255}
|
||||
: evo::render::Color{80, 220, 130, 255})
|
||||
: footprint ? evo::render::Color{52, 58, 64, 255}
|
||||
: evo::render::Color{115, 125, 135, 255}});
|
||||
}
|
||||
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) {
|
||||
@@ -456,6 +436,7 @@ int main(int argc, char** argv) try {
|
||||
view.remote = remote->status();
|
||||
view.outcomes = &remote->outcomes();
|
||||
view.cellular_perception = remote->cellular_perception();
|
||||
view.cellular_play = &remote->cellular_play();
|
||||
view.cellular_feed_target = cellular_feed_target;
|
||||
}
|
||||
view.visible_organisms = drawn_organisms;
|
||||
@@ -508,23 +489,47 @@ int main(int argc, char** argv) try {
|
||||
disconnect_dialog.reset();
|
||||
if (actions.dismiss_notice)
|
||||
static_cast<void>(ui.dismiss(*actions.dismiss_notice));
|
||||
if (actions.stop_feeding)
|
||||
if (actions.stop_feeding) {
|
||||
cellular_feed_target.reset();
|
||||
if (actions.feed_patch)
|
||||
buffers.cellular_controls.auto_feed = false;
|
||||
}
|
||||
if (actions.feed_patch) {
|
||||
cellular_feed_target = actions.feed_patch;
|
||||
if (auto* remote = host.session(); remote && mode() == Mode::remote)
|
||||
buffers.cellular_controls.auto_feed = false;
|
||||
}
|
||||
if (auto* remote = host.session(); remote && mode() == Mode::remote) {
|
||||
if (actions.cell_action && remote->request_cellular(*actions.cell_action))
|
||||
cellular_feed_target.reset();
|
||||
if (actions.mutation)
|
||||
static_cast<void>(remote->request_cellular(evo::client_app::CellAction::mutation,
|
||||
*actions.mutation));
|
||||
if (actions.restart_life && remote->restart_cellular()) {
|
||||
cellular_feed_target.reset();
|
||||
selection.clear();
|
||||
}
|
||||
if (actions.keep_unknown)
|
||||
remote->keep_cellular_unknown();
|
||||
remote->set_cellular_feed_target(cellular_trial ? cellular_feed_target : std::nullopt);
|
||||
remote->set_cellular_controls(buffers.cellular_controls);
|
||||
}
|
||||
controls.step(actions, **app, ui);
|
||||
actions = {};
|
||||
// The launcher and modal dialogs own input: no world movement or selection.
|
||||
const auto* input_session = host.session();
|
||||
const bool cell_input_blocked = input_session && input_session->cellular_trial() &&
|
||||
(!input_session->cellular_play().fresh() ||
|
||||
input_session->cellular_play().life() == 0 ||
|
||||
input_session->cellular_play().ended().has_value());
|
||||
(*app)->set_ui_capture(mode() == Mode::launcher || ui.dialog().has_value() ||
|
||||
controls.open());
|
||||
controls.open() || cell_input_blocked);
|
||||
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;
|
||||
host.step(now, *intention, ui); // Only while connecting or connected.
|
||||
if (const auto* remote = host.session(); remote && cellular_trial)
|
||||
cellular_feed_target = remote->cellular_feed_target();
|
||||
// M10.5c: the camera follows the server's view until the user moves it; from then
|
||||
// on its centre is the session's interest (the server clamps and filters it).
|
||||
if (auto* remote = host.session(); remote && mode() == Mode::remote) {
|
||||
@@ -581,16 +586,20 @@ int main(int argc, char** argv) try {
|
||||
&evo::client::OrganismCell::id);
|
||||
if (own != cells.end()) {
|
||||
const double pitch = evo::world::cell_pitch_mm;
|
||||
const evo::client::WorldPoint centre{
|
||||
static_cast<double>(own->voxel.x) * pitch +
|
||||
static_cast<double>(own->x.value) / 1000,
|
||||
static_cast<double>(own->voxel.y) * pitch +
|
||||
static_cast<double>(own->y.value) / 1000};
|
||||
evo::client::WorldPoint centre{static_cast<double>(own->voxel.x) * pitch +
|
||||
static_cast<double>(own->x.value) / 1000,
|
||||
static_cast<double>(own->voxel.y) * pitch +
|
||||
static_cast<double>(own->y.value) /
|
||||
1000};
|
||||
const double scale =
|
||||
cellular_framed ? camera->units_per_mm()
|
||||
: static_cast<double>(std::min(state.logical_width,
|
||||
state.logical_height)) /
|
||||
cellular_view_mm;
|
||||
// Keep the followed cell in the visible arena beside the journal.
|
||||
const double shift = state.logical_width < 880 ? 171.0 : -10.0;
|
||||
centre.x_mm -= shift / scale;
|
||||
centre.y_mm += 29.0 / scale;
|
||||
if (auto moved =
|
||||
evo::client::Camera::create(camera->viewport(), centre, scale)) {
|
||||
*camera = *moved;
|
||||
@@ -632,14 +641,14 @@ int main(int argc, char** argv) try {
|
||||
{(static_cast<double>(patch.x_um) + 1000) / 1000,
|
||||
(static_cast<double>(patch.y_um) + 1000) / 1000});
|
||||
if (low && high)
|
||||
patch_box(boxes, *low, *high,
|
||||
patch.energy_pj != 0 ||
|
||||
std::ranges::any_of(patch.matter_fg,
|
||||
[](auto v) { return v != 0; }),
|
||||
cellular_feed_target &&
|
||||
cellular_feed_target->first == patch.x_um &&
|
||||
cellular_feed_target->second == patch.y_um,
|
||||
width, height);
|
||||
evo::client_app::patch_box(
|
||||
boxes, *low, *high,
|
||||
patch.energy_pj != 0 ||
|
||||
std::ranges::any_of(patch.matter_fg,
|
||||
[](auto v) { return v != 0; }),
|
||||
cellular_feed_target && cellular_feed_target->first == patch.x_um &&
|
||||
cellular_feed_target->second == patch.y_um,
|
||||
width, height, !remote->cellular_play().fresh());
|
||||
}
|
||||
const auto report = evo::render::append_organisms(
|
||||
boxes, organism_budget, orgs,
|
||||
|
||||
Reference in New Issue
Block a user