| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationEndpointWorkspace.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 GridForge.Grids.Topology; |
| | | 10 | | |
| | | 11 | | namespace Trailblazer.Pathing; |
| | | 12 | | |
| | | 13 | | /// <summary>Owns reusable endpoint-resolution buffers and exact dependencies.</summary> |
| | | 14 | | internal sealed class NavigationEndpointWorkspace |
| | | 15 | | { |
| | 16554 | 16 | | internal NavigationEndpointWorkspace( |
| | 16554 | 17 | | int mapCapacity, |
| | 16554 | 18 | | int pageCapacity, |
| | 16554 | 19 | | int componentCapacity) |
| | | 20 | | { |
| | 16554 | 21 | | SwiftThrowHelper.ThrowIfNegative(mapCapacity, nameof(mapCapacity)); |
| | 16554 | 22 | | SwiftThrowHelper.ThrowIfNegative(pageCapacity, nameof(pageCapacity)); |
| | 16554 | 23 | | SwiftThrowHelper.ThrowIfNegative(componentCapacity, nameof(componentCapacity)); |
| | 16554 | 24 | | CoveredAddressCursor = new GridCoveredAddressCursor(mapCapacity); |
| | 16554 | 25 | | CoveredAddressGenerations = mapCapacity == 0 |
| | 16554 | 26 | | ? Array.Empty<GridCoveredAddressGeneration>() |
| | 16554 | 27 | | : new GridCoveredAddressGeneration[mapCapacity]; |
| | 16554 | 28 | | CoveredAddressOutput = new GridCoveredAddress[1]; |
| | 16554 | 29 | | Dependencies = new NavigationDependencyWorkspace(pageCapacity, componentCapacity); |
| | 16554 | 30 | | } |
| | | 31 | | |
| | | 32 | | internal NavigationDependencyWorkspace Dependencies { get; } |
| | | 33 | | internal GridCoveredAddressCursor CoveredAddressCursor { get; } |
| | | 34 | | internal GridCoveredAddressGeneration[] CoveredAddressGenerations { get; } |
| | | 35 | | internal GridCoveredAddress[] CoveredAddressOutput { get; } |
| | 1906 | 36 | | internal GraphPageDependencyAddress[] Pages => Dependencies.Pages; |
| | 1907 | 37 | | internal NavigationSurfaceComponentKey[] Components => Dependencies.Components; |
| | | 38 | | internal int CoveredAddressGenerationCount { get; set; } |
| | 2764 | 39 | | internal int PageCount => Dependencies.PageCount; |
| | 2759 | 40 | | internal int ComponentCount => Dependencies.ComponentCount; |
| | | 41 | | |
| | | 42 | | internal void Reset() |
| | | 43 | | { |
| | 692 | 44 | | ResetResolution(); |
| | 692 | 45 | | Dependencies.Reset(); |
| | 692 | 46 | | } |
| | | 47 | | |
| | | 48 | | internal void ResetResolution() |
| | | 49 | | { |
| | 2026 | 50 | | if (CoveredAddressGenerationCount > 0) |
| | | 51 | | { |
| | 978 | 52 | | Array.Clear( |
| | 978 | 53 | | CoveredAddressGenerations, |
| | 978 | 54 | | 0, |
| | 978 | 55 | | CoveredAddressGenerationCount); |
| | | 56 | | } |
| | 2026 | 57 | | CoveredAddressOutput[0] = default; |
| | 2026 | 58 | | CoveredAddressGenerationCount = 0; |
| | 2026 | 59 | | } |
| | | 60 | | |
| | | 61 | | internal bool TryRecordComponent(NavigationSurfaceComponentKey component) |
| | 8282 | 62 | | => Dependencies.TryRecordComponent(component); |
| | | 63 | | |
| | | 64 | | internal bool TryRecordPage(string mapId, int pageIndex) |
| | 9317 | 65 | | => Dependencies.TryRecordPage(mapId, pageIndex); |
| | | 66 | | } |