| | | 1 | | //======================================================================= |
| | | 2 | | // NavigatorPathSessionRecord.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 Chronicler; |
| | | 10 | | using FixedMathSharp; |
| | | 11 | | using Trailblazer.Pathing; |
| | | 12 | | |
| | | 13 | | namespace Trailblazer.Navigation.Steering; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Records durable path intent while rebuilding the transient start from the loaded navigator frame. |
| | | 17 | | /// </summary> |
| | | 18 | | internal sealed class NavigatorPathSessionRecord : IRecordable |
| | | 19 | | { |
| | | 20 | | private const int CurrentSchemaVersion = 1; |
| | | 21 | | |
| | | 22 | | public int SchemaVersion; |
| | | 23 | | |
| | | 24 | | public bool HasQuery; |
| | | 25 | | |
| | | 26 | | public string? StartMapId; |
| | | 27 | | |
| | | 28 | | public EndpointResolutionPolicy StartResolution; |
| | | 29 | | |
| | | 30 | | public Fixed64 StartMaxResolutionDistance; |
| | | 31 | | |
| | | 32 | | public Vector3d EndPosition; |
| | | 33 | | |
| | | 34 | | public string? EndMapId; |
| | | 35 | | |
| | | 36 | | public EndpointResolutionPolicy EndResolution; |
| | | 37 | | |
| | | 38 | | public Fixed64 EndMaxResolutionDistance; |
| | | 39 | | |
| | | 40 | | public string? AreaPolicyId; |
| | | 41 | | |
| | | 42 | | public long AreaPolicyRevision; |
| | | 43 | | |
| | | 44 | | public TraversalMedia TargetMedia; |
| | | 45 | | |
| | | 46 | | public PathAlgorithm Algorithm; |
| | | 47 | | |
| | | 48 | | public int MaxLookupProbes; |
| | | 49 | | |
| | | 50 | | public int MaxEndpointCandidates; |
| | | 51 | | |
| | | 52 | | public int MaxExpandedNodes; |
| | | 53 | | |
| | | 54 | | public int MaxEvaluatedEdges; |
| | | 55 | | |
| | | 56 | | public int MaxConnectionLegs; |
| | | 57 | | |
| | | 58 | | public int MaxTransitionCandidates; |
| | | 59 | | |
| | | 60 | | public int MaxTransitionPairs; |
| | | 61 | | |
| | | 62 | | public int MaxStagedLegAttempts; |
| | | 63 | | |
| | | 64 | | public int MaxTraceIntervals; |
| | | 65 | | |
| | | 66 | | public int MaxCoveredVoxelIntervals; |
| | | 67 | | |
| | | 68 | | public int MaxSimplificationRays; |
| | | 69 | | |
| | | 70 | | public bool AllowTransitions; |
| | | 71 | | |
| | | 72 | | public Fixed64 ExtraIntegrationCost; |
| | | 73 | | |
| | | 74 | | public void Capture(PathQuery? query) |
| | | 75 | | { |
| | 77 | 76 | | SchemaVersion = CurrentSchemaVersion; |
| | 77 | 77 | | if (!query.HasValue) |
| | 55 | 78 | | return; |
| | | 79 | | |
| | 22 | 80 | | PathQuery value = query.Value; |
| | 22 | 81 | | HasQuery = true; |
| | 22 | 82 | | StartMapId = value.Start.MapId; |
| | 22 | 83 | | StartResolution = value.Start.Resolution; |
| | 22 | 84 | | StartMaxResolutionDistance = value.Start.MaxResolutionDistance; |
| | 22 | 85 | | EndPosition = value.End.Position; |
| | 22 | 86 | | EndMapId = value.End.MapId; |
| | 22 | 87 | | EndResolution = value.End.Resolution; |
| | 22 | 88 | | EndMaxResolutionDistance = value.End.MaxResolutionDistance; |
| | 22 | 89 | | AreaPolicyId = value.AreaPolicy.PolicyId; |
| | 22 | 90 | | AreaPolicyRevision = value.AreaPolicy.Revision; |
| | 22 | 91 | | TargetMedia = value.Traversal.TargetMedia; |
| | 22 | 92 | | Algorithm = value.Algorithm; |
| | 22 | 93 | | MaxLookupProbes = value.Budget.MaxLookupProbes; |
| | 22 | 94 | | MaxEndpointCandidates = value.Budget.MaxEndpointCandidates; |
| | 22 | 95 | | MaxExpandedNodes = value.Budget.MaxExpandedNodes; |
| | 22 | 96 | | MaxEvaluatedEdges = value.Budget.MaxEvaluatedEdges; |
| | 22 | 97 | | MaxConnectionLegs = value.Budget.MaxConnectionLegs; |
| | 22 | 98 | | MaxTransitionCandidates = value.Budget.MaxTransitionCandidates; |
| | 22 | 99 | | MaxTransitionPairs = value.Budget.MaxTransitionPairs; |
| | 22 | 100 | | MaxStagedLegAttempts = value.Budget.MaxStagedLegAttempts; |
| | 22 | 101 | | MaxTraceIntervals = value.Budget.MaxTraceIntervals; |
| | 22 | 102 | | MaxCoveredVoxelIntervals = value.Budget.MaxCoveredVoxelIntervals; |
| | 22 | 103 | | MaxSimplificationRays = value.Budget.MaxSimplificationRays; |
| | 22 | 104 | | AllowTransitions = value.AllowTransitions; |
| | 22 | 105 | | ExtraIntegrationCost = value.FlowField.ExtraIntegrationCost; |
| | 22 | 106 | | } |
| | | 107 | | |
| | | 108 | | public bool TryCreateQuery( |
| | | 109 | | Vector3d startPosition, |
| | | 110 | | TraversalMedium startMedium, |
| | | 111 | | NavigationAgentProfile agent, |
| | | 112 | | out PathQuery? query) |
| | | 113 | | { |
| | 64 | 114 | | query = null; |
| | 64 | 115 | | if (SchemaVersion != CurrentSchemaVersion) |
| | 2 | 116 | | return false; |
| | 62 | 117 | | if (!HasQuery) |
| | 41 | 118 | | return true; |
| | 21 | 119 | | if (Algorithm is not PathAlgorithm.AStar and not PathAlgorithm.FlowField |
| | 21 | 120 | | || TargetMedia == TraversalMedia.None |
| | 21 | 121 | | || (TargetMedia & ~NavigationCell.KnownMedia) != 0 |
| | 21 | 122 | | || string.IsNullOrWhiteSpace(AreaPolicyId)) |
| | | 123 | | { |
| | 10 | 124 | | return false; |
| | | 125 | | } |
| | | 126 | | |
| | | 127 | | try |
| | | 128 | | { |
| | 11 | 129 | | query = new PathQuery( |
| | 11 | 130 | | new NavigationEndpoint( |
| | 11 | 131 | | startPosition, |
| | 11 | 132 | | StartMapId, |
| | 11 | 133 | | StartResolution, |
| | 11 | 134 | | StartMaxResolutionDistance), |
| | 11 | 135 | | new NavigationEndpoint( |
| | 11 | 136 | | EndPosition, |
| | 11 | 137 | | EndMapId, |
| | 11 | 138 | | EndResolution, |
| | 11 | 139 | | EndMaxResolutionDistance), |
| | 11 | 140 | | agent, |
| | 11 | 141 | | new NavigationAreaPolicyKey(AreaPolicyId!, AreaPolicyRevision), |
| | 11 | 142 | | new TraversalIntent(startMedium, TargetMedia), |
| | 11 | 143 | | Algorithm, |
| | 11 | 144 | | new NavigationWorkBudget( |
| | 11 | 145 | | MaxLookupProbes, |
| | 11 | 146 | | MaxEndpointCandidates, |
| | 11 | 147 | | MaxExpandedNodes, |
| | 11 | 148 | | MaxEvaluatedEdges, |
| | 11 | 149 | | MaxConnectionLegs, |
| | 11 | 150 | | MaxTransitionCandidates, |
| | 11 | 151 | | MaxTransitionPairs, |
| | 11 | 152 | | MaxStagedLegAttempts, |
| | 11 | 153 | | MaxTraceIntervals, |
| | 11 | 154 | | MaxCoveredVoxelIntervals, |
| | 11 | 155 | | MaxSimplificationRays), |
| | 11 | 156 | | AllowTransitions, |
| | 11 | 157 | | Algorithm == PathAlgorithm.FlowField |
| | 11 | 158 | | ? new FlowFieldQueryOptions(ExtraIntegrationCost) |
| | 11 | 159 | | : default); |
| | 9 | 160 | | return true; |
| | | 161 | | } |
| | 2 | 162 | | catch (ArgumentException) |
| | | 163 | | { |
| | 2 | 164 | | return false; |
| | | 165 | | } |
| | 11 | 166 | | } |
| | | 167 | | |
| | | 168 | | public void RecordData(IChronicler chronicler) |
| | | 169 | | { |
| | 153 | 170 | | RecordValues.Look(chronicler, ref SchemaVersion, "SchemaVersion", 0); |
| | 153 | 171 | | RecordValues.Look(chronicler, ref HasQuery, "HasQuery", false); |
| | 153 | 172 | | RecordValues.Look(chronicler, ref StartMapId, "StartMapId", null); |
| | 153 | 173 | | RecordValues.Look(chronicler, ref StartResolution, "StartResolution", EndpointResolutionPolicy.Strict); |
| | 153 | 174 | | RecordValues.Look(chronicler, ref StartMaxResolutionDistance, "StartMaxResolutionDistance", Fixed64.Zero); |
| | 153 | 175 | | RecordValues.Look(chronicler, ref EndPosition, "EndPosition", Vector3d.Zero); |
| | 153 | 176 | | RecordValues.Look(chronicler, ref EndMapId, "EndMapId", null); |
| | 153 | 177 | | RecordValues.Look(chronicler, ref EndResolution, "EndResolution", EndpointResolutionPolicy.Strict); |
| | 153 | 178 | | RecordValues.Look(chronicler, ref EndMaxResolutionDistance, "EndMaxResolutionDistance", Fixed64.Zero); |
| | 153 | 179 | | RecordValues.Look(chronicler, ref AreaPolicyId, "AreaPolicyId", null); |
| | 153 | 180 | | RecordValues.Look(chronicler, ref AreaPolicyRevision, "AreaPolicyRevision", 0L); |
| | 153 | 181 | | RecordValues.Look(chronicler, ref TargetMedia, "TargetMedia", TraversalMedia.None); |
| | 153 | 182 | | RecordValues.Look(chronicler, ref Algorithm, "Algorithm", PathAlgorithm.AStar); |
| | 153 | 183 | | RecordValues.Look(chronicler, ref MaxLookupProbes, "MaxLookupProbes", 0); |
| | 153 | 184 | | RecordValues.Look(chronicler, ref MaxEndpointCandidates, "MaxEndpointCandidates", 0); |
| | 153 | 185 | | RecordValues.Look(chronicler, ref MaxExpandedNodes, "MaxExpandedNodes", 0); |
| | 153 | 186 | | RecordValues.Look(chronicler, ref MaxEvaluatedEdges, "MaxEvaluatedEdges", 0); |
| | 153 | 187 | | RecordValues.Look(chronicler, ref MaxConnectionLegs, "MaxConnectionLegs", 0); |
| | 153 | 188 | | RecordValues.Look(chronicler, ref MaxTransitionCandidates, "MaxTransitionCandidates", 0); |
| | 153 | 189 | | RecordValues.Look(chronicler, ref MaxTransitionPairs, "MaxTransitionPairs", 0); |
| | 153 | 190 | | RecordValues.Look(chronicler, ref MaxStagedLegAttempts, "MaxStagedLegAttempts", 0); |
| | 153 | 191 | | RecordValues.Look(chronicler, ref MaxTraceIntervals, "MaxTraceIntervals", 0); |
| | 153 | 192 | | RecordValues.Look(chronicler, ref MaxCoveredVoxelIntervals, "MaxCoveredVoxelIntervals", 0); |
| | 153 | 193 | | RecordValues.Look(chronicler, ref MaxSimplificationRays, "MaxSimplificationRays", 0); |
| | 153 | 194 | | RecordValues.Look(chronicler, ref AllowTransitions, "AllowTransitions", false); |
| | 153 | 195 | | RecordValues.Look(chronicler, ref ExtraIntegrationCost, "ExtraIntegrationCost", Fixed64.Zero); |
| | 153 | 196 | | } |
| | | 197 | | } |