Foundation / checks (deploy) (push) Successful in 3m27s
Foundation / checks (ecs) (push) Successful in 1m58s
Foundation / checks (client) (push) Successful in 12m20s
Foundation / checks (network) (push) Successful in 13m53s
Foundation / checks (tsan) (push) Successful in 8m9s
Foundation / checks (checks) (push) Successful in 33m4s
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 21m43s
Rules 3 is rules 2 with irradiance, growth, intake and decay per second. The community derives its per-tick form once at creation and restore (rationals exact via the tick in numerator and denominator, caps rounded down); steps and the snapshot layout are rules 2's; the codec reads formats 1-3. At 50 ms a x20 per-second twin steps identically through feeding, death and decay and across a snapshot; at 25 ms caps halve. Rules 1/2 and the development-v1 opening are unchanged. Development version 1 outputs stay tied to their 50 ms quantum and the tick-abstract M2 fixtures are not migrated (recorded). environmental-qualification's "unknown rules" case moves from 3 to 4. Refresh the dev session window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
112 lines
5.1 KiB
C++
112 lines
5.1 KiB
C++
#pragma once
|
|
#include "evo/world/transfers.hpp"
|
|
#include <optional>
|
|
namespace evo::processes {
|
|
// Explicit fixture parameters; units and array order in environmental-community.md.
|
|
// Rules 1 and 2 state rates per tick of `tick_microseconds`. Rules 3 (ADR-0099) is rules
|
|
// 2 with every rate per second: irradiance and growth as rationals per second (converted
|
|
// exactly), and intake and decay caps per second (rounded down at the tick).
|
|
struct EnvironmentalConfig {
|
|
std::uint64_t rules{1}, world{}, frame{}, producer{}, consumer{}, source{}, tick_microseconds{},
|
|
area_um2{}, irradiance_numerator{}, irradiance_denominator{1}, efficiency{},
|
|
growth_numerator{}, growth_denominator{1}, growth_cost{};
|
|
std::array<std::uint64_t, 5> recipe{}, intake{};
|
|
std::uint64_t assimilation{}, producer_min_mK{}, producer_max_mK{}, consumer_min_mK{},
|
|
consumer_max_mK{};
|
|
std::array<std::uint64_t, 10> decay{}; // Rules 2+: shared source-channel caps per tick
|
|
// (rules 3: per second).
|
|
auto operator<=>(const EnvironmentalConfig&) const = default;
|
|
};
|
|
struct EnvironmentalInput {
|
|
std::uint64_t temperature_mK{}, source_enabled{};
|
|
std::array<std::uint64_t, 5> bite{};
|
|
std::array<std::uint64_t, 2> terminal{}; // Rules 2: trusted host facts, actor order.
|
|
auto operator<=>(const EnvironmentalInput&) const = default;
|
|
};
|
|
struct EnvironmentalProgress {
|
|
std::uint64_t tick{}, source_remainder{}, last_funded{}, efficiency_remainder{},
|
|
growth_remainder{}, producer_terminal{};
|
|
std::uint64_t consumer_terminal{};
|
|
auto operator<=>(const EnvironmentalProgress&) const = default;
|
|
};
|
|
struct EnvironmentalReport {
|
|
std::uint64_t tick{}, captured{}, retained{}, capture_heat{}, grown{}, unmet{}, source_status{};
|
|
std::array<std::uint64_t, 5> assimilated{}, waste{};
|
|
std::uint64_t terminal_transition{};
|
|
std::uint64_t consumer_transition{};
|
|
std::array<std::uint64_t, 10> decomposed{};
|
|
auto operator<=>(const EnvironmentalReport&) const = default;
|
|
};
|
|
enum class CommunityError : std::uint8_t {
|
|
config,
|
|
input,
|
|
tick,
|
|
conflict,
|
|
stale,
|
|
capacity,
|
|
insufficient,
|
|
overflow,
|
|
budget,
|
|
format,
|
|
version,
|
|
checksum,
|
|
resources
|
|
};
|
|
class EnvironmentalCommunity {
|
|
public:
|
|
static constexpr std::size_t history_limit = 64, scratch_bytes = 65536,
|
|
max_snapshot_bytes = std::size_t{1024} * 1024;
|
|
[[nodiscard]] static std::expected<std::unique_ptr<EnvironmentalCommunity>, CommunityError>
|
|
create(EnvironmentalConfig config, std::unique_ptr<world::EnvironmentalTransfers> resources,
|
|
std::size_t budget);
|
|
[[nodiscard]] std::expected<EnvironmentalReport, CommunityError>
|
|
advance(std::uint64_t tick, const EnvironmentalInput& input);
|
|
[[nodiscard]] std::expected<world::WorldBytes, CommunityError> snapshot() const;
|
|
[[nodiscard]] static std::expected<std::unique_ptr<EnvironmentalCommunity>, CommunityError>
|
|
restore(std::span<const std::uint8_t> bytes, world::WorldIdentity identity, std::size_t budget);
|
|
[[nodiscard]] const world::EnvironmentalTransfers& resources() const noexcept {
|
|
return *resources_;
|
|
}
|
|
[[nodiscard]] EnvironmentalProgress progress() const noexcept {
|
|
return progress_;
|
|
}
|
|
[[nodiscard]] std::uint64_t tick_microseconds() const noexcept {
|
|
return config_.tick_microseconds;
|
|
}
|
|
[[nodiscard]] std::uint64_t world() const noexcept {
|
|
return config_.world;
|
|
}
|
|
// Clone support (ADR-0067): records the region under another nonzero world ID,
|
|
// keeping its frame. Rules, content and trajectory do not depend on the world ID
|
|
// (ADR-0044), so rebinding back yields byte-identical snapshots. False for 0.
|
|
[[nodiscard]] bool rebind_world(std::uint64_t world) noexcept;
|
|
|
|
private:
|
|
struct State {
|
|
std::array<std::uint64_t, 10> environment{}, producer{}, consumer{};
|
|
EnvironmentalProgress progress{};
|
|
auto operator<=>(const State&) const = default;
|
|
};
|
|
struct History {
|
|
EnvironmentalInput input{};
|
|
EnvironmentalReport report{};
|
|
};
|
|
EnvironmentalCommunity() = default;
|
|
[[nodiscard]] State state() const noexcept;
|
|
[[nodiscard]] bool valid(const State& s) const noexcept;
|
|
// Validates a configuration and returns its per-tick form (itself for rules 1 and 2;
|
|
// rules 3's rates converted at its tick), or nothing when invalid.
|
|
[[nodiscard]] static std::optional<EnvironmentalConfig>
|
|
configuration(const EnvironmentalConfig& c, const world::EnvironmentalTransfers& r) noexcept;
|
|
[[nodiscard]] std::expected<EnvironmentalReport, CommunityError>
|
|
step(State& candidate, std::uint64_t tick, const EnvironmentalInput& input) const noexcept;
|
|
EnvironmentalConfig config_{}; // As configured and persisted.
|
|
EnvironmentalConfig step_{}; // Its per-tick form, which every step uses.
|
|
std::unique_ptr<world::EnvironmentalTransfers> resources_;
|
|
EnvironmentalProgress progress_{};
|
|
State anchor_{};
|
|
std::array<History, history_limit> history_{};
|
|
std::size_t count_{}, next_{}, budget_{};
|
|
};
|
|
} // namespace evo::processes
|