Complete M6.1 environmental units and coupling contract
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
#pragma once
|
||||
|
||||
#include "evo/accounting/ledger.hpp"
|
||||
|
||||
#include <compare>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
|
||||
namespace evo::world {
|
||||
inline constexpr std::uint32_t environmental_units_version = 1;
|
||||
inline constexpr std::uint64_t habitat_axis_limit_um = 1'000'000;
|
||||
inline constexpr std::uint64_t habitat_volume_limit_um3 = 1'000'000'000'000'000'000;
|
||||
|
||||
struct Micrometres {
|
||||
std::uint64_t value{};
|
||||
auto operator<=>(const Micrometres&) const = default;
|
||||
};
|
||||
struct SquareMicrometres {
|
||||
std::uint64_t value{};
|
||||
auto operator<=>(const SquareMicrometres&) const = default;
|
||||
};
|
||||
struct CubicMicrometres {
|
||||
std::uint64_t value{};
|
||||
auto operator<=>(const CubicMicrometres&) const = default;
|
||||
};
|
||||
// Half-open, axis-aligned box inside one 1m voxel. No world identity or reservation.
|
||||
struct HabitatBox {
|
||||
Micrometres x, y, z;
|
||||
Micrometres width, height, depth;
|
||||
};
|
||||
struct HabitatMeasure {
|
||||
SquareMicrometres area;
|
||||
CubicMicrometres volume;
|
||||
auto operator<=>(const HabitatMeasure&) const = default;
|
||||
};
|
||||
// Read-only ratios, not inventories. Helpers return reduced forms (zero is 0/1).
|
||||
struct MassConcentration {
|
||||
std::uint64_t femtograms{}, cubic_micrometres{1};
|
||||
auto operator<=>(const MassConcentration&) const = default;
|
||||
};
|
||||
struct WaterSaturation {
|
||||
std::uint64_t numerator{}, denominator{1};
|
||||
auto operator<=>(const WaterSaturation&) const = default;
|
||||
};
|
||||
struct EnergyRate {
|
||||
std::uint64_t picojoules_numerator{}, ticks_denominator{1};
|
||||
};
|
||||
struct EnergyIntegral {
|
||||
accounting::Picojoules amount;
|
||||
// Numerator of a fractional pJ, with the input rate's unchanged denominator.
|
||||
std::uint64_t remainder{};
|
||||
auto operator<=>(const EnergyIntegral&) const = default;
|
||||
};
|
||||
enum class EnvironmentUnitError : std::uint8_t {
|
||||
invalid_extent,
|
||||
outside_voxel,
|
||||
invalid_volume,
|
||||
zero_capacity,
|
||||
excess_water,
|
||||
invalid_rate,
|
||||
invalid_remainder,
|
||||
overflow
|
||||
};
|
||||
|
||||
// Public aggregates are unvalidated input. All helpers are pure and checked.
|
||||
[[nodiscard]] std::expected<HabitatMeasure, EnvironmentUnitError>
|
||||
measure_habitat(HabitatBox box) noexcept;
|
||||
[[nodiscard]] std::expected<MassConcentration, EnvironmentUnitError>
|
||||
mass_concentration(accounting::Femtograms mass, CubicMicrometres volume) noexcept;
|
||||
[[nodiscard]] std::expected<WaterSaturation, EnvironmentUnitError>
|
||||
water_saturation(accounting::Femtograms water, accounting::Femtograms capacity) noexcept;
|
||||
// Requires numerator*ticks+remainder to fit u64 even if its quotient could fit.
|
||||
// Returns a proposal: does not fund energy, own a residual or advance an interval.
|
||||
[[nodiscard]] std::expected<EnergyIntegral, EnvironmentUnitError>
|
||||
integrate_energy(EnergyRate rate, std::uint64_t ticks, std::uint64_t remainder) noexcept;
|
||||
} // namespace evo::world
|
||||
Reference in New Issue
Block a user