| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationTokenLegendEntry.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> |
| | | 14 | | /// Describes the complete navigation payload and optional transition marker media for one token. |
| | | 15 | | /// </summary> |
| | | 16 | | public readonly struct NavigationTokenLegendEntry |
| | | 17 | | { |
| | | 18 | | /// <summary> |
| | | 19 | | /// Whether this entry emits an authored navigation cell. |
| | | 20 | | /// </summary> |
| | | 21 | | public bool EmitsCell { get; } |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// The complete cell payload emitted when <see cref="EmitsCell"/> is true. |
| | | 25 | | /// </summary> |
| | | 26 | | public NavigationCell Cell { get; } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// The subset of authored media exposed when the token carries a trailing marker. |
| | | 30 | | /// </summary> |
| | | 31 | | public TraversalMedia TransitionMedia { get; } |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Creates an entry that emits a complete cell payload. |
| | | 35 | | /// </summary> |
| | | 36 | | public NavigationTokenLegendEntry( |
| | | 37 | | NavigationCell cell, |
| | | 38 | | TraversalMedia transitionMedia = TraversalMedia.None) |
| | | 39 | | { |
| | 169 | 40 | | SwiftThrowHelper.ThrowIfArgument( |
| | 169 | 41 | | cell.Media == TraversalMedia.None, |
| | 169 | 42 | | nameof(cell), |
| | 169 | 43 | | "The emitted cell must contain at least one known traversal-medium bit."); |
| | | 44 | | |
| | | 45 | | System.Diagnostics.Debug.Assert((cell.Media & ~NavigationCell.KnownMedia) == 0); |
| | | 46 | | System.Diagnostics.Debug.Assert((cell.RequiredCapabilities & ~NavigationCell.KnownCapabilities) == 0); |
| | | 47 | | System.Diagnostics.Debug.Assert((cell.Flags & ~NavigationCell.KnownFlags) == 0); |
| | | 48 | | System.Diagnostics.Debug.Assert(cell.EnterCost >= Fixed64.Zero); |
| | | 49 | | System.Diagnostics.Debug.Assert(cell.RadiusClearance >= Fixed64.Zero); |
| | | 50 | | System.Diagnostics.Debug.Assert(cell.HeightClearance >= Fixed64.Zero); |
| | | 51 | | |
| | 168 | 52 | | SwiftThrowHelper.ThrowIfArgument( |
| | 168 | 53 | | (transitionMedia & ~NavigationCell.KnownMedia) != 0 |
| | 168 | 54 | | || (transitionMedia & ~cell.Media) != 0, |
| | 168 | 55 | | nameof(transitionMedia), |
| | 168 | 56 | | "Transition media must be a known subset of the emitted cell media."); |
| | | 57 | | |
| | 166 | 58 | | EmitsCell = true; |
| | 166 | 59 | | Cell = cell; |
| | 166 | 60 | | TransitionMedia = transitionMedia; |
| | 166 | 61 | | } |
| | | 62 | | |
| | | 63 | | /// <summary> |
| | | 64 | | /// Creates an entry that emits no cell or transition metadata. |
| | | 65 | | /// </summary> |
| | 67 | 66 | | public static NavigationTokenLegendEntry SkipCell() => default; |
| | | 67 | | |
| | | 68 | | internal NavigationCell CreateCell( |
| | | 69 | | Fixed64 inlineCost, |
| | | 70 | | bool hasInlineCost, |
| | | 71 | | bool hasTransitionMarker) |
| | | 72 | | { |
| | 35 | 73 | | NavigationCellFlags flags = Cell.Flags; |
| | 35 | 74 | | if (hasTransitionMarker) |
| | | 75 | | { |
| | 24 | 76 | | flags |= NavigationCellFlags.TransitionSourceHint |
| | 24 | 77 | | | NavigationCellFlags.TransitionDestinationHint; |
| | | 78 | | } |
| | | 79 | | |
| | 35 | 80 | | return new NavigationCell( |
| | 35 | 81 | | Cell.Media, |
| | 35 | 82 | | Cell.RequiredCapabilities, |
| | 35 | 83 | | Cell.Area, |
| | 35 | 84 | | hasInlineCost ? inlineCost : Cell.EnterCost, |
| | 35 | 85 | | Cell.RadiusClearance, |
| | 35 | 86 | | Cell.HeightClearance, |
| | 35 | 87 | | flags); |
| | | 88 | | } |
| | | 89 | | } |