Foundation / checks (ecs) (push) Successful in 2m26s
Foundation / checks (deploy) (push) Successful in 4m57s
Foundation / checks (network) (push) Successful in 20m53s
Foundation / checks (client) (push) Successful in 22m12s
Foundation / checks (tsan) (push) Successful in 39m45s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 45m41s
Foundation / checks (checks) (push) Canceled after 45m43s
96 lines
3.9 KiB
C++
96 lines
3.9 KiB
C++
#pragma once
|
|
|
|
#include "evo/server/lifecycle/cellular_population.hpp"
|
|
|
|
#include <array>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <expected>
|
|
#include <span>
|
|
#include <vector>
|
|
|
|
namespace evo::server {
|
|
inline constexpr std::uint32_t cellular_census_projection_version = 1;
|
|
inline constexpr std::uint32_t cellular_plan_census_projection_version = 2;
|
|
enum class CellularCensusKind : std::uint8_t {
|
|
individual_wildlife,
|
|
cohort_wildlife,
|
|
active_controlled,
|
|
lingering_controlled,
|
|
suspended_controlled
|
|
};
|
|
inline constexpr std::size_t cellular_census_kind_count = 5;
|
|
struct CellularCensusStock {
|
|
std::uint64_t count{};
|
|
accounting::Inventory body{}, reserve{};
|
|
bool operator==(const CellularCensusStock&) const = default;
|
|
};
|
|
struct CellularCensusTotals {
|
|
std::array<CellularCensusStock, cellular_census_kind_count> resident{};
|
|
// Historical observations only: no owned inventory/current viability claim.
|
|
std::uint64_t retained_nonresident_records{};
|
|
// Projection 2: references only, never additional organisms or inventory.
|
|
std::array<std::uint64_t, cellular_census_kind_count> living_plan_holders{};
|
|
std::uint64_t retained_dead_plan_records{};
|
|
bool operator==(const CellularCensusTotals&) const = default;
|
|
};
|
|
struct CellularCensusRow {
|
|
std::uint64_t genome{};
|
|
std::uint32_t schema{}, development{};
|
|
std::vector<std::uint64_t> parents;
|
|
CellularCensusTotals totals;
|
|
bool operator==(const CellularCensusRow&) const = default;
|
|
};
|
|
struct CellularCensusBoundary {
|
|
std::uint64_t world{}, region{}, frame{}, tick{};
|
|
std::uint32_t owner_format{}, rules{}, population_format{}; // Zero: raw owner.
|
|
std::uint64_t quantum_microseconds{biology::cellular_motion_tick_microseconds};
|
|
std::uint32_t projection_version{cellular_census_projection_version};
|
|
bool operator==(const CellularCensusBoundary&) const = default;
|
|
};
|
|
enum class CellularCensusScope : std::uint8_t { exact_genome, descendants, invalid = 255 };
|
|
enum class CellularCensusError : std::uint8_t {
|
|
unsupported,
|
|
history,
|
|
overflow,
|
|
unknown_genome,
|
|
invalid_scope
|
|
};
|
|
// Detached bounded observation, NOT a committed/world-complete evidence record.
|
|
// It never owns inventory, changes biology or reports terminal extinction.
|
|
// ADR-0159: rules 8/owner 6 or 7; rules 9/owner 7 (raw or population envelope 2).
|
|
// Growth observes retained body/reserve, never an unfunded adult forecast.
|
|
// ADR-0169/0171: rules 10/owner 8, raw or envelope 3, uses projection 2.
|
|
class CellularCensus {
|
|
public:
|
|
[[nodiscard]] static std::expected<CellularCensus, CellularCensusError>
|
|
observe(const CellularLives&);
|
|
[[nodiscard]] static std::expected<CellularCensus, CellularCensusError>
|
|
observe(const CellularPopulation&);
|
|
[[nodiscard]] const CellularCensusBoundary& boundary() const noexcept {
|
|
return boundary_;
|
|
}
|
|
// Ascending genome IDs. All retained ancestors remain, even with zero residents.
|
|
[[nodiscard]] std::span<const CellularCensusRow> rows() const noexcept {
|
|
return rows_;
|
|
}
|
|
// Descendants includes the anchor. Unknown is an error, never a zero report.
|
|
[[nodiscard]] std::expected<CellularCensusTotals, CellularCensusError>
|
|
query(std::uint64_t anchor, CellularCensusScope scope) const;
|
|
|
|
private:
|
|
friend class CellularCensusSet;
|
|
CellularCensus() = default;
|
|
[[nodiscard]] static std::expected<CellularCensus, CellularCensusError>
|
|
observe(const CellularLives&, std::span<const CellularCohortMember>, std::uint32_t population);
|
|
[[nodiscard]] std::size_t locate(std::uint64_t genome) const;
|
|
CellularCensusBoundary boundary_;
|
|
std::vector<CellularCensusRow> rows_;
|
|
std::vector<std::vector<std::size_t>> children_;
|
|
// Complete immutable identity evidence for cross-region consistency checks.
|
|
// A short content digest alone cannot establish equality.
|
|
std::vector<biology::Genome> genomes_;
|
|
std::vector<std::uint64_t> residents_;
|
|
};
|
|
} // namespace evo::server
|