载入中...
搜索中...
未找到
ClimbingAnchorGraph.cpp
浏览该文件的文档.
23float lengthSquared(Vec3 value) { return value.x * value.x + value.y * value.y + value.z * value.z; }
63 if (!std::isfinite(number) || number < -static_cast<double>(std::numeric_limits<float>::max()) ||
160bool readStringArray(const eve::Value::Object& object, std::string_view name, std::vector<std::string>& output) {
184 return !std::any_of(values.begin(), values.end(), [](const auto& value) { return value.empty(); }) &&
191 std::sort(graph.nodes.begin(), graph.nodes.end(), [](const auto& lhs, const auto& rhs) { return lhs.id < rhs.id; });
200bool sameEdgeIdentity(const ClimbingAnchorEdgeDefinition& lhs, const ClimbingAnchorEdgeDefinition& rhs) {
208eve::Result<void> validateClimbingAnchorGraphDefinition(const ClimbingAnchorGraphDefinition& graph) {
209 if (graph.id.empty() || graph.sourceGeometryContentId.empty() || graph.buildSettingsHash.empty())
214 if (graph.nodes.empty() || graph.nodes.size() > maxGraphNodes || graph.edges.size() > maxGraphEdges)
216 eve::DiagnosticCode::InvalidArgument, "anchor graph node and edge counts exceed supported bounds",
233 if (std::fabs(normalLength - 1.f) > frameTolerance || std::fabs(tangentLength - 1.f) > frameTolerance ||
236 eve::DiagnosticCode::InvalidArgument, "anchor normal and tangent must form an orthonormal local frame",
256 if (edge.from.empty() || edge.to.empty() || edge.from == edge.to || !nodeIds.contains(edge.from) ||
259 eve::DiagnosticCode::InvalidArgument, "anchor edge endpoints must name two distinct existing nodes",
316eve::Result<ClimbingAnchorGraphDefinition> decodeClimbingAnchorGraphDefinition(const eve::Value& value) {
320 eve::Diagnostic::error(eve::DiagnosticCode::ParseError, "anchor graph definition must be an object", {}, {},
329 if (!readString(*root, "schemaId", schemaId) || schemaId != ClimbingAnchorGraphDefinition::SchemaId ||
332 version != ClimbingAnchorGraphDefinition::SchemaVersion - 1) || !readString(*root, "id", graph.id) ||
337 eve::DiagnosticCode::UnknownVersion, "anchor graph schema version is unsupported", "schemaVersion", {},
340 eve::DiagnosticCode::ParseError, "anchor graph envelope has missing or invalid known fields", {}, {},
373 if (!object || !readString(*object, "from", edge.from) || !readString(*object, "to", edge.to) ||
380 edge.extensionMetadata = unknownFields(*object, {"from", "to", "kind", "bidirectional", "requiredTags"});
391eve::Result<ClimbingAnchorGraphInstance> ClimbingAnchorGraphInstance::bind(ClimbingAnchorGraphDefinition graph,
398 eve::Diagnostic::error(eve::DiagnosticCode::StaleHandle, "anchor graph target body handle is stale", "body",
408const ClimbingAnchorNodeDefinition* ClimbingAnchorGraphInstance::findNode(std::string_view nodeId) const noexcept {
414eve::Result<ClimbingAnchorNodeRef> ClimbingAnchorGraphInstance::nodeRef(std::string_view nodeId) const {
417 eve::DiagnosticCode::NotFound, "anchor node was not found", "nodeId", {}, "climbing.anchor_graph"));
418 return eve::Result<ClimbingAnchorNodeRef>::success({graph_.id, std::string(nodeId), generation_});
435 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "anchor node reference belongs to another graph",
444 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "anchor node was not found", "reference.nodeId", {},
448 eve::DiagnosticCode::StaleHandle, "anchor graph belongs to another or stale Physics world", "world", {},
453 eve::Diagnostic::error(eve::DiagnosticCode::StaleHandle, "anchor graph target body handle is stale", "body",
493 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "anchor node reference belongs to another graph",
501 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "anchor node was not found", "reference.nodeId", {},
524 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "route endpoints belong to another anchor graph",
526 if (request.start.graphGeneration != generation_ || request.goal.graphGeneration != generation_)
528 eve::DiagnosticCode::StaleHandle, "route endpoints belong to a stale graph generation", "request", {},
532 eve::DiagnosticCode::NotFound, "route endpoint was not found", "request", {}, "climbing.anchor_graph"));
541 eve::DiagnosticCode::InvalidArgument, "route requester must provide both agent and execution ids",
611 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "no permitted anchor route reaches the goal",
622 eve::Diagnostic::error(eve::DiagnosticCode::InvariantViolation, "route predecessor chain is incomplete",
645 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "anchor node reference belongs to another graph",
654 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "anchor node was not found", "reference.nodeId", {},
658 eve::DiagnosticCode::InvalidArgument, "anchor reservation requires non-zero agent and execution ids",
666 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "occupant already owns a slot on this anchor",
673 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "all anchor occupancy slots are reserved",
678 eve::DiagnosticCode::PreconditionViolation, "anchor reservation identity is exhausted", "reservationId", {},
685 {id, generation_, 1, node->id, slot, occupant}, eve::Status::success(eve::StatusCode::Applied));
688eve::Result<void> ClimbingAnchorGraphInstance::release(const ClimbingAnchorReservation& reservation) {
708 record.occupant != reservation.occupant || record.claimGeneration != reservation.claimGeneration)
740 eve::Diagnostic::error(eve::DiagnosticCode::NotFound, "snapshot reservation node was not found",
742 if (reservation.id.isZero() || reservation.claimGeneration == 0 || reservation.occupant.agentId.isZero() ||
745 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "snapshot reservation credential is invalid",
763 eve::DiagnosticCode::PreconditionViolation, "anchor reservation identity is exhausted", "reservationId", {},
775eve::Result<std::uint32_t> ClimbingAnchorGraphInstance::releaseOccupant(ClimbingAnchorOccupant occupant) {
778 eve::DiagnosticCode::InvalidArgument, "release requires non-zero agent and execution ids", "occupant", {},
793eve::Result<ClimbingAnchorGraphReload> ClimbingAnchorGraphInstance::reload(ClimbingAnchorGraphDefinition graph) {
798 eve::Diagnostic::error(eve::DiagnosticCode::PreconditionViolation, "anchor graph generation is exhausted",
#define EV_ASSERT(cond,...)
Assert an internal engine invariant (state that must always hold).
Definition Assert.h:37
Versioned body-local climbing topology, dynamic resolution, and deterministic occupancy.
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
constexpr bool isValid() const noexcept
Returns whether both coordinates are usable handle values.
Definition RuntimeHandle.h:146
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.h:81
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
Definition Value.h:180
Runtime instance binding one immutable graph generation to one Physics body.
Definition ClimbingAnchorGraph.h:198
eve::Result< std::vector< ClimbingAnchorEdgeDefinition > > edgesFrom(const ClimbingAnchorNodeRef &reference) const
Returns deterministic outgoing edges for a current-generation node reference.
Definition ClimbingAnchorGraph.cpp:489
eve::Result< ClimbingAnchorNodeRef > nodeRef(std::string_view nodeId) const
Returns a current-generation reference for a stable node id.
Definition ClimbingAnchorGraph.cpp:414
physics::PhysicsBodyHandle body() const noexcept
Target Physics body handle; stale detection occurs during resolve.
Definition ClimbingAnchorGraph.h:261
static eve::Result< ClimbingAnchorGraphInstance > bind(ClimbingAnchorGraphDefinition graph, physics::World3D &world, physics::PhysicsBodyHandle body)
Validates and binds a graph snapshot to an existing Physics body.
Definition ClimbingAnchorGraph.cpp:391
eve::Result< ResolvedClimbingAnchorNode > resolveNodeKinematics(physics::World3D &world, const ClimbingAnchorNodeRef &reference) const
Resolves per-tick anchor transforms without copying cold tag metadata.
Definition ClimbingAnchorGraph.cpp:431
eve::Result< ResolvedClimbingAnchorNode > resolveNode(physics::World3D &world, const ClimbingAnchorNodeRef &reference) const
Resolves a current node from body-local to world space after validating world/body generation.
Definition ClimbingAnchorGraph.cpp:421
eve::Result< ClimbingAnchorRoute > planRoute(const ClimbingAnchorRouteRequest &request) const
Finds the shortest occupancy-aware route using stable edge-kind/node-id tie breaking.
Definition ClimbingAnchorGraph.cpp:520
constexpr bool isZero() const noexcept
Returns whether this value is zero.
Definition StrongUint64.h:28
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
const char * nodeKindName(NodeKind kind) noexcept
Stable wire name for a node kind. @ownership Non-owning pointer to a static string literal; do not fr...
Definition ArchSpaceTypes.h:141
Definition Climbing.cpp:19
ClimbingAnchorEdgeKind
Allowed authored transition between two explicit anchors.
Definition ClimbingAnchorGraph.h:34
eve::Result< ClimbingAnchorGraphDefinition > decodeClimbingAnchorGraphDefinition(const eve::Value &value)
Decodes and validates a complete owning graph candidate transactionally.
Definition ClimbingAnchorGraph.cpp:316
ClimbingAnchorKind
Authored semantic of one explicit climbing anchor.
Definition ClimbingAnchorGraph.h:31
@ LadderRung
@ CornerInner
@ CornerOuter
eve::Result< void > validateClimbingAnchorGraphDefinition(const ClimbingAnchorGraphDefinition &graph)
Validates all graph identities, frames, slots, tags, and edge endpoints.
Definition ClimbingAnchorGraph.cpp:208
eve::Result< eve::Value > encodeClimbingAnchorGraphDefinition(const ClimbingAnchorGraphDefinition &graph)
Encodes a validated graph to its canonical owning Value representation.
Definition ClimbingAnchorGraph.cpp:273
bool readString(const eve::Value::Object &object, const char *name, std::string &output)
Definition ArtifactProvider.cpp:20
const EditorValue * field(const EditorValue &value, const char *name)
Definition RoadNetworkEditTarget.cpp:15
@ InvalidArgument
@ NotFound
@ UnknownVersion
@ PreconditionViolation
@ AlreadyExists
@ InvariantViolation
@ ParseError
@ StaleHandle
@ Conflict
@ NoOp
@ Applied
Definition Container.h:602
Directed authored transition in a climbing anchor graph.
Definition ClimbingAnchorGraph.h:63
std::string from
Definition ClimbingAnchorGraph.h:64
Versioned graph asset; topology is authoritative while collision remains owned by Physics.
Definition ClimbingAnchorGraph.h:74
eve::Value::Object extensionMetadata
Unknown schema fields retained across decode and encode.
Definition ClimbingAnchorGraph.h:86
std::vector< ClimbingAnchorNodeDefinition > nodes
Definition ClimbingAnchorGraph.h:83
std::vector< ClimbingAnchorEdgeDefinition > edges
Definition ClimbingAnchorGraph.h:84
std::string sourceGeometryContentId
Definition ClimbingAnchorGraph.h:81
std::string buildSettingsHash
Definition ClimbingAnchorGraph.h:82
static constexpr std::int64_t SchemaVersion
Current schema version.
Definition ClimbingAnchorGraph.h:78
Atomic graph-reload outcome and owners whose old-generation reservations were invalidated.
Definition ClimbingAnchorGraph.h:186
std::vector< ClimbingAnchorOccupant > invalidatedOccupants
Definition ClimbingAnchorGraph.h:189
std::uint64_t newGeneration
Definition ClimbingAnchorGraph.h:188
std::uint64_t oldGeneration
Definition ClimbingAnchorGraph.h:187
One body-local anchor node with deterministic occupancy slots.
Definition ClimbingAnchorGraph.h:47
Generation-qualified reference to an authored anchor node.
Definition ClimbingAnchorGraph.h:121
Compound occupancy owner; execution ids are only unique inside one agent/runtime.
Definition ClimbingAnchorGraph.h:111
ClimbingAnchorAgentId agentId
Definition ClimbingAnchorGraph.h:112
ClimbingExecutionId executionId
Definition ClimbingAnchorGraph.h:113
Owning reservation credential; release validates every field.
Definition ClimbingAnchorGraph.h:128
std::uint32_t slot
Definition ClimbingAnchorGraph.h:133
std::string nodeId
Definition ClimbingAnchorGraph.h:132
std::uint64_t claimGeneration
Definition ClimbingAnchorGraph.h:131
ClimbingAnchorOccupant occupant
Definition ClimbingAnchorGraph.h:134
ClimbingAnchorReservationId id
Definition ClimbingAnchorGraph.h:129
std::uint64_t graphGeneration
Definition ClimbingAnchorGraph.h:130
Read-only route request over one current anchor-graph generation.
Definition ClimbingAnchorGraph.h:141
World-space projection of a body-local anchor at one synchronous resolve point.
Definition ClimbingAnchorGraph.h:171
Vec3 position
Definition ClimbingAnchorGraph.h:175
physics::PhysicsBodyHandle body
Definition ClimbingAnchorGraph.h:174
ClimbingAnchorKind kind
Definition ClimbingAnchorGraph.h:173
ClimbingAnchorNodeRef reference
Definition ClimbingAnchorGraph.h:172
Vec3 feetSocket
Definition ClimbingAnchorGraph.h:180
Vec3 rightHandSocket
Definition ClimbingAnchorGraph.h:179
Vec3 leftHandSocket
Definition ClimbingAnchorGraph.h:178
Vec3 pointVelocity
Definition ClimbingAnchorGraph.h:181