载入中...
搜索中...
未找到
Logistics.cpp
浏览该文件的文档.
30Result<void> Logistics::configure(int width, int height, int layers, float cellSize, float originX, float originY) {
34 return fail(DiagnosticCode::InvalidArgument, "cellSize must be a positive finite float", "cellSize");
90 return (static_cast<std::size_t>(layer) * static_cast<std::size_t>(height_) + static_cast<std::size_t>(cy)) *
116Result<int> Logistics::registerRecipe(std::string id, int inputType, int inputCount, int outputType, int outputCount,
118 if (id.empty()) return failT<int>(DiagnosticCode::InvalidArgument, "recipe id must be non-empty", "id");
122 return failT<int>(DiagnosticCode::InvalidArgument, "recipe duration must be positive finite", "duration");
125 recipes_[i] = Recipe{std::move(id), inputType, inputCount, outputType, outputCount, durationSec};
129 recipes_.push_back(Recipe{std::move(id), inputType, inputCount, outputType, outputCount, durationSec});
135 if (!inBounds(cx, cy, layer)) return fail(DiagnosticCode::InvalidArgument, "cell out of bounds", "placeBelt");
136 if (dir < 0 || dir > 3) return fail(DiagnosticCode::InvalidArgument, "dir must be 0..3", "dir");
151 if (!inBounds(cx, cy, layer)) return fail(DiagnosticCode::InvalidArgument, "cell out of bounds", "clearCell");
161Result<int> Logistics::placeMachine(int cx, int cy, int width, int height, std::string_view recipeId, int layer) {
166 return failT<int>(DiagnosticCode::InvalidArgument, "machine footprint out of bounds", "placeMachine");
174 if (recipeIndex < 0) return failT<int>(DiagnosticCode::NotFound, "recipe id is not registered", "recipeId");
181 return failT<int>(DiagnosticCode::Conflict, "machine footprint overlaps items", "placeMachine");
222Result<void> Logistics::placeSource(int cx, int cy, int itemType, float itemsPerSec, int layer) {
224 if (!inBounds(cx, cy, layer)) return fail(DiagnosticCode::InvalidArgument, "cell out of bounds", "placeSource");
226 return fail(DiagnosticCode::InvalidArgument, "itemsPerSec must be positive finite", "itemsPerSec");
229 return fail(DiagnosticCode::Conflict, "cannot place source on machine footprint", "placeSource");
241 if (!inBounds(cx, cy, layer)) return fail(DiagnosticCode::InvalidArgument, "cell out of bounds", "placeSink");
286 if (!inBounds(cx, cy, layer)) return failT<int>(DiagnosticCode::InvalidArgument, "cell out of bounds", "spawnItem");
313 state.x = originX_ + (static_cast<float>(item.cellX) + 0.5f) * cellSize_ + static_cast<float>(dx) * along;
314 state.y = originY_ + (static_cast<float>(item.cellY) + 0.5f) * cellSize_ + static_cast<float>(dy) * along;
368 if (!machine.alive) return failT<MachineState>(DiagnosticCode::NotFound, "machine slot is empty", "machineAt");
571 if (auto ready = ensureConfigured(); !ready.ok()) return Result<StepReport>::failure(ready.status());
573 return failT<StepReport>(DiagnosticCode::InvalidArgument, "advance dt must be positive finite", "dt");
575 return failT<StepReport>(DiagnosticCode::Conflict, "simulation tick must strictly increase", "tick");
590 return failT<StepReport>(DiagnosticCode::InvalidArgument, "advance dt must be positive finite", "dt");
EVEngine assertion entry point, backed by zeroerr.
#define EV_ASSERT(cond,...)
Assert an internal engine invariant (state that must always hold).
Definition Assert.h:37
Stable, structured diagnostics shared by engine modules.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
static Result< Duration > fromSeconds(double seconds)
Convert finite seconds to the nearest nanosecond.
Definition Time.cpp:17
bool ok() const noexcept
Whether this result represents a non-failure outcome.
Definition Result.h:514
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
constexpr std::uint64_t value() const noexcept
Returns the underlying value at an explicit protocol boundary.
Definition StrongUint64.h:26
static constexpr StrongUint64 zero() noexcept
Returns the zero value for this strong type.
Definition StrongUint64.h:24
Deterministic 2D factory logistics: belts, discrete items, machine buffers, crafts.
Definition Logistics.h:82
Result< void > removeMachine(int machineId)
Remove a machine by id and free its footprint cells.
Definition Logistics.cpp:206
Result< int > registerRecipe(std::string id, int inputType, int inputCount, int outputType, int outputCount, float durationSec)
Register or replace a named recipe.
Definition Logistics.cpp:116
Result< int > placeMachine(int cx, int cy, int width, int height, std::string_view recipeId, int layer=0)
Place a rectangular machine footprint and bind a recipe.
Definition Logistics.cpp:161
Result< void > configure(int width, int height, int layers, float cellSize, float originX, float originY)
Size the factory grid and world mapping.
Definition Logistics.cpp:30
std::string machineOwnerId(int index) const
Stable Production-owner string for machine slot i (empty when invalid).
Definition Logistics.cpp:384
Result< std::vector< float > > packItemSimFloats() const
Pack GPU-friendly floats: [cellX,cellY,progress,dir,type,layer] * itemCount. @cost O(items); amortize...
Definition Logistics.cpp:331
Result< void > placeSink(int cx, int cy, int layer=0)
Place a sink that destroys items arriving from the westward adjacent belt.
Definition Logistics.cpp:239
int cellDir(int cx, int cy, int layer=0) const noexcept
Belt direction at cell, or -1 when not a belt.
Definition Logistics.cpp:395
Result< void > placeSource(int cx, int cy, int itemType, float itemsPerSec, int layer=0)
Place an item emitter that injects itemType onto the eastward adjacent belt.
Definition Logistics.cpp:222
Result< void > clearCell(int cx, int cy, int layer=0)
Remove belt/source/sink content from a cell (machines must use removeMachine).
Definition Logistics.cpp:149
Result< StepReport > advance(const SimulationStep &step)
Advance one fixed logistics step.
Definition Logistics.cpp:570
Result< void > placeBelt(int cx, int cy, int dir, int layer=0)
Place a belt cell facing dir (0=E,1=S,2=W,3=N) on layer.
Definition Logistics.cpp:133
int cellKind(int cx, int cy, int layer=0) const noexcept
Cell kind at (cx,cy,layer); Empty when out of range.
Definition Logistics.cpp:390
void clear()
Clear every cell, item, machine, recipe and reset the simulation clock.
Definition Logistics.cpp:62
Result< MachineState > machineAt(int index) const
Copy machine slot i; NotFound when empty/out of range.
Definition Logistics.cpp:364
Result< std::vector< float > > packItemWorldFloats() const
Pack world positions for CPU draw fallback: [x,y,type] * itemCount. @cost O(items).
Definition Logistics.cpp:346
Result< ItemState > itemAt(int index) const
Copy item i; NotFound when index is out of range.
Definition Logistics.cpp:318
int cellMachine(int cx, int cy, int layer=0) const noexcept
Machine id occupying the cell, or -1.
Definition Logistics.cpp:401
Result< int > spawnItem(int cx, int cy, int itemType, int layer=0)
Spawn one item onto a belt cell at progress 0.
Definition Logistics.cpp:284
Definition Logistics.cpp:11
@ South
@ North
@ Machine
@ Source
@ InvalidArgument
@ NotFound
@ Conflict
Compact recipe: consume inputCount of inputType, emit outputCount of outputType.
Definition Logistics.h:22