Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 1m53s
Foundation / checks (client) (push) Failing after 4m23s
Foundation / checks (network) (push) Failing after 3m5s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (tsan) (push) Canceled after 32s
Foundation / checks (checks) (push) Canceled after 5m42s
Foundation / checks (postgres) (push) Canceled after 1m19s
71 lines
2.9 KiB
C++
71 lines
2.9 KiB
C++
#pragma once
|
|
|
|
#include "evo/biology/metabolism.hpp"
|
|
|
|
#include <compare>
|
|
#include <cstdint>
|
|
#include <expected>
|
|
|
|
namespace evo::biology {
|
|
inline constexpr std::uint64_t cellular_motion_tick_microseconds = 50'000;
|
|
inline constexpr std::uint64_t cellular_motion_axis_limit_um = 1'000'000;
|
|
inline constexpr std::int32_t cellular_intent_component_limit = 1'000;
|
|
|
|
struct CellularArea {
|
|
std::uint64_t width_um{}, height_um{};
|
|
auto operator<=>(const CellularArea&) const = default;
|
|
};
|
|
// Lower-left corner of the cell's square footprint, in micrometres.
|
|
struct CellularPosition {
|
|
std::uint64_t x_um{}, y_um{};
|
|
auto operator<=>(const CellularPosition&) const = default;
|
|
};
|
|
// Bounded movement direction/magnitude, not a position or speed claim.
|
|
struct CellularIntent {
|
|
std::int16_t x{}, y{};
|
|
auto operator<=>(const CellularIntent&) const = default;
|
|
};
|
|
struct CellularMotionProposal {
|
|
CellularPosition position;
|
|
std::uint64_t distance_um{}; // Conservative integer upper bound on actual travel.
|
|
accounting::Picojoules movement_cost{};
|
|
auto operator<=>(const CellularMotionProposal&) const = default;
|
|
};
|
|
struct CellularMotionCandidate {
|
|
CellularPosition position;
|
|
accounting::Inventory reserve_after;
|
|
accounting::Inventory heat_after;
|
|
accounting::Picojoules movement_cost{};
|
|
auto operator<=>(const CellularMotionCandidate&) const = default;
|
|
};
|
|
enum class CellularMotionError : std::uint8_t {
|
|
invalid_area,
|
|
invalid_extent,
|
|
outside_area,
|
|
invalid_intent,
|
|
unsupported_rate_period,
|
|
insufficient_reserve,
|
|
overflow
|
|
};
|
|
|
|
// Pure M11.3 proposal for one 50 ms tick. Costs are reported, not spent; the
|
|
// authoritative state owner must apply the proposal only when its reserve can
|
|
// fund the movement_cost. Only per-second development-v2 budgets are accepted.
|
|
[[nodiscard]] std::expected<CellularMotionProposal, CellularMotionError>
|
|
propose_cellular_motion(CellularArea area, CellularPosition position, std::uint32_t extent_um,
|
|
CellularIntent intent, const MetabolicBudget& budget) noexcept;
|
|
|
|
// Detached one-tick candidate: movement is refused if reserve cannot pay, and
|
|
// paid energy moves to heat in the same returned value. Inputs are unchanged.
|
|
[[nodiscard]] std::expected<CellularMotionCandidate, CellularMotionError>
|
|
propose_funded_cellular_motion(CellularArea area, CellularPosition position,
|
|
std::uint32_t extent_um, CellularIntent intent,
|
|
const MetabolicBudget& budget, accounting::Inventory reserve,
|
|
accounting::Inventory heat) noexcept;
|
|
|
|
// Axis-aligned square footprints touching at an edge count as in contact.
|
|
[[nodiscard]] bool cellular_footprints_contact(CellularPosition a, std::uint32_t extent_a_um,
|
|
CellularPosition b,
|
|
std::uint32_t extent_b_um) noexcept;
|
|
} // namespace evo::biology
|