Preserve terminal inventories and add bounded decomposition
This commit is contained in:
@@ -20,12 +20,19 @@ struct FeedReceipt {
|
||||
bool target_depleted;
|
||||
auto operator<=>(const FeedReceipt&) const = default;
|
||||
};
|
||||
struct TerminalEvent {
|
||||
std::uint32_t actor;
|
||||
};
|
||||
struct DecompositionConfig {
|
||||
accounting::Inventory per_tick_limit{};
|
||||
};
|
||||
enum class FeedingError : std::uint8_t {
|
||||
invalid_config,
|
||||
wrong_tick,
|
||||
invalid_batch,
|
||||
invalid_actor,
|
||||
inactive_actor,
|
||||
not_corpse,
|
||||
intake_limit,
|
||||
insufficient_inventory,
|
||||
accounting_failure
|
||||
@@ -37,9 +44,10 @@ class FeedingCommunity {
|
||||
[[nodiscard]] static std::expected<FeedingCommunity, FeedingError>
|
||||
create(ProducerConfig producer, accounting::Picojoules source,
|
||||
std::array<accounting::Femtograms, 4> nutrients,
|
||||
std::span<const ConsumerConfig> consumers);
|
||||
std::span<const ConsumerConfig> consumers, DecompositionConfig decomposition = {});
|
||||
[[nodiscard]] std::expected<std::vector<FeedReceipt>, FeedingError>
|
||||
advance(Tick target, std::span<const FeedIntent> inputs = {});
|
||||
advance(Tick target, std::span<const FeedIntent> inputs = {},
|
||||
std::span<const TerminalEvent> terminal_events = {});
|
||||
[[nodiscard]] std::span<const accounting::Inventory> balances() const noexcept {
|
||||
return producer_.balances();
|
||||
}
|
||||
@@ -48,12 +56,21 @@ class FeedingCommunity {
|
||||
}
|
||||
// Process IDs are one-based. Out-of-range is a query error, not an inactive actor.
|
||||
[[nodiscard]] std::expected<bool, FeedingError> active(std::uint32_t id) const noexcept;
|
||||
[[nodiscard]] std::expected<accounting::Inventory, FeedingError>
|
||||
corpse(std::uint32_t id) const noexcept;
|
||||
[[nodiscard]] accounting::Inventory last_decomposed() const noexcept {
|
||||
return last_decomposed_;
|
||||
}
|
||||
|
||||
private:
|
||||
FeedingCommunity(ProducerProcess producer, std::vector<ConsumerConfig> consumers);
|
||||
FeedingCommunity(ProducerProcess producer, std::vector<ConsumerConfig> consumers,
|
||||
DecompositionConfig decomposition);
|
||||
[[nodiscard]] std::expected<FeedReceipt, FeedingError> feed(const FeedIntent& input);
|
||||
[[nodiscard]] std::expected<void, FeedingError> decompose();
|
||||
ProducerProcess producer_;
|
||||
std::vector<ConsumerConfig> consumers_;
|
||||
std::vector<std::uint8_t> active_;
|
||||
DecompositionConfig decomposition_;
|
||||
accounting::Inventory last_decomposed_{};
|
||||
};
|
||||
} // namespace evo::processes
|
||||
|
||||
Reference in New Issue
Block a user