| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationRayWorkspace.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 | | using SwiftCollections; |
| | | 12 | | |
| | | 13 | | namespace Trailblazer.Pathing; |
| | | 14 | | |
| | | 15 | | /// <summary>Owns fixed caller-side storage for one exclusive navigation ray.</summary> |
| | | 16 | | internal sealed class NavigationRayWorkspace |
| | | 17 | | { |
| | 18037 | 18 | | internal NavigationRayWorkspace( |
| | 18037 | 19 | | int mapCapacity, |
| | 18037 | 20 | | int pageCapacity, |
| | 18037 | 21 | | int componentCapacity, |
| | 18037 | 22 | | int coveredAddressCapacity, |
| | 18037 | 23 | | int traceIntervalCapacity) |
| | | 24 | | { |
| | 18037 | 25 | | SwiftThrowHelper.ThrowIfNegative(mapCapacity, nameof(mapCapacity)); |
| | 18037 | 26 | | SwiftThrowHelper.ThrowIfNegative(pageCapacity, nameof(pageCapacity)); |
| | 18037 | 27 | | SwiftThrowHelper.ThrowIfNegative(componentCapacity, nameof(componentCapacity)); |
| | 18037 | 28 | | SwiftThrowHelper.ThrowIfNegative( |
| | 18037 | 29 | | coveredAddressCapacity, |
| | 18037 | 30 | | nameof(coveredAddressCapacity)); |
| | 18037 | 31 | | SwiftThrowHelper.ThrowIfNegative( |
| | 18037 | 32 | | traceIntervalCapacity, |
| | 18037 | 33 | | nameof(traceIntervalCapacity)); |
| | 18037 | 34 | | SwiftThrowHelper.ThrowIfArgument( |
| | 18037 | 35 | | traceIntervalCapacity > coveredAddressCapacity, |
| | 18037 | 36 | | nameof(traceIntervalCapacity), |
| | 18037 | 37 | | "Trace-interval capacity cannot exceed covered-address capacity."); |
| | | 38 | | |
| | 18037 | 39 | | MapCapacity = mapCapacity; |
| | 18037 | 40 | | CoveredAddressCapacity = coveredAddressCapacity; |
| | 18037 | 41 | | TraceIntervalCapacity = traceIntervalCapacity; |
| | 18037 | 42 | | TraceScratch = new GridTraceIntervalScratch(mapCapacity, coveredAddressCapacity); |
| | 18037 | 43 | | TraceIntervals = new SwiftList<GridTraceInterval>(traceIntervalCapacity); |
| | 18037 | 44 | | BodyTraceCells = new SwiftList<GridNavigationBodyTraceCell>(coveredAddressCapacity); |
| | 18037 | 45 | | BodyTraceScratch = new GridNavigationBodyTraceScratch( |
| | 18037 | 46 | | mapCapacity, |
| | 18037 | 47 | | coveredAddressCapacity); |
| | 18037 | 48 | | ChainRecords = traceIntervalCapacity == 0 |
| | 18037 | 49 | | ? Array.Empty<NavigationRayChainRecord>() |
| | 18037 | 50 | | : new NavigationRayChainRecord[traceIntervalCapacity]; |
| | 18037 | 51 | | Dependencies = new NavigationDependencyWorkspace(pageCapacity, componentCapacity); |
| | 18037 | 52 | | } |
| | | 53 | | |
| | | 54 | | internal int MapCapacity { get; } |
| | | 55 | | |
| | | 56 | | internal int CoveredAddressCapacity { get; } |
| | | 57 | | |
| | | 58 | | internal int TraceIntervalCapacity { get; } |
| | | 59 | | |
| | | 60 | | internal GridTraceIntervalScratch TraceScratch { get; } |
| | | 61 | | |
| | | 62 | | internal SwiftList<GridTraceInterval> TraceIntervals { get; } |
| | | 63 | | |
| | | 64 | | internal SwiftList<GridNavigationBodyTraceCell> BodyTraceCells { get; } |
| | | 65 | | |
| | | 66 | | internal GridNavigationBodyTraceScratch BodyTraceScratch { get; } |
| | | 67 | | |
| | | 68 | | internal NavigationRayChainRecord[] ChainRecords { get; } |
| | | 69 | | |
| | | 70 | | internal NavigationDependencyWorkspace Dependencies { get; } |
| | | 71 | | |
| | | 72 | | internal void Reset() |
| | | 73 | | { |
| | 7771 | 74 | | TraceScratch.Clear(); |
| | 7771 | 75 | | TraceIntervals.Clear(); |
| | 7771 | 76 | | BodyTraceCells.Clear(); |
| | 7771 | 77 | | BodyTraceScratch.Clear(); |
| | 7771 | 78 | | Dependencies.Reset(); |
| | 7771 | 79 | | } |
| | | 80 | | } |
| | | 81 | | |
| | | 82 | | internal enum NavigationRayChainRecordState : byte |
| | | 83 | | { |
| | | 84 | | Unavailable, |
| | | 85 | | Unreached, |
| | | 86 | | Ready, |
| | | 87 | | Expanded |
| | | 88 | | } |
| | | 89 | | |
| | | 90 | | internal struct NavigationRayChainRecord |
| | | 91 | | { |
| | | 92 | | internal NavigationNodeRef Node; |
| | | 93 | | internal int PredecessorOrdinal; |
| | | 94 | | internal int RootOrdinal; |
| | | 95 | | internal Fixed64 ArrivalParameter; |
| | | 96 | | internal Fixed64 TraversalCost; |
| | | 97 | | internal NavigationExplicitConnectionRecord IncomingExplicitConnection; |
| | | 98 | | internal NavigationRayChainRecordState State; |
| | | 99 | | internal bool IsSemanticCostNeutral; |
| | | 100 | | } |