载入中...
搜索中...
未找到
Production.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
6#include "common/Module.h"
7#include "common/Scheduling.h"
8#include "common/Snapshot.h"
10#include "common/Time.h"
12
13#include <cstdint>
14#include <deque>
15#include <memory>
16#include <ostream>
17#include <string>
18#include <string_view>
19#include <tuple>
20#include <vector>
21
22namespace eve::production {
23
28
31
44
50
53
61 std::vector<std::string> prerequisites;
62 std::vector<std::string> blocks;
63 std::vector<eve::definition::DefinitionHandle> requiredDefinitions;
64 std::vector<std::string> requiredTags;
65};
66
69 std::string resource;
70 int units = 1;
71};
72
75
78
85
88
91 std::string stream;
92 std::uint64_t seed = 0;
93 std::uint64_t drawStart = 0;
94 std::uint32_t drawCount = 0;
95};
96
99 std::uint32_t totalCycles = 1;
100 bool continuous = false;
103};
104
113
122
128
135
156
187
198
201public:
202 // The queue owns move-only members (std::deque<std::unique_ptr<ProductionTask>>),
203 // so it is not copyable; dllexport must not instantiate the implicitly declared
204 // copy operations, whose bodies cannot compile. Deleting the copies is a no-op and
205 // the defaulted moves keep the previous implicit behaviour.
206 WorkQueue(const WorkQueue&) = delete;
207 WorkQueue& operator=(const WorkQueue&) = delete;
209 WorkQueue(WorkQueue&&) = default;
212
214 explicit WorkQueue(eve::PersistentId instanceId = {});
225 [[nodiscard]] eve::Result<std::string> enqueue(std::string_view owner, std::string_view kind,
226 std::string_view product, eve::Value context, double duration,
227 int priority = 0);
231 [[nodiscard]] eve::Result<void> pause(std::string_view taskId);
233 [[nodiscard]] eve::Result<void> resume(std::string_view taskId);
235 [[nodiscard]] eve::Result<void> cancel(std::string_view taskId, std::string_view reason = "cancelled");
237 [[nodiscard]] eve::Result<void> fail(std::string_view taskId, std::string_view reason = "failed");
239 [[nodiscard]] eve::Result<void> settle(std::string_view taskId, ProductionSettlementReceipt receipt);
241 [[nodiscard]] eve::Result<void> failSettlement(std::string_view taskId, std::string_view reason);
243 [[nodiscard]] eve::Result<void> retrySettlement(std::string_view taskId);
245 [[nodiscard]] eve::Result<ProductionReservationRelease> releaseReservation(
246 std::string_view taskId, std::string_view releaseId);
248 [[nodiscard]] eve::Result<void> contribute(std::string_view taskId, WorkContribution contribution);
250 [[nodiscard]] eve::Result<void> reportStock(std::string_view taskId, int observedStock);
251
259 [[nodiscard]] eve::Result<void> advance(const eve::SimulationStep& step);
261 [[nodiscard]] eve::Result<std::uint32_t> advanceTo(eve::SimulationTick target, eve::Duration fixedDelta,
262 std::uint32_t maxSteps);
263
265 [[nodiscard]] eve::SimulationTick currentTick() const noexcept { return tick_; }
266
268 [[nodiscard]] eve::Result<void> setSlotCount(std::string_view owner, int slots);
270 int slotCount(std::string_view owner) const;
272 int runningCount(std::string_view owner) const;
274 [[nodiscard]] eve::Result<void> setSchedulerStrategy(std::string_view owner, SchedulerStrategy strategy);
276 SchedulerStrategy schedulerStrategy(std::string_view owner) const;
278 [[nodiscard]] eve::Result<void> setResourceCapacity(std::string_view owner, std::string_view resource,
279 int capacity);
281 int resourceCapacity(std::string_view owner, std::string_view resource) const;
283 [[nodiscard]] eve::Result<std::string> blockReason(std::string_view taskId) const;
285 [[nodiscard]] eve::Result<void> setDefinitionAvailable(
286 std::string_view owner, const eve::definition::DefinitionHandle& definition, bool available);
288 [[nodiscard]] eve::Result<void> setTagAvailable(std::string_view owner, std::string_view tag, bool available);
290 [[nodiscard]] bool definitionAvailable(
291 std::string_view owner, const eve::definition::DefinitionHandle& definition) const;
293 [[nodiscard]] bool tagAvailable(std::string_view owner, std::string_view tag) const;
295 [[nodiscard]] eve::Result<ProductionPrediction> predict(std::string_view taskId) const;
297 [[nodiscard]] eve::Result<ProductionDiagnostic> diagnose(std::string_view taskId) const;
298
306 [[nodiscard]] eve::OptionalRef<const ProductionTask> find(std::string_view taskId);
308 [[nodiscard]] eve::OptionalRef<const ProductionTask> find(std::string_view taskId) const;
310 int taskCount() const;
312 [[nodiscard]] eve::OptionalRef<const ProductionTask> taskAt(int index);
314 [[nodiscard]] eve::OptionalRef<const ProductionTask> taskAt(int index) const;
316 int ownerTaskCount(std::string_view owner) const;
318 [[nodiscard]] eve::OptionalRef<const ProductionTask> ownerTaskAt(std::string_view owner, int index);
320 [[nodiscard]] eve::OptionalRef<const ProductionTask> ownerTaskAt(std::string_view owner, int index) const;
321
323 int eventCount() const;
325 [[nodiscard]] eve::OptionalRef<ProductionEvent> eventAt(int index);
327 [[nodiscard]] eve::OptionalRef<const ProductionEvent> eventAt(int index) const;
329 void clearEvents();
331 [[nodiscard]] eve::Result<std::string> snapshot() const;
333 [[nodiscard]] eve::Result<void> restore(std::string_view json);
335 void clear();
336
338 [[nodiscard]] eve::Result<eve::SnapshotEnvelope> snapshot(const eve::SnapshotHashProvider& hashProvider) const;
345 [[nodiscard]] eve::Result<void> restoreSnapshot(const eve::SnapshotEnvelope& snapshot,
346 const eve::SnapshotHashProvider& hashProvider);
348 [[nodiscard]] eve::Result<std::string> snapshotEnvelopeJson(const eve::SnapshotHashProvider& hashProvider) const;
350 [[nodiscard]] eve::Result<void> restoreSnapshotJson(std::string_view json,
351 const eve::SnapshotHashProvider& hashProvider);
352
353private:
354 [[nodiscard]] ProductionTask* mutableFind(std::string_view taskId);
355 [[nodiscard]] bool dependenciesSatisfied(const ProductionTask& task) const;
356 [[nodiscard]] bool resourcesAvailable(const ProductionTask& task) const;
357 void completeIfReady(ProductionTask& task);
358 void continueAfterCycle(ProductionTask& task);
359 static std::uint32_t refundFor(const ProductionTask& task, RefundPolicy policy);
360 void scheduleAll();
361 void schedule(std::string_view owner);
362 void emit(ProductionEventKind kind, const ProductionTask& task, std::string_view reason = {});
363
364 uint64_t nextTaskId_ = 1;
365 uint64_t nextEnqueueSequence_ = 1;
366 uint64_t nextEventSequence_ = 1;
367 eve::PersistentId instanceId_;
370 std::deque<std::unique_ptr<ProductionTask>> tasks_;
371 std::deque<ProductionEvent> events_;
372 std::vector<std::pair<std::string, int>> slots_;
373 std::vector<std::pair<std::pair<std::string, std::string>, int>> resources_;
374 std::vector<std::pair<std::string, SchedulerStrategy>> schedulerStrategies_;
375 std::vector<std::tuple<std::string, std::string, std::uint64_t>> availableDefinitions_;
376 std::vector<std::pair<std::string, std::string>> availableTags_;
377};
378
380EVENGINE_API_FOUNDATION std::string_view taskStateName(TaskState state);
382inline std::ostream& operator<<(std::ostream& stream, TaskState state) { return stream << taskStateName(state); }
385
387class Production : public Module {
388public:
391 Production() = default;
393 ~Production() override = default;
394
400 [[nodiscard]] static eve::Result<WorkQueueHandleRef> newQueueHandle();
411 [[nodiscard]] static bool isStale(WorkQueueHandleRef reference) noexcept;
412
413private:
415};
416
417} // namespace eve::production
LogicalId target
float duration
AuthorityStoreHandleRef reference
Definition Authority.cpp:24
Vocabulary aliases for nullable and checked borrowed references.
int priority
Common identity and hot-reload contract for typed runtime instances.
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
const GltfImportRequest & request
std::uint32_t capacity
TokenKind kind
const std::string * tag
std::function< eve::Result< void >()> release
Definition Procgen.cpp:86
std::string taskId
Shared metadata for independently deployable command and work queues.
std::string resource
LocalPageCacheEntry slots[ShadowConfig::kLocalSlots]
Versioned, integrity-checked persistence envelopes.
Explicit Value/Owned/Borrowed semantics at the Squirrel boundary.
std::vector< ecs::EntityHandle > schedule
The round's activation queue, resolved against the target battle.
LogicalId definition
Common time values and an injectable deterministic simulation clock.
float step
Definition TreeMesh.cpp:314
uint32_t index
const VegetationPresetContext & context
Signed, fixed-resolution simulation duration in nanoseconds.
Definition Time.h:43
static constexpr Duration zero() noexcept
Return zero duration.
Definition Time.h:60
EVENGINE_API_FOUNDATION public API.
Definition Module.h:46
Move-only operation result carrying either a value or Status.
Definition Result.h:155
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
std::map< std::string, Value > Object
Definition Value.h:34
Id128 public API.
Definition Identity.h:112
static constexpr StrongUint64 zero() noexcept
Returns the zero value for this strong type.
Script module factory for generic production queues.
Definition Production.h:387
static eve::Result< WorkQueueHandleRef > newQueueHandle()
Allocates a production queue and returns its ownership reference.
static bool isStale(WorkQueueHandleRef reference) noexcept
Reports whether a queue reference is stale for the current module.
~Production() override=default
Releases Production resources.
Production()=default
Constructs a Production.
static eve::ResultRef< WorkQueue > resolve(WorkQueueHandleRef reference)
Resolves a generation-qualified work-queue identity.
Generic multi-owner, multi-slot continuous-progress work queue.
Definition Production.h:200
eve::SimulationTick currentTick() const noexcept
Return the latest simulation tick applied to this queue.
Definition Production.h:265
WorkQueue & operator=(WorkQueue &&)=default
Operator =.
WorkQueue & operator=(const WorkQueue &)=delete
WorkQueue(WorkQueue &&)=default
Work queue.
WorkQueue(const WorkQueue &)=delete
Slot/generation registry whose objects are exclusively unique-owned.
TaskState
Lifecycle state of a production task.
Definition Production.h:30
SchedulerStrategy
Stable owner-local queue ordering strategy.
Definition Production.h:87
ReservationState
Lifecycle of opaque domain reservation evidence.
Definition Production.h:77
TaskDependencyMode
Completion rule for prerequisite production tasks.
Definition Production.h:52
ProductionEventKind
Kind of a deterministic production lifecycle event.
Definition Production.h:33
std::string_view eventKindName(ProductionEventKind kind)
Returns the stable lowercase name of an event kind.
std::string_view taskStateName(TaskState state)
Returns the stable lowercase name of a task state.
std::ostream & operator<<(std::ostream &stream, TaskState state)
Writes the stable task-state spelling to a stream.
Definition Production.h:382
RefundPolicy
Reservation refund rule applied when work terminates before settlement.
Definition Production.h:74
std::optional< std::reference_wrapper< T > > OptionalRef
Optional borrowed reference; it does not extend T's lifetime.
Definition BorrowedRef.h:24
std::function< Result< ContentId >(std::string_view canonicalInput)> SnapshotHashProvider
Injected content-digest implementation used by snapshots.
Definition Snapshot.h:36
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158
Stable outer format shared by persistence and cross-process snapshots.
Definition Snapshot.h:46
A generation-qualified reference to one definition incarnation.
Replayable provenance for domain-owned random output draws.
Definition Production.h:90
Stable task-to-task constraints for a small production DAG.
Definition Production.h:59
std::vector< std::string > prerequisites
Definition Production.h:61
std::vector< std::string > blocks
Definition Production.h:62
std::vector< std::string > requiredTags
Definition Production.h:64
std::vector< eve::definition::DefinitionHandle > requiredDefinitions
Definition Production.h:63
Structured task diagnostic carrying stable correlation identity.
Definition Production.h:115
Deterministically sequenced production lifecycle event.
Definition Production.h:189
Side-effect-free estimate under an unchanged queue configuration.
Definition Production.h:106
Repetition and externally reported maintain-stock contract.
Definition Production.h:98
Validated input used to create a domain-neutral production task.
Definition Production.h:137
ProductionRepeatPolicy repeat
Definition Production.h:150
ProductionTerminationPolicy termination
Definition Production.h:148
ProductionDependencies dependencies
Definition Production.h:146
std::vector< ProductionResourceRequirement > resources
Definition Production.h:147
OutputRandomProvenance random
Definition Production.h:149
eve::definition::DefinitionHandle definition
Definition Production.h:144
Idempotent release evidence used by a domain adapter to perform rollback/refund.
Definition Production.h:80
Named capacity consumed while a task is running.
Definition Production.h:68
Owning proof that a domain consumer published one task exactly once.
Definition Production.h:46
A subject-agnostic continuous task retained for audit and save games.
Definition Production.h:158
ReservationState reservationState
Definition Production.h:169
eve::definition::DefinitionHandle definition
Definition Production.h:167
ProductionDependencies dependencies
Definition Production.h:173
ProductionRepeatPolicy repeat
Definition Production.h:177
ProductionTerminationPolicy termination
Definition Production.h:175
std::vector< ProductionResourceRequirement > resources
Definition Production.h:174
OutputRandomProvenance random
Definition Production.h:176
std::uint32_t workRemainderPermille
Unapplied fixed-point work numerator in thousandths of one nanosecond.
Definition Production.h:183
ProductionSettlementReceipt settlement
Definition Production.h:171
ProductionReservationRelease reservationRelease
Definition Production.h:170
Explicit cancellation and failure refund contract.
Definition Production.h:124
Deterministic externally supplied work contribution.
Definition Production.h:130
Handle domain for a module-owned continuous-progress work queue.
Definition Production.h:25
Sequence and explanation shared by queue lifecycle events.
Definition Scheduling.h:21
Identity, priority and terminal explanation shared by scheduled items.
Definition Scheduling.h:14
Handle plus owner-lifetime epoch for a non-ECS registry object.