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:
dingo
2026-10-01 18:21:53 -04:00
co-authored by Claude Opus 5.5
parent feca07f791
commit 9bb147de82
21 changed files with 1169 additions and 33 deletions
+77
View File
@@ -0,0 +1,77 @@
#include "evo/client/organism_inspector.hpp"
#include "evo/render/organism.hpp"
#include <algorithm>
#include <cmath>
namespace evo::client {
namespace {
double logarithmic(std::uint64_t value, double decades) {
return std::clamp(std::log10(1 + static_cast<double>(value)) / decades, 0.0, 1.0);
}
double linear(std::uint64_t value, std::uint64_t full) {
return std::clamp(static_cast<double>(value) / static_cast<double>(full), 0.0, 1.0);
}
void fill(std::vector<render::Rectangle>& out, render::ScreenBox b, double width, double height,
render::Color color) {
const double left = std::max(b.left, 0.0), top = std::max(b.top, 0.0);
const double right = std::min(b.right, width), bottom = std::min(b.bottom, height);
if (right > left && bottom > top)
out.push_back({static_cast<float>(left), static_cast<float>(top),
static_cast<float>(right - left), static_cast<float>(bottom - top), color});
}
} // namespace
std::array<double, inspector_gauges> inspector_gauge_values(const OrganismCell& cell) noexcept {
const auto& p = cell.phenotype;
return {logarithmic(p.extent, 3),
logarithmic(p.total_mass, 12),
p.total_mass == 0 ? 0.0 : linear(p.membrane_mass, p.total_mass),
logarithmic(p.maintenance, 12),
logarithmic(p.movement_speed, 5),
logarithmic(p.ingestion_rate, 6),
linear(p.conversion_per_thousand, 1000),
linear(cell.growth.realized_per_thousand, 1000),
linear(cell.growth.damage_per_thousand, 1000),
logarithmic(p.thermal_shortfall, 5)};
}
std::optional<std::size_t> pick_organism(const OrganismPresentation& presentation,
const Camera& camera, ScreenPoint pointer) noexcept {
const auto cells = presentation.cells();
for (std::size_t i = cells.size(); i-- > 0;) {
const auto b = render::organism_bounds(cells[i], camera);
if (pointer.x >= b.left && pointer.x < b.right && pointer.y >= b.top &&
pointer.y < b.bottom)
return i;
}
return std::nullopt;
}
std::expected<void, InspectorError> append_inspector(std::vector<render::Rectangle>& out,
std::size_t budget, const OrganismCell& cell,
const Camera& camera) {
if (budget < inspector_rectangles)
return std::unexpected(InspectorError::invalid_budget);
const auto viewport = camera.viewport();
const double width = viewport.width, height = viewport.height;
constexpr render::Color highlight{240, 240, 240, 255};
const auto b = render::organism_bounds(cell, camera);
const render::ScreenBox h{b.left - 3, b.top - 3, b.right + 3, b.bottom + 3};
fill(out, {h.left, h.top, h.right, h.top + 1}, width, height, highlight);
fill(out, {h.left, h.bottom - 1, h.right, h.bottom}, width, height, highlight);
fill(out, {h.left, h.top + 1, h.left + 1, h.bottom - 1}, width, height, highlight);
fill(out, {h.right - 1, h.top + 1, h.right, h.bottom - 1}, width, height, highlight);
const double left = width - 136, top = height - 104;
fill(out, {left, top, width - 8, height - 8}, width, height,
cell.state == OrganismState::dead ? render::Color{70, 60, 52, 255}
: render::Color{24, 28, 36, 255});
const auto values = inspector_gauge_values(cell);
for (std::size_t i = 0; i < values.size(); ++i) {
const double y = top + 8 + 9 * static_cast<double>(i);
fill(out, {left + 8, y, left + 120, y + 6}, width, height, {60, 64, 72, 255});
fill(out, {left + 8, y, left + 8 + 112 * values.at(i), y + 6}, width, height,
{220, 220, 220, 255});
}
return {};
}
} // namespace evo::client