Add finite producer capture and resource-limited growth process

This commit is contained in:
dingo
2026-09-20 08:56:46 -04:00
parent 28a0e40db8
commit af293b8b50
11 changed files with 499 additions and 5 deletions
+64
View File
@@ -0,0 +1,64 @@
#pragma once
#include "evo/accounting/ledger.hpp"
#include "evo/core/types.hpp"
namespace evo::processes {
struct CaptureRate {
accounting::Picojoules energy;
std::uint32_t ticks;
};
struct GrowthRate {
std::uint64_t units;
std::uint32_t ticks;
};
struct ProducerConfig {
CaptureRate capture;
GrowthRate growth;
std::uint16_t efficiency_per_thousand;
accounting::Picojoules growth_cost;
std::array<accounting::Femtograms, 4> recipe;
};
struct ProducerReport {
accounting::Picojoules captured;
accounting::Picojoules retained;
accounting::Picojoules capture_heat;
std::uint64_t grown_units;
std::uint64_t unmet_growth_units;
auto operator<=>(const ProducerReport&) const = default;
};
struct ProducerProgress {
Tick tick{};
std::uint32_t capture_remainder{};
std::uint32_t growth_remainder{};
std::uint32_t efficiency_remainder{};
auto operator<=>(const ProducerProgress&) const = default;
};
enum class ProducerError : std::uint8_t {
invalid_config,
wrong_tick,
tick_exhausted,
ledger_failure
};
class ProducerProcess {
public:
[[nodiscard]] static std::expected<ProducerProcess, ProducerError>
create(ProducerConfig config, accounting::Picojoules source,
std::array<accounting::Femtograms, 4> nutrients);
[[nodiscard]] std::expected<ProducerReport, ProducerError> advance(Tick target);
// Reservoir order: source, nutrients, producer, heat. Valid until mutation.
[[nodiscard]] std::span<const accounting::Inventory> balances() const noexcept {
return ledger_.balances();
}
[[nodiscard]] ProducerProgress progress() const noexcept {
return progress_;
}
private:
ProducerProcess(ProducerConfig config, accounting::Ledger ledger);
ProducerConfig config_;
accounting::Ledger ledger_;
ProducerProgress progress_{};
};
} // namespace evo::processes