载入中...
搜索中...
未找到
Climbing.cpp
浏览该文件的文档.
29void ClimbingCandidateSet::considerWithActionId(ClimbingCandidate candidate, std::string_view actionId) {
56 std::sort(values_.begin(), values_.begin() + static_cast<std::ptrdiff_t>(size_), isCandidateLess);
65eve::Result<void> ClimbingRuntime::requireEventCapacity(std::size_t count, eve::SimulationTick tick) const {
68 eve::DiagnosticCode::Conflict, "climbing event queue must be drained before simulation can continue",
78 EV_ASSERT(pendingEvents_.size() < PendingEventCapacity, "climbing event queue capacity invariant");
90 return eve::Result<std::vector<ClimbingEvent>>::success(std::move(events), eve::Status::success(code));
102eve::Result<void> ClimbingRuntime::publishProfile(ClimbingProfile profile, bool allowActiveExecution) {
110 return eve::Result<void>::failure(eve::Diagnostic::error(eve::DiagnosticCode::PreconditionViolation,
119 eve::DiagnosticCode::Conflict, "profile contains duplicate action ids", "profile.actions", {}, "climbing"));
191 eve::DiagnosticCode::StaleHandle, "physics world is no longer valid", "world", {}, "climbing"));
192 if (!isFinite(pose.feet) || !isFinite(pose.forward) || !isFinite(pose.speed) || pose.speed < 0.f ||
229 auto localLanding = body->worldToLocalPointOwned(candidate.landingFeet.x, candidate.landingFeet.y,
258 const bool hasSlide = std::any_of(profile_.actions.begin(), profile_.actions.end(), [&](const auto& action) {
259 return action.kind == ClimbingActionKind::Slide && isActionEnabledForPose(profile_, action, pose) &&
271 boundedDebugPush(lastDebugQueries_, ClimbingDebugQuery{"", ground.hit ? "slide.ground" : "slide.no_ground",
273 if (ground.hit && broadPhaseContains(ground.shape) && ground.normalY >= profile_.minTopNormalY) {
275 if (action.kind != ClimbingActionKind::Slide || !isActionEnabledForPose(profile_, action, pose) ||
292 const float upperY = landing.y + profile_.compactCapsuleHeight - profile_.capsuleRadius + profile_.skin;
294 auto overlap = world.queryCapsuleOwned(landing.x, lowerY, landing.z, landing.x, upperY, landing.z,
337 const bool hasWallRun = std::any_of(profile_.actions.begin(), profile_.actions.end(), [&](const auto& action) {
338 return action.kind == ClimbingActionKind::WallRun && isActionEnabledForPose(profile_, action, pose) &&
351 boundedDebugPush(lastDebugQueries_, ClimbingDebugQuery{"", hit.hit ? "wall_run.wall" : "wall_run.miss",
360 if (action.kind != ClimbingActionKind::WallRun || !isActionEnabledForPose(profile_, action, pose) ||
371 const float upperY = landing.y + profile_.capsuleHeight - profile_.capsuleRadius + profile_.skin;
373 auto overlap = world.queryCapsuleOwned(landing.x, lowerY, landing.z, landing.x, upperY, landing.z,
423 // A single chest-height ray skips low vault obstacles entirely. The obstacle recipe starts just above the
424 // capsule's lower hemisphere so it can see every valid obstacle above the profile's physical skin; top and
431 world.rayCastOwned(frontStart.x, frontStart.y, frontStart.z, frontEnd.x, frontEnd.y, frontEnd.z, filter);
435 boundedDebugPush(lastDebugQueries_, ClimbingDebugQuery{"", front.hit ? "front.hit" : "front.miss",
444 auto topResult = world.rayCastOwned(overFront.x, overFront.y, overFront.z, topEnd.x, topEnd.y, topEnd.z, filter);
448 boundedDebugPush(lastDebugQueries_, ClimbingDebugQuery{"", top.hit ? "top.hit" : "top.miss", overFront,
468 if (action.minDepth > baseDepth + epsilon || action.maxDepth < 999.f || action.maxCurvature < 999.f) {
470 depthProbeDistance = std::max(depthProbeDistance, std::max(action.minDepth, action.maxDepth < 999.f
475 depthProbeDistance = std::min(profile_.maxProbeDistance, std::max(0.f, depthProbeDistance - baseDepth));
496 measuredCurvature = std::max(measuredCurvature, std::acos(dot) / std::max(stepDistance, epsilon));
505 boundedDebugPush(lastEvidence_, ClimbingCandidateEvidence{action.id, "definition_policy_rejected"});
528 topSlope - epsilon > action.maxSlopeRadians || measuredCurvature - epsilon > action.maxCurvature ||
532 boundedDebugPush(lastEvidence_, ClimbingCandidateEvidence{action.id, "support_geometry_rejected"});
542 if ((wantsHang && (pose.grounded || pose.verticalSpeed > epsilon)) || (!wantsHang && !pose.grounded)) {
554 : Vec3{top.x + forward.x * action.landingForward, top.y, top.z + forward.z * action.landingForward};
556 const float upperY = landing.y + profile_.capsuleHeight - profile_.capsuleRadius + profile_.skin;
558 auto overlap = world.queryCapsuleOwned(landing.x, lowerY, landing.z, landing.x, upperY, landing.z,
577 supportStart + forward * (profile_.capsuleRadius + profile_.skin + action.hangBodyOffset + 0.25f);
579 auto supportHit = world.rayCastOwned(supportStart.x, supportStart.y, supportStart.z, supportEnd.x,
597 boundedDebugPush(lastEvidence_, ClimbingCandidateEvidence{action.id, "geometry_policy_rejected"});
610 boundedDebugPush(lastEvidence_, ClimbingCandidateEvidence{action.id, "accepted", biasCost, heightCost,
626 candidate.leftHandAnchor = candidate.topPoint - candidate.surfaceTangent * (action.handSpacing * 0.5f);
627 candidate.rightHandAnchor = candidate.topPoint + candidate.surfaceTangent * (action.handSpacing * 0.5f);
656 return eve::Result<void>::failure(eve::Diagnostic::error(eve::DiagnosticCode::PreconditionViolation,
667 if (!released && released.error() && released.error()->code() != eve::DiagnosticCode::StaleHandle &&
671 enqueueEvent({ClimbingEventKind::Dropped, execution_->candidate.actionId, tick, execution_->executionId});
684 return eve::Result<void>::failure(eve::Diagnostic::error(eve::DiagnosticCode::PreconditionViolation,
691 const auto found = std::find_if(profile_.actions.begin(), profile_.actions.end(), [&](const auto& action) {
692 return (action.kind == ClimbingActionKind::ClimbUp || action.kind == ClimbingActionKind::Mantle) &&
702 if (!released && released.error() && released.error()->code() != eve::DiagnosticCode::StaleHandle &&
728eve::Result<void> ClimbingRuntime::cancel(ClimbingCancelReason reason, eve::SimulationTick tick) {
730 return eve::Result<void>::failure(eve::Diagnostic::error(eve::DiagnosticCode::PreconditionViolation,
740 ? static_cast<float>(std::clamp(execution_->elapsed.seconds() / action.duration.seconds(), 0.0, 1.0))
746 "the active definition does not allow cancellation in this window", "action.cancelWindow", {}, "climbing"));
751 if (!released && released.error() && released.error()->code() != eve::DiagnosticCode::StaleHandle &&
755 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.
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
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
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 considerWithActionId(ClimbingCandidate candidate, std::string_view actionId)
Consider a candidate while reusing slot-owned action-id storage on the production probe path.
Definition Climbing.cpp:29
void consider(ClimbingCandidate candidate)
Consider one candidate and retain it only when it belongs to the best fixed-capacity set.
Definition Climbing.cpp:23
const ClimbingCandidate * end() const noexcept
Returns the sentinel following the last candidate for synchronous read-only iteration.
Definition Climbing.h:366
void swap(ClimbingCandidateSet &other) noexcept
Exchange complete owning slot storage without allocating.
Definition Climbing.cpp:60
void sortAndLimit(std::size_t limit)
Sort by canonical deterministic selection key and clamp to a validated limit.
Definition Climbing.cpp:55
const ClimbingCandidate * begin() const noexcept
Returns the first candidate for synchronous read-only iteration.
Definition Climbing.h:360
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:766
eve::Result< void > setProfile(ClimbingProfile profile)
Replaces the runtime profile after validating all dimensions and action definitions.
Definition Climbing.cpp:93
eve::Result< void > drop(eve::SimulationTick tick)
Enters an explicit physics-constrained drop from a hanging pose.
Definition Climbing.cpp:654
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:794
ClimbingLocomotionPolicy locomotionPolicy() const noexcept
Return an owning ordinary-locomotion policy snapshot safe across later profile reloads.
Definition Climbing.cpp:97
eve::Result< eve::Value > snapshot() const
Captures deterministic runtime state; debug candidates and final bone poses are excluded.
Definition ClimbingSnapshot.cpp:393
eve::Result< std::vector< ClimbingEvent > > drainEvents()
Atomically takes all events queued by simulation operations in stable production order.
Definition Climbing.cpp:86
eve::Result< ClimbingCandidateSet > probe(physics::World3D &world, const ClimbingPose &pose) const
Probes, validates, and deterministically sorts all matching candidates.
Definition Climbing.cpp:166
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:174
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:145
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:728
eve::Result< void > climbUp(eve::SimulationTick tick)
Branches from hanging into the best compatible mantle/climb-up definition.
Definition Climbing.cpp:682
eve::Result< void > upsertAction(ClimbingActionDefinition action)
Adds or replaces one action definition by stable id.
Definition Climbing.cpp:126
static constexpr std::size_t PendingEventCapacity
Hard bound for undelivered post-simulation events owned by one runtime.
Definition Climbing.h:660
void setDebugCapture(ClimbingDebugCapture capture) noexcept
Enables or disables bounded diagnostic capture; disabling immediately releases captured data.
Definition Climbing.cpp:784
RuntimeTelemetryScope public API.
Definition ClimbingRuntimeInternal.h:17
3D rigid body (Box3D) in meter-space coordinates (+Y up by convention). Owned by a World3D; create pr...
Definition Body3D.h:24
Box3D rigid-body world. Script coordinates are meters (Box3D native), unlike 2D World which uses pixe...
Definition World3D.h:63
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:19
@ Cancelled
@ Launching
@ Dropping
@ MotionBlocked
@ AnchorStale
@ WarpBudgetExceeded
ClimbingDebugCapture
Runtime policy controlling optional owning diagnostic capture.
Definition Climbing.h:600
eve::Result< void > validateClimbingActionDefinition(const ClimbingActionDefinition &action)
Validate every known field of one action definition.
Definition ClimbingCodec.cpp:291
@ Cancelled
@ LedgeGrab
eve::Result< void > validateClimbingProfileDefinition(const ClimbingProfileDefinition &profile)
Validate every known field and nested action of one profile definition.
Definition ClimbingCodec.cpp:395
@ 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:613
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:603
Bounded owning debug snapshot, independent of Physics query caches.
Definition Climbing.h:633
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:36
Query filter applied atomically for one owning query operation.
Definition OwnedQuery3D.h:22