| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationRayStatus.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 | | using GridForge.Grids; |
| | | 11 | | |
| | | 12 | | namespace Trailblazer.Pathing; |
| | | 13 | | |
| | | 14 | | internal enum NavigationRayStatus : byte |
| | | 15 | | { |
| | | 16 | | Pending, |
| | | 17 | | Success, |
| | | 18 | | Blocked, |
| | | 19 | | BudgetExceeded, |
| | | 20 | | CostOverflow, |
| | | 21 | | CapacityExceeded, |
| | | 22 | | Stale |
| | | 23 | | } |
| | | 24 | | |
| | | 25 | | internal enum NavigationRayEndpointAllowance : byte |
| | | 26 | | { |
| | | 27 | | None, |
| | | 28 | | StartPrefix, |
| | | 29 | | DestinationSuffix |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | internal enum NavigationRayChainConstraintKind : byte |
| | | 33 | | { |
| | | 34 | | Unrestricted, |
| | | 35 | | SourceAddress, |
| | | 36 | | SelectedEdge, |
| | | 37 | | SeedAddress, |
| | | 38 | | FinishAddress |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | internal readonly struct NavigationRayChainConstraint |
| | | 42 | | { |
| | | 43 | | private NavigationRayChainConstraint( |
| | | 44 | | NavigationRayChainConstraintKind kind, |
| | | 45 | | NavigationCellAddress sourceAddress, |
| | | 46 | | NavigationCellAddress targetAddress, |
| | | 47 | | int edgeOrdinal) |
| | | 48 | | { |
| | | 49 | | Kind = kind; |
| | | 50 | | SourceAddress = sourceAddress; |
| | | 51 | | TargetAddress = targetAddress; |
| | | 52 | | EdgeOrdinal = edgeOrdinal; |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | internal NavigationRayChainConstraintKind Kind { get; } |
| | | 56 | | |
| | | 57 | | internal NavigationCellAddress SourceAddress { get; } |
| | | 58 | | |
| | | 59 | | internal NavigationCellAddress TargetAddress { get; } |
| | | 60 | | |
| | | 61 | | internal int EdgeOrdinal { get; } |
| | | 62 | | |
| | | 63 | | internal static NavigationRayChainConstraint SourceOnly( |
| | | 64 | | NavigationCellAddress sourceAddress) => |
| | | 65 | | new(NavigationRayChainConstraintKind.SourceAddress, sourceAddress, default, -1); |
| | | 66 | | |
| | | 67 | | internal static NavigationRayChainConstraint SelectedEdge( |
| | | 68 | | NavigationCellAddress sourceAddress, |
| | | 69 | | NavigationCellAddress targetAddress, |
| | | 70 | | int edgeOrdinal) |
| | | 71 | | { |
| | | 72 | | SwiftThrowHelper.ThrowIfNegative(edgeOrdinal, nameof(edgeOrdinal)); |
| | | 73 | | return new( |
| | | 74 | | NavigationRayChainConstraintKind.SelectedEdge, |
| | | 75 | | sourceAddress, |
| | | 76 | | targetAddress, |
| | | 77 | | edgeOrdinal); |
| | | 78 | | } |
| | | 79 | | |
| | | 80 | | internal static NavigationRayChainConstraint SeedAt( |
| | | 81 | | NavigationCellAddress sourceAddress) => |
| | | 82 | | new(NavigationRayChainConstraintKind.SeedAddress, sourceAddress, default, -1); |
| | | 83 | | |
| | | 84 | | internal static NavigationRayChainConstraint FinishAt( |
| | | 85 | | NavigationCellAddress targetAddress) => |
| | | 86 | | new(NavigationRayChainConstraintKind.FinishAddress, default, targetAddress, -1); |
| | | 87 | | } |
| | | 88 | | |
| | | 89 | | internal readonly struct NavigationRayRequest |
| | | 90 | | { |
| | | 91 | | internal NavigationRayRequest( |
| | | 92 | | GridWorld world, |
| | | 93 | | NavigationWorldGraphStore store, |
| | | 94 | | NavigationWorldGraph expectedGraph, |
| | | 95 | | NavigationAgentProfile profile, |
| | | 96 | | NavigationAreaPolicy areaPolicy, |
| | | 97 | | TraversalMedium medium, |
| | | 98 | | Vector3d start, |
| | | 99 | | Vector3d end, |
| | | 100 | | NavigationRayEndpointAllowance endpointAllowance, |
| | | 101 | | NavigationRayChainConstraint chainConstraint = default) |
| | | 102 | | { |
| | | 103 | | SwiftThrowHelper.ThrowIfNull(world, nameof(world)); |
| | | 104 | | SwiftThrowHelper.ThrowIfNull(store, nameof(store)); |
| | | 105 | | SwiftThrowHelper.ThrowIfNull(expectedGraph, nameof(expectedGraph)); |
| | | 106 | | SwiftThrowHelper.ThrowIfNull(areaPolicy, nameof(areaPolicy)); |
| | | 107 | | if (medium is not TraversalMedium.Solid |
| | | 108 | | and not TraversalMedium.Gas |
| | | 109 | | and not TraversalMedium.Liquid) |
| | | 110 | | { |
| | | 111 | | throw new ArgumentOutOfRangeException(nameof(medium)); |
| | | 112 | | } |
| | | 113 | | World = world; |
| | | 114 | | Store = store; |
| | | 115 | | ExpectedGraph = expectedGraph; |
| | | 116 | | Profile = profile; |
| | | 117 | | AreaPolicy = areaPolicy; |
| | | 118 | | Medium = medium; |
| | | 119 | | Start = start; |
| | | 120 | | End = end; |
| | | 121 | | EndpointAllowance = endpointAllowance; |
| | | 122 | | ChainConstraint = chainConstraint; |
| | | 123 | | } |
| | | 124 | | |
| | | 125 | | internal GridWorld World { get; } |
| | | 126 | | |
| | | 127 | | internal NavigationWorldGraphStore Store { get; } |
| | | 128 | | |
| | | 129 | | internal NavigationWorldGraph ExpectedGraph { get; } |
| | | 130 | | |
| | | 131 | | internal NavigationAgentProfile Profile { get; } |
| | | 132 | | |
| | | 133 | | internal NavigationAreaPolicy AreaPolicy { get; } |
| | | 134 | | |
| | | 135 | | internal TraversalMedium Medium { get; } |
| | | 136 | | |
| | | 137 | | internal Vector3d Start { get; } |
| | | 138 | | |
| | | 139 | | internal Vector3d End { get; } |
| | | 140 | | |
| | | 141 | | internal NavigationRayEndpointAllowance EndpointAllowance { get; } |
| | | 142 | | |
| | | 143 | | internal NavigationRayChainConstraint ChainConstraint { get; } |
| | | 144 | | } |
| | | 145 | | |
| | | 146 | | internal readonly struct NavigationRayResult |
| | | 147 | | { |
| | | 148 | | internal NavigationRayResult( |
| | | 149 | | NavigationRayStatus status, |
| | | 150 | | NavigationCellAddress startAddress, |
| | | 151 | | NavigationCellAddress endAddress, |
| | | 152 | | Fixed64 traversalCost, |
| | | 153 | | bool isSemanticCostNeutral) |
| | | 154 | | { |
| | 1955 | 155 | | Status = status; |
| | 1955 | 156 | | StartAddress = startAddress; |
| | 1955 | 157 | | EndAddress = endAddress; |
| | 1955 | 158 | | TraversalCost = traversalCost; |
| | 1955 | 159 | | IsSemanticCostNeutral = isSemanticCostNeutral; |
| | 1955 | 160 | | } |
| | | 161 | | |
| | | 162 | | internal NavigationRayStatus Status { get; } |
| | | 163 | | |
| | | 164 | | internal NavigationCellAddress StartAddress { get; } |
| | | 165 | | |
| | | 166 | | internal NavigationCellAddress EndAddress { get; } |
| | | 167 | | |
| | | 168 | | internal Fixed64 TraversalCost { get; } |
| | | 169 | | |
| | | 170 | | internal bool IsSemanticCostNeutral { get; } |
| | | 171 | | } |