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
@@ -16,12 +16,29 @@ struct CellularCohortMember {
std::uint64_t life{}, genome{};
auto operator<=>(const CellularCohortMember&) const = default;
};
enum class CellularPopulationError : std::uint8_t { unsupported, absent, ineligible };
enum class CellularPopulationError : std::uint8_t {
unsupported,
absent,
ineligible,
format,
checksum,
identity,
overflow
};
struct CellularTierPolicy {
bool automatic{false};
std::uint32_t materialize_radius_um{1'200}, collapse_radius_um{1'800};
auto operator<=>(const CellularTierPolicy&) const = default;
};
inline constexpr std::size_t cellular_population_header_bytes = 80;
inline constexpr std::size_t max_cellular_population_bytes = cellular_population_header_bytes +
16 * biology::max_cellular_tick_lives +
max_cellular_lives_bytes + 8;
class CellularPopulation {
public:
[[nodiscard]] static std::expected<std::unique_ptr<CellularPopulation>, CellularPopulationError>
create(std::unique_ptr<CellularLives> state);
create(std::unique_ptr<CellularLives> state, CellularTierPolicy policy = {});
CellularPopulation(const CellularPopulation&) = delete;
CellularPopulation& operator=(const CellularPopulation&) = delete;
@@ -29,6 +46,16 @@ class CellularPopulation {
[[nodiscard]] const CellularLives& state() const noexcept;
[[nodiscard]] std::span<const CellularCohortMember> members() const noexcept;
[[nodiscard]] bool in_cohort(std::uint64_t life) const noexcept;
[[nodiscard]] CellularTierPolicy policy() const noexcept;
[[nodiscard]] std::uint64_t conversion_sequence() const noexcept;
[[nodiscard]] std::vector<std::uint8_t> snapshot() const;
[[nodiscard]] static std::expected<std::unique_ptr<CellularPopulation>, CellularPopulationError>
restore(std::span<const std::uint8_t> bytes, std::uint64_t world, std::uint64_t region,
std::uint64_t frame, std::uint64_t tick);
// Detached exact sample for publication. Never acknowledge it before a fenced
// durable head commits its complete snapshot; recovery restores that sample.
[[nodiscard]] std::expected<std::unique_ptr<CellularPopulation>, CellularPopulationError>
conversion_candidate(std::uint64_t genome, bool to_cohort) const;
// Convert the WHOLE eligible wildlife genome group. No selectable healthy subset,
// resampling, rounding, new identity, healing, age reset or inventory transfer.
@@ -45,8 +72,11 @@ class CellularPopulation {
std::span<const CellularMutationSelection> selections = {});
private:
explicit CellularPopulation(std::unique_ptr<CellularLives> state);
explicit CellularPopulation(std::unique_ptr<CellularLives> state, CellularTierPolicy policy);
void apply_policy();
std::unique_ptr<CellularLives> state_;
std::vector<CellularCohortMember> members_; // Sorted life IDs, unique ownership tags.
CellularTierPolicy policy_;
std::uint64_t conversion_sequence_{};
};
} // namespace evo::server