feat(ecology): make photosynthesis regions playable on DEV
Foundation / checks (ecs) (push) Successful in 2m19s
Foundation / checks (deploy) (push) Successful in 4m47s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 16m48s
Foundation / checks (network) (push) Canceled after 16m46s
Foundation / checks (postgres) (push) Canceled after 16m47s
Foundation / checks (client) (push) Canceled after 16m53s
Foundation / checks (tsan) (push) Canceled after 14m33s

ADR-0176 and schema 57 admit raw cellular bundle 13 (rules 11 on owner
format 9) through parser-local normalization to bundle 12, and a fenced
no-tick 12 -> 13 upgrade that declares the region's light; recovery reads
the light from the target and re-derives the whole target from the source.
The resumable cellular-v8 opening provisions a cellular-v7 genesis, one
empty tick and the durable upgrades to bundle 13.

Session v12 adds the owner's captured light and the producers it can see
to its perception, and lets offers name photosynthesis; older sessions keep
their layouts and never receive photosynthesis candidates. The client
draws chloroplasts by efficiency, shows sunlight in the HUD and offers
photosynthesis cards. DEV now provisions and serves region 9 with the
trial light; region 8 stays stored but unserved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-19 23:04:34 -04:00
co-authored by Claude Opus 5.5
parent 108f29eda5
commit b73ccbae9a
38 changed files with 1106 additions and 140 deletions
+17
View File
@@ -840,6 +840,18 @@ int main(int argc, char** argv) try {
}
}
const auto own = cellular_remote->cellular_play().life();
// ADR-0176: the owner's view lists the producers it can see, by organism.
const auto* seen = cellular_remote->cellular_perception();
const auto photosynthesis = [&](std::uint64_t organism) -> std::uint32_t {
if (!seen)
return 0;
const auto found = std::ranges::lower_bound(
seen->producers, organism, {},
&evo::network::CellularPerceivedProducer::organism);
return found != seen->producers.end() && found->organism == organism
? found->photosynthesis_per_thousand
: 0;
};
if (orgs)
for (const auto& cell : orgs->cells()) {
const auto bounds = evo::render::organism_bounds(cell, *camera);
@@ -863,6 +875,11 @@ int main(int argc, char** argv) try {
c.membrane = static_cast<float>(std::clamp(1.0 + wall * 6.0, 1.0, 7.0));
c.organelles = 2 + static_cast<int>(std::min<std::uint32_t>(
3, ph.conversion_per_thousand / 250));
c.photosynthesis_per_thousand = photosynthesis(cell.id);
c.chloroplasts = c.photosynthesis_per_thousand == 0
? 0
: 1 + static_cast<int>(std::min<std::uint32_t>(
5, c.photosynthesis_per_thousand / 200));
c.own = own != 0 && cell.id == own;
c.dead = cell.state == evo::client::OrganismState::dead;
c.stale =
+26 -7
View File
@@ -740,6 +740,15 @@ void draw_cell(ImDrawList& list, const SceneCell& c, float time) {
add(add(centre, times(axis, u * radius.x * 1.1F)), times(normal, v * radius.y * 0.9F)),
std::max(1.5F, r * 0.16F), organelle);
}
// Producers (ADR-0176): chloroplasts, more of them for more efficient cells.
for (int k = 0; k < c.chloroplasts; ++k) {
const auto key = c.seed * 53U + 11U + static_cast<std::uint64_t>(k);
const float u = unit_of(key) - 0.55F, v = unit_of(key + 5U) - 0.5F;
const ImVec2 at =
add(add(centre, times(axis, u * radius.x * 1.1F)), times(normal, v * radius.y * 0.9F));
list.AddCircleFilled(at, std::max(1.8F, r * 0.18F), IM_COL32(64, 168, 84, 230));
list.AddCircleFilled(at, std::max(0.8F, r * 0.08F), IM_COL32(150, 222, 128, 230));
}
const ImVec2 nucleus = add(centre, times(axis, radius.x * 0.42F));
list.AddCircleFilled(nucleus, std::max(2.0F, r * 0.3F), IM_COL32(224, 86, 63, 220));
list.AddCircleFilled(nucleus, std::max(1.0F, r * 0.14F), IM_COL32(255, 156, 134, 235));
@@ -895,6 +904,8 @@ void inspect_cell(ImDrawList& list, const SceneCell& c) {
c.mass_fg == 0 ? 0U : static_cast<unsigned>(c.membrane_fg * 100 / c.mass_fg));
ImGui::Text("Intake %s/s", mass_text(c.ingestion_fg_s).c_str());
ImGui::Text("Converts %u%% of food energy", c.conversion_per_thousand / 10);
if (c.photosynthesis_per_thousand != 0)
ImGui::Text("Light %u%% photosynthesis", c.photosynthesis_per_thousand / 10);
}
ImGui::EndTooltip();
}
@@ -1059,6 +1070,8 @@ void hud_vitals(const PanelView& v, bool compact) {
movement.at(static_cast<std::size_t>(d->movement)),
intake.at(static_cast<std::size_t>(d->intake)),
energy_text(d->maintenance_cost_pj).c_str());
if (d->light_pj != 0)
ImGui::TextDisabled("Sunlight +%s", energy_text(d->light_pj).c_str());
}
ImGui::End();
}
@@ -1259,11 +1272,11 @@ void hud_callout(const PanelView& v, FormBuffers& form) {
ImGui::PopStyleColor(3);
ImGui::End();
}
constexpr std::array capability_names{"Energy conversion", "Membrane", "Movement",
"Ingestion", "Reproduction", "Size",
"Thermal tolerance"};
constexpr std::array capability_kinds{"Metabolism", "Defense", "Movement", "Feeding",
"Reproduction", "Size", "Environment"};
constexpr std::array capability_names{"Energy conversion", "Membrane", "Movement",
"Ingestion", "Reproduction", "Size",
"Thermal tolerance", "Photosynthesis"};
constexpr std::array capability_kinds{"Metabolism", "Defense", "Movement", "Feeding",
"Reproduction", "Size", "Environment", "Producer"};
constexpr std::array effect_names{"Increase", "Decrease", "Acquire", "Shed"};
constexpr std::array increase_text{"Convert more of what you eat into usable energy.",
"A thicker wall: prey must be much larger to engulf you.",
@@ -1271,14 +1284,16 @@ constexpr std::array increase_text{"Convert more of what you eat into usable ene
"Take food faster from every patch you touch.",
"Better at budding: cheaper buds, more twins (+10%).",
"Grow toward a larger body: harder to engulf, slower to fill.",
"Tolerate a wider range of temperatures."};
"Tolerate a wider range of temperatures.",
"Capture 10% more light while still; heavier and slower."};
constexpr std::array decrease_text{"Convert less of what you eat into energy.",
"A thinner, cheaper wall that is easier to breach.",
"Swim 10% slower and spend less on movement.",
"Take food more slowly from each patch.",
"Worse at budding: dearer buds, fewer twins (-10%).",
"Grow toward a smaller body that is cheaper to keep.",
"Tolerate a narrower range of temperatures."};
"Tolerate a narrower range of temperatures.",
"Capture 10% less light; lighter and a little faster."};
// A small before/after drawing of the cell for one candidate.
void candidate_glyph(const network::CellularOfferedCandidate& c, float width) {
const ImVec2 at = ImGui::GetCursorScreenPos();
@@ -1303,6 +1318,10 @@ void candidate_glyph(const network::CellularOfferedCandidate& c, float width) {
case 0:
after.organelles = up ? 5 : 1;
break;
case 7:
after.chloroplasts = c.effect == 3 ? 0 : up ? 5 : 2;
before.chloroplasts = c.effect == 2 ? 0 : 3;
break;
default:
break;
}
+2
View File
@@ -35,6 +35,8 @@ struct SceneCell {
// What hovering the cell shows (its replicated phenotype; no hidden state).
std::uint32_t extent_um{}, speed_um_s{}, conversion_per_thousand{}, grown_per_thousand{};
std::uint64_t mass_fg{}, membrane_fg{}, ingestion_fg_s{};
std::uint32_t photosynthesis_per_thousand{}; // Zero unless the owner's view lists it.
int chloroplasts{}; // ADR-0176: green organelles in proportion to photosynthesis.
};
struct ScenePatch {
float x{}, y{}, half{}; // Centre and half side of the 1 mm contact footprint.
+2 -1
View File
@@ -499,7 +499,8 @@ class RemoteSession {
return false;
client::RegionSessionClientConfig config;
if (cellular_trial_)
config.protocol_version = network::session_protocol_v11; // ADR-0136 deposits.
// ADR-0176: v12 is v11 (deposits) plus captured light and visible producers.
config.protocol_version = network::session_protocol_v12;
const auto route = routes_.find(target_region_);
config.transport = route != routes_.end() ? route->second : transport_;
if (ticket_) { // A handoff: the ticket replaces a grant, once.
+49 -7
View File
@@ -284,13 +284,11 @@ class CellularBridge {
const auto before = deposit_stock_.find(patch.id);
deposit.drained = before != deposit_stock_.end() &&
(patch.available.energy.value < before->second.energy.value ||
std::ranges::any_of(
std::array{0, 1, 2, 3},
[&](int c) {
const auto i = static_cast<std::size_t>(c);
return patch.available.matter.at(i).value <
before->second.matter.at(i).value;
}));
std::ranges::any_of(std::array{0, 1, 2, 3}, [&](int c) {
const auto i = static_cast<std::size_t>(c);
return patch.available.matter.at(i).value <
before->second.matter.at(i).value;
}));
seen_stock_[patch.id] = patch.available;
const auto dx = std::int64_t{patch.address.x_um} - centre_x;
const auto dy = std::int64_t{patch.address.y_um} - centre_y;
@@ -320,6 +318,50 @@ class CellularBridge {
visible.matter_fg[i] = patch.available.matter[i].value;
view.patches.push_back(visible);
}
// ADR-0176 (v12): light this cell captured, and the photosynthetic cells it can
// see within its perception radius (nearest 256), by ascending organism.
if (view.diagnostics && feedback != state.last_tick_feedback().end() &&
feedback->life_id == life.identity.life)
view.diagnostics->light_pj = feedback->light.value;
if (life.account != server::LifeAccount{}) {
std::vector<std::pair<std::uint64_t, network::CellularPerceivedProducer>> seen;
for (const auto& other : state.lives()) {
if (other.presence == server::CellularPresence::suspended)
continue;
const auto genome = state.archive().find(other.identity.genome);
if (!genome || !genome->carries(biology::Capability::photosynthesis))
continue;
const auto dx = static_cast<std::int64_t>(other.position.x_um) - centre_x;
const auto dy = static_cast<std::int64_t>(other.position.y_um) - centre_y;
const auto distance = static_cast<std::uint64_t>(dx * dx + dy * dy);
constexpr auto radius =
std::uint64_t{biology::cellular_trial_perception_radius_um};
if (distance > radius * radius)
continue;
const auto efficiency =
genome->parameter(biology::Capability::photosynthesis).value_or(0);
if (efficiency == 0 || efficiency > 1000)
continue;
seen.emplace_back(distance, network::CellularPerceivedProducer{
other.identity.organism,
static_cast<std::uint16_t>(efficiency)});
}
if (seen.size() > network::max_cellular_perceived_producers) {
std::ranges::nth_element(
seen,
seen.begin() +
static_cast<std::ptrdiff_t>(network::max_cellular_perceived_producers),
[](const auto& a, const auto& b) {
return std::pair{a.first, a.second.organism} <
std::pair{b.first, b.second.organism};
});
seen.resize(network::max_cellular_perceived_producers);
}
for (const auto& [distance, producer] : seen)
view.producers.push_back(producer);
std::ranges::sort(view.producers, {},
&network::CellularPerceivedProducer::organism);
}
(void)sessions_->send_cellular_perception(network::AccountId{life.account}, view);
send_offer(state, life, tick);
}
+133 -8
View File
@@ -10,7 +10,7 @@
// evo-world-clone check-store --world W --region R --pg-* ... --objects DIR
// [--reserve-mib N]
// evo-world-clone provision --world W --region R --opening
// development-v1|primitive-v1|cellular-v1 to cellular-v7
// development-v1|primitive-v1|cellular-v1 to cellular-v8
// --pg-* ... --objects DIR --build HEX [--commit HEX32] [--retain-build]
// primitive-v1 also requires --frame N --source-id N, every --funding-*-* channel,
// and one or more ordered --site X,Y values.
@@ -70,6 +70,7 @@
// Exit: 0 done, 2 usage, 3 source/history/database failure, 4 target/objects refused,
// 5 target unknown, 6 compared histories differ.
#include "evo/biology/cellular_habitat.hpp"
#include "evo/persistence/checkpoint_store.hpp"
#include "evo/persistence/region_clone.hpp"
#include "evo/persistence/sha256.hpp"
#include "evo/processes/development_opening.hpp"
@@ -116,7 +117,8 @@ struct Options {
std::optional<std::uint32_t> cellular_width_um, cellular_height_um, cellular_temperature_mk;
std::vector<biology::CellularPatch> cellular_patches;
std::vector<biology::CellularPatch> cellular_pools; // cellular-v7
std::optional<biology::CellularMoteField> cellular_motes; // cellular-v7
std::optional<biology::CellularMoteField> cellular_motes; // cellular-v7 and v8
std::optional<std::uint64_t> light_pj; // cellular-v8: pJ per square um per tick
std::optional<std::uint64_t> life_allocator_start;
std::optional<persistence::Sha256Digest> build;
bool retain_build{};
@@ -333,8 +335,11 @@ std::optional<Options> parse(int argc, char** argv) {
else if (o.command == "provision" && flag == "--opening" &&
(value == "development-v1" || value == "primitive-v1" || value == "cellular-v1" ||
value == "cellular-v2" || value == "cellular-v3" || value == "cellular-v4" ||
value == "cellular-v5" || value == "cellular-v6" || value == "cellular-v7"))
value == "cellular-v5" || value == "cellular-v6" || value == "cellular-v7" ||
value == "cellular-v8"))
o.opening = value;
else if (o.command == "provision" && flag == "--light-pj" && n && *n > 0)
o.light_pj = n;
else if (o.command == "provision" && flag == "--frame" && n)
o.primitive_frame = n;
else if (o.command == "provision" && flag == "--source-id" && n)
@@ -418,8 +423,11 @@ std::optional<Options> parse(int argc, char** argv) {
return std::nullopt;
if (cellular_options)
return std::nullopt;
} else if (o.opening == "cellular-v7") {
// Pools and bubbles only: square patches belong to the earlier openings.
} else if (o.opening == "cellular-v7" || o.opening == "cellular-v8") {
// Pools and bubbles only: square patches belong to the earlier openings. Only
// cellular-v8 (ADR-0176) declares light.
if ((o.opening == "cellular-v8") != o.light_pj.has_value())
return std::nullopt;
if (!o.primitive_frame || *o.primitive_frame == 0 || !o.primitive_source ||
*o.primitive_source == 0 || o.primitive_sites.empty() ||
!std::ranges::all_of(o.primitive_funding,
@@ -540,12 +548,104 @@ std::vector<std::uint8_t> probe_bytes() {
return out;
}
// ADR-0176 cellular-v8: a cellular-v7 genesis taken through one empty tick and the durable
// bundle 9 -> 10 -> 11 -> 12 -> 13 upgrades, declaring the region's light. Resumable: it
// continues from whichever bundle the head has reached, and does nothing at bundle 13.
int finish_photosynthesis_opening(const Options& o, persistence::Postgres& db,
const persistence::FilesystemObjectStore& store,
std::uint64_t frame, const persistence::Sha256Digest& build,
std::uint64_t light_pj) {
const auto& key = o.source.key;
auto lease =
persistence::acquire_region_lease(db, key, build, std::chrono::seconds{60}, timeout);
if (!lease) {
std::puts("photosynthesis opening lease refused");
return 3;
}
const auto finish = [&](int code) {
// A failed release only delays the next owner until the lease expires.
if (!persistence::release_region_lease(db, key, *lease, timeout))
std::puts("photosynthesis opening lease left to expire");
return code;
};
auto head = persistence::load_region_checkpoint(db, key, timeout);
if (!head)
return finish(3);
for (unsigned step = 0; step < 6; ++step) {
const auto manifest = persistence::decode_manifest(head->manifest);
if (!manifest || manifest->profile != persistence::CheckpointProfile::cellular_lives_v1 ||
manifest->frame != frame)
return finish(4);
const auto& versions = manifest->cellular_versions;
if (versions == persistence::cellular_v13_versions)
return finish(0);
const auto id = [&] {
persistence::Uuid made{};
if (::getrandom(made.data(), made.size(), 0) != static_cast<ssize_t>(made.size()))
made = {};
return made;
}();
if (id == persistence::Uuid{})
return finish(4);
if (manifest->sequence == 0) {
// Upgrades follow a committed tick, never the genesis itself.
const std::array<persistence::Sha256Digest, 1> builds{build};
auto opening =
persistence::recover_cellular_checkpoint(db, store, key, *lease, builds, timeout);
if (!opening)
return finish(4);
const server::CellularBatchHeader h{key.world,
key.region,
frame,
head->head.commit,
head->head.digest,
head->head.end_tick,
head->head.end_tick + 1};
const server::CellularBatch tick{h, {{}}};
auto next = server::replay_cellular_batch(*opening->state, tick);
if (!next)
return finish(4);
auto published = persistence::publish_cellular_batch(db, store, *lease, *head, tick,
**next, id, build, timeout);
if (!published)
return finish(4);
head = std::move(published->committed);
continue;
}
std::expected<persistence::CommittedCheckpoint,
persistence::CellularProfileMigrationFailure>
upgraded = std::unexpected(persistence::CellularProfileMigrationFailure{});
if (versions == persistence::cellular_v9_versions)
upgraded = persistence::migrate_cellular_boundary_profile(db, store, *lease, *head, id,
build, timeout);
else if (versions == persistence::cellular_v10_versions)
upgraded = persistence::migrate_cellular_maturation_profile(db, store, *lease, *head,
id, build, timeout);
else if (versions == persistence::cellular_v11_versions)
upgraded = persistence::migrate_cellular_inheritance_profile(db, store, *lease, *head,
id, build, timeout);
else if (versions == persistence::cellular_v12_versions)
upgraded = persistence::migrate_cellular_photosynthesis_profile(
db, store, *lease, *head, id, build,
{light_pj, 1, {std::numeric_limits<std::uint64_t>::max() / 2}}, timeout);
else
return finish(4);
if (!upgraded) {
std::printf("photosynthesis opening upgrade refused %u\n",
static_cast<unsigned>(upgraded.error().kind));
return finish(4);
}
head = std::move(*upgraded);
}
return finish(4);
}
int provision(const Options& o) {
const bool primitive = o.opening == "primitive-v1";
const bool cellular = o.opening == "cellular-v1" || o.opening == "cellular-v2" ||
o.opening == "cellular-v3" || o.opening == "cellular-v4" ||
o.opening == "cellular-v5" || o.opening == "cellular-v6" ||
o.opening == "cellular-v7";
o.opening == "cellular-v7" || o.opening == "cellular-v8";
const auto primitive_frame = o.primitive_frame.value_or(0);
if ((primitive || cellular) && primitive_frame == 0)
return 2;
@@ -640,7 +740,7 @@ int provision(const Options& o) {
habitat_config.width_um = cellular_width_um;
habitat_config.height_um = cellular_height_um;
habitat_config.patches = o.cellular_patches;
if (o.opening == "cellular-v7") {
if (o.opening == "cellular-v7" || o.opening == "cellular-v8") {
// ADR-0136 step A: pools and bubbles scattered from the genesis commit's bytes.
auto field = o.cellular_motes.value_or(biology::CellularMoteField{0, 1, {}, 0});
const auto commit = o.commit.value_or(persistence::Uuid{});
@@ -662,7 +762,8 @@ int provision(const Options& o) {
auto opening = server::CellularLives::create(
*primitive_opening, std::move(*habitat),
{{cellular_width_um, cellular_height_um}, 0, cellular_temperature_mk},
o.opening == "cellular-v7" ? server::CellularLivesProfile::foraging
o.opening == "cellular-v7" || o.opening == "cellular-v8"
? server::CellularLivesProfile::foraging
: o.opening == "cellular-v6" ? server::CellularLivesProfile::reproduction
: o.opening == "cellular-v5" ? server::CellularLivesProfile::balance
: o.opening == "cellular-v4" ? server::CellularLivesProfile::presence
@@ -705,6 +806,22 @@ int provision(const Options& o) {
std::puts("provision refused existing profile/frame mismatch");
return 4;
}
if (o.opening == "cellular-v8") {
if (manifest->sequence == 0 &&
!persistence::provision_cellular_region(*db, *store, o.source.key,
primitive_frame, *cellular_opening,
commit, manifest->build, timeout)) {
std::puts("provision refused existing cellular region; use its original "
"--commit to resolve genesis");
return 4;
}
if (const auto finished = finish_photosynthesis_opening(
o, *db, *store, primitive_frame, build, o.light_pj.value_or(0));
finished != 0)
return finished;
auto head = persistence::load_region_checkpoint(*db, o.source.key, timeout);
return head ? report("already-provisioned", head->head) : 3;
}
if (manifest->sequence > 0)
return report("already-provisioned", existing->head);
auto same_genesis = persistence::provision_cellular_region(
@@ -751,6 +868,14 @@ int provision(const Options& o) {
static_cast<unsigned>(made.error().kind));
return 4;
}
if (o.opening == "cellular-v8") {
if (const auto finished = finish_photosynthesis_opening(o, *db, *store, primitive_frame,
build, o.light_pj.value_or(0));
finished != 0)
return finished;
auto head = persistence::load_region_checkpoint(*db, o.source.key, timeout);
return head ? report("provisioned", head->head) : 3;
}
return report("provisioned", made->head);
}
if (primitive) {