载入中...
搜索中...
未找到
RTSReplay.cpp
浏览该文件的文档.
39 if (static_cast<unsigned>(command.operation) > static_cast<unsigned>(RTSReplayOperation::MovementGroup))
46 return replayFailure("Movement-group lead distance must be finite and positive", "command.groupLeadDistance");
51 if (command.units.empty()) return replayFailure("RTS replay command requires units", "command.units");
53 return replayFailure("RTS replay entity targets require a stable SubjectRef", "command.targetEntity");
56 command.units.erase(std::unique(command.units.begin(), command.units.end()), command.units.end());
58 (command.units.size() < 2 || command.command.kind != OrderKind::Move || command.command.append ||
60 !command.command.definitionId.empty() || command.targetEntity.isValid() || command.command.radius != 0.f ||
62 return replayFailure("Movement-group replay requires two units, immediate Move and positive lead distance",
65 if (command.units.size() != 1 || !command.faction.isValid() || !command.resultSubject.isValid() ||
67 return replayFailure("RTS construction replay requires builder, faction, result, and definition",
71 if (!command.producer.isValid() || !command.resultSubject.isValid() || !command.definition.isValid())
95 } else if (command.operation == RTSReplayOperation::CancelFireSupport && !command.producer.isValid()) {
96 return replayFailure("RTS fire-support cancellation requires a requester", "command.fireSupport");
107 (command.units.empty() || !command.targetEntity.isValid() || !std::isfinite(command.command.radius) ||
110 return replayFailure("RTS escort requires units, target, guard radius, and spacing", "command.escort");
116 command.units.erase(std::unique(command.units.begin(), command.units.end()), command.units.end());
118 if (std::any_of(command.units.begin(), command.units.end(), [](SubjectRef value) { return !value.isValid(); }))
127 if (found == queued_.end()) return Result<std::size_t>::success(0, Status::success(StatusCode::NoOp));
135 DiagnosticCode::NotFound, "RTS replay construction actor cannot be resolved", "command.construction"));
285 const bool extended = oriented || std::any_of(history_.begin(), history_.end(), [](const auto& value) {
292 const unsigned version = grouped ? 5u : (oriented ? 4u : (fireSupport ? 3u : (extended ? 2u : 1u)));
300 << std::quoted(value.resultSubject.isValid() ? value.resultSubject.format() : std::string{}) << ' '
308 << value.command.timeoutSeconds << ' ' << value.command.target.x << ' ' << value.command.target.y << ' '
309 << value.command.secondaryTarget.x << ' ' << value.command.secondaryTarget.y << ' ' << value.command.radius
322Result<void> RTSCommandLog::importText(std::string_view text, SimulationTick currentTick, bool clearExisting) {
336 if (!(in >> tick >> operation >> std::quoted(producer) >> std::quoted(faction) >> std::quoted(result) >>
346 const auto decode = [](const std::string& text) { return text.empty() ? SubjectRef{} : parseSubject(text); };
350 if ((!producer.empty() && !value.producer.isValid()) || (!faction.empty() && !value.faction.isValid()) ||
355 if (!parsedDefinition) return replayFailure("invalid RTS command definition", "commandLog.definition");
363 if (!(in >> commandTick >> kind >> std::quoted(value.command.definitionId) >> value.command.priority >>
372 if (!(in >> std::quoted(target) >> unitCount) || kind > static_cast<unsigned>(OrderKind::SupplyRelay) ||
373 formation > static_cast<unsigned>(version >= 4 ? FormationKind::Dispersed : FormationKind::Wedge) ||
384 if (!value.targetEntity.isValid()) return replayFailure("invalid target subject", "commandLog.target");
389 if (!(in >> std::quoted(unit))) return replayFailure("missing unit subject", "commandLog.units");
418 if (value.nanoseconds() <= 0) return replayFailure("RTS lockstep interval must be strictly positive", "fixedStep");
423Result<std::size_t> RTSLockstep::step(RTS& world, IRTSActionExecutor& executor, std::uint64_t count) {
Stable tick-addressed RTS command recording and replay.
RTS module owner and phase-one composition profile entry point.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
constexpr std::int64_t nanoseconds() const noexcept
Return the exact signed nanosecond representation.
Definition Time.h:69
static Result< Duration > fromSeconds(double seconds)
Convert finite seconds to the nearest nanosecond.
Definition Time.cpp:16
static std::optional< LogicalId > parse(std::string_view text)
Parses a scoped logical name.
Definition Identity.cpp:36
bool isValid() const noexcept
Returns whether this value contains a valid namespace and name.
Definition Identity.h:433
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.h:81
static SubjectRef fromPersistentId(PersistentId id) noexcept
Wrap a persistent identity without changing its bytes.
Definition SubjectRef.h:32
bool isValid() const noexcept
Return whether this reference is valid and non-nil.
Definition SubjectRef.h:38
static std::optional< Id128 > parse(std::string_view text) noexcept
Parses canonical UUID text.
Definition Identity.h:151
constexpr std::uint64_t value() const noexcept
Returns the underlying value at an explicit protocol boundary.
Definition StrongUint64.h:26
static Result< FanOutReceipt > fanOut(std::span< const ecs::EntityHandle > unitHandles, const CommandSpec &command, const FormationSpec &formation)
Submit one command to every selected live Unit.
Definition RTSFormation.cpp:124
Interface isolating RTS orders from the shared action runtime.
Definition RTSAction.h:38
Deterministic lockstep input buffer and portable command log.
Definition RTSReplay.h:63
Result< void > importText(std::string_view text, SimulationTick currentTick={}, bool clearExisting=true)
Parse and atomically import a command log.
Definition RTSReplay.cpp:322
Result< std::size_t > apply(SimulationTick tick, RTS &world)
Apply all commands for one tick through the existing RTS order boundary.
Definition RTSReplay.cpp:125
Result< void > queue(RTSReplayCommand command, SimulationTick currentTick={})
Validate, normalize, queue, and retain one future command.
Definition RTSReplay.cpp:36
std::string exportText() const
Export retained commands in a locale-independent text format.
Definition RTSReplay.cpp:275
Result< void > setFixedStep(Duration value)
Set a finite, strictly positive fixed interval.
Definition RTSReplay.cpp:417
Result< std::size_t > step(RTS &world, IRTSActionExecutor &executor, std::uint64_t count=1)
Advance an exact number of deterministic ticks.
Definition RTSReplay.cpp:423
void reset(SimulationTick tick={}, bool clearCommands=true) noexcept
Reset the timeline and optionally retain the command history/queue.
Definition RTSReplay.cpp:441
Definition RTS.cpp:24
@ SupplyRelay
RTSReplayOperation
Stable operation kinds accepted by the shared deterministic RTS input stream.
Definition RTSReplay.h:20
@ CancelFireSupport
@ RequestFireSupport
@ Construction
@ MovementGroup
@ CancelProduction
@ Production
@ SellBuilding
@ SuppressArea
@ CancelAbility
@ ReinforcementProduction
@ CancelConstruction
@ Research
@ UnitCommand
@ Dispersed
@ InvalidArgument
@ NotFound
@ InvariantViolation
@ NoOp
@ Applied
Result< void > validate() const
Validate coordinates and command metadata without mutating state.
Definition RTSTypes.cpp:201
EVENGINE_API_DOMAINS Result< void > validate() const
Validate layout kind, spacing, grid columns and finite rotation.
Definition RTSFormation.cpp:12
Caller-built admission batch for an immediate coordinated Move command. @cost Linear in unit count; c...
Definition RTSSystems.h:48
float leadDistance
Positive world-space allowance before leaders slow for lagging members.
Definition RTSSystems.h:52
std::vector< SubjectRef > units
Owned stable identities; no entity pointers are retained.
Definition RTSSystems.h:49
One process-independent command using stable subjects instead of ECS handles.
Definition RTSReplay.h:39