| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationAutomaticSeamPair.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 GridForge.Grids.Topology; |
| | | 9 | | using System; |
| | | 10 | | |
| | | 11 | | namespace Trailblazer.Pathing; |
| | | 12 | | |
| | | 13 | | /// <summary>Owns one canonical absolute portal shared by both seam directions.</summary> |
| | | 14 | | internal sealed class NavigationAutomaticSeamPair |
| | | 15 | | { |
| | | 16 | | internal const long RetainedSize = 168L; |
| | | 17 | | |
| | | 18 | | internal NavigationAutomaticSeamPair( |
| | | 19 | | NavigationCellAddress first, |
| | | 20 | | NavigationCellAddress second, |
| | | 21 | | GridNavigationPortal portal) |
| | | 22 | | { |
| | | 23 | | First = first; |
| | | 24 | | Second = second; |
| | | 25 | | Portal = portal; |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | internal NavigationCellAddress First { get; } |
| | | 29 | | |
| | | 30 | | internal NavigationCellAddress Second { get; } |
| | | 31 | | |
| | | 32 | | internal GridNavigationPortal Portal { get; } |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | /// <summary>Stores snapshot-local active state without duplicating canonical portal geometry.</summary> |
| | | 36 | | internal sealed class NavigationAutomaticSeamPairRecord |
| | | 37 | | { |
| | | 38 | | internal const long RetainedSize = 32L; |
| | | 39 | | |
| | | 40 | | internal NavigationAutomaticSeamPairRecord( |
| | | 41 | | NavigationAutomaticSeamPair pair, |
| | | 42 | | bool isActive) |
| | | 43 | | { |
| | | 44 | | Pair = pair; |
| | | 45 | | IsActive = isActive; |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | internal NavigationAutomaticSeamPair Pair { get; } |
| | | 49 | | |
| | | 50 | | internal bool IsActive { get; } |
| | | 51 | | } |
| | | 52 | | |
| | | 53 | | /// <summary>Identifies one directed use of a canonical automatic seam.</summary> |
| | | 54 | | internal readonly struct NavigationAutomaticSeamRef |
| | | 55 | | { |
| | | 56 | | internal NavigationAutomaticSeamRef(NavigationAutomaticSeamPair pair, bool reverse) |
| | | 57 | | { |
| | | 58 | | Pair = pair; |
| | | 59 | | IsReverse = reverse; |
| | | 60 | | } |
| | | 61 | | |
| | | 62 | | internal NavigationAutomaticSeamPair Pair { get; } |
| | | 63 | | |
| | | 64 | | internal bool IsReverse { get; } |
| | | 65 | | |
| | | 66 | | internal NavigationCellAddress Source => IsReverse ? Pair.Second : Pair.First; |
| | | 67 | | |
| | | 68 | | internal NavigationCellAddress Destination => IsReverse ? Pair.First : Pair.Second; |
| | | 69 | | |
| | | 70 | | internal GridNavigationPortal Portal => Pair.Portal; |
| | | 71 | | } |
| | | 72 | | |
| | | 73 | | /// <summary>Orders one canonical unordered durable seam pair.</summary> |
| | | 74 | | internal readonly struct NavigationAutomaticSeamPairKey : IComparable<NavigationAutomaticSeamPairKey> |
| | | 75 | | { |
| | | 76 | | internal NavigationAutomaticSeamPairKey( |
| | | 77 | | NavigationCellAddress first, |
| | | 78 | | NavigationCellAddress second) |
| | | 79 | | { |
| | 102939 | 80 | | if (CompareAddress(first, second) > 0) |
| | 1795 | 81 | | (first, second) = (second, first); |
| | 102939 | 82 | | First = first; |
| | 102939 | 83 | | Second = second; |
| | 102939 | 84 | | } |
| | | 85 | | |
| | | 86 | | internal NavigationCellAddress First { get; } |
| | | 87 | | |
| | | 88 | | internal NavigationCellAddress Second { get; } |
| | | 89 | | |
| | | 90 | | public int CompareTo(NavigationAutomaticSeamPairKey other) |
| | | 91 | | { |
| | 907840 | 92 | | int comparison = CompareAddress(First, other.First); |
| | 907840 | 93 | | return comparison != 0 ? comparison : CompareAddress(Second, other.Second); |
| | | 94 | | } |
| | | 95 | | |
| | | 96 | | private static int CompareAddress( |
| | | 97 | | NavigationCellAddress left, |
| | | 98 | | NavigationCellAddress right) |
| | | 99 | | { |
| | 1289295 | 100 | | int comparison = string.CompareOrdinal(left.MapId, right.MapId); |
| | 1289295 | 101 | | if (comparison != 0) |
| | 397034 | 102 | | return comparison; |
| | 892261 | 103 | | comparison = left.Index.x < right.Index.x |
| | 892261 | 104 | | ? -1 |
| | 892261 | 105 | | : left.Index.x > right.Index.x ? 1 : 0; |
| | 892261 | 106 | | if (comparison != 0) |
| | 294094 | 107 | | return comparison; |
| | 598167 | 108 | | comparison = left.Index.y < right.Index.y |
| | 598167 | 109 | | ? -1 |
| | 598167 | 110 | | : left.Index.y > right.Index.y ? 1 : 0; |
| | 598167 | 111 | | if (comparison != 0) |
| | 127076 | 112 | | return comparison; |
| | 471091 | 113 | | return left.Index.z < right.Index.z |
| | 471091 | 114 | | ? -1 |
| | 471091 | 115 | | : left.Index.z > right.Index.z ? 1 : 0; |
| | | 116 | | } |
| | | 117 | | } |
| | | 118 | | |
| | | 119 | | /// <summary>Provides an ordinal value key for one structural-link row.</summary> |
| | | 120 | | internal readonly struct NavigationAutomaticSeamMapKey : IComparable<NavigationAutomaticSeamMapKey> |
| | | 121 | | { |
| | | 122 | | internal NavigationAutomaticSeamMapKey(string mapId) => MapId = mapId; |
| | | 123 | | |
| | | 124 | | internal string MapId { get; } |
| | | 125 | | |
| | | 126 | | public int CompareTo(NavigationAutomaticSeamMapKey other) => |
| | | 127 | | string.CompareOrdinal(MapId, other.MapId); |
| | | 128 | | } |
| | | 129 | | |
| | | 130 | | /// <summary>Orders one directed structural seam dependency.</summary> |
| | | 131 | | internal readonly struct NavigationAutomaticSeamLinkKey : IComparable<NavigationAutomaticSeamLinkKey> |
| | | 132 | | { |
| | | 133 | | internal NavigationAutomaticSeamLinkKey(string sourceMapId, string destinationMapId) |
| | | 134 | | { |
| | | 135 | | SourceMapId = sourceMapId; |
| | | 136 | | DestinationMapId = destinationMapId; |
| | | 137 | | } |
| | | 138 | | |
| | | 139 | | internal string SourceMapId { get; } |
| | | 140 | | |
| | | 141 | | internal string DestinationMapId { get; } |
| | | 142 | | |
| | | 143 | | public int CompareTo(NavigationAutomaticSeamLinkKey other) |
| | | 144 | | { |
| | | 145 | | int comparison = string.CompareOrdinal(SourceMapId, other.SourceMapId); |
| | | 146 | | return comparison != 0 |
| | | 147 | | ? comparison |
| | | 148 | | : string.CompareOrdinal(DestinationMapId, other.DestinationMapId); |
| | | 149 | | } |
| | | 150 | | } |