M11.2a: fund equal primitive lives from finite spawn pools
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m44s
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 (network) (push) Canceled after 13s
Foundation / checks (checks) (push) Canceled after 3m9s
Foundation / checks (client) (push) Canceled after 3m8s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m44s
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 (network) (push) Canceled after 13s
Foundation / checks (checks) (push) Canceled after 3m9s
Foundation / checks (client) (push) Canceled after 3m8s
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
#pragma once
|
||||
|
||||
#include "evo/biology/founder.hpp"
|
||||
#include "evo/biology/lineage.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
// Portable, single-owner server orchestration, not the foundation simulation.
|
||||
// M11.2a is an in-memory candidate; success is NOT a durable acknowledgement.
|
||||
// The host must authorize requests and publish the entire state plus bindings
|
||||
// atomically (ADR-0100). No network, database, clocks or implicit biology here.
|
||||
namespace evo::server {
|
||||
using LifeAccount = std::array<std::uint8_t, 16>;
|
||||
struct SpawnSite {
|
||||
std::int32_t x_um{}, y_um{}; // Region/frame-local, micrometres.
|
||||
auto operator<=>(const SpawnSite&) const = default;
|
||||
};
|
||||
inline constexpr std::size_t max_primitive_lives = 256;
|
||||
inline constexpr std::int32_t spawn_coordinate_limit_um = 1'000'000'000;
|
||||
struct NurseryConfig {
|
||||
std::uint64_t world{}, region{}, frame{}, source{};
|
||||
accounting::Inventory funding{}; // Explicit finite opening, never replenished here.
|
||||
std::vector<SpawnSite> sites; // Server-approved habitat; sorted lexicographically.
|
||||
};
|
||||
struct LifeRequest {
|
||||
LifeAccount account{};
|
||||
std::uint64_t action{};
|
||||
auto operator<=>(const LifeRequest&) const = default;
|
||||
};
|
||||
// Obtained from the world's durable allocator by the host, never from the client.
|
||||
// All identities are distinct namespaces. Gaps are allowed, reuse is not.
|
||||
struct LifeAllocation {
|
||||
std::uint64_t life{}, organism{}, genome{}, event{};
|
||||
Tick born{};
|
||||
auto operator<=>(const LifeAllocation&) const = default;
|
||||
};
|
||||
struct PrimitiveLife {
|
||||
LifeRequest request{};
|
||||
LifeAllocation identity{};
|
||||
std::uint64_t source{}; // Funding provenance, within config.world.
|
||||
SpawnSite site{};
|
||||
biology::GrowthState growth{};
|
||||
accounting::ReservoirId body{}, reserve{};
|
||||
auto operator<=>(const PrimitiveLife&) const = default;
|
||||
};
|
||||
enum class LifeError : std::uint8_t {
|
||||
invalid,
|
||||
capacity,
|
||||
occupied,
|
||||
existing_life,
|
||||
identity_conflict,
|
||||
insufficient_funding,
|
||||
overflow,
|
||||
biology,
|
||||
archive
|
||||
};
|
||||
|
||||
class PrimitiveLives {
|
||||
public:
|
||||
[[nodiscard]] static std::expected<std::unique_ptr<PrimitiveLives>, LifeError>
|
||||
create(NurseryConfig config);
|
||||
~PrimitiveLives();
|
||||
PrimitiveLives(const PrimitiveLives&) = delete;
|
||||
PrimitiveLives& operator=(const PrimitiveLives&) = delete;
|
||||
// Selects the first free provisioned site. Exact successful retry resolves
|
||||
// before allocation/site/funding checks, returning the original life.
|
||||
// Different action for an account already living is refused. On any refusal
|
||||
// (or allocation exception), every inventory and history entry is unchanged.
|
||||
[[nodiscard]] std::expected<PrimitiveLife, LifeError> spawn(LifeRequest request,
|
||||
LifeAllocation allocation);
|
||||
// References/spans are invalidated by a successful non-retry spawn.
|
||||
[[nodiscard]] const NurseryConfig& config() const noexcept;
|
||||
[[nodiscard]] std::span<const PrimitiveLife> lives() const noexcept;
|
||||
[[nodiscard]] std::span<const accounting::Inventory> balances() const noexcept;
|
||||
[[nodiscard]] accounting::Inventory totals() const noexcept;
|
||||
[[nodiscard]] const biology::LineageArchive& archive() const noexcept;
|
||||
|
||||
private:
|
||||
struct State;
|
||||
explicit PrimitiveLives(std::unique_ptr<State> state);
|
||||
std::unique_ptr<State> state_;
|
||||
};
|
||||
} // namespace evo::server
|
||||
Reference in New Issue
Block a user