Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (checks) (push) Failing after 41s
Foundation / checks (ecs) (push) Successful in 1m55s
Foundation / checks (postgres) (push) Failing after 52s
Foundation / checks (tsan) (push) Failing after 31s
Foundation / checks (network) (push) Failing after 3m3s
Foundation / checks (client) (push) Failing after 4m26s
Foundation / postgres-tools (push) Skipped
Foundation / server-image (push) Skipped
Foundation / image (push) Skipped
112 lines
4.0 KiB
C++
112 lines
4.0 KiB
C++
#pragma once
|
|
|
|
#include "evo/biology/cellular_region_step.hpp"
|
|
#include "evo/server/lifecycle/primitive_lives.hpp"
|
|
|
|
#include <compare>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <expected>
|
|
#include <memory>
|
|
#include <span>
|
|
#include <vector>
|
|
|
|
namespace evo::server {
|
|
inline constexpr std::uint32_t cellular_lives_format = 1;
|
|
inline constexpr std::size_t max_cellular_lives_bytes = std::size_t{16} * 1024 * 1024;
|
|
|
|
struct CellularOwnedLife {
|
|
LifeAccount account{};
|
|
LifeAllocation identity{};
|
|
std::uint64_t source{};
|
|
biology::GrowthState growth{};
|
|
biology::CellularPosition position{};
|
|
accounting::Inventory body{};
|
|
accounting::Inventory reserve{};
|
|
auto operator<=>(const CellularOwnedLife&) const = default;
|
|
};
|
|
struct CellularOwnedCorpse {
|
|
std::uint64_t life_id{};
|
|
std::uint64_t organism{};
|
|
std::uint64_t source{};
|
|
std::uint64_t died_tick{};
|
|
biology::CellularPosition position{};
|
|
biology::GrowthState growth{};
|
|
std::uint32_t extent_um{};
|
|
accounting::Inventory inventory{};
|
|
auto operator<=>(const CellularOwnedCorpse&) const = default;
|
|
};
|
|
struct CellularLifeIntent {
|
|
std::uint64_t life_id{};
|
|
biology::CellularStepIntent intent{};
|
|
auto operator<=>(const CellularLifeIntent&) const = default;
|
|
};
|
|
struct CellularLivesConfig {
|
|
biology::CellularArea area{};
|
|
std::uint64_t tick{};
|
|
std::uint32_t ambient_temperature_millikelvin{};
|
|
};
|
|
enum class CellularLivesError : std::uint8_t {
|
|
identity,
|
|
invalid_config,
|
|
invalid_life,
|
|
duplicate_life,
|
|
invalid_tick,
|
|
invalid_intents,
|
|
biology,
|
|
region_step,
|
|
archive,
|
|
habitat,
|
|
overflow,
|
|
conservation,
|
|
format,
|
|
version,
|
|
checksum,
|
|
noncanonical
|
|
};
|
|
|
|
// In-memory authoritative cellular owner. It consumes funded profile-3 opening
|
|
// state but never mutates or reinterprets that checkpoint. Each tick is applied
|
|
// to a detached candidate and swapped only after life, corpse, heat, habitat and
|
|
// archive closure all validate. Durable profile-4 publication remains external.
|
|
class CellularLives {
|
|
public:
|
|
[[nodiscard]] static std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
|
|
create(const PrimitiveLives& opening, std::unique_ptr<biology::CellularHabitat> habitat,
|
|
CellularLivesConfig config);
|
|
CellularLives(const CellularLives&) = delete;
|
|
CellularLives& operator=(const CellularLives&) = delete;
|
|
~CellularLives();
|
|
|
|
[[nodiscard]] std::uint64_t world() const noexcept;
|
|
[[nodiscard]] std::uint64_t region() const noexcept;
|
|
[[nodiscard]] std::uint64_t frame() const noexcept;
|
|
[[nodiscard]] std::uint64_t tick() const noexcept;
|
|
[[nodiscard]] biology::CellularArea area() const noexcept;
|
|
[[nodiscard]] std::span<const CellularOwnedLife> lives() const noexcept;
|
|
[[nodiscard]] std::span<const CellularOwnedCorpse> corpses() const noexcept;
|
|
[[nodiscard]] const biology::CellularHabitat& habitat() const noexcept;
|
|
[[nodiscard]] const biology::LineageArchive& archive() const noexcept;
|
|
[[nodiscard]] accounting::Inventory nursery() const noexcept;
|
|
[[nodiscard]] accounting::Inventory heat() const noexcept;
|
|
[[nodiscard]] accounting::Inventory opening_total() const noexcept;
|
|
[[nodiscard]] accounting::Inventory current_total() const noexcept;
|
|
[[nodiscard]] std::vector<std::uint8_t> snapshot() const;
|
|
|
|
[[nodiscard]] static std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
|
|
restore(std::span<const std::uint8_t> bytes, std::uint64_t world, std::uint64_t region,
|
|
std::uint64_t frame, std::uint64_t tick);
|
|
|
|
// Advances every living cell exactly one 50 ms tick. Intentions are keyed by
|
|
// stable life ID and must cover the living set exactly. Any refusal leaves
|
|
// this owner byte-for-byte unchanged.
|
|
[[nodiscard]] std::expected<biology::CellularRegionStepCandidate, CellularLivesError>
|
|
advance_tick(std::span<const CellularLifeIntent> intents);
|
|
|
|
private:
|
|
struct State;
|
|
explicit CellularLives(std::unique_ptr<State> state);
|
|
std::unique_ptr<State> state_;
|
|
};
|
|
} // namespace evo::server
|