| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationAStarWorkspace.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 | | |
| | | 10 | | namespace Trailblazer.Pathing; |
| | | 11 | | |
| | | 12 | | /// <summary>Owns the reusable bounded buffers for one exclusive graph A* query.</summary> |
| | | 13 | | internal sealed class NavigationAStarWorkspace |
| | | 14 | | { |
| | 8052 | 15 | | internal NavigationAStarWorkspace( |
| | 8052 | 16 | | int mapCapacity, |
| | 8052 | 17 | | int endpointPageCapacity, |
| | 8052 | 18 | | int componentCapacity, |
| | 8052 | 19 | | int nodeCapacity, |
| | 8052 | 20 | | int rayCoveredAddressCapacity, |
| | 8052 | 21 | | int rayTraceIntervalCapacity, |
| | 8052 | 22 | | int guidePointCapacity) |
| | | 23 | | { |
| | 8052 | 24 | | SwiftThrowHelper.ThrowIfNegative(mapCapacity, nameof(mapCapacity)); |
| | 8052 | 25 | | SwiftThrowHelper.ThrowIfNegative(endpointPageCapacity, nameof(endpointPageCapacity)); |
| | 8052 | 26 | | SwiftThrowHelper.ThrowIfNegative(nodeCapacity, nameof(nodeCapacity)); |
| | 8052 | 27 | | SwiftThrowHelper.ThrowIfNegative(componentCapacity, nameof(componentCapacity)); |
| | 8052 | 28 | | SwiftThrowHelper.ThrowIfNegative(guidePointCapacity, nameof(guidePointCapacity)); |
| | 8052 | 29 | | EndpointWorkspace = new NavigationEndpointWorkspace( |
| | 8052 | 30 | | mapCapacity, |
| | 8052 | 31 | | endpointPageCapacity, |
| | 8052 | 32 | | componentCapacity); |
| | 8052 | 33 | | NodeTable = new NavigationAStarNodeTable(nodeCapacity); |
| | 8052 | 34 | | HeapNodes = nodeCapacity == 0 |
| | 8052 | 35 | | ? Array.Empty<NavigationMediumStateRef>() |
| | 8052 | 36 | | : new NavigationMediumStateRef[nodeCapacity]; |
| | 8052 | 37 | | PathNodes = nodeCapacity == 0 |
| | 8052 | 38 | | ? Array.Empty<NavigationMediumStateRef>() |
| | 8052 | 39 | | : new NavigationMediumStateRef[nodeCapacity]; |
| | 8052 | 40 | | PathNodeGuidePointOrdinals = nodeCapacity == 0 |
| | 8052 | 41 | | ? Array.Empty<int>() |
| | 8052 | 42 | | : new int[nodeCapacity]; |
| | 8052 | 43 | | RayWorkspace = new NavigationRayWorkspace( |
| | 8052 | 44 | | mapCapacity, |
| | 8052 | 45 | | endpointPageCapacity, |
| | 8052 | 46 | | componentCapacity, |
| | 8052 | 47 | | rayCoveredAddressCapacity, |
| | 8052 | 48 | | rayTraceIntervalCapacity); |
| | 8052 | 49 | | GuidePoints = guidePointCapacity == 0 |
| | 8052 | 50 | | ? Array.Empty<NavigationAStarGuidePoint>() |
| | 8052 | 51 | | : new NavigationAStarGuidePoint[guidePointCapacity]; |
| | 8052 | 52 | | } |
| | | 53 | | |
| | | 54 | | internal NavigationEndpointWorkspace EndpointWorkspace { get; } |
| | | 55 | | |
| | 454 | 56 | | internal GraphPageDependencyAddress[] EndpointPages => EndpointWorkspace.Pages; |
| | | 57 | | |
| | | 58 | | internal NavigationSurfaceComponentKey[] EndpointComponents => |
| | 454 | 59 | | EndpointWorkspace.Components; |
| | | 60 | | |
| | 630 | 61 | | internal int EndpointPageCount => EndpointWorkspace.PageCount; |
| | | 62 | | |
| | 631 | 63 | | internal int EndpointComponentCount => EndpointWorkspace.ComponentCount; |
| | | 64 | | |
| | | 65 | | internal NavigationAStarNodeTable NodeTable { get; } |
| | | 66 | | |
| | | 67 | | internal NavigationMediumStateRef[] HeapNodes { get; } |
| | | 68 | | |
| | | 69 | | internal NavigationMediumStateRef[] PathNodes { get; } |
| | | 70 | | |
| | | 71 | | internal int[] PathNodeGuidePointOrdinals { get; } |
| | | 72 | | |
| | | 73 | | internal NavigationRayWorkspace RayWorkspace { get; } |
| | | 74 | | |
| | | 75 | | internal NavigationAStarGuidePoint[] GuidePoints { get; } |
| | | 76 | | |
| | | 77 | | internal int HeapCount { get; set; } |
| | | 78 | | |
| | | 79 | | internal int PathNodeCount { get; set; } |
| | | 80 | | |
| | | 81 | | internal int GuidePointCount { get; set; } |
| | | 82 | | |
| | | 83 | | internal void Reset() |
| | | 84 | | { |
| | 2 | 85 | | EndpointWorkspace.Reset(); |
| | 2 | 86 | | RayWorkspace.Reset(); |
| | 2 | 87 | | ResetSearch(); |
| | 2 | 88 | | } |
| | | 89 | | |
| | | 90 | | internal bool TryRecordEndpointComponent(NavigationSurfaceComponentKey componentKey) |
| | | 91 | | { |
| | 3 | 92 | | return EndpointWorkspace.TryRecordComponent(componentKey); |
| | | 93 | | } |
| | | 94 | | |
| | | 95 | | internal void ResetSearch() |
| | | 96 | | { |
| | 251 | 97 | | NodeTable.Reset(); |
| | 251 | 98 | | HeapCount = 0; |
| | 251 | 99 | | PathNodeCount = 0; |
| | 251 | 100 | | GuidePointCount = 0; |
| | 251 | 101 | | } |
| | | 102 | | } |