Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (checks) (push) Failing after 39s
Foundation / checks (ecs) (push) Successful in 1m53s
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 (postgres) (push) Canceled after 50s
Foundation / checks (client) (push) Canceled after 2m59s
Foundation / checks (network) (push) Canceled after 2m22s
73 lines
2.7 KiB
C++
73 lines
2.7 KiB
C++
#pragma once
|
|
|
|
#include "evo/biology/cellular_step.hpp"
|
|
|
|
#include <compare>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <expected>
|
|
#include <span>
|
|
#include <vector>
|
|
|
|
namespace evo::biology {
|
|
inline constexpr std::size_t max_cellular_tick_lives = 256;
|
|
|
|
struct CellularLifeStepInput {
|
|
std::uint64_t life_id{}; // Stable world identity; arbitrates same-tick patch contention.
|
|
CellularPosition position;
|
|
std::uint32_t extent_um{};
|
|
CellularStepIntent intent;
|
|
accounting::Inventory body; // Structural matter; energy must be zero.
|
|
accounting::Inventory reserve;
|
|
accounting::Inventory heat; // Energy-only owner; matter channels must be zero.
|
|
MetabolicBudget budget;
|
|
auto operator<=>(const CellularLifeStepInput&) const = default;
|
|
};
|
|
struct CellularLifeStepResult {
|
|
std::uint64_t life_id{};
|
|
CellularStepCandidate candidate;
|
|
auto operator<=>(const CellularLifeStepResult&) const = default;
|
|
};
|
|
struct CellularPatchStockUpdate {
|
|
CellularPatchAddress address;
|
|
accounting::Inventory stock;
|
|
auto operator<=>(const CellularPatchStockUpdate&) const = default;
|
|
};
|
|
struct CellularCorpseCandidate {
|
|
std::uint64_t life_id{};
|
|
CellularPosition position;
|
|
accounting::Inventory inventory; // Body and reserve; accumulated heat is transferred out.
|
|
auto operator<=>(const CellularCorpseCandidate&) const = default;
|
|
};
|
|
struct CellularRegionStepCandidate {
|
|
std::uint64_t begin_tick{}, end_tick{};
|
|
// Sorted by stable life_id, independent of connection or input order.
|
|
std::vector<CellularLifeStepResult> lives;
|
|
std::vector<CellularPatchStockUpdate> patches;
|
|
std::vector<CellularCorpseCandidate> starved;
|
|
accounting::Picojoules heat_released{};
|
|
auto operator<=>(const CellularRegionStepCandidate&) const = default;
|
|
};
|
|
enum class CellularRegionStepError : std::uint8_t {
|
|
invalid_tick,
|
|
too_many_lives,
|
|
invalid_life_id,
|
|
duplicate_life_id,
|
|
invalid_body,
|
|
invalid_heat,
|
|
overflow,
|
|
life_step,
|
|
habitat
|
|
};
|
|
|
|
// Detached shared-habitat candidate. Same-tick claims resolve by ascending stable life id;
|
|
// the first valid claimant spends from each patch's remaining per-channel stock. Any refused
|
|
// life step rejects the complete candidate; the caller publishes nothing. If maintenance
|
|
// cannot be paid, the life dies in this tick: body and reserve move to one corpse candidate,
|
|
// and its accumulated heat is reported separately for transfer to the world heat owner.
|
|
[[nodiscard]] std::expected<CellularRegionStepCandidate, CellularRegionStepError>
|
|
propose_cellular_region_step(std::uint64_t begin_tick, CellularArea area,
|
|
std::span<const CellularLifeStepInput> lives,
|
|
const CellularHabitat& habitat);
|
|
} // namespace evo::biology
|