M12.3: persist exact population state and automatic conversion policy
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 3m16s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (client) (push) Canceled after 13m8s
Foundation / checks (checks) (push) Canceled after 13m12s
Foundation / checks (postgres) (push) Canceled after 13m2s
Foundation / checks (network) (push) Canceled after 13m4s
Foundation / checks (tsan) (push) Canceled after 13m9s

This commit is contained in:
dingo
2026-10-17 12:11:10 -04:00
parent 2b074b9ae1
commit 5decaa0326
14 changed files with 624 additions and 15 deletions
@@ -0,0 +1,51 @@
#include "evo/server/lifecycle/cellular_population.hpp"
#include <algorithm>
#include <set>
namespace evo::server {
void CellularPopulation::apply_policy() {
auto candidate = members_;
std::set<std::uint64_t> genomes;
for (const auto& life : state_->lives())
if (life.account == LifeAccount{})
genomes.insert(life.identity.genome);
const auto inner = std::uint64_t{policy_.materialize_radius_um} * policy_.materialize_radius_um;
const auto outer = std::uint64_t{policy_.collapse_radius_um} * policy_.collapse_radius_um;
for (const auto genome : genomes) {
bool near = false, far = true, eligible = true;
for (const auto& life : state_->lives()) {
if (life.account != LifeAccount{} || life.identity.genome != genome)
continue;
eligible = eligible && life.presence == CellularPresence::active;
for (const auto& observer : state_->lives()) {
if (observer.account == LifeAccount{} ||
observer.presence == CellularPresence::suspended)
continue;
const auto dx = life.position.x_um > observer.position.x_um
? life.position.x_um - observer.position.x_um
: observer.position.x_um - life.position.x_um;
const auto dy = life.position.y_um > observer.position.y_um
? life.position.y_um - observer.position.y_um
: observer.position.y_um - life.position.y_um;
const auto distance = dx * dx + dy * dy; // Coordinates bounded to 1e6 um.
near = near || distance <= inner;
far = far && distance > outer;
}
}
if (near || !eligible) {
std::erase_if(candidate, [genome](const auto& m) { return m.genome == genome; });
} else if (far) {
std::erase_if(candidate, [genome](const auto& m) { return m.genome == genome; });
for (const auto& life : state_->lives())
if (life.account == LifeAccount{} && life.identity.genome == genome)
candidate.push_back({life.identity.life, genome});
}
}
std::ranges::sort(candidate);
if (candidate != members_) {
members_.swap(candidate);
++conversion_sequence_;
}
}
} // namespace evo::server