Retain cellular death provenance and growth
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (network) (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 0s
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 41s
Foundation / checks (client) (push) Canceled after 42s
Foundation / checks (ecs) (push) Canceled after 38s

This commit is contained in:
dingo
2026-10-10 22:25:06 -04:00
parent 562781ce77
commit 04cdc1e9c7
4 changed files with 42 additions and 6 deletions
+19 -4
View File
@@ -53,6 +53,7 @@ sum_state(accounting::Inventory nursery, accounting::Inventory heat,
struct CellularLives::State {
std::uint64_t world{}, region{}, frame{};
CellularLivesConfig config{};
NurseryConfig nursery_config{};
std::unique_ptr<biology::CellularHabitat> habitat;
std::vector<CellularOwnedLife> lives;
std::vector<CellularOwnedCorpse> corpses;
@@ -63,12 +64,13 @@ struct CellularLives::State {
accounting::Inventory current_total{};
State(std::uint64_t world_id, std::uint64_t region_id, std::uint64_t frame_id,
CellularLivesConfig cfg, std::unique_ptr<biology::CellularHabitat> map,
CellularLivesConfig cfg, NurseryConfig nursery, std::unique_ptr<biology::CellularHabitat> map,
std::vector<CellularOwnedLife> living, std::vector<CellularOwnedCorpse> dead,
const biology::LineageArchive& history, accounting::Inventory source,
accounting::Inventory accumulated_heat, accounting::Inventory initial,
accounting::Inventory current)
: world{world_id}, region{region_id}, frame{frame_id}, config{cfg},
nursery_config{std::move(nursery)},
habitat{std::move(map)}, lives{std::move(living)}, corpses{std::move(dead)},
archive{history}, nursery{source}, heat{accumulated_heat}, opening_total{initial},
current_total{current} {}
@@ -83,7 +85,7 @@ CellularLives::create(const PrimitiveLives& opening,
CellularLivesConfig config) {
if (!habitat)
return std::unexpected{CellularLivesError::invalid_config};
const auto& nursery_config = opening.config();
auto nursery_config = opening.config();
const auto& map = habitat->config();
if (nursery_config.world == 0 || nursery_config.region == 0 || nursery_config.frame == 0 ||
map.world != nursery_config.world || map.region != nursery_config.region ||
@@ -136,6 +138,7 @@ CellularLives::create(const PrimitiveLives& opening,
if (!add_inventory(initial_total, habitat->totals()))
return std::unexpected{CellularLivesError::overflow};
const auto nursery = opening.balances()[0];
nursery_config.funding = nursery;
const auto heat = opening.balances()[1];
const auto current = sum_state(nursery, heat, *habitat, lives, {});
if (!current)
@@ -145,6 +148,7 @@ CellularLives::create(const PrimitiveLives& opening,
auto state = std::make_unique<State>(
nursery_config.world, nursery_config.region, nursery_config.frame, config,
std::move(nursery_config),
std::move(habitat), std::move(lives), std::vector<CellularOwnedCorpse>{},
opening.archive(), nursery, heat, initial_total, *current);
return std::unique_ptr<CellularLives>{new CellularLives{std::move(state)}};
@@ -226,8 +230,18 @@ CellularLives::advance_tick(std::span<const CellularLifeIntent> intents) {
if (found == next_lives.end() || found->identity.life != dead.life_id ||
!next_archive.record_death(found->identity.organism, {proposal->end_tick}))
return std::unexpected{CellularLivesError::archive};
next_corpses.push_back(
{found->identity.organism, proposal->end_tick, dead.position, dead.inventory});
const auto corpse_budget = budget_for(
next_archive, *found, state_->config.ambient_temperature_millikelvin);
if (!corpse_budget)
return std::unexpected{corpse_budget.error()};
next_corpses.push_back({found->identity.life,
found->identity.organism,
found->source,
proposal->end_tick,
dead.position,
found->growth,
corpse_budget->phenotype.extent,
dead.inventory});
next_lives.erase(found);
}
std::ranges::sort(next_corpses, {}, &CellularOwnedCorpse::organism);
@@ -258,6 +272,7 @@ CellularLives::advance_tick(std::span<const CellularLifeIntent> intents) {
state_->world, state_->region, state_->frame,
CellularLivesConfig{state_->config.area, proposal->end_tick,
state_->config.ambient_temperature_millikelvin},
state_->nursery_config,
std::move(*next_habitat), std::move(next_lives), std::move(next_corpses), next_archive,
state_->nursery, next_heat, state_->opening_total, *total);
state_.swap(next);