Resolve cellular patch contention per tick
Foundation / checks (deploy) (push) Successful in 6s
Foundation / checks (ecs) (push) Successful in 1m55s
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 1m26s
Foundation / checks (client) (push) Canceled after 3m33s
Foundation / checks (checks) (push) Canceled after 3m38s

This commit is contained in:
dingo
2026-10-10 21:51:38 -04:00
parent 747b063c65
commit b5e831f385
11 changed files with 343 additions and 11 deletions
+7
View File
@@ -89,6 +89,13 @@ class CellularHabitat {
[[nodiscard]] std::expected<CellularPatchUptakeProposal, CellularHabitatError>
propose_uptake(CellularPatchAddress address, CellularPosition position, std::uint32_t extent_um,
accounting::Inventory reserve, const MetabolicBudget& budget) const noexcept;
// Same authoritative map/contact checks with stock supplied by a detached shared-tick
// candidate after earlier life claims have been resolved.
[[nodiscard]] std::expected<CellularPatchUptakeProposal, CellularHabitatError>
propose_uptake_from_stock(CellularPatchAddress address, CellularPosition position,
std::uint32_t extent_um, accounting::Inventory patch_stock,
accounting::Inventory reserve,
const MetabolicBudget& budget) const noexcept;
// Canonical little-endian envelope, FNV-1a64 checksum for corruption checks only.
[[nodiscard]] std::vector<std::uint8_t> snapshot() const;
@@ -0,0 +1,58 @@
#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 reserve;
accounting::Inventory heat;
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 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;
auto operator<=>(const CellularRegionStepCandidate&) const = default;
};
enum class CellularRegionStepError : std::uint8_t {
invalid_tick,
too_many_lives,
invalid_life_id,
duplicate_life_id,
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.
[[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