载入中...
搜索中...
未找到
Climbing.cpp
浏览该文件的文档.
26 return std::tie(c.actionId, c.definitionGeneration, c.world, c.obstacleBody, c.obstacleShape, c.obstacleBodyId,
46void ClimbingCandidateSet::considerWithActionId(const ClimbingCandidate& candidate, std::string_view actionId) {
78eve::Result<void> ClimbingRuntime::requireEventCapacity(std::size_t count, eve::SimulationTick tick) const {
81 eve::DiagnosticCode::Conflict, "climbing event queue must be drained before simulation can continue",
91 EV_ASSERT(pendingEvents_.size() < PendingEventCapacity, "climbing event queue capacity invariant");
103 return eve::Result<std::vector<ClimbingEvent>>::success(std::move(events), eve::Status::success(code));
115eve::Result<void> ClimbingRuntime::publishProfile(ClimbingProfile profile, bool allowActiveExecution) {
123 return eve::Result<void>::failure(eve::Diagnostic::error(eve::DiagnosticCode::PreconditionViolation,
132 eve::DiagnosticCode::Conflict, "profile contains duplicate action ids", "profile.actions", {}, "climbing"));
209 eve::DiagnosticCode::StaleHandle, "physics world is no longer valid", "world", {}, "climbing"));
210 if (!isFinite(pose.feet) || !isFinite(pose.forward) || !isFinite(pose.speed) || pose.speed < 0.f ||
247 auto localLanding = body->worldToLocalPointOwned(candidate.landingFeet.x, candidate.landingFeet.y,
276 const bool hasSlide = std::any_of(profile_.actions.begin(), profile_.actions.end(), [&](const auto& action) {
277 return action.kind == ClimbingActionKind::Slide && isActionEnabledForPose(profile_, action, pose) &&
289 boundedDebugPush(lastDebugQueries_, ClimbingDebugQuery{"", ground.hit ? "slide.ground" : "slide.no_ground",
291 if (ground.hit && broadPhaseContains(ground.shape) && ground.normalY >= profile_.minTopNormalY) {
293 if (action.kind != ClimbingActionKind::Slide || !isActionEnabledForPose(profile_, action, pose) ||
310 const float upperY = landing.y + profile_.compactCapsuleHeight - profile_.capsuleRadius + profile_.skin;
312 auto overlap = world.queryCapsuleOwned(landing.x, lowerY, landing.z, landing.x, upperY, landing.z,
357 const bool hasWallRun = std::any_of(profile_.actions.begin(), profile_.actions.end(), [&](const auto& action) {
358 return action.kind == ClimbingActionKind::WallRun && isActionEnabledForPose(profile_, action, pose) &&
371 boundedDebugPush(lastDebugQueries_, ClimbingDebugQuery{"", hit.hit ? "wall_run.wall" : "wall_run.miss",
380 if (action.kind != ClimbingActionKind::WallRun || !isActionEnabledForPose(profile_, action, pose) ||
391 const float upperY = landing.y + profile_.capsuleHeight - profile_.capsuleRadius + profile_.skin;
393 auto overlap = world.queryCapsuleOwned(landing.x, lowerY, landing.z, landing.x, upperY, landing.z,
445 // A single chest-height ray skips low vault obstacles entirely. The obstacle recipe starts just above the
446 // capsule's lower hemisphere so it can see every valid obstacle above the profile's physical skin; top and
453 world.rayCastOwned(frontStart.x, frontStart.y, frontStart.z, frontEnd.x, frontEnd.y, frontEnd.z, filter);
457 boundedDebugPush(lastDebugQueries_, ClimbingDebugQuery{"", front.hit ? "front.hit" : "front.miss",
466 auto topResult = world.rayCastOwned(overFront.x, overFront.y, overFront.z, topEnd.x, topEnd.y, topEnd.z, filter);
470 boundedDebugPush(lastDebugQueries_, ClimbingDebugQuery{"", top.hit ? "top.hit" : "top.miss", overFront,
490 if (action.minDepth > baseDepth + epsilon || action.maxDepth < 999.f || action.maxCurvature < 999.f) {
492 depthProbeDistance = std::max(depthProbeDistance, std::max(action.minDepth, action.maxDepth < 999.f
497 depthProbeDistance = std::min(profile_.maxProbeDistance, std::max(0.f, depthProbeDistance - baseDepth));
518 measuredCurvature = std::max(measuredCurvature, std::acos(dot) / std::max(stepDistance, epsilon));
527 boundedDebugPush(lastEvidence_, ClimbingCandidateEvidence{action.id, "definition_policy_rejected"});
550 topSlope - epsilon > action.maxSlopeRadians || measuredCurvature - epsilon > action.maxCurvature ||
554 boundedDebugPush(lastEvidence_, ClimbingCandidateEvidence{action.id, "support_geometry_rejected"});
564 if ((wantsHang && (pose.grounded || pose.verticalSpeed > epsilon)) || (!wantsHang && !pose.grounded)) {
576 : Vec3{top.x + forward.x * action.landingForward, top.y, top.z + forward.z * action.landingForward};
578 const float upperY = landing.y + profile_.capsuleHeight - profile_.capsuleRadius + profile_.skin;
580 auto overlap = world.queryCapsuleOwned(landing.x, lowerY, landing.z, landing.x, upperY, landing.z,
599 supportStart + forward * (profile_.capsuleRadius + profile_.skin + action.hangBodyOffset + 0.25f);
601 auto supportHit = world.rayCastOwned(supportStart.x, supportStart.y, supportStart.z, supportEnd.x,
619 boundedDebugPush(lastEvidence_, ClimbingCandidateEvidence{action.id, "geometry_policy_rejected"});
632 boundedDebugPush(lastEvidence_, ClimbingCandidateEvidence{action.id, "accepted", biasCost, heightCost,
650 candidate.leftHandAnchor = candidate.topPoint - candidate.surfaceTangent * (action.handSpacing * 0.5f);
651 candidate.rightHandAnchor = candidate.topPoint + candidate.surfaceTangent * (action.handSpacing * 0.5f);
680 return eve::Result<void>::failure(eve::Diagnostic::error(eve::DiagnosticCode::PreconditionViolation,
691 if (!released && released.error() && released.error()->code() != eve::DiagnosticCode::StaleHandle &&
695 enqueueEvent({ClimbingEventKind::Dropped, execution_->candidate.actionId, tick, execution_->executionId});
708 return eve::Result<void>::failure(eve::Diagnostic::error(eve::DiagnosticCode::PreconditionViolation,
715 const auto found = std::find_if(profile_.actions.begin(), profile_.actions.end(), [&](const auto& action) {
716 return (action.kind == ClimbingActionKind::ClimbUp || action.kind == ClimbingActionKind::Mantle) &&
726 if (!released && released.error() && released.error()->code() != eve::DiagnosticCode::StaleHandle &&
752eve::Result<void> ClimbingRuntime::cancel(ClimbingCancelReason reason, eve::SimulationTick tick) {
754 return eve::Result<void>::failure(eve::Diagnostic::error(eve::DiagnosticCode::PreconditionViolation,
764 ? static_cast<float>(std::clamp(execution_->elapsed.seconds() / action.duration.seconds(), 0.0, 1.0))
770 "the active definition does not allow cancellation in this window", "action.cancelWindow", {}, "climbing"));
775 if (!released && released.error() && released.error()->code() != eve::DiagnosticCode::StaleHandle &&
779 enqueueEvent({ClimbingEventKind::Cancelled, execution_->candidate.actionId, tick, execution_->executionId});
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
Versioned, lossless codecs for climbing definitions.
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
Keyframed skeletal animation clip (local TRS tracks per bone). Script type: AnimClip.
Definition AnimClip.h:145
Fixed-capacity owning candidate set used by the production probe hot path.
Definition Climbing.h:329
void consider(ClimbingCandidate candidate)
Consider one candidate and retain it only when it belongs to the best fixed-capacity set.
Definition Climbing.cpp:40
void considerWithActionId(const ClimbingCandidate &candidate, std::string_view actionId)
Consider a candidate while reusing slot-owned action-id storage on the production probe path.
Definition Climbing.cpp:46
void swap(ClimbingCandidateSet &other) noexcept
Exchange complete owning slot storage without allocating.
Definition Climbing.cpp:73
void sortAndLimit(std::size_t limit)
Sort by canonical deterministic selection key and clamp to a validated limit.
Definition Climbing.cpp:66
static constexpr std::size_t Capacity
Definition Climbing.h:331
void clear() noexcept
Remove all candidates while retaining each slot's owned string capacity.
Definition Climbing.h:334
ClimbingDebugSnapshot inspect() const
Captures the latest bounded owning diagnostics without querying Physics.
Definition Climbing.cpp:790
eve::Result< void > setProfile(ClimbingProfile profile)
Replaces the runtime profile after validating all dimensions and action definitions.
Definition Climbing.cpp:106
eve::Result< void > drop(eve::SimulationTick tick)
Enters an explicit physics-constrained drop from a hanging pose.
Definition Climbing.cpp:678
void recordOrdinaryTick(eve::SimulationTick tick, std::uint32_t queryCount=0, std::uint32_t moverIterations=0, std::uint64_t elapsedNanoseconds=0) noexcept
Record one ordinary locomotion tick and its bounded Physics mover work.
Definition Climbing.cpp:818
ClimbingLocomotionPolicy locomotionPolicy() const noexcept
Return an owning ordinary-locomotion policy snapshot safe across later profile reloads.
Definition Climbing.cpp:110
eve::Result< eve::Value > snapshot() const
Captures deterministic runtime state; debug candidates and final bone poses are excluded.
Definition ClimbingSnapshot.cpp:325
eve::Result< std::vector< ClimbingEvent > > drainEvents()
Atomically takes all events queued by simulation operations in stable production order.
Definition Climbing.cpp:99
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 > probeInto(physics::World3D &world, const ClimbingPose &pose, ClimbingCandidateSet &output, eve::SimulationTick tick=eve::SimulationTick::zero()) const
Probe into caller-retained fixed storage; successful calls atomically replace output.
Definition Climbing.cpp:187
eve::Result< void > validateAnimationBinding(std::string_view actionId, const animation::AnimClip &clip)
Validates and records an action's clip notify contract without retaining the clip.
Definition Climbing.cpp:158
eve::Result< void > cancel(ClimbingCancelReason reason, eve::SimulationTick tick)
Cancels an active execution with an injected tick and stable, strongly typed reason.
Definition Climbing.cpp:752
eve::Result< void > climbUp(eve::SimulationTick tick)
Branches from hanging into the best compatible mantle/climb-up definition.
Definition Climbing.cpp:706
eve::Result< void > upsertAction(ClimbingActionDefinition action)
Adds or replaces one action definition by stable id.
Definition Climbing.cpp:139
static constexpr std::size_t PendingEventCapacity
Hard bound for undelivered post-simulation events owned by one runtime.
Definition Climbing.h:666
void setDebugCapture(ClimbingDebugCapture capture) noexcept
Enables or disables bounded diagnostic capture; disabling immediately releases captured data.
Definition Climbing.cpp:808
RuntimeTelemetryScope public API.
Definition ClimbingRuntimeInternal.h:17
Backend-neutral 3D rigid body in meter-space coordinates (+Y up by convention). Owned by a World3D; c...
Definition Body3D.h:31
Box3D rigid-body world. Script coordinates are meters (Box3D native), unlike 2D World which uses pixe...
Definition World3D.h:47
bool isActionEnabledForPose(const ClimbingProfile &profile, const ClimbingActionDefinition &action, const ClimbingPose &pose)
True when action enabled for pose.
Definition ClimbingRuntimeInternal.h:216
std::int64_t selectionCost(const ClimbingProfile &profile, const ClimbingActionDefinition &action, const ClimbingPose &pose, Vec3 targetDirection, Vec3 targetDelta, float heightError, float distance, std::int64_t stableTieBreak=0)
Selection cost.
Definition ClimbingRuntimeInternal.h:274
bool isCandidateLess(const ClimbingCandidate &lhs, const ClimbingCandidate &rhs)
True when candidate less.
Definition ClimbingRuntimeInternal.h:199
bool isRuntimeProbeKind(ClimbingActionKind kind)
True when runtime probe kind.
Definition ClimbingRuntimeInternal.h:161
const ClimbingActionDefinition * findAction(const ClimbingProfile &profile, std::string_view id)
Optional action. @borrowed From profile; lifetime ends when the caller-owned profile changes or is de...
Definition ClimbingRuntimeInternal.h:192
std::int64_t quantizeMillimeters(float value)
Quantize millimeters.
Definition ClimbingRuntimeInternal.h:184
bool isProbeRecipeMatchingKind(const ClimbingActionDefinition &action)
True when probe recipe matching kind.
Definition ClimbingRuntimeInternal.h:228
constexpr float epsilon
Definition ClimbingRuntimeInternal.h:13
bool isSupportSelectorMatch(const ClimbingActionDefinition &action, int shapeTag, int materialId)
True when support selector match.
Definition ClimbingRuntimeInternal.h:254
void boundedDebugPush(std::vector< T > &values, T value)
Bounded debug push.
Definition ClimbingRuntimeInternal.h:42
bool isObstacleProbeKind(ClimbingActionKind kind)
True when obstacle probe kind.
Definition ClimbingRuntimeInternal.h:168
bool isActivePhase(ClimbingPhase phase)
True when active phase.
Definition ClimbingRuntimeInternal.h:155
Definition Climbing.cpp:20
@ Cancelled
@ Launching
@ Dropping
@ MotionBlocked
@ AnchorStale
@ WarpBudgetExceeded
ClimbingDebugCapture
Runtime policy controlling optional owning diagnostic capture.
Definition Climbing.h:606
eve::Result< void > validateClimbingActionDefinition(const ClimbingActionDefinition &action)
Validate every known field of one action definition.
Definition ClimbingCodec.cpp:285
@ Cancelled
@ LedgeGrab
eve::Result< void > validateClimbingProfileDefinition(const ClimbingProfileDefinition &profile)
Validate every known field and nested action of one profile definition.
Definition ClimbingCodec.cpp:389
@ CandidateProbe
@ InvalidArgument
@ NotFound
@ PreconditionViolation
@ StaleHandle
@ Conflict
@ NoOp
@ Applied
Definition of one geometry-compatible climbing action.
Definition Climbing.h:160
Quantized selection cost and hard-decision evidence for one action definition.
Definition Climbing.h:619
Owning, replayable climbing candidate; contains no borrowed query pointers.
Definition Climbing.h:290
ClimbingProbeRecipe probeRecipe
Definition Climbing.h:317
std::uint64_t definitionGeneration
Definition generation used to produce this candidate.
Definition Climbing.h:293
physics::PhysicsBodyHandle obstacleBody
Definition Climbing.h:295
physics::PhysicsShapeHandle obstacleShape
Definition Climbing.h:296
Geometry-query evidence suitable for an engine debug-draw adapter.
Definition Climbing.h:609
Bounded owning debug snapshot, independent of Physics query caches.
Definition Climbing.h:639
Small owning projection of profile fields consumed by ordinary ground/air locomotion.
Definition Climbing.h:261
Input pose used for one deterministic candidate probe.
Definition Climbing.h:275
Runtime profile controlling capsule geometry and probe limits.
Definition Climbing.h:218
float groundAcceleration
Definition Climbing.h:238
std::uint32_t probeSectors
Definition Climbing.h:243
physics::QueryFilter3D queryFilter
Definition Climbing.h:254
std::uint64_t coyoteTicks
Definition Climbing.h:235
float maxObstacleHeight
Definition Climbing.h:229
float maxProbeDistance
Definition Climbing.h:228
std::vector< ClimbingActionDefinition > actions
Definition Climbing.h:255
std::uint32_t maxCandidates
Definition Climbing.h:244
float dropInitialSpeed
Definition Climbing.h:233
float compactCapsuleHeight
Definition Climbing.h:226
static constexpr std::uint32_t CandidateProbe
Definition ClimbingTelemetry.h:29
static constexpr std::uint32_t Ordinary
Definition ClimbingTelemetry.h:28
std::uint32_t rejectCount
Definition ClimbingTelemetry.h:49
std::uint32_t broadPhaseQueryCount
Definition ClimbingTelemetry.h:46
std::uint32_t queryBudget
Definition ClimbingTelemetry.h:53
ClimbingWorkload workload
Definition ClimbingTelemetry.h:45
ClimbingQueryBudgetState budgetState
Definition ClimbingTelemetry.h:54
std::uint32_t broadPhaseHitCount
Definition ClimbingTelemetry.h:47
std::uint32_t queryCount
Definition ClimbingTelemetry.h:48
std::int64_t selectedCost
Definition ClimbingTelemetry.h:50
Small owning world-space vector used at climbing module boundaries.
Definition ClimbingPrimitives.h:18
One generation-qualified shape returned by an owning broad-phase query.
Definition OwnedQuery3D.h:61
Query filter applied atomically for one owning query operation.
Definition OwnedQuery3D.h:47