| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationFlowFieldLease.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 | | |
| | | 11 | | namespace Trailblazer.Pathing; |
| | | 12 | | |
| | | 13 | | /// <summary>Owns one generation-validated graph flow field and its sampling cursor.</summary> |
| | | 14 | | public readonly struct NavigationFlowFieldLease : IDisposable |
| | | 15 | | { |
| | | 16 | | private readonly NavigationFlowFieldGuideLease? _inner; |
| | | 17 | | private readonly ulong _generation; |
| | | 18 | | |
| | | 19 | | internal NavigationFlowFieldLease(NavigationFlowFieldGuideLease inner) |
| | | 20 | | { |
| | 1179 | 21 | | _inner = inner; |
| | 1179 | 22 | | _generation = inner.Generation; |
| | 1179 | 23 | | } |
| | | 24 | | |
| | | 25 | | /// <summary>Gets the lease's current dependency-validated status.</summary> |
| | | 26 | | public NavigationGuideStatus Status => |
| | 35 | 27 | | _inner?.GetStatus(_generation) ?? NavigationGuideStatus.Stale; |
| | | 28 | | |
| | | 29 | | /// <summary>Gets the immutable integration cost at the resolved origin.</summary> |
| | | 30 | | public Fixed64 OriginIntegrationCost => |
| | 5 | 31 | | _inner?.GetOriginIntegrationCost(_generation) ?? Fixed64.Zero; |
| | | 32 | | |
| | | 33 | | /// <summary>Samples deterministic movement guidance or one pending semantic action.</summary> |
| | | 34 | | public NavigationGuideStatus TrySample( |
| | | 35 | | Vector3d actualFootPosition, |
| | | 36 | | GuideSampleWorkBudget budget, |
| | | 37 | | out NavigationFlowSample sample) |
| | | 38 | | { |
| | 1264 | 39 | | NavigationFlowFieldGuideLease? inner = _inner; |
| | 1264 | 40 | | if (inner == null) |
| | | 41 | | { |
| | 1 | 42 | | sample = default; |
| | 1 | 43 | | return NavigationGuideStatus.Stale; |
| | | 44 | | } |
| | 1263 | 45 | | var meter = new GuideSampleWorkMeter(budget); |
| | 1263 | 46 | | NavigationGuideStatus status = inner.TrySample( |
| | 1263 | 47 | | _generation, |
| | 1263 | 48 | | actualFootPosition, |
| | 1263 | 49 | | ref meter, |
| | 1263 | 50 | | out sample); |
| | 1263 | 51 | | return status; |
| | | 52 | | } |
| | | 53 | | |
| | | 54 | | internal NavigationGuideStatus TrySample( |
| | | 55 | | Vector3d actualFootPosition, |
| | | 56 | | ref GuideSampleWorkMeter meter, |
| | | 57 | | out NavigationFlowSample sample) |
| | | 58 | | { |
| | 7 | 59 | | NavigationFlowFieldGuideLease? inner = _inner; |
| | 7 | 60 | | if (inner == null) |
| | | 61 | | { |
| | 1 | 62 | | sample = default; |
| | 1 | 63 | | return NavigationGuideStatus.Stale; |
| | | 64 | | } |
| | 6 | 65 | | return inner.TrySample( |
| | 6 | 66 | | _generation, |
| | 6 | 67 | | actualFootPosition, |
| | 6 | 68 | | ref meter, |
| | 6 | 69 | | out sample); |
| | | 70 | | } |
| | | 71 | | |
| | | 72 | | /// <summary>Completes the exact current pending semantic action.</summary> |
| | | 73 | | public NavigationGuideStatus CompletePendingTransition( |
| | | 74 | | in NavigationTransitionInstruction instruction) => |
| | 13 | 75 | | _inner?.CompletePendingTransition(_generation, instruction) |
| | 13 | 76 | | ?? NavigationGuideStatus.Stale; |
| | | 77 | | |
| | | 78 | | /// <inheritdoc /> |
| | 1185 | 79 | | public void Dispose() => _inner?.Dispose(_generation); |
| | | 80 | | } |