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
-1
@@ -17,7 +17,7 @@
|
||||
{"name": "analysis", "configurePreset": "analysis"},
|
||||
{"name": "asan", "configurePreset": "asan"},
|
||||
{"name": "tsan", "configurePreset": "tsan"},
|
||||
{"name": "client", "configurePreset": "client", "targets": ["evo-client", "evo-client-lifecycle-tests", "evo-client-environment-tests"]},
|
||||
{"name": "client", "configurePreset": "client", "targets": ["evo-client", "evo-client-lifecycle-tests", "evo-client-environment-tests", "evo-client-organism-tests"]},
|
||||
{"name": "client-probe", "configurePreset": "client-probe", "targets": ["evo-client-probe"]}
|
||||
],
|
||||
"testPresets": [
|
||||
|
||||
@@ -174,3 +174,5 @@ M9.3 adds [camera navigation and input intentions](docs/engineering/CAMERA_INPUT
|
||||
with explicit UI capture and no authoritative movement or network connection.
|
||||
M9.4 renders [revision-tagged environment views](docs/engineering/ENVIRONMENT_RENDERING.md)
|
||||
with explicit missing/stale presentation from a local in-memory fixture authority.
|
||||
M9.5 adds [biology-derived organism rendering](docs/engineering/ORGANISM_RENDERING.md)
|
||||
with no player/NPC labels and an opt-in engineering inspector.
|
||||
|
||||
@@ -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}
|
||||
|
||||
+15
-3
@@ -53,18 +53,25 @@ if(EVO_BUILD_CLIENT)
|
||||
target_include_directories(evo_render_frame PUBLIC "${PROJECT_SOURCE_DIR}/include")
|
||||
evo_owned_target(evo_render_frame)
|
||||
# SDL-free environment presentation (M9.4): copies read-only world views, never the reverse.
|
||||
add_library(evo_client_views STATIC src/client/views/environment_view.cpp)
|
||||
target_link_libraries(evo_client_views PUBLIC evo::world)
|
||||
add_library(evo_client_views STATIC src/client/views/environment_view.cpp src/client/views/organism_view.cpp)
|
||||
target_link_libraries(evo_client_views PUBLIC evo::world evo::biology)
|
||||
evo_owned_target(evo_client_views)
|
||||
add_library(evo_render_environment STATIC src/render/environment/environment.cpp)
|
||||
target_link_libraries(evo_render_environment PUBLIC evo_client_views evo_client_controls evo_render_frame)
|
||||
evo_owned_target(evo_render_environment)
|
||||
# M9.5 organism projection and the engineering inspector (no text/ImGui dependency).
|
||||
add_library(evo_render_organism STATIC src/render/organism/organism.cpp)
|
||||
target_link_libraries(evo_render_organism PUBLIC evo_render_environment)
|
||||
evo_owned_target(evo_render_organism)
|
||||
add_library(evo_client_ui STATIC src/client/ui/organism_inspector.cpp)
|
||||
target_link_libraries(evo_client_ui PUBLIC evo_render_organism)
|
||||
evo_owned_target(evo_client_ui)
|
||||
add_library(evo_client_platform STATIC src/client/platform/application.cpp src/render/sdl_renderer.cpp)
|
||||
target_include_directories(evo_client_platform PRIVATE "${PROJECT_SOURCE_DIR}/src")
|
||||
target_link_libraries(evo_client_platform PUBLIC evo_render_frame evo_client_controls PRIVATE SDL3::SDL3)
|
||||
evo_owned_target(evo_client_platform)
|
||||
add_executable(evo-client apps/evo-client/main.cpp)
|
||||
target_link_libraries(evo-client PRIVATE evo_client_platform evo_render_environment)
|
||||
target_link_libraries(evo-client PRIVATE evo_client_platform evo_client_ui)
|
||||
evo_owned_target(evo-client)
|
||||
evo_client_runtime(evo-client)
|
||||
if(BUILD_TESTING)
|
||||
@@ -77,6 +84,11 @@ if(EVO_BUILD_CLIENT)
|
||||
target_link_libraries(evo-client-environment-tests PRIVATE evo_render_environment)
|
||||
evo_owned_target(evo-client-environment-tests)
|
||||
add_test(NAME client-environment COMMAND evo-client-environment-tests)
|
||||
add_executable(evo-client-organism-tests tests/client_organisms.cpp)
|
||||
target_link_libraries(evo-client-organism-tests PRIVATE evo_client_ui)
|
||||
evo_owned_target(evo-client-organism-tests)
|
||||
add_test(NAME client-organisms COMMAND evo-client-organism-tests)
|
||||
set_tests_properties(client-organisms PROPERTIES TIMEOUT 60 LABELS "client")
|
||||
set_tests_properties(client-environment PROPERTIES TIMEOUT 60 LABELS "client")
|
||||
add_test(NAME client-lifecycle COMMAND evo-client-lifecycle-tests)
|
||||
add_test(NAME client-smoke COMMAND evo-client --renderer software --frames 3)
|
||||
|
||||
@@ -41,12 +41,12 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
RUN cmake -P tools/prepare-sdl3.cmake \
|
||||
&& cmake --preset client-probe -DCMAKE_CXX_COMPILER=clang++-19 \
|
||||
-DEVO_BUILD_CLIENT=ON -DEVO_ENABLE_TIDY=ON -DSDL_X11=ON -DSDL_WAYLAND=OFF \
|
||||
&& cmake --build build/client-probe --target evo-client-probe evo-client evo-client-lifecycle-tests evo-client-environment-tests --parallel 2 \
|
||||
&& cmake --build build/client-probe --target evo-client-probe evo-client evo-client-lifecycle-tests evo-client-environment-tests evo-client-organism-tests --parallel 2 \
|
||||
&& ctest --preset client-probe --no-tests=error \
|
||||
&& xvfb-run -a env SDL_VIDEO_DRIVER=x11 ./build/client-probe/evo-client-probe --renderer software \
|
||||
&& xvfb-run -a env SDL_VIDEO_DRIVER=x11 ./build/client-probe/evo-client-lifecycle-tests \
|
||||
&& cmake --preset client-probe -DEVO_BUILD_CLIENT=ON -DEVO_SANITIZER=address -DEVO_ENABLE_TIDY=OFF \
|
||||
&& cmake --build build/client-probe --target evo-client evo-client-lifecycle-tests evo-client-environment-tests --parallel 2 \
|
||||
&& cmake --build build/client-probe --target evo-client evo-client-lifecycle-tests evo-client-environment-tests evo-client-organism-tests --parallel 2 \
|
||||
&& ctest --preset client-probe --no-tests=error \
|
||||
&& xvfb-run -a env SDL_VIDEO_DRIVER=x11 ./build/client-probe/evo-client-lifecycle-tests
|
||||
|
||||
|
||||
+7
-1
@@ -410,7 +410,13 @@ fixture ticks, not server time.
|
||||
ordered freshness (none/current/stale) and bounded camera-projected rendering
|
||||
with explicit missing, unrequested, present-zero and undefined encodings under
|
||||
ADR-0080. A local in-memory fixture authority stands in for server views until
|
||||
M9.7. Evidence in engineering/VALIDATION.md. Next gate: M9.5.
|
||||
M9.7. Evidence in engineering/VALIDATION.md.
|
||||
|
||||
**M9.5 status (2026-10-01):** biology-derived organism presentations with no
|
||||
controller/ownership fields, identical rendering for identical phenotypes,
|
||||
alive/dead/removed handling, budgeted detail with explicit truncation, and an
|
||||
opt-in rectangle-only engineering inspector under ADR-0081. ImGui is not adopted.
|
||||
Evidence in engineering/VALIDATION.md. Next gate: M9.6.
|
||||
|
||||
**Goal:** a native desktop cellular viewer/controller with input, camera, renderer,
|
||||
readable organism/environment views and a real development-server connection.
|
||||
|
||||
+15
-13
@@ -2,20 +2,22 @@
|
||||
|
||||
## Current gate — 2026-10-01
|
||||
|
||||
M9.4 renders microscopic environment views
|
||||
([ADR-0080](adr/0080-environment-presentation.md)). The client copies M6.3 views
|
||||
into owned, revision-tagged presentations; `EnvironmentLayer` rejects foreign or
|
||||
regressed updates and shows none/current/stale against observed authority
|
||||
watermarks. Habitats, terrain cells and voxel boundaries project through the
|
||||
M9.3 camera into at most 2313 clipped rectangles, with explicit missing,
|
||||
not-requested, present-zero, undefined-moisture and stale encodings. See
|
||||
[ENVIRONMENT_RENDERING.md](engineering/ENVIRONMENT_RENDERING.md) and
|
||||
[VALIDATION.md](engineering/VALIDATION.md). Remote Gitea client execution of the
|
||||
extended CI stage remains unverified locally.
|
||||
M9.5 renders organisms and an engineering debug view
|
||||
([ADR-0081](adr/0081-organism-presentation.md)). Organism presentations are
|
||||
derived from M3 phenotypes and contain no controller, owner or level field, so
|
||||
identical biology renders identically for players and NPCs. Death shows as a
|
||||
remnant; removal is absence. Rendering is budgeted with explicit truncation; the
|
||||
opt-in inspector draws biology gauges only. ImGui is not adopted. See
|
||||
[ORGANISM_RENDERING.md](engineering/ORGANISM_RENDERING.md) and
|
||||
[VALIDATION.md](engineering/VALIDATION.md). Remote Gitea execution of the
|
||||
extended client CI stage remains unverified locally.
|
||||
|
||||
Next: **M9.5**, organism and debug views. The app's environment comes from a local
|
||||
in-memory fixture authority, not a connected region; its tick is a fixture counter.
|
||||
No deployment, simulation rules, persistent formats or world snapshots changed.
|
||||
Next: **M9.6**, the narrow secure dev-session protocol. The app still shows a local
|
||||
in-memory fixture (static organism population, environment water moves); no
|
||||
ecology runs in the client and no deployment, rule or format changed.
|
||||
|
||||
M9.4 added owned revision-tagged environment presentations and explicit
|
||||
missing/stale rendering ([ADR-0080](adr/0080-environment-presentation.md)).
|
||||
|
||||
M9.3 added local-mm pan/zoom camera mapping and bounded sequence/tick input
|
||||
intentions ([ADR-0079](adr/0079-camera-and-input-intentions.md)).
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
# ADR-0081: Biology-derived organism presentation and engineering inspector
|
||||
|
||||
## Status
|
||||
Accepted for the M9.5 engineering client. Colours, scales, floors and gauge
|
||||
mappings are presentation choices, not biology rules or final player UI.
|
||||
|
||||
## Context
|
||||
The vision requires shared presentation: perceivable biological state follows the
|
||||
same rules for players and NPCs, with no player/NPC/level/ownership labels. The
|
||||
M3 contract derives a `Phenotype` from genome, growth and environment. No placed,
|
||||
authoritative organism view exists yet (the M1 particle fixture must not be
|
||||
mapped into the habitat plane), and organisms are micrometre scale beside 1 m
|
||||
voxels. A debug view is needed without letting debug ownership leak into play.
|
||||
|
||||
## Decision
|
||||
Add `OrganismPresentation` (include/evo/client/organism_view.hpp): up to 1024
|
||||
copied cells in one Z slice, ordered by an opaque id, each holding voxel and
|
||||
micrometre centre offset, the M3 `Phenotype`, `GrowthState` and alive/dead state.
|
||||
The cell has **no controller, owner, account, name, level or player/NPC field**;
|
||||
a structured-binding test pins the field list. `present_organism` derives the
|
||||
phenotype with `biology::derive_phenotype`, so visuals come only from biology.
|
||||
Removal is absence from a later presentation. `OrganismLayer` reuses ADR-0080
|
||||
ordering/freshness semantics (identity, tick, revision; none/current/stale).
|
||||
|
||||
`append_organisms` (include/evo/render/organism.hpp) projects bodies through the
|
||||
camera: side = extent (with a uniform 5-unit visibility floor), body colour from
|
||||
conversion, realized growth and damage, a membrane outline sized by membrane mass
|
||||
share, a motility ring when movement speed is nonzero, an ingestion mark scaled
|
||||
by log ingestion rate. Dead remnants blend toward a remnant colour and drop the
|
||||
ring/mark. Collapsed bodies get a dark halo. Output respects a caller budget: full
|
||||
detail when every visible organism fits at 10 rectangles, otherwise one body each;
|
||||
any organisms beyond the budget are counted, not drawn, and a magenta truncation
|
||||
marker appears beside the organism freshness chip. Order is id order.
|
||||
|
||||
The engineering inspector (include/evo/client/organism_inspector.hpp, src/client/ui)
|
||||
picks the topmost organism under the pointer using the same drawn bounds, and
|
||||
draws a highlight plus ten normalized phenotype gauges. It shows biology values
|
||||
only; there is nothing else to show. It is opt-in (`--inspect`).
|
||||
|
||||
ImGui remains optional and is **not adopted**: rectangles suffice for gauges, and
|
||||
a UI library would need its own dependency ADR, text/font handling and input
|
||||
capture integration. Revisit when engineering text is needed (M9.8 or later).
|
||||
|
||||
The app adds a static fixture population built from real genomes. No ecology,
|
||||
movement or lifecycle runs in the client; the host does not decide energy,
|
||||
mutation, reproduction or death.
|
||||
|
||||
## Alternatives considered
|
||||
- Per-controller colour or icon: violates shared presentation; rejected.
|
||||
- True-scale only: micrometre organisms vanish at habitat zoom; the floor is
|
||||
uniform and documented, with true values available in the inspector.
|
||||
- Dropping organisms silently over budget: hides data; truncation is explicit.
|
||||
- ImGui inspector now: dependency and text scope not justified for this gate.
|
||||
|
||||
## Benefits
|
||||
Biology-only, deterministic, bounded output; identical rendering for identical
|
||||
biology regardless of host bookkeeping; testable without SDL.
|
||||
|
||||
## Costs
|
||||
Below the floor, drawn sizes do not compare; gauges have no numeric text. Single
|
||||
Z slice and 1024 organisms per presentation.
|
||||
|
||||
## Risks
|
||||
Gauge/colour choices are not accessibility-qualified. A future host could still
|
||||
add labels outside these APIs; review must keep debug overlays out of player UI.
|
||||
|
||||
## Consequences
|
||||
M9.7 builds `OrganismPresentation` from server views. Any new visual parameter
|
||||
must derive from biology and update this ADR, tests and ORGANISM_RENDERING.md.
|
||||
@@ -92,3 +92,4 @@ design. No unadopted candidate is a link dependency of the proof.
|
||||
- [ADR-0078: Native client lifecycle](0078-native-client-lifecycle.md) - main-thread RAII application, immutable presentation frames and explicit surface/device failure handling.
|
||||
- [ADR-0079: Camera and input intentions](0079-camera-and-input-intentions.md) - local-mm projection, bounded sequence/tick intentions, focus/UI capture and explicit host event ordering.
|
||||
- [ADR-0080: Environment presentation](0080-environment-presentation.md) - owned revision-tagged environment presentations, ordered freshness and bounded explicit missing/stale rendering.
|
||||
- [ADR-0081: Organism presentation](0081-organism-presentation.md) - biology-only organism cells without controller labels, budgeted rendering with explicit truncation and an engineering gauge inspector; ImGui deferred.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Native client boundary (M9.2–M9.4)
|
||||
# Native client boundary (M9.2–M9.5)
|
||||
|
||||
Implemented scope: desktop lifecycle and primitive presentation, not gameplay.
|
||||
ADR-0077 selects SDL; ADR-0078 defines its ownership and view boundary.
|
||||
@@ -12,6 +12,9 @@ flowchart LR
|
||||
World[M6.3 EnvironmentView] -- copied once --> Views[EnvironmentPresentation / Layer]
|
||||
Views --> Env[build_environment + Camera]
|
||||
Env -- bounded rectangles --> Frame
|
||||
Bio[M3 Phenotype] -- derive_phenotype --> Orgs[OrganismPresentation / Layer]
|
||||
Orgs --> OrgRender[append_organisms + inspector]
|
||||
OrgRender -- budgeted rectangles --> Frame
|
||||
```
|
||||
|
||||
`include/evo/client/application.hpp` and `include/evo/render/frame.hpp` contain
|
||||
@@ -59,6 +62,13 @@ at most 2313 clipped rectangles with explicit missing, unrequested, present-zero
|
||||
undefined and stale encodings. The client libraries link the headless world
|
||||
library read-only; no world or simulation target links client code.
|
||||
|
||||
M9.5 ([ORGANISM_RENDERING.md](../engineering/ORGANISM_RENDERING.md), ADR-0081)
|
||||
adds `client/organism_view.hpp`, `render/organism.hpp` and the engineering
|
||||
`client/organism_inspector.hpp`. Organism cells carry phenotype, growth, position
|
||||
and alive/dead only; no controller, owner or level field exists, so players and
|
||||
NPCs share one presentation. Rendering takes an explicit rectangle budget and
|
||||
reports truncation; the inspector draws biology gauges only. ImGui is not adopted.
|
||||
|
||||
Failure tests inject actual SDL events, including foreign window IDs, with no
|
||||
test-only production hooks. Real device failures and physical DPI/input require
|
||||
manual hardware qualification at M9.8. The native client is opt-in and never
|
||||
|
||||
@@ -46,8 +46,9 @@ the simulation state. Durable account references live in orchestration mapping.
|
||||
M9.2 implements the opt-in [native client boundary](CLIENT_ARCHITECTURE.md):
|
||||
copied immutable presentation frames and one main-thread platform owner. M9.4
|
||||
projects owned copies of M6.3 environment views (ADR-0080); the dependency runs
|
||||
world -> client views -> render only. It does not yet render organisms or connect
|
||||
to a region server.
|
||||
world -> client views -> render only. M9.5 renders organisms from M3 phenotypes
|
||||
(ADR-0081) without controller or ownership labels. It does not yet connect to a
|
||||
region server.
|
||||
|
||||
| Boundary | Owns | Must not own |
|
||||
|---|---|---|
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
# Native engineering client (M9.2–M9.4)
|
||||
# Native engineering client (M9.2–M9.5)
|
||||
|
||||
This opens a resizable native window showing camera-controlled environment habitats
|
||||
from a local in-memory fixture authority (M9.4). It does not run an ecosystem,
|
||||
and biology-derived organisms (M9.5) from a local in-memory fixture authority.
|
||||
It does not run an ecosystem,
|
||||
connect to a server or implement cellular gameplay.
|
||||
Contract: [client architecture](../architecture/CLIENT_ARCHITECTURE.md), ADR-0078.
|
||||
Camera/input: [contracts and limits](CAMERA_INPUT.md), ADR-0079.
|
||||
Environment: [presentation and encodings](ENVIRONMENT_RENDERING.md), ADR-0080.
|
||||
Organisms/inspector: [encodings and budget](ORGANISM_RENDERING.md), ADR-0081.
|
||||
|
||||
## Build and run
|
||||
|
||||
@@ -29,6 +31,7 @@ one explicit backend, without fallback. `--frames N` exits after N bounded steps
|
||||
window and pauses drawing. These options permit unattended smoke checks.
|
||||
`--layer NAME` selects the displayed field or `moisture`; `--refresh-every N`
|
||||
(1..1000 fixture authority ticks) delays view refresh so the stale state is visible.
|
||||
`--inspect` shows biology gauges for the organism under the pointer.
|
||||
Usage errors exit 2, lifecycle/fixture failures exit 1, orderly exit returns 0.
|
||||
|
||||
Engineering controls: arrow keys pan, mouse wheel zooms around the pointer, WASD
|
||||
@@ -37,8 +40,9 @@ toggles UI capture: the top-left bar turns orange and navigation/movement input
|
||||
is suppressed. Leaving capture/focus loss requires fresh presses. This is a
|
||||
focus exercise, not the final player UI. The host's input tick is a local fixture
|
||||
counter and is never interpreted as authoritative server time. The top-right
|
||||
chip shows environment freshness (green current, amber stale, red none); the
|
||||
bottom-left legend shows the value ramp.
|
||||
chips show environment then organism freshness (green current, amber stale, red
|
||||
none; magenta marker: organisms truncated); the bottom-left legend shows the ramp.
|
||||
The organism cluster is near (410 mm, 480 mm); zoom in with the wheel to see it.
|
||||
|
||||
For native X11 regression on a CI host:
|
||||
|
||||
@@ -48,7 +52,9 @@ xvfb-run -a env SDL_VIDEO_DRIVER=x11 ./build/client/evo-client-lifecycle-tests
|
||||
|
||||
CTest uses the dummy driver. `client-environment` is an SDL-free suite for
|
||||
presentation validation, ordering/freshness, encodings, seams and bounds; it
|
||||
prints an `environment_profile` line (rectangles, bytes, microseconds per build). The lifecycle suite runs 32 open/destroy rounds,
|
||||
prints an `environment_profile` line (rectangles, bytes, microseconds per build).
|
||||
`client-organisms` covers phenotype derivation, controller parity, death/removal,
|
||||
dense scenes and truncation, ordering, picking and the inspector. The lifecycle suite runs 32 open/destroy rounds,
|
||||
resize/scale queries, non-unit drawable-scale pixel checks, minimize/restore,
|
||||
show/hide, focus/foreign events, reset/loss and close. Separate process checks
|
||||
exercise initialization failure. Tests stay active under NDEBUG. Synthetic
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
# M9.5 organism rendering and engineering inspector
|
||||
|
||||
Decision: [ADR-0081](../adr/0081-organism-presentation.md). Headers:
|
||||
`include/evo/client/organism_view.hpp`, `include/evo/render/organism.hpp`,
|
||||
`include/evo/client/organism_inspector.hpp`. None includes SDL. Dependency
|
||||
direction: biology (phenotype) -> client views -> render organism -> client UI
|
||||
inspector -> immutable `Frame`. Environment rules (ADR-0080) are unchanged.
|
||||
|
||||
```cpp
|
||||
auto cell = client::present_organism(id, voxel, x_um, y_um, genome, growth, environment,
|
||||
client::OrganismState::alive); // derive_phenotype
|
||||
layer.accept(*client::OrganismPresentation::create(revision, slice_z, cells));
|
||||
render::append_organisms(rects, budget, layer.current(), layer.freshness(), camera);
|
||||
if (auto i = client::pick_organism(*layer.current(), camera, pointer))
|
||||
client::append_inspector(rects, client::inspector_rectangles, layer.current()->cells()[*i], camera);
|
||||
```
|
||||
|
||||
## Shared presentation rule
|
||||
|
||||
An `OrganismCell` holds only: opaque id (draw order, never displayed), voxel and
|
||||
micrometre centre offset, `Phenotype`, `GrowthState`, alive/dead. There is no
|
||||
controller, owner, account, name, level or player/NPC field, and no API accepts
|
||||
one. Identical biology renders identically wherever the host keeps its controller
|
||||
bookkeeping; tests verify byte-identical rectangles and inspector panels for a
|
||||
player-controlled and an NPC organism with the same genome and growth.
|
||||
|
||||
## Validation and ordering
|
||||
|
||||
Presentations hold 0..1024 cells (empty is valid: no organisms in view), strictly
|
||||
ascending nonzero ids, one Z slice, offsets in [0, 1e6) um, consistent masses
|
||||
(total = structural + membrane), extent within one voxel, conversion/growth/damage
|
||||
<= 1000 per thousand and a known state. `OrganismLayer` rejects foreign worlds and
|
||||
regressed tick/revision, tracks observed watermarks and reports none/current/stale
|
||||
like `EnvironmentLayer`. Death is a state; removal is absence from a later
|
||||
presentation. Neither is decided by the client.
|
||||
|
||||
## Visual encodings
|
||||
|
||||
| Biology | Encoding |
|
||||
|---|---|
|
||||
| extent (um) | body side at camera scale; minimum 5 logical units for all organisms |
|
||||
| conversion per thousand | body hue, teal (0) to amber (1000) |
|
||||
| realized growth | body brightness, 40% to 100% |
|
||||
| damage | blend toward red, up to 80% |
|
||||
| membrane mass share | light outline, thickness side*share/2 in [1, side/4] |
|
||||
| movement speed > 0 | light ring 2 units outside the body (alive only) |
|
||||
| ingestion rate > 0 | dark central mark, 15%..50% of side by log10 rate over 6 decades (alive only) |
|
||||
| dead | body blended 75% toward remnant brown; no ring or mark |
|
||||
| stale presentation | all organism colours dimmed; amber organism chip |
|
||||
|
||||
Bodies under 6 units draw as a dark halo plus body. Thermal shortfall,
|
||||
maintenance and mass are inspector-only. The organism freshness chip sits below
|
||||
the environment chip (top-right): green current, amber stale, red none. A magenta
|
||||
marker left of it means organisms were not drawn because of the frame budget.
|
||||
|
||||
## Budget
|
||||
|
||||
`append_organisms` appends at most `budget` rectangles (minimum 2 for the chip and
|
||||
marker). If every visible organism fits at 10 rectangles, full detail is used;
|
||||
otherwise each visible organism is a single body; beyond the budget, organisms are
|
||||
counted as visible but not drawn and the marker appears. The engineering app
|
||||
budgets 4096 - 2313 (environment) - 25 (inspector) - 3 (host UI) = 1755, so 1024
|
||||
organisms always fit as bodies. No textures, caches or history are kept.
|
||||
|
||||
## Engineering inspector
|
||||
|
||||
`--inspect` enables hover inspection: the topmost organism whose drawn (floored)
|
||||
box contains the pointer gets a white highlight, and a bottom-right panel shows
|
||||
ten gauges in order: extent (log10 over 3 decades um), total mass (12 decades fg),
|
||||
membrane share, maintenance (12 decades pJ/tick), movement speed (5 decades),
|
||||
ingestion rate (6 decades), conversion, realized growth, damage, thermal shortfall
|
||||
(5 decades mK). The panel darkens to brown for remnants. Rectangles only: there is
|
||||
no text, ImGui or input capture; this is engineering UI, not player UI.
|
||||
|
||||
## Fixture population
|
||||
|
||||
The app adds 48 organisms from real genomes: a 4x4 cluster 60 um apart near the
|
||||
(0, 0) voxel's 410 mm / 480 mm offset for zoomed viewing, and one in every second
|
||||
voxel along x and y.
|
||||
Genome parameters, growth and damage vary by id; ids 5 and 23 are dead remnants.
|
||||
It is static presentation data refreshed with the environment cadence, not an
|
||||
ecosystem, controller or spawning rule.
|
||||
@@ -3344,3 +3344,48 @@ extended `ci-client` stage was not observed locally. No full headless suite or
|
||||
TSan rerun (headless sources unchanged; client state is main-thread-only). No
|
||||
physical DPI, real GPU, Wayland, accessibility or human visual acceptance is
|
||||
claimed. No network traffic, database, deployment or persistent format changed.
|
||||
|
||||
## M9.5 organism and debug views — 2026-10-01
|
||||
|
||||
Implemented ADR-0081 and ORGANISM_RENDERING.md: biology-derived
|
||||
`OrganismPresentation` (no controller/owner/level fields), `OrganismLayer`
|
||||
ordering/freshness, budgeted organism projection with explicit truncation, and an
|
||||
opt-in rectangle-only hover inspector. ImGui was evaluated as optional and not
|
||||
adopted. The app adds a static 48-organism fixture built from real genomes.
|
||||
|
||||
Executed:
|
||||
|
||||
- Windows MSVC 19.44 Release via `tools/windows-check.ps1 -Preset client -Action
|
||||
check` (child `powershell.exe`): 5/5 labeled tests including `client-organisms`.
|
||||
App runs `--frames 300 --refresh-every 2 --inspect` and `--frames 120 --layer
|
||||
moisture` exited 0; `--frames 0` exited 2 (usage).
|
||||
- Linux GCC 14 Release (`build/client-probe-linux`): 7/7 labeled tests, native
|
||||
Xvfb/X11 lifecycle suite, X11 app with `--inspect --refresh-every 3`.
|
||||
- Clang 19 Debug ASan/UBSan (`build/client-asan`): 5/5 labeled tests, X11
|
||||
lifecycle, X11 app (`--inspect --layer moisture --refresh-every 2`, 300 frames)
|
||||
and hidden dummy-driver app (`--inspect`, 200 frames); leak detection on, no
|
||||
suppressions.
|
||||
- Organism tests: phenotype equals `derive_phenotype` (20 um cube, hand-checked
|
||||
bounds 390..410 at 1000 units/mm); a structured binding pins the cell's seven
|
||||
fields; membrane thickness cap, motility ring and ingestion mark only with the
|
||||
capabilities; conversion/growth/damage change body colour; visibility floor and
|
||||
halo; byte-identical rectangles and inspector panels for player- and
|
||||
NPC-controlled hosts with identical biology (ids 5 vs 900), translation-only
|
||||
differences when moved; death (remnant colour, no ring/mark, same size) and
|
||||
removal (absence, then empty presentation); 1024 visible organisms collapsing to
|
||||
bodies within the 1755 app budget, explicit truncation at budget 500 (498 drawn
|
||||
plus marker), invalid budget; a worst-case frame (environment bound + organisms
|
||||
+ inspector + UI) within `Frame` limits; regression/foreign/watermark ordering
|
||||
and stale dimming; 15 invalid presentation shapes and over-capacity; topmost picking on
|
||||
floored bounds; gauge values and widths.
|
||||
- Visual sanity check (offline rasterization of the app fixture at habitat zoom
|
||||
and 2000 units/mm with the inspector): 3-unit floored organisms were hard to see
|
||||
against habitats, so the floor became 5 units with a dark halo for collapsed
|
||||
bodies. Not human, colour-vision or accessibility acceptance.
|
||||
- clang-tidy 19 with warnings-as-errors on the five new/changed translation units:
|
||||
passed after reserving a test vector. Repository-wide clang-format 19 passed.
|
||||
|
||||
Limits: Docker/Gitea execution of the extended `ci-client` stage was not observed
|
||||
locally. No headless source changed; no full headless suite or TSan rerun. The
|
||||
fixture population is static presentation data, not ecology. No network, database,
|
||||
deployment, persistent format or simulation rule changed.
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include "evo/client/camera.hpp"
|
||||
#include "evo/client/organism_view.hpp"
|
||||
#include "evo/render/frame.hpp"
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
namespace evo::client {
|
||||
// Engineering debug view only: hover highlight plus a panel of normalized phenotype
|
||||
// gauges. It reads biology values and nothing else; there is no ownership,
|
||||
// controller or level information to show. Not final player UI.
|
||||
inline constexpr std::size_t inspector_gauges = 10;
|
||||
inline constexpr std::size_t inspector_rectangles = 4 + 1 + 2 * inspector_gauges;
|
||||
// Gauge order: extent, total mass, membrane share, maintenance, movement speed,
|
||||
// ingestion rate, conversion, realized growth, damage, thermal shortfall.
|
||||
// Each is in [0, 1]; log scales are documented in ORGANISM_RENDERING.md.
|
||||
[[nodiscard]] std::array<double, inspector_gauges>
|
||||
inspector_gauge_values(const OrganismCell& cell) noexcept;
|
||||
// Index of the topmost (last drawn) organism whose drawn body contains `pointer`.
|
||||
[[nodiscard]] std::optional<std::size_t> pick_organism(const OrganismPresentation& presentation,
|
||||
const Camera& camera,
|
||||
ScreenPoint pointer) noexcept;
|
||||
enum class InspectorError : std::uint8_t { invalid_budget };
|
||||
// Appends exactly-bounded rectangles (at most inspector_rectangles, clipped).
|
||||
[[nodiscard]] std::expected<void, InspectorError>
|
||||
append_inspector(std::vector<render::Rectangle>& out, std::size_t budget, const OrganismCell& cell,
|
||||
const Camera& camera);
|
||||
} // namespace evo::client
|
||||
@@ -0,0 +1,81 @@
|
||||
#pragma once
|
||||
#include "evo/biology/development.hpp"
|
||||
#include "evo/client/environment_view.hpp"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
namespace evo::client {
|
||||
inline constexpr std::size_t max_organism_cells = 1024;
|
||||
// Authority revision an organism presentation was copied from (e.g. a community
|
||||
// command watermark). Not a capability or session grant.
|
||||
struct OrganismRevision {
|
||||
world::WorldIdentity identity;
|
||||
std::uint64_t tick{}, revision{};
|
||||
auto operator<=>(const OrganismRevision&) const = default;
|
||||
};
|
||||
// Dead organisms remain as remnants until their terminal inventory is gone; removal
|
||||
// is absence from a later presentation, never a state.
|
||||
enum class OrganismState : std::uint8_t { alive, dead };
|
||||
// Copied presentation values. Deliberately has no controller, owner, account,
|
||||
// player/NPC, level or name field: every organism is presented by biology alone.
|
||||
struct OrganismCell {
|
||||
std::uint64_t id{}; // Opaque stable draw-order key; never displayed.
|
||||
world::VoxelAddress voxel;
|
||||
world::Micrometres x, y; // Centre offset inside the voxel, each in [0, 1e6).
|
||||
biology::Phenotype phenotype;
|
||||
biology::GrowthState growth;
|
||||
OrganismState state{OrganismState::alive};
|
||||
};
|
||||
// Immutable owned copy of up to 1024 organisms in one Z slice; may be empty.
|
||||
class OrganismPresentation {
|
||||
public:
|
||||
[[nodiscard]] static std::expected<OrganismPresentation, ViewError>
|
||||
create(OrganismRevision revision, std::int64_t slice_z, std::span<const OrganismCell> cells);
|
||||
[[nodiscard]] OrganismRevision revision() const noexcept {
|
||||
return revision_;
|
||||
}
|
||||
[[nodiscard]] std::int64_t slice_z() const noexcept {
|
||||
return slice_z_;
|
||||
}
|
||||
// Strictly ascending by id, which is also draw order.
|
||||
[[nodiscard]] std::span<const OrganismCell> cells() const noexcept {
|
||||
return cells_;
|
||||
}
|
||||
|
||||
private:
|
||||
OrganismPresentation(OrganismRevision revision, std::int64_t z,
|
||||
std::span<const OrganismCell> cells)
|
||||
: revision_{revision}, slice_z_{z}, cells_(cells.begin(), cells.end()) {}
|
||||
OrganismRevision revision_;
|
||||
std::int64_t slice_z_;
|
||||
std::vector<OrganismCell> cells_;
|
||||
};
|
||||
// Derives the phenotype with the M3 contract; visual parameters never come from
|
||||
// anything but the genome, growth state and environment supplied here.
|
||||
[[nodiscard]] std::expected<OrganismCell, ViewError>
|
||||
present_organism(std::uint64_t id, world::VoxelAddress voxel, world::Micrometres x,
|
||||
world::Micrometres y, const biology::Genome& genome, biology::GrowthState growth,
|
||||
const biology::EnvironmentState& environment, OrganismState state);
|
||||
|
||||
// Same ordering/freshness semantics as EnvironmentLayer (ADR-0080), without chunks.
|
||||
class OrganismLayer {
|
||||
public:
|
||||
[[nodiscard]] std::expected<void, ViewError> accept(OrganismPresentation next);
|
||||
[[nodiscard]] std::expected<void, ViewError> observe(OrganismRevision latest);
|
||||
void mark_stale() noexcept;
|
||||
void reset() noexcept;
|
||||
[[nodiscard]] const OrganismPresentation* current() const noexcept {
|
||||
return current_ ? &*current_ : nullptr;
|
||||
}
|
||||
[[nodiscard]] Freshness freshness() const noexcept;
|
||||
|
||||
private:
|
||||
std::optional<OrganismPresentation> current_;
|
||||
std::optional<OrganismRevision> latest_;
|
||||
bool stale_{};
|
||||
};
|
||||
} // namespace evo::client
|
||||
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
#include "evo/client/camera.hpp"
|
||||
#include "evo/client/organism_view.hpp"
|
||||
#include "evo/render/frame.hpp"
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <vector>
|
||||
|
||||
namespace evo::render {
|
||||
// Full detail: motility ring (4), body (1), membrane (4), ingestion mark (1). Bodies
|
||||
// smaller than organism_detail_side draw as a dark halo plus body (2).
|
||||
inline constexpr std::size_t organism_detail_rectangles = 10;
|
||||
// Freshness chip plus an explicit truncation marker.
|
||||
inline constexpr std::size_t organism_status_rectangles = 2;
|
||||
// Uniform minimum on-screen body side (logical units) so micrometre organisms stay
|
||||
// visible when zoomed out. Below it, drawn sizes are not comparable; inspect values.
|
||||
inline constexpr double organism_visibility_floor = 5;
|
||||
inline constexpr double organism_detail_side = 6;
|
||||
namespace organism_palette {
|
||||
inline constexpr Color ring{200, 230, 240, 255};
|
||||
inline constexpr Color mouth{20, 16, 24, 255};
|
||||
inline constexpr Color halo{8, 8, 12, 255}; // Contrast backing for collapsed bodies.
|
||||
inline constexpr Color remnant{110, 95, 80, 255};
|
||||
inline constexpr Color truncated{255, 0, 200, 255};
|
||||
} // namespace organism_palette
|
||||
struct ScreenBox {
|
||||
double left{}, top{}, right{}, bottom{};
|
||||
};
|
||||
// Unclipped body box in logical window units, after the visibility floor. Shared by
|
||||
// rendering and picking so both agree on what is under the pointer.
|
||||
[[nodiscard]] ScreenBox organism_bounds(const client::OrganismCell& cell,
|
||||
const client::Camera& camera) noexcept;
|
||||
// Body colour from conversion, realized growth, damage and alive/dead state only.
|
||||
[[nodiscard]] Color organism_fill(const client::OrganismCell& cell) noexcept;
|
||||
enum class OrganismDetail : std::uint8_t { full, body_only };
|
||||
struct OrganismRenderReport {
|
||||
std::size_t visible{}, drawn{};
|
||||
OrganismDetail detail{OrganismDetail::full};
|
||||
};
|
||||
enum class OrganismRenderError : std::uint8_t { invalid_budget };
|
||||
// Appends at most `budget` rectangles (>= organism_status_rectangles) in id order.
|
||||
// Detail is chosen once per call: full when every visible organism fits at full
|
||||
// detail, otherwise one body rectangle each (no halo); organisms beyond the budget are not
|
||||
// drawn and the magenta truncation marker appears. Nothing is dropped silently.
|
||||
[[nodiscard]] std::expected<OrganismRenderReport, OrganismRenderError>
|
||||
append_organisms(std::vector<Rectangle>& out, std::size_t budget,
|
||||
const client::OrganismPresentation* presentation, client::Freshness freshness,
|
||||
const client::Camera& camera);
|
||||
} // namespace evo::render
|
||||
@@ -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
|
||||
@@ -0,0 +1,100 @@
|
||||
#include "evo/client/organism_view.hpp"
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
namespace evo::client {
|
||||
namespace {
|
||||
constexpr std::uint64_t voxel_um = world::habitat_axis_limit_um;
|
||||
bool in_range(std::int64_t value) {
|
||||
return value >= -world::voxel_limit && value < world::voxel_limit;
|
||||
}
|
||||
bool valid(const OrganismCell& cell, std::int64_t z) {
|
||||
const auto& p = cell.phenotype;
|
||||
return cell.id != 0 && cell.voxel.z == z && in_range(cell.voxel.x) && in_range(cell.voxel.y) &&
|
||||
cell.x.value < voxel_um && cell.y.value < voxel_um &&
|
||||
p.structural_mass <= p.total_mass &&
|
||||
p.total_mass - p.structural_mass == p.membrane_mass && p.extent <= voxel_um &&
|
||||
p.conversion_per_thousand <= 1000 && cell.growth.realized_per_thousand <= 1000 &&
|
||||
cell.growth.damage_per_thousand <= 1000 &&
|
||||
(cell.state == OrganismState::alive || cell.state == OrganismState::dead);
|
||||
}
|
||||
bool regressed(OrganismRevision next, OrganismRevision previous) {
|
||||
return next.tick < previous.tick || next.revision < previous.revision;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::expected<OrganismPresentation, ViewError>
|
||||
OrganismPresentation::create(OrganismRevision revision, std::int64_t slice_z,
|
||||
std::span<const OrganismCell> cells) {
|
||||
if (!in_range(slice_z))
|
||||
return std::unexpected(ViewError::invalid_view);
|
||||
if (cells.size() > max_organism_cells)
|
||||
return std::unexpected(ViewError::too_many_cells);
|
||||
for (std::size_t i = 0; i < cells.size(); ++i)
|
||||
if (!valid(cells[i], slice_z) || (i > 0 && cells[i - 1].id >= cells[i].id))
|
||||
return std::unexpected(ViewError::invalid_view);
|
||||
return OrganismPresentation{revision, slice_z, cells};
|
||||
}
|
||||
|
||||
std::expected<OrganismCell, ViewError>
|
||||
present_organism(std::uint64_t id, world::VoxelAddress voxel, world::Micrometres x,
|
||||
world::Micrometres y, const biology::Genome& genome, biology::GrowthState growth,
|
||||
const biology::EnvironmentState& environment, OrganismState state) {
|
||||
const auto phenotype = biology::derive_phenotype(genome, growth, environment);
|
||||
if (!phenotype)
|
||||
return std::unexpected(ViewError::invalid_view);
|
||||
OrganismCell cell;
|
||||
cell.id = id;
|
||||
cell.voxel = voxel;
|
||||
cell.x = x;
|
||||
cell.y = y;
|
||||
cell.phenotype = *phenotype;
|
||||
cell.growth = growth;
|
||||
cell.state = state;
|
||||
if (!valid(cell, voxel.z))
|
||||
return std::unexpected(ViewError::invalid_view);
|
||||
return cell;
|
||||
}
|
||||
|
||||
std::expected<void, ViewError> OrganismLayer::accept(OrganismPresentation next) {
|
||||
const auto revision = next.revision();
|
||||
if (latest_ && revision.identity != latest_->identity)
|
||||
return std::unexpected(ViewError::foreign_world);
|
||||
if (current_ && regressed(revision, current_->revision()))
|
||||
return std::unexpected(ViewError::regressed);
|
||||
if (latest_)
|
||||
latest_ = OrganismRevision{revision.identity, std::max(latest_->tick, revision.tick),
|
||||
std::max(latest_->revision, revision.revision)};
|
||||
else
|
||||
latest_ = revision;
|
||||
current_ = std::move(next);
|
||||
stale_ = *latest_ != revision;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::expected<void, ViewError> OrganismLayer::observe(OrganismRevision latest) {
|
||||
if (latest_ && latest.identity != latest_->identity)
|
||||
return std::unexpected(ViewError::foreign_world);
|
||||
if (latest_ && regressed(latest, *latest_))
|
||||
return std::unexpected(ViewError::regressed);
|
||||
latest_ = latest;
|
||||
stale_ = stale_ || (current_ && latest != current_->revision());
|
||||
return {};
|
||||
}
|
||||
|
||||
void OrganismLayer::mark_stale() noexcept {
|
||||
stale_ = current_.has_value();
|
||||
}
|
||||
|
||||
void OrganismLayer::reset() noexcept {
|
||||
current_.reset();
|
||||
latest_.reset();
|
||||
stale_ = false;
|
||||
}
|
||||
|
||||
Freshness OrganismLayer::freshness() const noexcept {
|
||||
if (!current_)
|
||||
return Freshness::none;
|
||||
return stale_ ? Freshness::stale : Freshness::current;
|
||||
}
|
||||
} // namespace evo::client
|
||||
@@ -0,0 +1,146 @@
|
||||
#include "evo/render/organism.hpp"
|
||||
#include "evo/render/environment.hpp"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
namespace evo::render {
|
||||
namespace {
|
||||
using client::OrganismState;
|
||||
constexpr double pitch = static_cast<double>(world::cell_pitch_mm);
|
||||
constexpr double um_per_mm = 1000;
|
||||
std::uint8_t mix(std::uint8_t a, std::uint8_t b, double t) {
|
||||
return static_cast<std::uint8_t>(std::lround(a + (b - a) * t));
|
||||
}
|
||||
Color mix(Color a, Color b, double t) {
|
||||
return {mix(a.red, b.red, t), mix(a.green, b.green, t), mix(a.blue, b.blue, t), 255};
|
||||
}
|
||||
double fraction(std::uint32_t per_thousand) {
|
||||
return static_cast<double>(std::min<std::uint32_t>(per_thousand, 1000)) / 1000;
|
||||
}
|
||||
class Emitter {
|
||||
public:
|
||||
Emitter(std::vector<Rectangle>& out, double width, double height, bool stale)
|
||||
: out_{out}, width_{width}, height_{height}, stale_{stale} {}
|
||||
void fill(ScreenBox b, 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))
|
||||
return;
|
||||
out_.push_back({static_cast<float>(left), static_cast<float>(top),
|
||||
static_cast<float>(right - left), static_cast<float>(bottom - top),
|
||||
stale_ ? dim(color) : color});
|
||||
}
|
||||
void outline(ScreenBox b, double t, Color color) {
|
||||
fill({b.left, b.top, b.right, b.top + t}, color);
|
||||
fill({b.left, b.bottom - t, b.right, b.bottom}, color);
|
||||
fill({b.left, b.top + t, b.left + t, b.bottom - t}, color);
|
||||
fill({b.right - t, b.top + t, b.right, b.bottom - t}, color);
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<Rectangle>& out_;
|
||||
double width_, height_;
|
||||
bool stale_;
|
||||
};
|
||||
bool visible(ScreenBox b, double width, double height) {
|
||||
return b.right > 0 && b.left < width && b.bottom > 0 && b.top < height;
|
||||
}
|
||||
void draw(Emitter& emit, const client::OrganismCell& cell, ScreenBox body, OrganismDetail mode) {
|
||||
const auto& p = cell.phenotype;
|
||||
const bool alive = cell.state == OrganismState::alive;
|
||||
const double side = body.right - body.left;
|
||||
const Color fill = organism_fill(cell);
|
||||
if (mode == OrganismDetail::body_only) {
|
||||
emit.fill(body, fill);
|
||||
return;
|
||||
}
|
||||
if (side < organism_detail_side) {
|
||||
emit.fill({body.left - 1, body.top - 1, body.right + 1, body.bottom + 1},
|
||||
organism_palette::halo);
|
||||
emit.fill(body, fill);
|
||||
return;
|
||||
}
|
||||
if (alive && p.movement_speed > 0)
|
||||
emit.outline({body.left - 2, body.top - 2, body.right + 2, body.bottom + 2}, 1,
|
||||
organism_palette::ring);
|
||||
emit.fill(body, fill);
|
||||
if (p.membrane_mass > 0 && p.total_mass > 0) {
|
||||
const double share =
|
||||
static_cast<double>(p.membrane_mass) / static_cast<double>(p.total_mass);
|
||||
emit.outline(body, std::clamp(side * share / 2, 1.0, side / 4),
|
||||
mix(fill, {255, 255, 255, 255}, 0.5));
|
||||
}
|
||||
if (alive && p.ingestion_rate > 0) {
|
||||
const double scale =
|
||||
std::min(1.0, std::log10(1 + static_cast<double>(p.ingestion_rate)) / 6);
|
||||
const double half = side * (0.15 + 0.35 * scale) / 2;
|
||||
const double cx = (body.left + body.right) / 2, cy = (body.top + body.bottom) / 2;
|
||||
emit.fill({cx - half, cy - half, cx + half, cy + half}, organism_palette::mouth);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
ScreenBox organism_bounds(const client::OrganismCell& cell, const client::Camera& camera) noexcept {
|
||||
const auto viewport = camera.viewport();
|
||||
const double scale = camera.units_per_mm();
|
||||
const double x =
|
||||
static_cast<double>(cell.voxel.x) * pitch + static_cast<double>(cell.x.value) / um_per_mm;
|
||||
const double y =
|
||||
static_cast<double>(cell.voxel.y) * pitch + static_cast<double>(cell.y.value) / um_per_mm;
|
||||
// Camera projection from CAMERA_INPUT.md.
|
||||
const double sx = (x - camera.centre().x_mm) * scale + viewport.width / 2.0;
|
||||
const double sy = (camera.centre().y_mm - y) * scale + viewport.height / 2.0;
|
||||
const double side = std::max(static_cast<double>(cell.phenotype.extent) / um_per_mm * scale,
|
||||
organism_visibility_floor);
|
||||
return {sx - side / 2, sy - side / 2, sx + side / 2, sy + side / 2};
|
||||
}
|
||||
|
||||
Color organism_fill(const client::OrganismCell& cell) noexcept {
|
||||
const Color base = mix(Color{40, 150, 150, 255}, Color{220, 170, 60, 255},
|
||||
fraction(cell.phenotype.conversion_per_thousand));
|
||||
Color color =
|
||||
mix(Color{30, 35, 40, 255}, base, 0.4 + 0.6 * fraction(cell.growth.realized_per_thousand));
|
||||
color = mix(color, Color{150, 30, 30, 255}, 0.8 * fraction(cell.growth.damage_per_thousand));
|
||||
if (cell.state == OrganismState::dead)
|
||||
color = mix(color, organism_palette::remnant, 0.75);
|
||||
return color;
|
||||
}
|
||||
|
||||
std::expected<OrganismRenderReport, OrganismRenderError>
|
||||
append_organisms(std::vector<Rectangle>& out, std::size_t budget,
|
||||
const client::OrganismPresentation* presentation, client::Freshness freshness,
|
||||
const client::Camera& camera) {
|
||||
if (budget < organism_status_rectangles)
|
||||
return std::unexpected(OrganismRenderError::invalid_budget);
|
||||
const auto viewport = camera.viewport();
|
||||
const double width = viewport.width, height = viewport.height;
|
||||
if (freshness == client::Freshness::none)
|
||||
presentation = nullptr;
|
||||
const bool stale = presentation != nullptr && freshness == client::Freshness::stale;
|
||||
OrganismRenderReport report;
|
||||
const std::size_t available = budget - organism_status_rectangles;
|
||||
if (presentation != nullptr) {
|
||||
for (const auto& cell : presentation->cells())
|
||||
report.visible += visible(organism_bounds(cell, camera), width, height) ? 1 : 0;
|
||||
if (report.visible > available / organism_detail_rectangles)
|
||||
report.detail = OrganismDetail::body_only;
|
||||
Emitter emit{out, width, height, stale};
|
||||
for (const auto& cell : presentation->cells()) {
|
||||
if (report.drawn == std::min(report.visible, available))
|
||||
break;
|
||||
const auto body = organism_bounds(cell, camera);
|
||||
if (!visible(body, width, height))
|
||||
continue;
|
||||
draw(emit, cell, body, report.detail);
|
||||
++report.drawn;
|
||||
}
|
||||
}
|
||||
Emitter status{out, width, height, false};
|
||||
status.fill({width - 72, 20, width - 8, 28}, presentation == nullptr ? palette::status_none
|
||||
: stale ? palette::status_stale
|
||||
: palette::status_current);
|
||||
if (report.drawn < report.visible)
|
||||
status.fill({width - 84, 20, width - 76, 28}, organism_palette::truncated);
|
||||
return report;
|
||||
}
|
||||
} // namespace evo::render
|
||||
@@ -0,0 +1,341 @@
|
||||
#include "evo/client/organism_inspector.hpp"
|
||||
#include "evo/render/environment.hpp"
|
||||
#include "evo/render/organism.hpp"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <cstdio>
|
||||
#include <exception>
|
||||
#include <optional>
|
||||
#include <source_location>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
using namespace evo;
|
||||
using biology::Capability;
|
||||
using client::Freshness;
|
||||
using client::OrganismCell;
|
||||
using client::OrganismState;
|
||||
using client::ViewError;
|
||||
constexpr world::WorldIdentity identity{3, 4};
|
||||
constexpr biology::EnvironmentState temperate{
|
||||
293'150, {{1'000'000'000}, {accounting::Femtograms{1'000'000'000}, {}, {}, {}}}};
|
||||
void check(bool ok, std::source_location at = std::source_location::current()) {
|
||||
if (!ok)
|
||||
throw std::runtime_error("client organisms line " + std::to_string(at.line()));
|
||||
}
|
||||
#define CHECK(...) check(static_cast<bool>(__VA_ARGS__))
|
||||
template <typename T, typename E> bool refused(const std::expected<T, E>& r, E e) {
|
||||
return !r && r.error() == e;
|
||||
}
|
||||
bool same(render::Color a, render::Color b) {
|
||||
return a.red == b.red && a.green == b.green && a.blue == b.blue && a.alpha == b.alpha;
|
||||
}
|
||||
bool same(const render::Rectangle& a, const render::Rectangle& b) {
|
||||
return a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height &&
|
||||
same(a.color, b.color);
|
||||
}
|
||||
bool same(const std::vector<render::Rectangle>& a, const std::vector<render::Rectangle>& b) {
|
||||
return a.size() == b.size() &&
|
||||
std::equal(a.begin(), a.end(), b.begin(),
|
||||
[](const auto& x, const auto& y) { return same(x, y); });
|
||||
}
|
||||
// Development-test genome (ADR-0031): full growth is an exact 20 um cube.
|
||||
biology::Genome genome(std::uint32_t conversion = 400, std::uint32_t movement = 0,
|
||||
std::uint32_t ingestion = 0) {
|
||||
biology::GenomeDraft draft{
|
||||
7,
|
||||
1,
|
||||
1,
|
||||
{},
|
||||
{{Capability::energy_conversion, conversion, 0}, {Capability::membrane, 10, 0}}};
|
||||
if (movement != 0)
|
||||
draft.capabilities.push_back({Capability::movement, movement, 0});
|
||||
if (ingestion != 0)
|
||||
draft.capabilities.push_back({Capability::ingestion, ingestion, 0});
|
||||
draft.capabilities.push_back({Capability::target_size, 8'000'000, 0});
|
||||
auto result = biology::Genome::create(draft);
|
||||
CHECK(result);
|
||||
return *result;
|
||||
}
|
||||
OrganismCell organism(std::uint64_t id, std::uint64_t x_um, const biology::Genome& g,
|
||||
biology::GrowthState growth = {1000, 0},
|
||||
OrganismState state = OrganismState::alive) {
|
||||
auto cell =
|
||||
client::present_organism(id, {0, 0, 0}, {x_um}, {500000}, g, growth, temperate, state);
|
||||
CHECK(cell);
|
||||
return *cell;
|
||||
}
|
||||
client::OrganismPresentation presentation(std::vector<OrganismCell> cells,
|
||||
client::OrganismRevision revision = {identity, 1, 1}) {
|
||||
auto result = client::OrganismPresentation::create(revision, 0, cells);
|
||||
CHECK(result);
|
||||
return std::move(*result);
|
||||
}
|
||||
client::Camera camera(client::WorldPoint centre, double scale,
|
||||
client::Viewport viewport = {800, 600, 1600, 1200}) {
|
||||
auto result = client::Camera::create(viewport, centre, scale);
|
||||
CHECK(result);
|
||||
return *result;
|
||||
}
|
||||
std::vector<render::Rectangle> draw(const client::OrganismPresentation& p, const client::Camera& c,
|
||||
Freshness f = Freshness::current, std::size_t budget = 1755) {
|
||||
std::vector<render::Rectangle> out;
|
||||
const auto report = render::append_organisms(out, budget, &p, f, c);
|
||||
CHECK(report && out.size() <= budget);
|
||||
return out;
|
||||
}
|
||||
|
||||
void derived_from_biology() {
|
||||
const auto g = genome();
|
||||
const auto cell = organism(1, 500000, g);
|
||||
const auto expected = biology::derive_phenotype(g, {1000, 0}, temperate);
|
||||
CHECK(expected && cell.phenotype == *expected && cell.phenotype.extent == 20);
|
||||
// Structural binding pins the field list: adding a controller/owner/label
|
||||
// field fails to compile here (PROJECT_VISION shared presentation rule).
|
||||
const auto& [id, voxel, x, y, phenotype, growth, state] = cell;
|
||||
CHECK(id == 1 && voxel.z == 0 && x.value == 500000 && y.value == 500000 &&
|
||||
phenotype.extent == 20 && growth.realized_per_thousand == 1000 &&
|
||||
state == OrganismState::alive);
|
||||
// 20 um at 1000 units/mm is 20 logical units, centred at voxel offset 500 mm.
|
||||
const auto c = camera({500, 500}, 1000);
|
||||
const auto b = render::organism_bounds(cell, c);
|
||||
CHECK(b.left == 390 && b.right == 410 && b.top == 290 && b.bottom == 310);
|
||||
const auto plain = draw(presentation({cell}), c);
|
||||
// Body + membrane outline + status chip; no motility ring or ingestion mark.
|
||||
CHECK(plain.size() == 1 + 4 + 1);
|
||||
CHECK(same(plain[0].color, render::organism_fill(cell)));
|
||||
// Membrane share 28.8e6 / 36.8e6 of a 20-unit side: thickness capped at side/4.
|
||||
CHECK(plain[1].height == 5.0F);
|
||||
const auto capable = organism(1, 500000, genome(400, 50, 2000));
|
||||
CHECK(capable.phenotype.movement_speed > 0 && capable.phenotype.ingestion_rate > 0);
|
||||
const auto full = draw(presentation({capable}), c);
|
||||
CHECK(full.size() == render::organism_detail_rectangles + 1);
|
||||
CHECK(same(full[0].color, render::organism_palette::ring));
|
||||
CHECK(same(full[9].color, render::organism_palette::mouth));
|
||||
// Conversion, partial growth and damage change the body colour; nothing else does.
|
||||
CHECK(!same(render::organism_fill(organism(1, 500000, genome(900))),
|
||||
render::organism_fill(cell)));
|
||||
const auto half = organism(1, 500000, g, {500, 0});
|
||||
CHECK(half.phenotype.extent == 15 &&
|
||||
!same(render::organism_fill(half), render::organism_fill(cell)));
|
||||
const auto hurt = organism(1, 500000, g, {1000, 600});
|
||||
CHECK(render::organism_fill(hurt).red > render::organism_fill(hurt).green);
|
||||
// Zoomed out, the uniform visibility floor applies and detail collapses.
|
||||
const auto far = camera({500, 500}, 0.05);
|
||||
const auto tiny = render::organism_bounds(cell, far);
|
||||
CHECK(tiny.right - tiny.left == render::organism_visibility_floor);
|
||||
const auto collapsed = draw(presentation({capable}), far);
|
||||
CHECK(collapsed.size() == 2 + 1 && same(collapsed[0].color, render::organism_palette::halo));
|
||||
CHECK(collapsed[0].width == 7.0F && same(collapsed[1].color, render::organism_fill(capable)));
|
||||
}
|
||||
|
||||
// Controllers are host bookkeeping only; they never reach presentation inputs.
|
||||
enum class Controller : std::uint8_t { player, npc };
|
||||
struct HostOrganism {
|
||||
Controller controller;
|
||||
OrganismCell cell;
|
||||
};
|
||||
void controller_parity() {
|
||||
const auto g = genome(400, 50, 2000);
|
||||
const std::array<HostOrganism, 2> hosted{{{Controller::player, organism(5, 500000, g)},
|
||||
{Controller::npc, organism(900, 500000, g)}}};
|
||||
CHECK(hosted[0].controller != hosted[1].controller);
|
||||
const auto c = camera({500, 500}, 1000);
|
||||
const auto player = draw(presentation({hosted[0].cell}), c);
|
||||
const auto npc = draw(presentation({hosted[1].cell}), c);
|
||||
CHECK(same(player, npc)); // Identical biology renders identically.
|
||||
std::vector<render::Rectangle> a, b;
|
||||
CHECK(client::append_inspector(a, 25, hosted[0].cell, c) &&
|
||||
client::append_inspector(b, 25, hosted[1].cell, c) && same(a, b));
|
||||
// Same biology at different positions differs only by translation.
|
||||
const auto moved = organism(900, 500100, g);
|
||||
const auto shifted = draw(presentation({moved}), c);
|
||||
CHECK(shifted.size() == player.size());
|
||||
for (std::size_t i = 0; i + 1 < player.size(); ++i)
|
||||
CHECK(std::abs(shifted[i].x - player[i].x - 100) < 1e-3F && shifted[i].y == player[i].y &&
|
||||
shifted[i].width == player[i].width && same(shifted[i].color, player[i].color));
|
||||
// Draw output contains only biology encodings and status colours.
|
||||
for (const auto& r : player)
|
||||
CHECK(!same(r.color, render::organism_palette::truncated));
|
||||
}
|
||||
|
||||
void death_and_removal() {
|
||||
const auto g = genome(400, 50, 2000);
|
||||
const auto c = camera({500, 500}, 1000);
|
||||
client::OrganismLayer layer;
|
||||
CHECK(layer.accept(presentation({organism(1, 500000, g), organism(2, 500200, g)})));
|
||||
CHECK(draw(*layer.current(), c).size() == 2 * render::organism_detail_rectangles + 1);
|
||||
// Death: a remnant without motility ring or ingestion mark, same size.
|
||||
const auto dead = organism(2, 500200, g, {1000, 0}, OrganismState::dead);
|
||||
CHECK(layer.accept(presentation({organism(1, 500000, g), dead}, {identity, 2, 2})));
|
||||
const auto after = draw(*layer.current(), c);
|
||||
CHECK(after.size() == render::organism_detail_rectangles + 1 + 4 + 1);
|
||||
const auto remnant = after[render::organism_detail_rectangles];
|
||||
CHECK(same(remnant.color, render::organism_fill(dead)));
|
||||
CHECK(remnant.width == 20.0F &&
|
||||
same(render::organism_fill(dead),
|
||||
render::organism_fill(
|
||||
organism(2, 500200, genome(400), {1000, 0}, OrganismState::dead))));
|
||||
// Removal: absent from the next presentation, so nothing is drawn for it.
|
||||
CHECK(layer.accept(presentation({organism(1, 500000, g)}, {identity, 3, 3})));
|
||||
CHECK(draw(*layer.current(), c).size() == render::organism_detail_rectangles + 1);
|
||||
CHECK(layer.accept(presentation({}, {identity, 4, 4})) && layer.current()->cells().empty());
|
||||
const auto empty = draw(*layer.current(), c);
|
||||
CHECK(empty.size() == 1 && same(empty[0].color, render::palette::status_current));
|
||||
}
|
||||
|
||||
void dense_scenes() {
|
||||
const auto g = genome(400, 50, 2000);
|
||||
std::vector<OrganismCell> cells;
|
||||
cells.reserve(client::max_organism_cells);
|
||||
for (std::uint64_t i = 0; i < client::max_organism_cells; ++i)
|
||||
cells.push_back(organism(i + 1, 1000 * (i % 32) + 484000, g, {1000, 0}));
|
||||
for (std::size_t i = 0; i < cells.size(); ++i)
|
||||
cells[i].y = {1000 * (i / 32) + 484000};
|
||||
const auto p = presentation(cells);
|
||||
// Every organism visible at full scale: detail collapses to one body each.
|
||||
const auto c = camera({500, 500}, 25, {1280, 1280, 1280, 1280});
|
||||
std::vector<render::Rectangle> out;
|
||||
auto report = render::append_organisms(out, 1755, &p, Freshness::current, c);
|
||||
CHECK(report && report->visible == 1024 && report->drawn == 1024 &&
|
||||
report->detail == render::OrganismDetail::body_only && out.size() == 1025);
|
||||
// A small budget truncates explicitly: drawn < visible and the marker appears.
|
||||
out.clear();
|
||||
report = render::append_organisms(out, 500, &p, Freshness::stale, c);
|
||||
CHECK(report && report->drawn == 498 && out.size() == 500);
|
||||
CHECK(same(out.back().color, render::organism_palette::truncated));
|
||||
CHECK(same(out[out.size() - 2].color, render::palette::status_stale));
|
||||
out.clear();
|
||||
CHECK(refused(render::append_organisms(out, 1, &p, Freshness::current, c),
|
||||
render::OrganismRenderError::invalid_budget));
|
||||
// A narrow view draws few organisms at full detail.
|
||||
const auto zoomed = camera({500, 500}, 1000, {200, 200, 200, 200});
|
||||
report = render::append_organisms(out, 1755, &p, Freshness::current, zoomed);
|
||||
CHECK(report && report->detail == render::OrganismDetail::full && report->visible > 0 &&
|
||||
report->visible < 20 && out.size() <= report->visible * 10 + 1);
|
||||
// Worst-case frame: environment bound + organisms + inspector + host UI fit Frame.
|
||||
out.assign(render::max_environment_rectangles, {0, 0, 1, 1, {}});
|
||||
CHECK(render::append_organisms(out, 1755, &p, Freshness::current, c));
|
||||
CHECK(client::append_inspector(out, client::inspector_rectangles, cells[0], c));
|
||||
out.resize(out.size() + 3, {0, 0, 1, 1, {}});
|
||||
CHECK(out.size() <= render::max_rectangles && render::Frame::create(out));
|
||||
for (const auto& r : out)
|
||||
CHECK(r.x >= 0 && r.y >= 0 && r.x + r.width <= 1280.01F && r.y + r.height <= 1280.01F);
|
||||
}
|
||||
|
||||
void ordering_and_freshness() {
|
||||
const auto g = genome();
|
||||
client::OrganismLayer layer;
|
||||
CHECK(layer.freshness() == Freshness::none);
|
||||
const auto c = camera({500, 500}, 1000);
|
||||
std::vector<render::Rectangle> out;
|
||||
CHECK(render::append_organisms(out, 10, nullptr, Freshness::current, c));
|
||||
CHECK(out.size() == 1 && same(out[0].color, render::palette::status_none));
|
||||
CHECK(layer.accept(presentation({organism(1, 500000, g)}, {identity, 5, 5})));
|
||||
CHECK(refused(layer.accept(presentation({}, {identity, 4, 9})), ViewError::regressed));
|
||||
CHECK(refused(layer.accept(presentation({}, {identity, 9, 4})), ViewError::regressed));
|
||||
CHECK(refused(layer.accept(presentation({}, {{3, 5}, 9, 9})), ViewError::foreign_world));
|
||||
CHECK(refused(layer.observe({identity, 5, 4}), ViewError::regressed));
|
||||
CHECK(layer.observe({identity, 5, 5}) && layer.freshness() == Freshness::current);
|
||||
CHECK(layer.observe({identity, 6, 5}) && layer.freshness() == Freshness::stale);
|
||||
const auto stale = draw(*layer.current(), c, layer.freshness());
|
||||
CHECK(same(stale[0].color, render::dim(render::organism_fill(layer.current()->cells()[0]))));
|
||||
CHECK(same(stale.back().color, render::palette::status_stale));
|
||||
CHECK(layer.accept(presentation({organism(1, 500000, g)}, {identity, 6, 5})) &&
|
||||
layer.freshness() == Freshness::current);
|
||||
layer.mark_stale();
|
||||
CHECK(layer.freshness() == Freshness::stale);
|
||||
layer.reset();
|
||||
CHECK(layer.freshness() == Freshness::none && layer.accept(presentation({}, {{3, 5}, 1, 1})));
|
||||
}
|
||||
|
||||
void invalid_cells() {
|
||||
const auto valid = organism(2, 500000, genome());
|
||||
const auto create = [](std::vector<OrganismCell> cells, std::int64_t z = 0) {
|
||||
return client::OrganismPresentation::create({identity, 1, 1}, z, cells);
|
||||
};
|
||||
CHECK(create({valid}) && create({}));
|
||||
CHECK(refused(create({valid}, world::voxel_limit), ViewError::invalid_view));
|
||||
CHECK(refused(create({valid, valid}), ViewError::invalid_view));
|
||||
auto lower = valid;
|
||||
lower.id = 1;
|
||||
CHECK(create({lower, valid}) && refused(create({valid, lower}), ViewError::invalid_view));
|
||||
const auto broken = [&](auto mutate) {
|
||||
auto cell = valid;
|
||||
mutate(cell);
|
||||
return refused(create({cell}), ViewError::invalid_view);
|
||||
};
|
||||
CHECK(broken([](OrganismCell& c) { c.id = 0; }));
|
||||
CHECK(broken([](OrganismCell& c) { c.voxel.z = 1; }));
|
||||
CHECK(broken([](OrganismCell& c) { c.voxel.x = world::voxel_limit; }));
|
||||
CHECK(broken([](OrganismCell& c) { c.x.value = 1'000'000; }));
|
||||
CHECK(broken([](OrganismCell& c) { c.y.value = 1'000'000; }));
|
||||
CHECK(broken([](OrganismCell& c) { c.phenotype.total_mass += 1; }));
|
||||
CHECK(
|
||||
broken([](OrganismCell& c) { c.phenotype.structural_mass = c.phenotype.total_mass + 1; }));
|
||||
CHECK(broken([](OrganismCell& c) { c.phenotype.extent = 1'000'001; }));
|
||||
CHECK(broken([](OrganismCell& c) { c.phenotype.conversion_per_thousand = 1001; }));
|
||||
CHECK(broken([](OrganismCell& c) { c.growth.realized_per_thousand = 1001; }));
|
||||
CHECK(broken([](OrganismCell& c) { c.growth.damage_per_thousand = 1001; }));
|
||||
// Out-of-range enumerator models untrusted decoded input; rejecting it is the point.
|
||||
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
|
||||
CHECK(broken([](OrganismCell& c) { c.state = OrganismState{2}; }));
|
||||
std::vector<OrganismCell> many;
|
||||
for (std::uint64_t i = 1; i <= client::max_organism_cells + 1; ++i) {
|
||||
auto cell = valid;
|
||||
cell.id = i;
|
||||
many.push_back(cell);
|
||||
}
|
||||
CHECK(refused(create(many), ViewError::too_many_cells));
|
||||
// Invalid ids and phenotype derivation failures surface as invalid views.
|
||||
CHECK(refused(client::present_organism(0, {}, {}, {}, genome(), {1000, 0}, temperate,
|
||||
OrganismState::alive),
|
||||
ViewError::invalid_view));
|
||||
CHECK(refused(client::present_organism(1, {}, {}, {}, genome(), {1001, 0}, temperate,
|
||||
OrganismState::alive),
|
||||
ViewError::invalid_view));
|
||||
}
|
||||
|
||||
void picking_and_inspector() {
|
||||
const auto g = genome(400, 50, 2000);
|
||||
const auto p = presentation({organism(1, 500000, g), organism(2, 500010, g)});
|
||||
const auto c = camera({500, 500}, 1000);
|
||||
CHECK(client::pick_organism(p, c, {395, 300}) == std::optional<std::size_t>{0});
|
||||
CHECK(client::pick_organism(p, c, {405, 300}) == std::optional<std::size_t>{1}); // Topmost.
|
||||
CHECK(!client::pick_organism(p, c, {100, 100}));
|
||||
// Zoomed out, picking uses the same floored box that is drawn.
|
||||
const auto far = camera({500, 500}, 0.05);
|
||||
const auto b = render::organism_bounds(p.cells()[0], far);
|
||||
CHECK(client::pick_organism(p, far, {(b.left + b.right) / 2, (b.top + b.bottom) / 2}));
|
||||
const auto values = client::inspector_gauge_values(p.cells()[0]);
|
||||
CHECK(std::abs(values[2] - 28.8 / 36.8) < 1e-12 && values[6] == 0.4 && values[7] == 1 &&
|
||||
values[8] == 0 && values[4] > 0 && values[5] > 0);
|
||||
for (const double v : values)
|
||||
CHECK(v >= 0 && v <= 1);
|
||||
std::vector<render::Rectangle> out;
|
||||
CHECK(refused(client::append_inspector(out, client::inspector_rectangles - 1, p.cells()[0], c),
|
||||
client::InspectorError::invalid_budget));
|
||||
CHECK(client::append_inspector(out, client::inspector_rectangles, p.cells()[0], c));
|
||||
CHECK(out.size() <= client::inspector_rectangles && out.size() >= 4 + 1 + 10);
|
||||
// Gauge fill width encodes the value: conversion 0.4 of 112 units.
|
||||
CHECK(std::abs(out[4 + 1 + 2 * 6 + 1].width - 44.8F) < 1e-3F);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main() try {
|
||||
derived_from_biology();
|
||||
controller_parity();
|
||||
death_and_removal();
|
||||
dense_scenes();
|
||||
ordering_and_freshness();
|
||||
invalid_cells();
|
||||
picking_and_inspector();
|
||||
std::puts("client organism tests passed");
|
||||
return 0;
|
||||
} catch (const std::exception& e) {
|
||||
std::fprintf(stderr, "%s\n", e.what());
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user