载入中...
搜索中...
未找到
ClimbingInput.cpp
浏览该文件的文档.
43 [&](const auto& entry) { return entry.command == command && entry.pressedTick == pressedTick; }))
48 return eve::Result<void>::failure(eve::Diagnostic::error(eve::DiagnosticCode::PreconditionViolation,
52 {command, pressedTick, eve::SimulationTick(pressedTick.value() + bufferTicks), ClimbingExecutionId::zero()});
63std::size_t ClimbingInputSystem::prune(ClimbingIntent& intent, eve::SimulationTick currentTick) noexcept {
71eve::Result<std::optional<BufferedClimbingCommand>> ClimbingInputSystem::consume(ClimbingIntent& intent,
77 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "consuming execution id must be non-zero",
80 const auto found = std::find_if(intent.commands.begin(), intent.commands.end(), [&](const auto& entry) {
92std::optional<BufferedClimbingCommand> ClimbingInputSystem::peek(const ClimbingIntent& intent, ClimbingCommand command,
94 const auto found = std::find_if(intent.commands.begin(), intent.commands.end(), [&](const auto& entry) {
95 return entry.command == command && entry.pressedTick <= currentTick && currentTick <= entry.expiryTick &&
105 return currentTick.value() - lastGroundedTick.value() <= coyoteTicks ? ClimbingCoyoteState::Eligible
159 return chain.root >= 0 && chain.mid >= 0 && chain.tip >= 0 && chain.root < boneCount && chain.mid < boneCount &&
164bool finite(Vec3 value) { return std::isfinite(value.x) && std::isfinite(value.y) && std::isfinite(value.z); }
177eve::Result<ClimbingPoseResult> applyClimbingPose(animation::AnimSkeleton& skeleton, animation::AnimPose& pose,
207 const float leftWeight = binding.enableLeftHand ? (hasLimbWeights ? authoredLeft : legacyWeight) : 0.f;
208 const float rightWeight = binding.enableRightHand ? (hasLimbWeights ? authoredRight : legacyWeight) : 0.f;
210 binding.enableLeftFoot && advance.hasLeftFootAnchor ? std::clamp(advance.leftFootWeight, 0.f, 1.f) : 0.f;
212 binding.enableRightFoot && advance.hasRightFootAnchor ? std::clamp(advance.rightFootWeight, 0.f, 1.f) : 0.f;
215 return eve::Result<ClimbingPoseResult>::success(std::move(result), eve::Status::success(eve::StatusCode::NoOp));
223 return poseFailure("right hand target must be finite in model space", "advance.rightHandAnchor");
230 return poseFailure("right foot target must be finite in model space", "advance.rightFootAnchor");
235 constraints.addTwoBoneIK(binding.leftArm.root, binding.leftArm.mid, binding.leftArm.tip, target.x, target.y,
241 constraints.addTwoBoneIK(binding.rightArm.root, binding.rightArm.mid, binding.rightArm.tip, target.x, target.y,
246 constraints.addTwoBoneIK(binding.leftLeg.root, binding.leftLeg.mid, binding.leftLeg.tip, leftFootTarget.x,
251 constraints.addTwoBoneIK(binding.rightLeg.root, binding.rightLeg.mid, binding.rightLeg.tip, rightFootTarget.x,
256 return eve::Result<ClimbingPoseResult>::success(std::move(result), eve::Status::success(eve::StatusCode::Applied));
278 appendByte(hash, static_cast<std::uint8_t>((bits >> (index * 8)) & static_cast<Unsigned>(0xff)));
322bool readUint64String(const eve::Value::Object& object, std::string_view name, std::uint64_t& output, int base = 10) {
336eve::Value::Object unknownFields(const eve::Value::Object& object, std::initializer_list<std::string_view> known) {
414 if (!object || !readString(*object, "actionId", key.actionId) || !readInt64(*object, "kind", kind) || kind < 0 ||
417 !readInt64(*object, "sortedRank", rank) || rank < 0 || rank > std::numeric_limits<std::uint32_t>::max() ||
433 if (!object || !readString(*object, "schemaId", schemaId) || schemaId != ClimbingRuntime::SnapshotSchemaId ||
436 eve::DiagnosticCode::ParseError, "authoritative snapshot has an invalid climbing runtime envelope",
440 eve::DiagnosticCode::UnknownVersion, "authoritative snapshot version is newer than this runtime",
448 return validKey(decision.authoritativeCandidate) && decision.reason == ClimbingPredictionReason::None;
454eve::Result<eve::Value::Object> readEnvelope(const eve::Value& value, std::string_view schemaId) {
458 eve::DiagnosticCode::ParseError, "prediction payload must be an object", {}, {}, "climbing.prediction"));
463 eve::Diagnostic::error(eve::DiagnosticCode::ParseError, "prediction schemaId is missing or mismatched",
467 eve::Diagnostic::error(eve::DiagnosticCode::ParseError, "prediction schemaVersion must be an integer",
471 eve::Diagnostic::error(eve::DiagnosticCode::UnknownVersion, "prediction schema version is unsupported",
477 return phase != ClimbingPhase::Idle && phase != ClimbingPhase::Completed && phase != ClimbingPhase::Cancelled &&
483ClimbingCandidateKey makeClimbingCandidateKey(const ClimbingCandidate& candidate, std::uint32_t sortedRank) noexcept {
511eve::Result<eve::Value> encodeClimbingPredictionRequest(const ClimbingPredictionRequest& request) {
514 eve::DiagnosticCode::InvalidArgument, "prediction request requires a non-zero sequence and candidate key",
525eve::Result<ClimbingPredictionRequest> decodeClimbingPredictionRequest(const eve::Value& value) {
536 eve::Diagnostic::error(eve::DiagnosticCode::ParseError, "prediction request has missing or invalid fields",
541 unknownFields(root.value(), {"schemaId", "schemaVersion", "sequence", "clientTick", "candidate"});
545eve::Result<eve::Value> encodeClimbingPredictionDecision(const ClimbingPredictionDecision& decision) {
565eve::Result<ClimbingPredictionDecision> decodeClimbingPredictionDecision(const eve::Value& value) {
579 !readString(root.value(), "disposition", disposition) || !readDisposition(disposition, decision.disposition) ||
583 eve::Diagnostic::error(eve::DiagnosticCode::ParseError, "prediction decision has missing or invalid fields",
590 eve::Diagnostic::error(eve::DiagnosticCode::ParseError, "prediction decision fields are inconsistent",
594 if (!snapshotEnvelope) return eve::Result<ClimbingPredictionDecision>::failure(snapshotEnvelope.status());
596 unknownFields(root.value(), {"schemaId", "schemaVersion", "sequence", "clientTick", "serverTick", "disposition",
601eve::Result<ClimbingPredictionDecision> ClimbingRuntime::tryBeginPredicted(physics::World3D& world,
610 const auto finish = [this](ClimbingPredictionDecision value) -> eve::Result<ClimbingPredictionDecision> {
Versioned, lossless codecs for climbing definitions.
Tick-addressed command buffering for deterministic climbing input.
Synchronous Animation TwoBoneIK adapter for climbing contact anchors.
Deterministic climbing/parkour planning and capsule-constrained execution.
std::map< std::array< int, 4 >, std::vector< const Subject * > > candidates
Definition Sensing.cpp:32
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 failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.cpp:19
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:177
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
Definition Value.h:209
Ordered main-thread post-process stack with aim, limb IK and foot planting.
Definition AnimConstraintStack.h:17
void apply(AnimPose *pose) const
Apply constraints in insertion order and refresh world transforms. Main-thread only.
Definition AnimConstraintStack.cpp:40
void addTwoBoneIK(int root, int mid, int tip, float targetX, float targetY, float targetZ, float weight=1.f)
Append a weighted two-bone IK constraint.
Definition AnimConstraintStack.cpp:26
Evaluated local (and optional world) pose for an AnimSkeleton. Script type: AnimPose.
Definition AnimPose.h:17
3D bone hierarchy + bind-pose local TRS for skeletal animation. Independent of ik::Skeleton3D (FABRIK...
Definition AnimSkeleton.h:16
static std::size_t prune(ClimbingIntent &intent, eve::SimulationTick currentTick) noexcept
Remove expired and already-consumed records; returns the number removed.
Definition ClimbingInput.cpp:63
static constexpr std::size_t MaxBufferedCommands
Hard safety bound preventing an untrusted producer from growing intent indefinitely.
Definition ClimbingInput.h:55
static ClimbingCoyoteState coyoteWindowState(eve::SimulationTick currentTick, eve::SimulationTick lastGroundedTick, std::uint64_t coyoteTicks) noexcept
Evaluate a grounded grace window without reading wall clock.
Definition ClimbingInput.cpp:101
static eve::Result< void > submit(ClimbingIntent &intent, ClimbingCommand command, eve::SimulationTick pressedTick, std::uint64_t bufferTicks)
Queue one edge command with expiry derived from an exact tick budget.
Definition ClimbingInput.cpp:31
static eve::Result< std::optional< BufferedClimbingCommand > > consume(ClimbingIntent &intent, ClimbingCommand command, eve::SimulationTick currentTick, ClimbingExecutionId executionId)
Atomically mark the oldest eligible command consumed by one committed execution.
Definition ClimbingInput.cpp:71
static std::optional< BufferedClimbingCommand > peek(const ClimbingIntent &intent, ClimbingCommand command, eve::SimulationTick currentTick) noexcept
Observe the oldest eligible command without consuming or pruning intent.
Definition ClimbingInput.cpp:92
eve::Result< std::string > snapshotJson() const
Serializes the canonical runtime snapshot as JSON.
Definition ClimbingInput.cpp:134
eve::Result< void > reloadProfileJson(std::string_view json)
Parses and hot-reloads a canonical profile JSON document transactionally.
Definition ClimbingInput.cpp:126
eve::Result< void > setProfile(ClimbingProfile profile)
Replaces the runtime profile after validating all dimensions and action definitions.
Definition Climbing.cpp:106
static constexpr std::int64_t SnapshotSchemaVersion
Current runtime snapshot version; v3 is N-1 and historical v2/v1/v0 remain migratable.
Definition Climbing.h:664
eve::Result< void > restoreJson(std::string_view json, physics::World3D &world)
Parses and atomically restores a canonical runtime snapshot JSON document.
Definition ClimbingInput.cpp:140
eve::Result< eve::Value > snapshot() const
Captures deterministic runtime state; debug candidates and final bone poses are excluded.
Definition ClimbingSnapshot.cpp:325
eve::Result< void > setProfileJson(std::string_view json)
Parses and installs a canonical profile JSON document transactionally.
Definition ClimbingInput.cpp:118
eve::Result< void > reloadProfile(ClimbingProfile profile)
Atomically publishes a validated profile while pinning any active execution to its old snapshot.
Definition ClimbingInput.cpp:114
eve::Result< ClimbingCandidateSet > probe(physics::World3D &world, const ClimbingPose &pose) const
Probes, validates, and deterministically sorts all matching candidates.
Definition Climbing.cpp:179
eve::Result< void > restore(const eve::Value &value, physics::World3D &world)
Restores a fully parsed candidate atomically after revalidating all process-local Physics links.
Definition ClimbingSnapshot.cpp:378
eve::Result< ClimbingPredictionDecision > tryBeginPredicted(physics::World3D &world, const ClimbingPose &pose, const ClimbingPredictionRequest &request, eve::SimulationTick serverTick, std::uint64_t maxClientTickLead)
Re-probes authoritative state and commits only the exact server-matched predicted candidate.
Definition ClimbingInput.cpp:601
static constexpr std::string_view SnapshotSchemaId
Stable schema id for owning runtime snapshots.
Definition Climbing.h:662
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
constexpr bool isZero() const noexcept
Returns whether this value is zero.
Definition StrongUint64.h:28
Box3D rigid-body world. Script coordinates are meters (Box3D native), unlike 2D World which uses pixe...
Definition World3D.h:47
const Value * field(const Value &value, const char *key)
Borrow an optional object field.
Definition BuildingSnapshot.cpp:96
Definition Climbing.cpp:20
ClimbingCoyoteState
Named result of evaluating the deterministic grounded grace window.
Definition ClimbingInput.h:25
EVENGINE_API_DOMAINS eve::Result< eve::Value > encodeClimbingPredictionRequest(const ClimbingPredictionRequest &request)
Encodes a validated prediction request to its canonical owning Value representation.
Definition ClimbingInput.cpp:511
eve::Result< ClimbingProfileDefinition > decodeClimbingProfileDefinition(const eve::Value &value)
Decode and validate an owning profile candidate transactionally.
Definition ClimbingCodec.cpp:732
ClimbingPhase
Execution lifecycle visible to gameplay and animation adapters.
Definition Climbing.h:470
@ Completed
@ Cancelled
EVENGINE_API_DOMAINS eve::Result< eve::Value > encodeClimbingPredictionDecision(const ClimbingPredictionDecision &decision)
Encodes a validated authoritative decision to its canonical owning Value representation.
Definition ClimbingInput.cpp:545
ClimbingPredictionReason
Stable reason for a non-accepted prediction decision.
Definition Climbing.h:421
@ RuntimeBusy
@ CandidateMismatch
@ TickTooFarAhead
@ InvalidRequest
@ NoCandidate
ClimbingPredictionDisposition
Named server-authoritative outcome of one prediction request.
Definition Climbing.h:418
EVENGINE_API_DOMAINS eve::Result< ClimbingPredictionDecision > decodeClimbingPredictionDecision(const eve::Value &value)
Decodes a complete authoritative decision transactionally.
Definition ClimbingInput.cpp:565
eve::detail::StrongUint64< detail::ClimbingPredictionSequenceTag > ClimbingPredictionSequence
Non-zero client command sequence used to pair one prediction decision.
Definition Climbing.h:380
ClimbingCommand
Edge and held commands understood by the climbing input phase.
Definition ClimbingInput.h:22
ClimbingActionKind
Data-driven action family; stable action identity remains the definition id.
Definition Climbing.h:46
eve::Result< ClimbingPoseResult > applyClimbingPose(animation::AnimSkeleton &skeleton, animation::AnimPose &pose, const ClimbingAdvance &advance, const ClimbingPoseBinding &binding)
Applies contact anchors to an already evaluated animation pose.
Definition ClimbingInput.cpp:177
EVENGINE_API_DOMAINS eve::Result< ClimbingPredictionRequest > decodeClimbingPredictionRequest(const eve::Value &value)
Decodes a complete request and rejects unknown schema versions transactionally.
Definition ClimbingInput.cpp:525
EVENGINE_API_DOMAINS ClimbingCandidateKey makeClimbingCandidateKey(const ClimbingCandidate &candidate, std::uint32_t sortedRank) noexcept
Creates the opaque key for one candidate at its deterministic sorted rank.
Definition ClimbingInput.cpp:483
bool readString(const eve::Value::Object &object, const char *name, std::string &output)
Definition ArtifactProvider.cpp:21
Result< std::int64_t > readInt64(const Value::Object &object, std::string_view name)
Reads a required signed decimal integer string.
Definition WorldSnapshotParsing.cpp:42
bool readUint64String(const eve::Value::Object &object, const char *name, std::uint64_t &output)
Definition ArtifactProvider.cpp:46
Result< std::vector< uint8_t > > quantize(std::span< const float > input, float scale, int zero, bool sign)
Affine quantization to int8/uint8 bytes, saturating and rounding ties to even.
Definition AffineQuant.cpp:24
@ InvalidArgument
@ UnknownVersion
@ PreconditionViolation
@ ParseError
@ Conflict
@ NoOp
@ Applied
detail::StrongUint64< detail::SimulationTickTag > SimulationTick
Deterministic simulation time step; it is not wall-clock time.
Definition Time.h:31
Result< std::string > readStringMember(const Value::Object &object, std::string_view name)
Read a required string field, including an empty string, as an owning value.
Definition Value.cpp:25
Result< std::int64_t > readInt64Value(const Value &value)
Read an Int64 without narrowing or numeric coercion.
Definition Value.cpp:57
One owning edge command with deterministic lifetime and consumption evidence.
Definition ClimbingInput.h:28
float rightFootWeight
Right-foot constraint weight resolved from the immutable action contact windows.
Definition Climbing.h:590
float leftFootWeight
Left-foot constraint weight resolved from the immutable action contact windows.
Definition Climbing.h:588
Vec3 leftFootAnchor
Owning world-space foot targets, resolved for this tick only.
Definition Climbing.h:598
bool hasLeftFootAnchor
Whether a supported foot target exists; weights alone never imply a target.
Definition Climbing.h:601
float pelvisWeight
Pelvis constraint weight resolved from the immutable action contact windows.
Definition Climbing.h:592
Opaque deterministic identity of one sorted candidate; contains no client-authored position.
Definition Climbing.h:389
Owning, replayable climbing candidate; contains no borrowed query pointers.
Definition Climbing.h:290
Hot authoritative intent component; contains no device or callback pointers.
Definition ClimbingInput.h:39
std::vector< BufferedClimbingCommand > commands
Definition ClimbingInput.h:43
Borrowed-pose adapter inputs; no skeleton or pose pointer is retained.
Definition ClimbingPose.h:26
Observable result of applying built-in hand and foot constraints.
Definition ClimbingPose.h:41
Input pose used for one deterministic candidate probe.
Definition Climbing.h:275
Server-to-client decision carrying the authoritative runtime snapshot for reconciliation.
Definition Climbing.h:431
ClimbingPredictionSequence sequence
Definition Climbing.h:437
eve::Value authoritativeSnapshot
Canonical server runtime state after the decision, used for rollback/replay reconciliation.
Definition Climbing.h:445
eve::SimulationTick serverTick
Definition Climbing.h:439
static constexpr std::int64_t SchemaVersion
Current decision schema version.
Definition Climbing.h:435
ClimbingPredictionReason reason
Definition Climbing.h:441
eve::SimulationTick clientTick
Definition Climbing.h:438
eve::Value::Object extensionMetadata
Unknown schema fields retained across decode and encode.
Definition Climbing.h:447
ClimbingPredictionDisposition disposition
Definition Climbing.h:440
ClimbingCandidateKey authoritativeCandidate
Server-selected key; fingerprint zero means no authoritative candidate was available.
Definition Climbing.h:443
static constexpr std::string_view SchemaId
Canonical cross-process schema id.
Definition Climbing.h:433
Client-to-server request containing selection identity only, never a world-space target.
Definition Climbing.h:404
static constexpr std::string_view SchemaId
Canonical cross-process schema id.
Definition Climbing.h:406
Runtime profile controlling capsule geometry and probe limits.
Definition Climbing.h:218
std::uint64_t inputBufferTicks
Definition Climbing.h:234
Small owning world-space vector used at climbing module boundaries.
Definition ClimbingPrimitives.h:18