Implement M9.5 biology-derived organism rendering and inspector
Add OrganismPresentation cells derived via biology::derive_phenotype with no controller, owner or level fields (pinned by test), so identical biology renders identically for players and NPCs. OrganismLayer reuses the ADR-0080 ordering/freshness semantics; death is a remnant state and removal is absence. Rendering takes an explicit rectangle budget, falls back to body-only detail and marks truncation instead of dropping data. An opt-in rectangle-only hover inspector shows phenotype gauges; ImGui is not adopted. ADR-0081 records the decision; evidence in VALIDATION.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "evo/client/application.hpp"
|
||||
#include "evo/client/organism_inspector.hpp"
|
||||
#include "evo/render/environment.hpp"
|
||||
#include "evo/render/organism.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <charconv>
|
||||
@@ -21,14 +23,50 @@ 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 + 3 host UI rectangles.
|
||||
constexpr std::size_t organism_budget = evo::render::max_rectangles -
|
||||
evo::render::max_environment_rectangles -
|
||||
evo::client::inspector_rectangles - 3;
|
||||
// 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 {
|
||||
std::unique_ptr<evo::world::FieldStore> fields;
|
||||
std::unique_ptr<evo::world::ChunkStore> terrain;
|
||||
std::vector<evo::world::VoxelAddress> footprint;
|
||||
// Static presentation population: phenotypes derive from real genomes, but no
|
||||
// ecology runs here. Two remnants show the dead encoding.
|
||||
std::vector<evo::client::OrganismCell> organisms;
|
||||
std::uint64_t tick{1};
|
||||
};
|
||||
bool add_organism(FixtureAuthority& authority, std::uint64_t id, evo::world::VoxelAddress voxel,
|
||||
std::uint64_t x_um, std::uint64_t y_um) {
|
||||
using evo::biology::Capability;
|
||||
const auto k = static_cast<std::uint32_t>(id);
|
||||
evo::biology::GenomeDraft draft{
|
||||
id,
|
||||
1,
|
||||
1,
|
||||
{},
|
||||
{{Capability::energy_conversion, 200 + 100 * (k % 7), 0}, {Capability::membrane, 10, 0}}};
|
||||
if (k % 3 == 0)
|
||||
draft.capabilities.push_back({Capability::movement, 50, 0});
|
||||
if (k % 2 == 0)
|
||||
draft.capabilities.push_back({Capability::ingestion, 2000, 0});
|
||||
draft.capabilities.push_back({Capability::target_size, 8'000'000, 0});
|
||||
const auto genome = evo::biology::Genome::create(draft);
|
||||
if (!genome)
|
||||
return false;
|
||||
constexpr evo::biology::EnvironmentState temperate{
|
||||
293'150, {{1'000'000'000}, {evo::accounting::Femtograms{1'000'000'000}, {}, {}, {}}}};
|
||||
const auto cell = evo::client::present_organism(
|
||||
id, voxel, {x_um}, {y_um}, *genome, {400 + 100 * (k % 7), k % 5 == 0 ? 300U : 0U},
|
||||
temperate,
|
||||
k == 5 || k == 23 ? evo::client::OrganismState::dead : evo::client::OrganismState::alive);
|
||||
if (!cell)
|
||||
return false;
|
||||
authority.organisms.push_back(*cell);
|
||||
return true;
|
||||
}
|
||||
std::optional<FixtureAuthority> make_authority() {
|
||||
FixtureAuthority authority;
|
||||
std::vector<evo::world::FieldSite> sites;
|
||||
@@ -63,6 +101,17 @@ std::optional<FixtureAuthority> make_authority() {
|
||||
for (const auto voxel : authority.footprint)
|
||||
if (!authority.terrain->load(evo::world::split(voxel, evo::world::base_chunk_edge)->chunk))
|
||||
return std::nullopt;
|
||||
// A 4x4 cluster 60 um apart in voxel (0, 0) for zoomed inspection, then one
|
||||
// organism in every other voxel of the fixture.
|
||||
std::uint64_t id = 1;
|
||||
for (std::uint64_t i = 0; i < 16; ++i)
|
||||
if (!add_organism(authority, id++, {0, 0, fixture_z}, 410000 + 60 * (i % 4),
|
||||
480000 + 60 * (i / 4)))
|
||||
return std::nullopt;
|
||||
for (std::int64_t x = -8; x < 8; x += 2)
|
||||
for (std::int64_t y = -4; y < 4; y += 2)
|
||||
if (!add_organism(authority, id++, {x, y, fixture_z}, 500000, 500000))
|
||||
return std::nullopt;
|
||||
return authority;
|
||||
}
|
||||
// One conserved same-channel water move per authority tick (finite fixture stock).
|
||||
@@ -89,6 +138,13 @@ std::optional<evo::client::EnvironmentPresentation> query(const FixtureAuthority
|
||||
return std::nullopt;
|
||||
return std::move(*presentation);
|
||||
}
|
||||
std::optional<evo::client::OrganismPresentation> organisms(const FixtureAuthority& authority) {
|
||||
auto presentation = evo::client::OrganismPresentation::create(
|
||||
{fixture_identity, authority.tick, 1}, fixture_z, authority.organisms);
|
||||
if (!presentation)
|
||||
return std::nullopt;
|
||||
return std::move(*presentation);
|
||||
}
|
||||
std::optional<evo::render::EnvironmentDisplay> parse_layer(std::string_view name) {
|
||||
using Mode = evo::render::EnvironmentDisplay::Mode;
|
||||
constexpr std::array<std::string_view, evo::world::field_count> names{"water",
|
||||
@@ -117,11 +173,14 @@ bool parse_count(std::string_view value, unsigned limit, unsigned& out) {
|
||||
int main(int argc, char** argv) try {
|
||||
evo::client::Config config;
|
||||
unsigned frames = 0, refresh_every = 1;
|
||||
bool inspect = false;
|
||||
evo::render::EnvironmentDisplay display;
|
||||
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 == "--renderer" && i + 1 < argc)
|
||||
config.renderer = argv[++i];
|
||||
else if (arg == "--frames" && i + 1 < argc) {
|
||||
@@ -138,7 +197,7 @@ int main(int argc, char** argv) try {
|
||||
} else {
|
||||
std::fputs("usage: evo-client [--renderer NAME] [--hidden] [--frames 1..100000]\n"
|
||||
" [--layer water|nitrogen|...|heat|moisture]\n"
|
||||
" [--refresh-every 1..1000]\n",
|
||||
" [--refresh-every 1..1000] [--inspect]\n",
|
||||
stderr);
|
||||
return 2;
|
||||
}
|
||||
@@ -149,6 +208,7 @@ int main(int argc, char** argv) try {
|
||||
return 1;
|
||||
}
|
||||
evo::client::EnvironmentLayer environment;
|
||||
evo::client::OrganismLayer population;
|
||||
auto app = evo::client::Application::open(config);
|
||||
if (!app) {
|
||||
std::fprintf(stderr, "client initialization error=%d\n", static_cast<int>(app.error()));
|
||||
@@ -161,7 +221,8 @@ int main(int argc, char** argv) try {
|
||||
if (!camera)
|
||||
return 1;
|
||||
std::puts("Arrows: pan | wheel: zoom | WASD: intention indicator | Tab: UI capture (orange)");
|
||||
std::puts("Environment chip: green current | amber stale | red no view");
|
||||
std::puts("Status chips (environment, organisms): green current | amber stale | red none;"
|
||||
" magenta marker: organisms truncated");
|
||||
std::vector<evo::render::Rectangle> boxes;
|
||||
std::uint64_t count = 0;
|
||||
auto previous = std::chrono::steady_clock::now();
|
||||
@@ -189,11 +250,14 @@ int main(int argc, char** argv) try {
|
||||
return 1;
|
||||
if ((authority->tick - 1) % refresh_every == 0) {
|
||||
auto next = query(*authority);
|
||||
if (!next || !environment.accept(std::move(*next)))
|
||||
auto cells = organisms(*authority);
|
||||
if (!next || !cells || !environment.accept(std::move(*next)) ||
|
||||
!population.accept(std::move(*cells)))
|
||||
return 1;
|
||||
}
|
||||
if (!environment.observe(
|
||||
{fixture_identity, authority->tick, authority->fields->last_command()}))
|
||||
{fixture_identity, authority->tick, authority->fields->last_command()}) ||
|
||||
!population.observe({fixture_identity, authority->tick, 1}))
|
||||
return 1;
|
||||
}
|
||||
boxes.clear();
|
||||
@@ -214,8 +278,17 @@ int main(int argc, char** argv) try {
|
||||
return 1;
|
||||
// Copied presentation only; clipped to the viewport before float conversion.
|
||||
if (!evo::render::build_environment(boxes, environment.current(),
|
||||
environment.freshness(), *camera, display))
|
||||
environment.freshness(), *camera, display) ||
|
||||
!evo::render::append_organisms(boxes, organism_budget, population.current(),
|
||||
population.freshness(), *camera))
|
||||
return 1;
|
||||
// Engineering inspector: biology gauges for the hovered organism only.
|
||||
if (const auto* shown = population.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;
|
||||
}
|
||||
boxes.push_back({8, 8, 64, 8,
|
||||
(*app)->ui_captured() ? evo::render::Color{240, 140, 32, 255}
|
||||
|
||||
Reference in New Issue
Block a user