< Summary

Information
Class: Trailblazer.Navigation.Steering.NavigatorPathSessionRecord
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Steering/Serialization/NavigatorPathSessionRecord.cs
Line coverage
100%
Covered lines: 102
Uncovered lines: 0
Coverable lines: 102
Total lines: 197
Line coverage: 100%
Branch coverage
100%
Covered branches: 18
Total branches: 18
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Capture(...)100%22100%
TryCreateQuery(...)100%1616100%
RecordData(...)100%11100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Steering/Serialization/NavigatorPathSessionRecord.cs

#LineLine coverage
 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
 8using System;
 9using Chronicler;
 10using FixedMathSharp;
 11using Trailblazer.Pathing;
 12
 13namespace Trailblazer.Navigation.Steering;
 14
 15/// <summary>
 16/// Records durable path intent while rebuilding the transient start from the loaded navigator frame.
 17/// </summary>
 18internal 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    {
 7776        SchemaVersion = CurrentSchemaVersion;
 7777        if (!query.HasValue)
 5578            return;
 79
 2280        PathQuery value = query.Value;
 2281        HasQuery = true;
 2282        StartMapId = value.Start.MapId;
 2283        StartResolution = value.Start.Resolution;
 2284        StartMaxResolutionDistance = value.Start.MaxResolutionDistance;
 2285        EndPosition = value.End.Position;
 2286        EndMapId = value.End.MapId;
 2287        EndResolution = value.End.Resolution;
 2288        EndMaxResolutionDistance = value.End.MaxResolutionDistance;
 2289        AreaPolicyId = value.AreaPolicy.PolicyId;
 2290        AreaPolicyRevision = value.AreaPolicy.Revision;
 2291        TargetMedia = value.Traversal.TargetMedia;
 2292        Algorithm = value.Algorithm;
 2293        MaxLookupProbes = value.Budget.MaxLookupProbes;
 2294        MaxEndpointCandidates = value.Budget.MaxEndpointCandidates;
 2295        MaxExpandedNodes = value.Budget.MaxExpandedNodes;
 2296        MaxEvaluatedEdges = value.Budget.MaxEvaluatedEdges;
 2297        MaxConnectionLegs = value.Budget.MaxConnectionLegs;
 2298        MaxTransitionCandidates = value.Budget.MaxTransitionCandidates;
 2299        MaxTransitionPairs = value.Budget.MaxTransitionPairs;
 22100        MaxStagedLegAttempts = value.Budget.MaxStagedLegAttempts;
 22101        MaxTraceIntervals = value.Budget.MaxTraceIntervals;
 22102        MaxCoveredVoxelIntervals = value.Budget.MaxCoveredVoxelIntervals;
 22103        MaxSimplificationRays = value.Budget.MaxSimplificationRays;
 22104        AllowTransitions = value.AllowTransitions;
 22105        ExtraIntegrationCost = value.FlowField.ExtraIntegrationCost;
 22106    }
 107
 108    public bool TryCreateQuery(
 109        Vector3d startPosition,
 110        TraversalMedium startMedium,
 111        NavigationAgentProfile agent,
 112        out PathQuery? query)
 113    {
 64114        query = null;
 64115        if (SchemaVersion != CurrentSchemaVersion)
 2116            return false;
 62117        if (!HasQuery)
 41118            return true;
 21119        if (Algorithm is not PathAlgorithm.AStar and not PathAlgorithm.FlowField
 21120            || TargetMedia == TraversalMedia.None
 21121            || (TargetMedia & ~NavigationCell.KnownMedia) != 0
 21122            || string.IsNullOrWhiteSpace(AreaPolicyId))
 123        {
 10124            return false;
 125        }
 126
 127        try
 128        {
 11129            query = new PathQuery(
 11130                new NavigationEndpoint(
 11131                    startPosition,
 11132                    StartMapId,
 11133                    StartResolution,
 11134                    StartMaxResolutionDistance),
 11135                new NavigationEndpoint(
 11136                    EndPosition,
 11137                    EndMapId,
 11138                    EndResolution,
 11139                    EndMaxResolutionDistance),
 11140                agent,
 11141                new NavigationAreaPolicyKey(AreaPolicyId!, AreaPolicyRevision),
 11142                new TraversalIntent(startMedium, TargetMedia),
 11143                Algorithm,
 11144                new NavigationWorkBudget(
 11145                    MaxLookupProbes,
 11146                    MaxEndpointCandidates,
 11147                    MaxExpandedNodes,
 11148                    MaxEvaluatedEdges,
 11149                    MaxConnectionLegs,
 11150                    MaxTransitionCandidates,
 11151                    MaxTransitionPairs,
 11152                    MaxStagedLegAttempts,
 11153                    MaxTraceIntervals,
 11154                    MaxCoveredVoxelIntervals,
 11155                    MaxSimplificationRays),
 11156                AllowTransitions,
 11157                Algorithm == PathAlgorithm.FlowField
 11158                    ? new FlowFieldQueryOptions(ExtraIntegrationCost)
 11159                    : default);
 9160            return true;
 161        }
 2162        catch (ArgumentException)
 163        {
 2164            return false;
 165        }
 11166    }
 167
 168    public void RecordData(IChronicler chronicler)
 169    {
 153170        RecordValues.Look(chronicler, ref SchemaVersion, "SchemaVersion", 0);
 153171        RecordValues.Look(chronicler, ref HasQuery, "HasQuery", false);
 153172        RecordValues.Look(chronicler, ref StartMapId, "StartMapId", null);
 153173        RecordValues.Look(chronicler, ref StartResolution, "StartResolution", EndpointResolutionPolicy.Strict);
 153174        RecordValues.Look(chronicler, ref StartMaxResolutionDistance, "StartMaxResolutionDistance", Fixed64.Zero);
 153175        RecordValues.Look(chronicler, ref EndPosition, "EndPosition", Vector3d.Zero);
 153176        RecordValues.Look(chronicler, ref EndMapId, "EndMapId", null);
 153177        RecordValues.Look(chronicler, ref EndResolution, "EndResolution", EndpointResolutionPolicy.Strict);
 153178        RecordValues.Look(chronicler, ref EndMaxResolutionDistance, "EndMaxResolutionDistance", Fixed64.Zero);
 153179        RecordValues.Look(chronicler, ref AreaPolicyId, "AreaPolicyId", null);
 153180        RecordValues.Look(chronicler, ref AreaPolicyRevision, "AreaPolicyRevision", 0L);
 153181        RecordValues.Look(chronicler, ref TargetMedia, "TargetMedia", TraversalMedia.None);
 153182        RecordValues.Look(chronicler, ref Algorithm, "Algorithm", PathAlgorithm.AStar);
 153183        RecordValues.Look(chronicler, ref MaxLookupProbes, "MaxLookupProbes", 0);
 153184        RecordValues.Look(chronicler, ref MaxEndpointCandidates, "MaxEndpointCandidates", 0);
 153185        RecordValues.Look(chronicler, ref MaxExpandedNodes, "MaxExpandedNodes", 0);
 153186        RecordValues.Look(chronicler, ref MaxEvaluatedEdges, "MaxEvaluatedEdges", 0);
 153187        RecordValues.Look(chronicler, ref MaxConnectionLegs, "MaxConnectionLegs", 0);
 153188        RecordValues.Look(chronicler, ref MaxTransitionCandidates, "MaxTransitionCandidates", 0);
 153189        RecordValues.Look(chronicler, ref MaxTransitionPairs, "MaxTransitionPairs", 0);
 153190        RecordValues.Look(chronicler, ref MaxStagedLegAttempts, "MaxStagedLegAttempts", 0);
 153191        RecordValues.Look(chronicler, ref MaxTraceIntervals, "MaxTraceIntervals", 0);
 153192        RecordValues.Look(chronicler, ref MaxCoveredVoxelIntervals, "MaxCoveredVoxelIntervals", 0);
 153193        RecordValues.Look(chronicler, ref MaxSimplificationRays, "MaxSimplificationRays", 0);
 153194        RecordValues.Look(chronicler, ref AllowTransitions, "AllowTransitions", false);
 153195        RecordValues.Look(chronicler, ref ExtraIntegrationCost, "ExtraIntegrationCost", Fixed64.Zero);
 153196    }
 197}