| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationSurfaceAStarWork.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2024-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using System; |
| | | 9 | | using FixedMathSharp; |
| | | 10 | | using GridForge.Grids; |
| | | 11 | | |
| | | 12 | | namespace Trailblazer.Pathing; |
| | | 13 | | |
| | | 14 | | internal enum NavigationSurfaceAStarStatus : byte |
| | | 15 | | { |
| | | 16 | | Pending = 0, |
| | | 17 | | Success = 1, |
| | | 18 | | NoPath = 2, |
| | | 19 | | BudgetExceeded = 3, |
| | | 20 | | CostOverflow = 4, |
| | | 21 | | CapacityExceeded = 5, |
| | | 22 | | Stale = 6 |
| | | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <summary>Runs one bounded fixed-point surface A* query over a leased graph.</summary> |
| | | 26 | | internal sealed class NavigationSurfaceAStarWork : IDisposable |
| | | 27 | | { |
| | | 28 | | private enum Stage : byte |
| | | 29 | | { |
| | | 30 | | Search = 0, |
| | | 31 | | Reconstruct = 1, |
| | | 32 | | ReversePath = 2, |
| | | 33 | | ExpandGuide = 3, |
| | | 34 | | Simplify = 4, |
| | | 35 | | CopyRaw = 5, |
| | | 36 | | SortDependencies = 6, |
| | | 37 | | CaptureDependencies = 7, |
| | | 38 | | BuildPayload = 8 |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | private NavigationResolvedPathQuery? _query; |
| | | 42 | | private NavigationWorldGraph? _graph; |
| | | 43 | | private readonly GridWorld _world; |
| | | 44 | | private readonly NavigationWorldGraphStore _store; |
| | | 45 | | private readonly NavigationRayWork _rayWork; |
| | | 46 | | private readonly NavigationAStarWorkspace _workspace; |
| | | 47 | | private readonly NavigationWorkMeter _meter; |
| | | 48 | | private readonly long _maximumPayloadBytes; |
| | | 49 | | private readonly Vector3d _targetFootAnchor; |
| | | 50 | | private readonly bool _useEuclideanHeuristic; |
| | | 51 | | private NavigationTraversalEdgeEnumerator _edges; |
| | | 52 | | private NavigationMediumStateRef _current; |
| | | 53 | | private NavigationMediumStateRef _pathCursor; |
| | | 54 | | private NavigationMediumStateRef _goal; |
| | | 55 | | private NavigationDependencySortWork _dependencySort; |
| | | 56 | | private NavigationDependencyStampWork? _dependencyStamp; |
| | | 57 | | private NavigationAStarGuidePoint[]? _payloadGuidePoints; |
| | | 58 | | private NavigationTransitionInstruction[]? _payloadTransitionInstructions; |
| | | 59 | | private NavigationSurfaceAStarStatus _resultStatus; |
| | | 60 | | private Stage _stage; |
| | | 61 | | private int _pathWrite; |
| | | 62 | | private int _reverseLeft; |
| | | 63 | | private int _reverseRight; |
| | | 64 | | private int _pathEdgeOrdinal; |
| | | 65 | | private int _payloadWrite; |
| | | 66 | | private int _transitionPayloadWrite; |
| | | 67 | | private int _simplificationSourcePathOrdinal; |
| | | 68 | | private int _simplificationCandidatePathOrdinal; |
| | | 69 | | private int _simplificationWriteOrdinal; |
| | | 70 | | private int _transitionBarrierScanOrdinal; |
| | | 71 | | private int _nextTransitionPathOrdinal; |
| | | 72 | | private int _rawCopyOrdinal; |
| | | 73 | | private int _rawCopyEndOrdinal; |
| | | 74 | | private int _finalizationLookupReservation; |
| | | 75 | | private ulong _simplificationWorldChangeSequence; |
| | | 76 | | private bool _requiresWorldStamp; |
| | | 77 | | private bool _hasCurrent; |
| | | 78 | | private bool _lastGuidePointIsNode; |
| | | 79 | | private bool _hasCompletedSimplificationProof; |
| | | 80 | | |
| | 250 | 81 | | internal NavigationSurfaceAStarWork( |
| | 250 | 82 | | GridWorld world, |
| | 250 | 83 | | NavigationWorldGraphStore store, |
| | 250 | 84 | | NavigationResolvedPathQuery query, |
| | 250 | 85 | | NavigationAStarWorkspace workspace, |
| | 250 | 86 | | NavigationRayWork rayWork, |
| | 250 | 87 | | long maximumPayloadBytes) |
| | | 88 | | { |
| | 250 | 89 | | SwiftThrowHelper.ThrowIfNull(world, nameof(world)); |
| | 250 | 90 | | SwiftThrowHelper.ThrowIfNull(store, nameof(store)); |
| | 250 | 91 | | SwiftThrowHelper.ThrowIfNull(query, nameof(query)); |
| | 250 | 92 | | SwiftThrowHelper.ThrowIfNull(workspace, nameof(workspace)); |
| | 250 | 93 | | SwiftThrowHelper.ThrowIfNull(rayWork, nameof(rayWork)); |
| | 250 | 94 | | if (maximumPayloadBytes < 0) |
| | 1 | 95 | | throw new ArgumentOutOfRangeException(nameof(maximumPayloadBytes)); |
| | 249 | 96 | | _world = world; |
| | 249 | 97 | | _store = store; |
| | 249 | 98 | | _query = query; |
| | 249 | 99 | | _graph = query.Graph; |
| | 249 | 100 | | _workspace = workspace; |
| | 249 | 101 | | _rayWork = rayWork; |
| | 249 | 102 | | _workspace.ResetSearch(); |
| | 249 | 103 | | _meter = query.Meter; |
| | 249 | 104 | | _maximumPayloadBytes = maximumPayloadBytes; |
| | 249 | 105 | | _simplificationWorldChangeSequence = query.WorldChangeSequence; |
| | 249 | 106 | | _requiresWorldStamp = query.RequiresWorldStamp |
| | 249 | 107 | | || query.StartMedium == TraversalMedium.Gas |
| | 249 | 108 | | || query.StartMedium == TraversalMedium.Liquid; |
| | 249 | 109 | | _resultStatus = NavigationSurfaceAStarStatus.Success; |
| | 249 | 110 | | _useEuclideanHeuristic = !query.Query.AllowTransitions |
| | 249 | 111 | | && _graph.SurfaceComponents.TryGet( |
| | 249 | 112 | | query.Start.Address, |
| | 249 | 113 | | query.StartMedium, |
| | 249 | 114 | | out NavigationSurfaceComponent startComponent) |
| | 249 | 115 | | && startComponent.AllSurfaceEdgesEuclideanCertified; |
| | 249 | 116 | | _targetFootAnchor = query.End.FootAnchor; |
| | 249 | 117 | | if (!query.Query.AllowTransitions |
| | 249 | 118 | | && !_graph.AreInSameSurfaceComponent( |
| | 249 | 119 | | query.Start.Address, |
| | 249 | 120 | | query.StartMedium, |
| | 249 | 121 | | query.End.Address, |
| | 249 | 122 | | query.StartMedium)) |
| | | 123 | | { |
| | 6 | 124 | | _resultStatus = NavigationSurfaceAStarStatus.NoPath; |
| | 6 | 125 | | _workspace.PathNodeCount = 0; |
| | 6 | 126 | | _dependencySort = new NavigationDependencySortWork(_workspace); |
| | 6 | 127 | | _stage = Stage.SortDependencies; |
| | 6 | 128 | | return; |
| | | 129 | | } |
| | 243 | 130 | | var startStateRef = new NavigationMediumStateRef( |
| | 243 | 131 | | query.Start.Node, |
| | 243 | 132 | | query.StartMedium); |
| | 243 | 133 | | if (!_workspace.NodeTable.TryGetOrAdd( |
| | 243 | 134 | | startStateRef, |
| | 243 | 135 | | out int startSlot, |
| | 243 | 136 | | out _)) |
| | | 137 | | { |
| | 1 | 138 | | Finish(NavigationSurfaceAStarStatus.CapacityExceeded); |
| | 1 | 139 | | return; |
| | | 140 | | } |
| | 242 | 141 | | ref NavigationAStarNodeRecord start = ref _workspace.NodeTable.GetRecord(startSlot); |
| | 242 | 142 | | start.Cost = Fixed64.Zero; |
| | 242 | 143 | | start.Heuristic = GetHeuristic(startStateRef); |
| | 242 | 144 | | start.EstimatedTotalCost = start.Heuristic; |
| | 242 | 145 | | Push(startStateRef, startSlot); |
| | 242 | 146 | | } |
| | | 147 | | |
| | | 148 | | internal NavigationSurfaceAStarStatus Status { get; private set; } |
| | | 149 | | |
| | | 150 | | internal NavigationAStarPayload Result { get; private set; } = null!; |
| | | 151 | | |
| | | 152 | | internal NavigationSurfaceAStarStatus Advance( |
| | | 153 | | int lookupStepLimit, |
| | | 154 | | int nodeStepLimit, |
| | | 155 | | int edgeStepLimit, |
| | | 156 | | int connectionStepLimit) |
| | | 157 | | { |
| | 1234 | 158 | | SwiftThrowHelper.ThrowIfNegative(lookupStepLimit, nameof(lookupStepLimit)); |
| | 1234 | 159 | | SwiftThrowHelper.ThrowIfNegative(nodeStepLimit, nameof(nodeStepLimit)); |
| | 1234 | 160 | | SwiftThrowHelper.ThrowIfNegative(edgeStepLimit, nameof(edgeStepLimit)); |
| | 1234 | 161 | | SwiftThrowHelper.ThrowIfNegative(connectionStepLimit, nameof(connectionStepLimit)); |
| | 1234 | 162 | | if (Status != NavigationSurfaceAStarStatus.Pending) |
| | 1 | 163 | | return Status; |
| | 1233 | 164 | | if (!IsWorldCurrent()) |
| | 2 | 165 | | return Finish(NavigationSurfaceAStarStatus.Stale); |
| | 1231 | 166 | | int lookupRemaining = lookupStepLimit; |
| | 1231 | 167 | | int nodeRemaining = nodeStepLimit; |
| | 1231 | 168 | | int edgeRemaining = edgeStepLimit; |
| | 1231 | 169 | | int connectionRemaining = connectionStepLimit; |
| | | 170 | | |
| | 23487 | 171 | | while (Status == NavigationSurfaceAStarStatus.Pending) |
| | | 172 | | { |
| | 23487 | 173 | | if (_stage == Stage.Search) |
| | | 174 | | { |
| | 15285 | 175 | | if (!_hasCurrent) |
| | | 176 | | { |
| | 2995 | 177 | | if (_workspace.HeapCount == 0) |
| | | 178 | | { |
| | 11 | 179 | | _resultStatus = NavigationSurfaceAStarStatus.NoPath; |
| | 11 | 180 | | _workspace.PathNodeCount = 0; |
| | 11 | 181 | | _dependencySort = new NavigationDependencySortWork(_workspace); |
| | 11 | 182 | | _stage = Stage.SortDependencies; |
| | 11 | 183 | | continue; |
| | | 184 | | } |
| | 2984 | 185 | | if (nodeRemaining == 0) |
| | | 186 | | { |
| | 38 | 187 | | return _meter.RemainingExpandedNodes == 0 |
| | 38 | 188 | | ? Finish(NavigationSurfaceAStarStatus.BudgetExceeded) |
| | 38 | 189 | | : Status; |
| | | 190 | | } |
| | 2946 | 191 | | if (!_meter.TryConsumeExpandedNodes(1)) |
| | 2 | 192 | | return Finish(NavigationSurfaceAStarStatus.BudgetExceeded); |
| | 2944 | 193 | | nodeRemaining--; |
| | 2944 | 194 | | _current = Pop(); |
| | 2944 | 195 | | _workspace.NodeTable.TryGetSlot(_current, out int currentSlot); |
| | 2944 | 196 | | ref NavigationAStarNodeRecord current = |
| | 2944 | 197 | | ref _workspace.NodeTable.GetRecord(currentSlot); |
| | 2944 | 198 | | current.Closed = true; |
| | 2944 | 199 | | if (IsTarget(_current)) |
| | | 200 | | { |
| | 208 | 201 | | _goal = _current; |
| | 208 | 202 | | _pathCursor = _current; |
| | 208 | 203 | | _stage = Stage.Reconstruct; |
| | 208 | 204 | | continue; |
| | | 205 | | } |
| | 2736 | 206 | | _edges = EnumerateEdges(_current, emittedSurfaceOrdinal: -1); |
| | 2736 | 207 | | _hasCurrent = true; |
| | | 208 | | } |
| | | 209 | | |
| | 15026 | 210 | | NavigationTraversalEdgeAdvanceStatus edgeStatus = _edges.AdvanceOne( |
| | 15026 | 211 | | _meter, |
| | 15026 | 212 | | _workspace.EndpointWorkspace.Dependencies, |
| | 15026 | 213 | | ref edgeRemaining, |
| | 15026 | 214 | | ref connectionRemaining); |
| | 15026 | 215 | | CaptureWorldDependency(_edges); |
| | 15026 | 216 | | edgeStatus = NavigationSearchFinalizationRules.ResolveTraversalEpochStatus( |
| | 15026 | 217 | | edgeStatus, |
| | 15026 | 218 | | IsWorldCurrent()); |
| | 15026 | 219 | | if (edgeStatus == NavigationTraversalEdgeAdvanceStatus.Blocked) |
| | | 220 | | { |
| | 150 | 221 | | return ApplyTerminalStatus( |
| | 150 | 222 | | NavigationSearchFinalizationRules.ResolveBlockedTraversalStatus( |
| | 150 | 223 | | _edges.RequiresConnectionProgress, |
| | 150 | 224 | | _meter.RemainingConnectionLegs, |
| | 150 | 225 | | _meter.RemainingEvaluatedEdges)); |
| | | 226 | | } |
| | 14876 | 227 | | if (edgeStatus == NavigationTraversalEdgeAdvanceStatus.Pending) |
| | | 228 | | continue; |
| | 11949 | 229 | | if (edgeStatus == NavigationTraversalEdgeAdvanceStatus.Complete) |
| | | 230 | | { |
| | 2723 | 231 | | _edges = default; |
| | 2723 | 232 | | _hasCurrent = false; |
| | 2723 | 233 | | continue; |
| | | 234 | | } |
| | 9226 | 235 | | if (NavigationSearchFinalizationRules.TryResolveTraversalTerminalStatus( |
| | 9226 | 236 | | edgeStatus, |
| | 9226 | 237 | | out NavigationSurfaceAStarStatus terminalStatus)) |
| | | 238 | | { |
| | 9 | 239 | | return Finish(terminalStatus); |
| | | 240 | | } |
| | 9217 | 241 | | if (edgeStatus != NavigationTraversalEdgeAdvanceStatus.Edge) |
| | | 242 | | continue; |
| | 9217 | 243 | | NavigationMediumStateRef target = _edges.CurrentTarget; |
| | 9217 | 244 | | if (_workspace.NodeTable.TryGetSlot(target, out int existingSlot) |
| | 9217 | 245 | | && _workspace.NodeTable.GetRecord(existingSlot).Closed) |
| | | 246 | | { |
| | | 247 | | continue; |
| | | 248 | | } |
| | 4801 | 249 | | NavigationSurfaceAStarStatus completion = ApplyRoute( |
| | 4801 | 250 | | target, |
| | 4801 | 251 | | _edges.CurrentCost, |
| | 4801 | 252 | | _edges.CurrentOrdinal, |
| | 4801 | 253 | | _edges.CurrentKind); |
| | 4801 | 254 | | if (completion != NavigationSurfaceAStarStatus.Pending) |
| | 3 | 255 | | return completion; |
| | | 256 | | continue; |
| | | 257 | | } |
| | | 258 | | |
| | 8202 | 259 | | if (_stage == Stage.Reconstruct) |
| | | 260 | | { |
| | 940 | 261 | | if (nodeRemaining == 0) |
| | 118 | 262 | | return Status; |
| | 822 | 263 | | nodeRemaining--; |
| | 822 | 264 | | _workspace.PathNodes[_pathWrite++] = _pathCursor; |
| | 822 | 265 | | if (_pathCursor.Equals(new NavigationMediumStateRef( |
| | 822 | 266 | | _query!.Start.Node, |
| | 822 | 267 | | _query.StartMedium))) |
| | | 268 | | { |
| | 208 | 269 | | _workspace.PathNodeCount = _pathWrite; |
| | 208 | 270 | | _reverseLeft = 0; |
| | 208 | 271 | | _reverseRight = _pathWrite - 1; |
| | 208 | 272 | | _stage = Stage.ReversePath; |
| | 208 | 273 | | continue; |
| | | 274 | | } |
| | 614 | 275 | | _workspace.NodeTable.TryGetSlot(_pathCursor, out int pathSlot); |
| | 614 | 276 | | NavigationAStarNodeRecord pathRecord = |
| | 614 | 277 | | _workspace.NodeTable.GetRecord(pathSlot); |
| | 614 | 278 | | if (pathRecord.ParentEdgeKind == NavigationTraversalEdgeKind.Transition) |
| | 48 | 279 | | _transitionPayloadWrite = checked(_transitionPayloadWrite + 1); |
| | 614 | 280 | | _pathCursor = pathRecord.Parent; |
| | 614 | 281 | | continue; |
| | | 282 | | } |
| | | 283 | | |
| | 7262 | 284 | | if (_stage == Stage.ReversePath) |
| | | 285 | | { |
| | 659 | 286 | | if (_reverseLeft < _reverseRight) |
| | | 287 | | { |
| | 426 | 288 | | if (nodeRemaining == 0) |
| | 56 | 289 | | return Status; |
| | 370 | 290 | | nodeRemaining--; |
| | 370 | 291 | | (_workspace.PathNodes[_reverseLeft], _workspace.PathNodes[_reverseRight]) = |
| | 370 | 292 | | (_workspace.PathNodes[_reverseRight], _workspace.PathNodes[_reverseLeft]); |
| | 370 | 293 | | _reverseLeft++; |
| | 370 | 294 | | _reverseRight--; |
| | 370 | 295 | | continue; |
| | | 296 | | } |
| | 233 | 297 | | if (nodeRemaining == 0) |
| | 25 | 298 | | return Status; |
| | 208 | 299 | | nodeRemaining--; |
| | 208 | 300 | | _payloadTransitionInstructions = _transitionPayloadWrite == 0 |
| | 208 | 301 | | ? Array.Empty<NavigationTransitionInstruction>() |
| | 208 | 302 | | : new NavigationTransitionInstruction[_transitionPayloadWrite]; |
| | 208 | 303 | | _transitionPayloadWrite = 0; |
| | 208 | 304 | | NavigationMediumStateRef startNode = _workspace.PathNodes[0]; |
| | 208 | 305 | | _graph!.TryGetNodeAddress( |
| | 208 | 306 | | startNode.Node, |
| | 208 | 307 | | out NavigationCellAddress startAddress); |
| | 208 | 308 | | _graph.TryGetNodeState( |
| | 208 | 309 | | startNode.Node, |
| | 208 | 310 | | startNode.Medium, |
| | 208 | 311 | | out NavigationNodeState startState); |
| | 208 | 312 | | if (!AppendGuidePoint( |
| | 208 | 313 | | new NavigationAStarGuidePoint( |
| | 208 | 314 | | startAddress, |
| | 208 | 315 | | GetGuideAnchor(startState, startNode.Medium), |
| | 208 | 316 | | startNode.Medium), |
| | 208 | 317 | | pathNodeOrdinal: 0)) |
| | | 318 | | { |
| | 1 | 319 | | return Finish(NavigationSurfaceAStarStatus.CapacityExceeded); |
| | | 320 | | } |
| | 207 | 321 | | _pathEdgeOrdinal = 0; |
| | 207 | 322 | | BeginSelectedEdgeReplay(_pathEdgeOrdinal); |
| | 207 | 323 | | _stage = Stage.ExpandGuide; |
| | 207 | 324 | | continue; |
| | | 325 | | } |
| | | 326 | | |
| | 6603 | 327 | | if (_stage == Stage.ExpandGuide) |
| | | 328 | | { |
| | 4042 | 329 | | if (_pathEdgeOrdinal + 1 >= _workspace.PathNodeCount) |
| | | 330 | | { |
| | 200 | 331 | | _edges = default; |
| | 200 | 332 | | BeginSimplification(); |
| | 200 | 333 | | continue; |
| | | 334 | | } |
| | 3842 | 335 | | NavigationMediumStateRef sourceNode = |
| | 3842 | 336 | | _workspace.PathNodes[_pathEdgeOrdinal]; |
| | 3842 | 337 | | NavigationMediumStateRef targetNode = |
| | 3842 | 338 | | _workspace.PathNodes[_pathEdgeOrdinal + 1]; |
| | 3842 | 339 | | _workspace.NodeTable.TryGetSlot(targetNode, out int targetSlot); |
| | 3842 | 340 | | NavigationAStarNodeRecord targetRecord = _workspace.NodeTable |
| | 3842 | 341 | | .GetRecord(targetSlot); |
| | 3842 | 342 | | int parentEdgeOrdinal = targetRecord.ParentEdgeOrdinal; |
| | 3842 | 343 | | NavigationTraversalEdgeAdvanceStatus edgeStatus = _edges.AdvanceOne( |
| | 3842 | 344 | | _meter, |
| | 3842 | 345 | | _workspace.EndpointWorkspace.Dependencies, |
| | 3842 | 346 | | ref edgeRemaining, |
| | 3842 | 347 | | ref connectionRemaining); |
| | 3842 | 348 | | CaptureWorldDependency(_edges); |
| | 3842 | 349 | | edgeStatus = NavigationSearchFinalizationRules.ResolveTraversalEpochStatus( |
| | 3842 | 350 | | edgeStatus, |
| | 3842 | 351 | | IsWorldCurrent()); |
| | 3842 | 352 | | if (NavigationSearchFinalizationRules.ShouldConsumeTraversalSurfacePoint( |
| | 3842 | 353 | | _edges.HasCurrentSurfacePoint, |
| | 3842 | 354 | | edgeStatus)) |
| | | 355 | | { |
| | 2089 | 356 | | if (nodeRemaining == 0) |
| | 274 | 357 | | return Status; |
| | 1815 | 358 | | nodeRemaining--; |
| | 1815 | 359 | | bool isTarget = _edges.CurrentSurfacePointIsTargetFootAnchor; |
| | 1815 | 360 | | if (!AppendGuidePoint( |
| | 1815 | 361 | | _edges.CurrentSurfacePoint, |
| | 1815 | 362 | | isTarget ? _pathEdgeOrdinal + 1 : -1)) |
| | | 363 | | { |
| | 1 | 364 | | return Finish(NavigationSurfaceAStarStatus.CapacityExceeded); |
| | | 365 | | } |
| | 1814 | 366 | | _edges.ConsumeCurrentSurfacePoint(); |
| | 1814 | 367 | | continue; |
| | | 368 | | } |
| | 1753 | 369 | | if (edgeStatus == NavigationTraversalEdgeAdvanceStatus.Blocked) |
| | | 370 | | { |
| | 12 | 371 | | return ApplyTerminalStatus( |
| | 12 | 372 | | NavigationSearchFinalizationRules.ResolveBlockedTraversalStatus( |
| | 12 | 373 | | _edges.RequiresConnectionProgress, |
| | 12 | 374 | | _meter.RemainingConnectionLegs, |
| | 12 | 375 | | _meter.RemainingEvaluatedEdges)); |
| | | 376 | | } |
| | 1741 | 377 | | if (edgeStatus == NavigationTraversalEdgeAdvanceStatus.Pending) |
| | | 378 | | continue; |
| | 661 | 379 | | if (NavigationSearchFinalizationRules.TryResolveTraversalTerminalStatus( |
| | 661 | 380 | | edgeStatus, |
| | 661 | 381 | | out NavigationSurfaceAStarStatus terminalStatus)) |
| | | 382 | | { |
| | 2 | 383 | | return Finish(terminalStatus); |
| | | 384 | | } |
| | | 385 | | System.Diagnostics.Debug.Assert( |
| | | 386 | | edgeStatus == NavigationTraversalEdgeAdvanceStatus.Edge, |
| | | 387 | | "the immutable selected edge passed the same evaluator during search"); |
| | 659 | 388 | | if (_edges.CurrentOrdinal < parentEdgeOrdinal) |
| | | 389 | | continue; |
| | 610 | 390 | | if (_edges.CurrentKind == NavigationTraversalEdgeKind.Transition) |
| | | 391 | | { |
| | 48 | 392 | | if (!AppendTransitionGuidePoints(sourceNode, targetNode)) |
| | 2 | 393 | | return Finish(NavigationSurfaceAStarStatus.CapacityExceeded); |
| | | 394 | | } |
| | 562 | 395 | | else if (_edges.CurrentKind == NavigationTraversalEdgeKind.Volume) |
| | | 396 | | { |
| | 20 | 397 | | _graph!.TryGetNodeAddress( |
| | 20 | 398 | | targetNode.Node, |
| | 20 | 399 | | out NavigationCellAddress targetAddress); |
| | 20 | 400 | | _graph.TryGetNodeState( |
| | 20 | 401 | | targetNode.Node, |
| | 20 | 402 | | targetNode.Medium, |
| | 20 | 403 | | out NavigationNodeState targetState); |
| | 20 | 404 | | if (!AppendGuidePoint( |
| | 20 | 405 | | new NavigationAStarGuidePoint( |
| | 20 | 406 | | targetAddress, |
| | 20 | 407 | | GetGuideAnchor(targetState, targetNode.Medium), |
| | 20 | 408 | | targetNode.Medium), |
| | 20 | 409 | | _pathEdgeOrdinal + 1)) |
| | | 410 | | { |
| | 2 | 411 | | return Finish(NavigationSurfaceAStarStatus.CapacityExceeded); |
| | | 412 | | } |
| | | 413 | | } |
| | 606 | 414 | | _pathEdgeOrdinal++; |
| | 606 | 415 | | BeginSelectedEdgeReplay(_pathEdgeOrdinal); |
| | 606 | 416 | | continue; |
| | | 417 | | } |
| | | 418 | | |
| | 2561 | 419 | | if (_stage == Stage.Simplify) |
| | 93 | 420 | | return AdvanceSimplification(ref nodeRemaining); |
| | | 421 | | |
| | 2468 | 422 | | if (_stage == Stage.CopyRaw) |
| | | 423 | | { |
| | 203 | 424 | | if (_rawCopyOrdinal <= _rawCopyEndOrdinal) |
| | | 425 | | { |
| | 142 | 426 | | if (nodeRemaining == 0) |
| | 1 | 427 | | return Status; |
| | 141 | 428 | | nodeRemaining--; |
| | 141 | 429 | | _workspace.GuidePoints[_simplificationWriteOrdinal++] = |
| | 141 | 430 | | _workspace.GuidePoints[_rawCopyOrdinal++]; |
| | 141 | 431 | | continue; |
| | | 432 | | } |
| | 61 | 433 | | if (_rawCopyEndOrdinal == _workspace.GuidePointCount - 1) |
| | | 434 | | { |
| | 59 | 435 | | PrepareDependencyFinalization(); |
| | 59 | 436 | | continue; |
| | | 437 | | } |
| | 2 | 438 | | _simplificationSourcePathOrdinal++; |
| | 2 | 439 | | if (_simplificationSourcePathOrdinal >= _nextTransitionPathOrdinal) |
| | | 440 | | { |
| | 1 | 441 | | _nextTransitionPathOrdinal = -1; |
| | 1 | 442 | | _transitionBarrierScanOrdinal = |
| | 1 | 443 | | _simplificationSourcePathOrdinal + 1; |
| | | 444 | | } |
| | 2 | 445 | | _simplificationCandidatePathOrdinal = _workspace.PathNodeCount - 1; |
| | 2 | 446 | | _stage = Stage.Simplify; |
| | 2 | 447 | | continue; |
| | | 448 | | } |
| | | 449 | | |
| | 2265 | 450 | | if (_stage == Stage.SortDependencies) |
| | | 451 | | { |
| | 225 | 452 | | int lookupBefore = _meter.LookupProbes; |
| | 225 | 453 | | bool complete = _dependencySort.Advance(_meter, lookupRemaining); |
| | 225 | 454 | | lookupRemaining -= _meter.LookupProbes - lookupBefore; |
| | 225 | 455 | | if (!complete) |
| | | 456 | | { |
| | 11 | 457 | | return ApplyTerminalStatus( |
| | 11 | 458 | | NavigationSearchFinalizationRules.ResolveIncompleteLookupStatus( |
| | 11 | 459 | | _meter.RemainingLookupProbes)); |
| | | 460 | | } |
| | 214 | 461 | | _dependencySort = default; |
| | 214 | 462 | | _stage = Stage.CaptureDependencies; |
| | 214 | 463 | | continue; |
| | | 464 | | } |
| | | 465 | | |
| | 2040 | 466 | | if (_stage == Stage.CaptureDependencies) |
| | | 467 | | { |
| | 263 | 468 | | if (!AdvanceDependencyCapture(ref lookupRemaining)) |
| | 51 | 469 | | return Status; |
| | 212 | 470 | | long requiredPayloadBytes = NavigationAStarPayload.GetRetainedBytes( |
| | 212 | 471 | | _workspace.GuidePointCount, |
| | 212 | 472 | | _payloadTransitionInstructions?.Length ?? 0, |
| | 212 | 473 | | _dependencyStamp!.Result); |
| | 212 | 474 | | if (requiredPayloadBytes > _maximumPayloadBytes) |
| | 1 | 475 | | return Finish(NavigationSurfaceAStarStatus.CapacityExceeded); |
| | 211 | 476 | | _payloadGuidePoints = _workspace.GuidePointCount == 0 |
| | 211 | 477 | | ? Array.Empty<NavigationAStarGuidePoint>() |
| | 211 | 478 | | : new NavigationAStarGuidePoint[_workspace.GuidePointCount]; |
| | 211 | 479 | | _payloadTransitionInstructions ??= |
| | 211 | 480 | | Array.Empty<NavigationTransitionInstruction>(); |
| | 211 | 481 | | _stage = Stage.BuildPayload; |
| | 211 | 482 | | continue; |
| | | 483 | | } |
| | | 484 | | |
| | 1777 | 485 | | if (_payloadWrite < _workspace.GuidePointCount) |
| | | 486 | | { |
| | 1566 | 487 | | if (nodeRemaining == 0) |
| | 168 | 488 | | return Status; |
| | 1398 | 489 | | nodeRemaining--; |
| | 1398 | 490 | | _payloadGuidePoints![_payloadWrite] = |
| | 1398 | 491 | | _workspace.GuidePoints[_payloadWrite]; |
| | 1398 | 492 | | _payloadWrite++; |
| | 1398 | 493 | | continue; |
| | | 494 | | } |
| | 211 | 495 | | CompletePayloadBuild(IsWorldCurrent()); |
| | 211 | 496 | | break; |
| | | 497 | | } |
| | 211 | 498 | | return Status; |
| | | 499 | | } |
| | | 500 | | |
| | | 501 | | public void Dispose() |
| | | 502 | | { |
| | 250 | 503 | | NavigationResolvedPathQuery? query = _query; |
| | 250 | 504 | | _query = null; |
| | 250 | 505 | | query?.Dispose(); |
| | 250 | 506 | | ReleaseRuntimeState(); |
| | 250 | 507 | | } |
| | | 508 | | |
| | | 509 | | private void BeginSimplification() |
| | | 510 | | { |
| | 200 | 511 | | _simplificationSourcePathOrdinal = 0; |
| | 200 | 512 | | _simplificationCandidatePathOrdinal = _workspace.PathNodeCount - 1; |
| | 200 | 513 | | _simplificationWriteOrdinal = 1; |
| | 200 | 514 | | _transitionBarrierScanOrdinal = 1; |
| | 200 | 515 | | _nextTransitionPathOrdinal = -1; |
| | 200 | 516 | | if (!NavigationSearchFinalizationRules.TryAdmitSimplification( |
| | 200 | 517 | | _workspace.PathNodeCount, |
| | 200 | 518 | | _meter.RemainingSimplificationRays, |
| | 200 | 519 | | _workspace.EndpointComponentCount, |
| | 200 | 520 | | _workspace.EndpointPageCount, |
| | 200 | 521 | | _meter, |
| | 200 | 522 | | out _finalizationLookupReservation)) |
| | | 523 | | { |
| | 122 | 524 | | FinalizeWithoutSimplification(); |
| | | 525 | | } |
| | | 526 | | else |
| | | 527 | | { |
| | 78 | 528 | | _stage = Stage.Simplify; |
| | | 529 | | } |
| | 78 | 530 | | } |
| | | 531 | | |
| | | 532 | | private void FinalizeWithoutSimplification() |
| | | 533 | | { |
| | 122 | 534 | | _simplificationWriteOrdinal = _workspace.GuidePointCount; |
| | 122 | 535 | | PrepareDependencyFinalization(); |
| | 122 | 536 | | } |
| | | 537 | | |
| | | 538 | | private NavigationSurfaceAStarStatus AdvanceSimplification( |
| | | 539 | | ref int nodeRemaining) |
| | | 540 | | { |
| | 93 | 541 | | NavigationSurfaceAStarStatus result = |
| | 93 | 542 | | NavigationSearchFinalizationRules.ResolveAStarEpochStatus( |
| | 93 | 543 | | NavigationSurfaceAStarStatus.Pending, |
| | 93 | 544 | | IsWorldCurrent()); |
| | 93 | 545 | | return AdvanceSimplification(result, ref nodeRemaining); |
| | | 546 | | } |
| | | 547 | | |
| | | 548 | | internal NavigationSurfaceAStarStatus AdvanceSimplification( |
| | | 549 | | NavigationSurfaceAStarStatus result, |
| | | 550 | | ref int nodeRemaining) |
| | | 551 | | { |
| | 94 | 552 | | if (result == NavigationSurfaceAStarStatus.Pending) |
| | 93 | 553 | | result = AdvanceCurrentSimplification(ref nodeRemaining); |
| | 94 | 554 | | if (Status == NavigationSurfaceAStarStatus.Pending) |
| | 92 | 555 | | ApplyTerminalStatus(result); |
| | 94 | 556 | | return Status; |
| | | 557 | | } |
| | | 558 | | |
| | | 559 | | private NavigationSurfaceAStarStatus AdvanceCurrentSimplification( |
| | | 560 | | ref int nodeRemaining) |
| | | 561 | | { |
| | 157 | 562 | | while (_nextTransitionPathOrdinal < 0 |
| | 157 | 563 | | && _transitionBarrierScanOrdinal < _workspace.PathNodeCount) |
| | | 564 | | { |
| | 114 | 565 | | if (nodeRemaining == 0) |
| | 4 | 566 | | return Status; |
| | 110 | 567 | | nodeRemaining--; |
| | 110 | 568 | | NavigationMediumStateRef scanned = |
| | 110 | 569 | | _workspace.PathNodes[_transitionBarrierScanOrdinal]; |
| | 110 | 570 | | _workspace.NodeTable.TryGetSlot(scanned, out int scannedSlot); |
| | 110 | 571 | | if (_workspace.NodeTable.GetRecord(scannedSlot).ParentEdgeKind |
| | 110 | 572 | | == NavigationTraversalEdgeKind.Transition) |
| | | 573 | | { |
| | 46 | 574 | | _nextTransitionPathOrdinal = _transitionBarrierScanOrdinal; |
| | 46 | 575 | | break; |
| | | 576 | | } |
| | 64 | 577 | | _transitionBarrierScanOrdinal++; |
| | | 578 | | } |
| | 89 | 579 | | if (_nextTransitionPathOrdinal < 0) |
| | 33 | 580 | | _nextTransitionPathOrdinal = int.MaxValue; |
| | 89 | 581 | | if (_simplificationCandidatePathOrdinal >= _nextTransitionPathOrdinal) |
| | | 582 | | { |
| | 46 | 583 | | _simplificationCandidatePathOrdinal = |
| | 46 | 584 | | _nextTransitionPathOrdinal - 1; |
| | | 585 | | } |
| | 89 | 586 | | if (_meter.RemainingSimplificationRays == 0) |
| | | 587 | | { |
| | 4 | 588 | | BeginRawCopy(copySuffix: true); |
| | 4 | 589 | | return Status; |
| | | 590 | | } |
| | 85 | 591 | | if (_simplificationCandidatePathOrdinal <= _simplificationSourcePathOrdinal) |
| | | 592 | | { |
| | 46 | 593 | | BeginRawCopy(copySuffix: false); |
| | 46 | 594 | | return Status; |
| | | 595 | | } |
| | 39 | 596 | | if (_simplificationCandidatePathOrdinal == _simplificationSourcePathOrdinal + 1 |
| | 39 | 597 | | && _workspace.PathNodeGuidePointOrdinals[_simplificationCandidatePathOrdinal] |
| | 39 | 598 | | == _workspace.PathNodeGuidePointOrdinals[_simplificationSourcePathOrdinal] + 1) |
| | | 599 | | { |
| | 6 | 600 | | BeginRawCopy(copySuffix: false); |
| | 6 | 601 | | return Status; |
| | | 602 | | } |
| | 33 | 603 | | _meter.TryConsumeSimplificationRays(1); |
| | | 604 | | |
| | 33 | 605 | | int sourcePathOrdinal = _simplificationSourcePathOrdinal; |
| | 33 | 606 | | int candidatePathOrdinal = _simplificationCandidatePathOrdinal; |
| | 33 | 607 | | NavigationAStarGuidePoint source = _workspace.GuidePoints[ |
| | 33 | 608 | | _workspace.PathNodeGuidePointOrdinals[sourcePathOrdinal]]; |
| | 33 | 609 | | NavigationAStarGuidePoint candidate = _workspace.GuidePoints[ |
| | 33 | 610 | | _workspace.PathNodeGuidePointOrdinals[candidatePathOrdinal]]; |
| | 33 | 611 | | _rayWork.Begin(new NavigationRayRequest( |
| | 33 | 612 | | _world, |
| | 33 | 613 | | _store, |
| | 33 | 614 | | _graph!, |
| | 33 | 615 | | _query!.Query.Agent, |
| | 33 | 616 | | _query.AreaPolicy, |
| | 33 | 617 | | _workspace.PathNodes[sourcePathOrdinal].Medium, |
| | 33 | 618 | | source.Position, |
| | 33 | 619 | | candidate.Position, |
| | 33 | 620 | | NavigationRayEndpointAllowance.None, |
| | 33 | 621 | | NavigationRayChainConstraint.SeedAt(source.Address))); |
| | 33 | 622 | | NavigationRayStatus rayStatus = _rayWork.Advance(_meter); |
| | 33 | 623 | | NavigationSurfaceAStarStatus simplificationStatus = |
| | 33 | 624 | | rayStatus == NavigationRayStatus.Stale |
| | 33 | 625 | | ? NavigationSurfaceAStarStatus.Stale |
| | 33 | 626 | | : NavigationSurfaceAStarStatus.Pending; |
| | 33 | 627 | | if (simplificationStatus == NavigationSurfaceAStarStatus.Pending |
| | 33 | 628 | | && rayStatus is not NavigationRayStatus.Success |
| | 33 | 629 | | and not NavigationRayStatus.Blocked) |
| | | 630 | | { |
| | 4 | 631 | | BeginRawCopy(copySuffix: true); |
| | 4 | 632 | | return Status; |
| | | 633 | | } |
| | | 634 | | |
| | 29 | 635 | | bool accepted = false; |
| | 29 | 636 | | if (simplificationStatus == NavigationSurfaceAStarStatus.Pending |
| | 29 | 637 | | && rayStatus == NavigationRayStatus.Success) |
| | | 638 | | { |
| | 22 | 639 | | NavigationRayResult ray = _rayWork.Result; |
| | 22 | 640 | | NavigationMediumStateRef sourceNode = |
| | 22 | 641 | | _workspace.PathNodes[sourcePathOrdinal]; |
| | 22 | 642 | | NavigationMediumStateRef candidateNode = |
| | 22 | 643 | | _workspace.PathNodes[candidatePathOrdinal]; |
| | 22 | 644 | | _workspace.NodeTable.TryGetSlot(sourceNode, out int sourceSlot); |
| | 22 | 645 | | _workspace.NodeTable.TryGetSlot(candidateNode, out int candidateSlot); |
| | 22 | 646 | | Fixed64.TrySubtract( |
| | 22 | 647 | | _workspace.NodeTable.GetRecord(candidateSlot).Cost, |
| | 22 | 648 | | _workspace.NodeTable.GetRecord(sourceSlot).Cost, |
| | 22 | 649 | | out Fixed64 rawCost); |
| | 22 | 650 | | accepted = NavigationSearchFinalizationRules.ShouldAcceptSimplificationRay( |
| | 22 | 651 | | ray.EndAddress, |
| | 22 | 652 | | candidate.Address, |
| | 22 | 653 | | ray.TraversalCost, |
| | 22 | 654 | | rawCost); |
| | | 655 | | } |
| | | 656 | | |
| | 29 | 657 | | if (simplificationStatus == NavigationSurfaceAStarStatus.Pending) |
| | | 658 | | { |
| | 28 | 659 | | simplificationStatus = NavigationSearchFinalizationRules |
| | 28 | 660 | | .ResolveAStarEpochStatus( |
| | 28 | 661 | | NavigationSurfaceAStarStatus.Pending, |
| | 28 | 662 | | IsSimplificationEpochCurrent()); |
| | | 663 | | } |
| | 29 | 664 | | bool dependenciesMerged = simplificationStatus |
| | 29 | 665 | | == NavigationSurfaceAStarStatus.Pending |
| | 29 | 666 | | && TryMergeRayDependencies(); |
| | 29 | 667 | | if (simplificationStatus == NavigationSurfaceAStarStatus.Pending |
| | 29 | 668 | | && !dependenciesMerged) |
| | | 669 | | { |
| | 1 | 670 | | simplificationStatus = NavigationSearchFinalizationRules |
| | 1 | 671 | | .ResolveAStarEpochStatus( |
| | 1 | 672 | | NavigationSurfaceAStarStatus.Pending, |
| | 1 | 673 | | IsSimplificationEpochCurrent()); |
| | 1 | 674 | | if (simplificationStatus == NavigationSurfaceAStarStatus.Pending) |
| | | 675 | | { |
| | 1 | 676 | | BeginRawCopy(copySuffix: true); |
| | 1 | 677 | | return Status; |
| | | 678 | | } |
| | | 679 | | } |
| | 28 | 680 | | if (simplificationStatus == NavigationSurfaceAStarStatus.Pending) |
| | | 681 | | { |
| | 26 | 682 | | _hasCompletedSimplificationProof = true; |
| | 26 | 683 | | simplificationStatus = NavigationSearchFinalizationRules |
| | 26 | 684 | | .ResolveAStarEpochStatus( |
| | 26 | 685 | | NavigationSurfaceAStarStatus.Pending, |
| | 26 | 686 | | IsWorldCurrent()); |
| | | 687 | | } |
| | 28 | 688 | | if (simplificationStatus != NavigationSurfaceAStarStatus.Pending) |
| | 2 | 689 | | return Finish(simplificationStatus); |
| | | 690 | | |
| | 26 | 691 | | if (!accepted) |
| | | 692 | | { |
| | 7 | 693 | | _simplificationCandidatePathOrdinal--; |
| | 7 | 694 | | return Status; |
| | | 695 | | } |
| | 19 | 696 | | _workspace.GuidePoints[_simplificationWriteOrdinal++] = candidate; |
| | 19 | 697 | | _simplificationSourcePathOrdinal = candidatePathOrdinal; |
| | 19 | 698 | | _simplificationCandidatePathOrdinal = _workspace.PathNodeCount - 1; |
| | 19 | 699 | | if (_simplificationSourcePathOrdinal + 1 >= _workspace.PathNodeCount) |
| | 17 | 700 | | PrepareDependencyFinalization(); |
| | 19 | 701 | | return Status; |
| | | 702 | | } |
| | | 703 | | |
| | | 704 | | private bool TryMergeRayDependencies() |
| | | 705 | | { |
| | 27 | 706 | | NavigationDependencyWorkspace target = _workspace.EndpointWorkspace.Dependencies; |
| | 27 | 707 | | NavigationDependencyWorkspace source = _workspace.RayWorkspace.Dependencies; |
| | 27 | 708 | | int priorReservation = _finalizationLookupReservation; |
| | | 709 | | // A terminal ray and both dependency passes are one bounded atomic unit: |
| | | 710 | | // prove and debit the complete append pass before mutating the target. |
| | 27 | 711 | | if (!NavigationSearchFinalizationRules.TryPrepareDependencyMerge( |
| | 27 | 712 | | IsSimplificationEpochCurrent(), |
| | 27 | 713 | | target, |
| | 27 | 714 | | source, |
| | 27 | 715 | | _meter, |
| | 27 | 716 | | priorReservation, |
| | 27 | 717 | | out int enlargedReservation)) |
| | | 718 | | { |
| | 1 | 719 | | return false; |
| | | 720 | | } |
| | 26 | 721 | | target.CommitMerge(source); |
| | 26 | 722 | | _meter.RecordSuccessfulDependencyMerge(); |
| | 26 | 723 | | _finalizationLookupReservation = enlargedReservation; |
| | 26 | 724 | | return IsSimplificationEpochCurrent(); |
| | | 725 | | } |
| | | 726 | | |
| | | 727 | | private void BeginRawCopy(bool copySuffix) |
| | | 728 | | { |
| | 61 | 729 | | _rawCopyOrdinal = _workspace.PathNodeGuidePointOrdinals[ |
| | 61 | 730 | | _simplificationSourcePathOrdinal] + 1; |
| | 61 | 731 | | _rawCopyEndOrdinal = copySuffix |
| | 61 | 732 | | ? _workspace.GuidePointCount - 1 |
| | 61 | 733 | | : _workspace.PathNodeGuidePointOrdinals[_simplificationSourcePathOrdinal + 1]; |
| | 61 | 734 | | _stage = Stage.CopyRaw; |
| | 61 | 735 | | } |
| | | 736 | | |
| | | 737 | | private void PrepareDependencyFinalization() |
| | | 738 | | { |
| | 198 | 739 | | NavigationSurfaceAStarStatus finalizationStatus = |
| | 198 | 740 | | NavigationSearchFinalizationRules.ResolveAStarEpochStatus( |
| | 198 | 741 | | NavigationSurfaceAStarStatus.Pending, |
| | 198 | 742 | | IsWorldCurrent()); |
| | 198 | 743 | | PrepareDependencyFinalization(finalizationStatus); |
| | 198 | 744 | | } |
| | | 745 | | |
| | | 746 | | internal void PrepareDependencyFinalization( |
| | | 747 | | NavigationSurfaceAStarStatus finalizationStatus) |
| | | 748 | | { |
| | 199 | 749 | | if (finalizationStatus == NavigationSurfaceAStarStatus.Pending) |
| | | 750 | | { |
| | 198 | 751 | | _workspace.GuidePointCount = _simplificationWriteOrdinal; |
| | 198 | 752 | | _meter.ReleaseLookupReservationFloor(); |
| | 198 | 753 | | _finalizationLookupReservation = 0; |
| | 198 | 754 | | _dependencySort = new NavigationDependencySortWork(_workspace); |
| | 198 | 755 | | _stage = Stage.SortDependencies; |
| | | 756 | | } |
| | 199 | 757 | | ApplyTerminalStatus(finalizationStatus); |
| | 199 | 758 | | } |
| | | 759 | | |
| | | 760 | | private bool AdvanceDependencyCapture(ref int lookupRemaining) => |
| | 263 | 761 | | AdvanceDependencyCapture( |
| | 263 | 762 | | NavigationSearchFinalizationRules.ResolveAStarEpochStatus( |
| | 263 | 763 | | NavigationSurfaceAStarStatus.Pending, |
| | 263 | 764 | | IsWorldCurrent()), |
| | 263 | 765 | | ref lookupRemaining); |
| | | 766 | | |
| | | 767 | | internal bool AdvanceDependencyCapture( |
| | | 768 | | NavigationSurfaceAStarStatus captureStatus, |
| | | 769 | | ref int lookupRemaining) |
| | | 770 | | { |
| | 264 | 771 | | bool complete = false; |
| | 264 | 772 | | if (captureStatus == NavigationSurfaceAStarStatus.Pending) |
| | | 773 | | { |
| | 263 | 774 | | _dependencyStamp ??= new NavigationDependencyStampWork( |
| | 263 | 775 | | _graph!, |
| | 263 | 776 | | _query!.AreaPolicy, |
| | 263 | 777 | | _workspace.EndpointComponents, |
| | 263 | 778 | | _workspace.EndpointComponentCount, |
| | 263 | 779 | | _workspace.EndpointPages, |
| | 263 | 780 | | _workspace.EndpointPageCount, |
| | 263 | 781 | | _workspace.EndpointWorkspace.Dependencies.HasTransitionDependency); |
| | 263 | 782 | | int lookupBefore = _meter.LookupProbes; |
| | 263 | 783 | | complete = _dependencyStamp.Advance(_meter, lookupRemaining); |
| | 263 | 784 | | lookupRemaining -= _meter.LookupProbes - lookupBefore; |
| | 263 | 785 | | captureStatus = complete |
| | 263 | 786 | | ? NavigationSearchFinalizationRules.ResolveAStarEpochStatus( |
| | 263 | 787 | | NavigationSurfaceAStarStatus.Pending, |
| | 263 | 788 | | IsWorldCurrent()) |
| | 263 | 789 | | : _meter.RemainingLookupProbes == 0 |
| | 263 | 790 | | ? NavigationSurfaceAStarStatus.BudgetExceeded |
| | 263 | 791 | | : NavigationSurfaceAStarStatus.Pending; |
| | | 792 | | } |
| | 264 | 793 | | if (captureStatus != NavigationSurfaceAStarStatus.Pending) |
| | | 794 | | { |
| | 2 | 795 | | Finish(captureStatus); |
| | 2 | 796 | | return false; |
| | | 797 | | } |
| | 262 | 798 | | return complete; |
| | | 799 | | } |
| | | 800 | | |
| | | 801 | | internal void CompletePayloadBuild(bool buildEpochCurrent) |
| | | 802 | | { |
| | 212 | 803 | | NavigationSurfaceAStarStatus finalStatus = |
| | 212 | 804 | | NavigationSearchFinalizationRules.ResolveAStarEpochStatus( |
| | 212 | 805 | | _resultStatus, |
| | 212 | 806 | | buildEpochCurrent); |
| | 212 | 807 | | if (buildEpochCurrent) |
| | | 808 | | { |
| | 211 | 809 | | NavigationResolvedPathQuery resolved = _query!; |
| | 211 | 810 | | Fixed64 resultCost = Fixed64.Zero; |
| | 211 | 811 | | if (_resultStatus == NavigationSurfaceAStarStatus.Success) |
| | | 812 | | { |
| | 194 | 813 | | _workspace.NodeTable.TryGetSlot(_goal, out int endSlot); |
| | 194 | 814 | | resultCost = _workspace.NodeTable.GetRecord(endSlot).Cost; |
| | | 815 | | } |
| | 211 | 816 | | Result = new NavigationAStarPayload( |
| | 211 | 817 | | new NavigationAStarPayloadKey( |
| | 211 | 818 | | resolved.Query, |
| | 211 | 819 | | resolved.Start.Address, |
| | 211 | 820 | | resolved.End.Address, |
| | 211 | 821 | | resolved.StartMedium, |
| | 211 | 822 | | resolved.TargetMedia), |
| | 211 | 823 | | _payloadGuidePoints!, |
| | 211 | 824 | | _payloadTransitionInstructions!, |
| | 211 | 825 | | resultCost, |
| | 211 | 826 | | _dependencyStamp!.Result, |
| | 211 | 827 | | _requiresWorldStamp || _hasCompletedSimplificationProof |
| | 211 | 828 | | ? _simplificationWorldChangeSequence |
| | 211 | 829 | | : null, |
| | 211 | 830 | | _resultStatus); |
| | 211 | 831 | | finalStatus = NavigationSearchFinalizationRules.ResolveAStarEpochStatus( |
| | 211 | 832 | | _resultStatus, |
| | 211 | 833 | | IsWorldCurrent()); |
| | | 834 | | } |
| | 212 | 835 | | ApplyTerminalStatus(finalStatus); |
| | 212 | 836 | | } |
| | | 837 | | |
| | 21315 | 838 | | private bool IsWorldCurrent() => NavigationSearchFinalizationRules.IsEpochCurrent( |
| | 21315 | 839 | | _requiresWorldStamp || _hasCompletedSimplificationProof, |
| | 21315 | 840 | | _simplificationWorldChangeSequence, |
| | 21315 | 841 | | _world.ChangeSequence); |
| | | 842 | | |
| | | 843 | | private bool IsSimplificationEpochCurrent() => |
| | 82 | 844 | | NavigationSearchFinalizationRules.IsEpochCurrent( |
| | 82 | 845 | | epochRequired: true, |
| | 82 | 846 | | expectedEpoch: _simplificationWorldChangeSequence, |
| | 82 | 847 | | currentEpoch: _world.ChangeSequence); |
| | | 848 | | |
| | | 849 | | private void CaptureWorldDependency( |
| | | 850 | | in NavigationTraversalEdgeEnumerator edges) |
| | | 851 | | { |
| | 18868 | 852 | | if (edges.RequiresWorldStamp) |
| | 460 | 853 | | _requiresWorldStamp = true; |
| | 18868 | 854 | | } |
| | | 855 | | |
| | | 856 | | private void ReleaseRuntimeState() |
| | | 857 | | { |
| | 495 | 858 | | _graph = null; |
| | 495 | 859 | | _edges = default; |
| | 495 | 860 | | _meter.ReleaseLookupReservationFloor(); |
| | 495 | 861 | | _finalizationLookupReservation = 0; |
| | 495 | 862 | | _rayWork.Reset(); |
| | 495 | 863 | | _dependencySort = default; |
| | 495 | 864 | | } |
| | | 865 | | |
| | | 866 | | private NavigationTraversalEdgeEnumerator EnumerateEdges( |
| | | 867 | | NavigationMediumStateRef source, |
| | 3349 | 868 | | int emittedSurfaceOrdinal) => new( |
| | 3349 | 869 | | _world, |
| | 3349 | 870 | | _graph!, |
| | 3349 | 871 | | source, |
| | 3349 | 872 | | _query!.Query.Agent, |
| | 3349 | 873 | | _query.AreaPolicy, |
| | 3349 | 874 | | _workspace.RayWorkspace, |
| | 3349 | 875 | | _query.Query.AllowTransitions, |
| | 3349 | 876 | | emittedSurfaceOrdinal); |
| | | 877 | | |
| | | 878 | | private void BeginSelectedEdgeReplay(int sourcePathOrdinal) |
| | | 879 | | { |
| | 813 | 880 | | _edges = default; |
| | 813 | 881 | | int targetPathOrdinal = sourcePathOrdinal + 1; |
| | 813 | 882 | | if (targetPathOrdinal >= _workspace.PathNodeCount) |
| | 200 | 883 | | return; |
| | 613 | 884 | | NavigationMediumStateRef target = _workspace.PathNodes[targetPathOrdinal]; |
| | 613 | 885 | | _workspace.NodeTable.TryGetSlot(target, out int targetSlot); |
| | 613 | 886 | | _edges = EnumerateEdges( |
| | 613 | 887 | | _workspace.PathNodes[sourcePathOrdinal], |
| | 613 | 888 | | _workspace.NodeTable.GetRecord(targetSlot).ParentEdgeOrdinal); |
| | 613 | 889 | | } |
| | | 890 | | |
| | | 891 | | private bool IsTarget(NavigationMediumStateRef state) => |
| | 2944 | 892 | | state.Node.Equals(_query!.End.Node) |
| | 2944 | 893 | | && (_query.TargetMedia & NavigationCell.ToMedia(state.Medium)) != 0; |
| | | 894 | | |
| | | 895 | | private Vector3d GetGuideAnchor( |
| | | 896 | | NavigationNodeState state, |
| | | 897 | | TraversalMedium medium) |
| | | 898 | | { |
| | 274 | 899 | | if (medium == TraversalMedium.Solid) |
| | 190 | 900 | | return state.FootAnchor; |
| | 84 | 901 | | state.TryGetCenteredVolumeFootAnchor( |
| | 84 | 902 | | _query!.Query.Agent.Shape.Height, |
| | 84 | 903 | | out Vector3d anchor); |
| | 84 | 904 | | return anchor; |
| | | 905 | | } |
| | | 906 | | |
| | | 907 | | private NavigationSurfaceAStarStatus Finish(NavigationSurfaceAStarStatus status) |
| | | 908 | | { |
| | 245 | 909 | | Status = status; |
| | | 910 | | System.Diagnostics.Debug.Assert(_query != null); |
| | 245 | 911 | | _query!.ReleaseLease(); |
| | 245 | 912 | | ReleaseRuntimeState(); |
| | 245 | 913 | | return Status; |
| | | 914 | | } |
| | | 915 | | |
| | | 916 | | private NavigationSurfaceAStarStatus ApplyTerminalStatus( |
| | | 917 | | NavigationSurfaceAStarStatus status) => |
| | 676 | 918 | | status == NavigationSurfaceAStarStatus.Pending |
| | 676 | 919 | | ? Status |
| | 676 | 920 | | : Finish(status); |
| | | 921 | | |
| | | 922 | | private NavigationSurfaceAStarStatus ApplyRoute( |
| | | 923 | | NavigationMediumStateRef targetState, |
| | | 924 | | Fixed64 edgeCost, |
| | | 925 | | int edgeOrdinal, |
| | | 926 | | NavigationTraversalEdgeKind edgeKind) |
| | | 927 | | { |
| | 4801 | 928 | | if (!_workspace.NodeTable.TryGetOrAdd( |
| | 4801 | 929 | | targetState, |
| | 4801 | 930 | | out int targetSlot, |
| | 4801 | 931 | | out bool added)) |
| | | 932 | | { |
| | 1 | 933 | | return Finish(NavigationSurfaceAStarStatus.CapacityExceeded); |
| | | 934 | | } |
| | 4800 | 935 | | ref NavigationAStarNodeRecord target = |
| | 4800 | 936 | | ref _workspace.NodeTable.GetRecord(targetSlot); |
| | 4800 | 937 | | _workspace.NodeTable.TryGetSlot(_current, out int sourceSlot); |
| | 4800 | 938 | | Fixed64 sourceCost = _workspace.NodeTable.GetRecord(sourceSlot).Cost; |
| | 4800 | 939 | | if (!Fixed64.TryAdd(sourceCost, edgeCost, out Fixed64 nextCost)) |
| | 1 | 940 | | return Finish(NavigationSurfaceAStarStatus.CostOverflow); |
| | 4799 | 941 | | if (!added && nextCost >= target.Cost) |
| | 1965 | 942 | | return Status; |
| | 2834 | 943 | | target.Cost = nextCost; |
| | 2834 | 944 | | target.Heuristic = GetHeuristic(targetState); |
| | 2834 | 945 | | if (!Fixed64.TryAdd( |
| | 2834 | 946 | | target.Cost, |
| | 2834 | 947 | | target.Heuristic, |
| | 2834 | 948 | | out target.EstimatedTotalCost)) |
| | | 949 | | { |
| | 1 | 950 | | return Finish(NavigationSurfaceAStarStatus.CostOverflow); |
| | | 951 | | } |
| | 2833 | 952 | | target.Parent = _current; |
| | 2833 | 953 | | target.ParentEdgeOrdinal = edgeOrdinal; |
| | 2833 | 954 | | target.ParentEdgeKind = edgeKind; |
| | 2833 | 955 | | target.HasParent = true; |
| | 2833 | 956 | | if (added) |
| | 2822 | 957 | | Push(targetState, targetSlot); |
| | | 958 | | else |
| | 11 | 959 | | SortUp(target.HeapIndex); |
| | 2833 | 960 | | return Status; |
| | | 961 | | } |
| | | 962 | | |
| | | 963 | | private bool AppendTransitionGuidePoints( |
| | | 964 | | NavigationMediumStateRef source, |
| | | 965 | | NavigationMediumStateRef target) |
| | | 966 | | { |
| | 48 | 967 | | int transitionOrdinal = _transitionPayloadWrite; |
| | 48 | 968 | | _graph!.TryGetNodeAddress(source.Node, out NavigationCellAddress sourceAddress); |
| | 48 | 969 | | _graph.TryGetNodeAddress(target.Node, out NavigationCellAddress targetAddress); |
| | | 970 | | |
| | 48 | 971 | | int guideRollback = _workspace.GuidePointCount; |
| | 48 | 972 | | _payloadTransitionInstructions![transitionOrdinal] = |
| | 48 | 973 | | new NavigationTransitionInstruction( |
| | 48 | 974 | | _edges.CurrentTransitionIdentityKind, |
| | 48 | 975 | | _edges.CurrentTransitionOwnerMapId, |
| | 48 | 976 | | _edges.CurrentTransitionId, |
| | 48 | 977 | | _edges.CurrentTransitionType, |
| | 48 | 978 | | sourceAddress, |
| | 48 | 979 | | targetAddress, |
| | 48 | 980 | | source.Medium, |
| | 48 | 981 | | target.Medium, |
| | 48 | 982 | | _edges.CurrentTransitionSourceAction, |
| | 48 | 983 | | _edges.CurrentTransitionDestinationAction, |
| | 48 | 984 | | _edges.CurrentTransitionHints); |
| | 48 | 985 | | _transitionPayloadWrite++; |
| | 48 | 986 | | _graph.TryGetNodeState( |
| | 48 | 987 | | target.Node, |
| | 48 | 988 | | target.Medium, |
| | 48 | 989 | | out NavigationNodeState targetState); |
| | 48 | 990 | | if (!AppendGuidePoint( |
| | 48 | 991 | | new NavigationAStarGuidePoint( |
| | 48 | 992 | | sourceAddress, |
| | 48 | 993 | | _edges.CurrentTransitionSourceAction, |
| | 48 | 994 | | source.Medium, |
| | 48 | 995 | | transitionOrdinal), |
| | 48 | 996 | | pathNodeOrdinal: -1) |
| | 48 | 997 | | || !AppendGuidePoint( |
| | 48 | 998 | | new NavigationAStarGuidePoint( |
| | 48 | 999 | | targetAddress, |
| | 48 | 1000 | | _edges.CurrentTransitionDestinationAction, |
| | 48 | 1001 | | target.Medium), |
| | 48 | 1002 | | pathNodeOrdinal: -1) |
| | 48 | 1003 | | || !AppendGuidePoint( |
| | 48 | 1004 | | new NavigationAStarGuidePoint( |
| | 48 | 1005 | | targetAddress, |
| | 48 | 1006 | | GetGuideAnchor(targetState, target.Medium), |
| | 48 | 1007 | | target.Medium), |
| | 48 | 1008 | | _pathEdgeOrdinal + 1)) |
| | | 1009 | | { |
| | 2 | 1010 | | _workspace.GuidePointCount = guideRollback; |
| | 2 | 1011 | | _payloadTransitionInstructions[transitionOrdinal] = default; |
| | 2 | 1012 | | _transitionPayloadWrite--; |
| | 2 | 1013 | | return false; |
| | | 1014 | | } |
| | 46 | 1015 | | return true; |
| | | 1016 | | } |
| | | 1017 | | |
| | | 1018 | | private bool AppendGuidePoint( |
| | | 1019 | | NavigationAStarGuidePoint point, |
| | | 1020 | | int pathNodeOrdinal) |
| | | 1021 | | { |
| | 2184 | 1022 | | bool isNode = pathNodeOrdinal >= 0; |
| | 2184 | 1023 | | int count = _workspace.GuidePointCount; |
| | 2184 | 1024 | | if (count != 0 |
| | 2184 | 1025 | | && !point.HasTransition |
| | 2184 | 1026 | | && !_workspace.GuidePoints[count - 1].HasTransition |
| | 2184 | 1027 | | && _workspace.GuidePoints[count - 1].Medium == point.Medium |
| | 2184 | 1028 | | && _workspace.GuidePoints[count - 1].Position == point.Position) |
| | | 1029 | | { |
| | 705 | 1030 | | int updatedCount = count; |
| | 705 | 1031 | | bool updatedLastGuidePointIsNode = _lastGuidePointIsNode; |
| | 705 | 1032 | | bool applied = TryApplyCoincidentGuidePoint( |
| | 705 | 1033 | | point, |
| | 705 | 1034 | | pathNodeOrdinal, |
| | 705 | 1035 | | _workspace.GuidePoints, |
| | 705 | 1036 | | _workspace.PathNodeGuidePointOrdinals, |
| | 705 | 1037 | | ref updatedCount, |
| | 705 | 1038 | | ref updatedLastGuidePointIsNode); |
| | 705 | 1039 | | _workspace.GuidePointCount = updatedCount; |
| | 705 | 1040 | | _lastGuidePointIsNode = updatedLastGuidePointIsNode; |
| | 705 | 1041 | | return applied; |
| | | 1042 | | } |
| | 1479 | 1043 | | if (count >= _workspace.GuidePoints.Length) |
| | 6 | 1044 | | return false; |
| | 1473 | 1045 | | _workspace.GuidePoints[count] = point; |
| | 1473 | 1046 | | _workspace.GuidePointCount = count + 1; |
| | 1473 | 1047 | | _lastGuidePointIsNode = isNode; |
| | 1473 | 1048 | | if (isNode) |
| | 740 | 1049 | | _workspace.PathNodeGuidePointOrdinals[pathNodeOrdinal] = count; |
| | 1473 | 1050 | | return true; |
| | | 1051 | | } |
| | | 1052 | | |
| | | 1053 | | internal static bool TryApplyCoincidentGuidePoint( |
| | | 1054 | | NavigationAStarGuidePoint point, |
| | | 1055 | | int pathNodeOrdinal, |
| | | 1056 | | NavigationAStarGuidePoint[] guidePoints, |
| | | 1057 | | int[] pathNodeGuidePointOrdinals, |
| | | 1058 | | ref int guidePointCount, |
| | | 1059 | | ref bool lastGuidePointIsNode) |
| | | 1060 | | { |
| | 710 | 1061 | | bool isNode = pathNodeOrdinal >= 0; |
| | 710 | 1062 | | int previousOrdinal = guidePointCount - 1; |
| | 710 | 1063 | | NavigationAStarGuidePoint previous = guidePoints[previousOrdinal]; |
| | 710 | 1064 | | if (lastGuidePointIsNode && !isNode) |
| | 30 | 1065 | | return true; |
| | 680 | 1066 | | if (!lastGuidePointIsNode || previous.Address == point.Address) |
| | | 1067 | | { |
| | 678 | 1068 | | guidePoints[previousOrdinal] = point; |
| | 678 | 1069 | | lastGuidePointIsNode = isNode; |
| | 678 | 1070 | | if (isNode) |
| | 74 | 1071 | | pathNodeGuidePointOrdinals[pathNodeOrdinal] = previousOrdinal; |
| | 678 | 1072 | | return true; |
| | | 1073 | | } |
| | 2 | 1074 | | if (guidePointCount >= guidePoints.Length) |
| | 1 | 1075 | | return false; |
| | | 1076 | | System.Diagnostics.Debug.Assert( |
| | | 1077 | | isNode, |
| | | 1078 | | "only a distinct addressed node can append after coincident-point preservation and replacement are rejected" |
| | 1 | 1079 | | guidePoints[guidePointCount] = point; |
| | 1 | 1080 | | pathNodeGuidePointOrdinals[pathNodeOrdinal] = guidePointCount; |
| | 1 | 1081 | | guidePointCount++; |
| | 1 | 1082 | | lastGuidePointIsNode = isNode; |
| | 1 | 1083 | | return true; |
| | | 1084 | | } |
| | | 1085 | | |
| | | 1086 | | private void Push(NavigationMediumStateRef node, int slot) |
| | | 1087 | | { |
| | 3064 | 1088 | | int index = _workspace.HeapCount++; |
| | 3064 | 1089 | | _workspace.HeapNodes[index] = node; |
| | 3064 | 1090 | | _workspace.NodeTable.GetRecord(slot).HeapIndex = index; |
| | 3064 | 1091 | | SortUp(index); |
| | 3064 | 1092 | | } |
| | | 1093 | | |
| | | 1094 | | private NavigationMediumStateRef Pop() |
| | | 1095 | | { |
| | 2944 | 1096 | | NavigationMediumStateRef result = _workspace.HeapNodes[0]; |
| | 2944 | 1097 | | int last = --_workspace.HeapCount; |
| | 2944 | 1098 | | if (last > 0) |
| | | 1099 | | { |
| | 2173 | 1100 | | _workspace.HeapNodes[0] = _workspace.HeapNodes[last]; |
| | 2173 | 1101 | | _workspace.NodeTable.TryGetSlot(_workspace.HeapNodes[0], out int slot); |
| | 2173 | 1102 | | _workspace.NodeTable.GetRecord(slot).HeapIndex = 0; |
| | 2173 | 1103 | | SortDown(0); |
| | | 1104 | | } |
| | 2944 | 1105 | | return result; |
| | | 1106 | | } |
| | | 1107 | | |
| | | 1108 | | private void SortUp(int index) |
| | | 1109 | | { |
| | 3176 | 1110 | | while (index > 0) |
| | | 1111 | | { |
| | 2279 | 1112 | | int parent = (index - 1) / 2; |
| | 2279 | 1113 | | if (CompareHeap(index, parent) >= 0) |
| | | 1114 | | break; |
| | 101 | 1115 | | SwapHeap(index, parent); |
| | 101 | 1116 | | index = parent; |
| | | 1117 | | } |
| | 3075 | 1118 | | } |
| | | 1119 | | |
| | | 1120 | | private void SortDown(int index) |
| | | 1121 | | { |
| | 7024 | 1122 | | while (true) |
| | | 1123 | | { |
| | 9197 | 1124 | | int left = checked((index * 2) + 1); |
| | 9197 | 1125 | | if (left >= _workspace.HeapCount) |
| | 2146 | 1126 | | return; |
| | 7051 | 1127 | | int right = left + 1; |
| | 7051 | 1128 | | int best = right < _workspace.HeapCount && CompareHeap(right, left) < 0 |
| | 7051 | 1129 | | ? right |
| | 7051 | 1130 | | : left; |
| | 7051 | 1131 | | if (CompareHeap(best, index) >= 0) |
| | 27 | 1132 | | return; |
| | 7024 | 1133 | | SwapHeap(index, best); |
| | 7024 | 1134 | | index = best; |
| | | 1135 | | } |
| | | 1136 | | } |
| | | 1137 | | |
| | | 1138 | | private int CompareHeap(int leftIndex, int rightIndex) |
| | | 1139 | | { |
| | 16162 | 1140 | | NavigationMediumStateRef left = _workspace.HeapNodes[leftIndex]; |
| | 16162 | 1141 | | NavigationMediumStateRef right = _workspace.HeapNodes[rightIndex]; |
| | 16162 | 1142 | | _workspace.NodeTable.TryGetSlot(left, out int leftSlot); |
| | 16162 | 1143 | | _workspace.NodeTable.TryGetSlot(right, out int rightSlot); |
| | 16162 | 1144 | | ref NavigationAStarNodeRecord leftRecord = |
| | 16162 | 1145 | | ref _workspace.NodeTable.GetRecord(leftSlot); |
| | 16162 | 1146 | | ref NavigationAStarNodeRecord rightRecord = |
| | 16162 | 1147 | | ref _workspace.NodeTable.GetRecord(rightSlot); |
| | 16162 | 1148 | | int comparison = leftRecord.EstimatedTotalCost.CompareTo( |
| | 16162 | 1149 | | rightRecord.EstimatedTotalCost); |
| | 16162 | 1150 | | if (comparison != 0) |
| | 7315 | 1151 | | return comparison; |
| | 8847 | 1152 | | comparison = leftRecord.Heuristic.CompareTo(rightRecord.Heuristic); |
| | 8847 | 1153 | | if (comparison != 0) |
| | 57 | 1154 | | return comparison; |
| | 8790 | 1155 | | _graph!.TryGetNodeAddress(left.Node, out NavigationCellAddress leftAddress); |
| | 8790 | 1156 | | _graph.TryGetNodeAddress(right.Node, out NavigationCellAddress rightAddress); |
| | 8790 | 1157 | | comparison = leftAddress.CompareTo(rightAddress); |
| | 8790 | 1158 | | return comparison != 0 |
| | 8790 | 1159 | | ? comparison |
| | 8790 | 1160 | | : ((int)left.Medium).CompareTo((int)right.Medium); |
| | | 1161 | | } |
| | | 1162 | | |
| | | 1163 | | private void SwapHeap(int left, int right) |
| | | 1164 | | { |
| | 7125 | 1165 | | (_workspace.HeapNodes[left], _workspace.HeapNodes[right]) = |
| | 7125 | 1166 | | (_workspace.HeapNodes[right], _workspace.HeapNodes[left]); |
| | 7125 | 1167 | | _workspace.NodeTable.TryGetSlot(_workspace.HeapNodes[left], out int leftSlot); |
| | 7125 | 1168 | | _workspace.NodeTable.TryGetSlot(_workspace.HeapNodes[right], out int rightSlot); |
| | 7125 | 1169 | | _workspace.NodeTable.GetRecord(leftSlot).HeapIndex = left; |
| | 7125 | 1170 | | _workspace.NodeTable.GetRecord(rightSlot).HeapIndex = right; |
| | 7125 | 1171 | | } |
| | | 1172 | | |
| | | 1173 | | private Fixed64 GetHeuristic(NavigationMediumStateRef node) |
| | | 1174 | | { |
| | 3076 | 1175 | | Fixed64 heuristic = Fixed64.Zero; |
| | 3076 | 1176 | | if (_useEuclideanHeuristic) |
| | | 1177 | | { |
| | 870 | 1178 | | bool hasState = _graph!.TryGetNodeState( |
| | 870 | 1179 | | node.Node, |
| | 870 | 1180 | | node.Medium, |
| | 870 | 1181 | | out NavigationNodeState state); |
| | | 1182 | | System.Diagnostics.Debug.Assert(hasState); |
| | 870 | 1183 | | bool hasFootAnchor = TryGetHeuristicFootAnchor( |
| | 870 | 1184 | | state, |
| | 870 | 1185 | | node.Medium, |
| | 870 | 1186 | | out Vector3d footAnchor); |
| | 870 | 1187 | | NavigationSearchFinalizationRules.TryGetEuclideanHeuristic( |
| | 870 | 1188 | | hasFootAnchor, |
| | 870 | 1189 | | footAnchor, |
| | 870 | 1190 | | _targetFootAnchor, |
| | 870 | 1191 | | out heuristic); |
| | | 1192 | | } |
| | 3076 | 1193 | | return heuristic; |
| | | 1194 | | } |
| | | 1195 | | |
| | | 1196 | | private bool TryGetHeuristicFootAnchor( |
| | | 1197 | | NavigationNodeState state, |
| | | 1198 | | TraversalMedium medium, |
| | | 1199 | | out Vector3d footAnchor) |
| | | 1200 | | { |
| | 870 | 1201 | | if (medium == TraversalMedium.Solid) |
| | | 1202 | | { |
| | 784 | 1203 | | footAnchor = state.FootAnchor; |
| | 784 | 1204 | | return true; |
| | | 1205 | | } |
| | | 1206 | | |
| | 86 | 1207 | | return state.TryGetCenteredVolumeFootAnchor( |
| | 86 | 1208 | | _query!.Query.Agent.Shape.Height, |
| | 86 | 1209 | | out footAnchor); |
| | | 1210 | | } |
| | | 1211 | | } |