< Summary

Information
Class: Trailblazer.Navigation.NavigatorGuidedTraversalState
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Navigator/Guidance/NavigatorGuidedTraversalState.cs
Line coverage
98%
Covered lines: 76
Uncovered lines: 1
Coverable lines: 77
Total lines: 191
Line coverage: 98.7%
Branch coverage
81%
Covered branches: 36
Total branches: 44
Branch coverage: 81.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ResolveInitialClimbIntent(...)100%22100%
PrepareFrame(...)100%44100%
SyncFromSteering(...)78.57%141495.65%
TryActivatePendingVolumeExitHandoff(...)81.25%1616100%
SetClimbIntent(...)100%11100%
ResetClimbIntent(...)100%11100%
CaptureRouteTopologyVersion(...)50%22100%
TryClearInactiveClimbIntent(...)83.33%66100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Navigator/Guidance/NavigatorGuidedTraversalState.cs

#LineLine coverage
 1using FixedMathSharp;
 2using System.Runtime.CompilerServices;
 3using Trailblazer.Navigation.Motor;
 4using Trailblazer.Navigation.Steering;
 5using Trailblazer.Pathing;
 6
 7namespace Trailblazer.Navigation;
 8
 9internal static class NavigatorGuidedTraversalState
 10{
 11    public static bool ResolveInitialClimbIntent(
 12        IPathRequest pathRequest,
 13        GuidedVolumeExitHandoff? pendingVolumeExitHandoff,
 14        bool? requestedClimb,
 15        out GuidedClimbIntentMode intentMode)
 16    {
 5117        if (requestedClimb.HasValue)
 18        {
 1319            intentMode = GuidedClimbIntentMode.Explicit;
 1320            return requestedClimb.Value;
 21        }
 22
 3823        intentMode = GuidedClimbIntentMode.Auto;
 3824        return GuidedClimbIntentResolver.Resolve(pathRequest, pendingVolumeExitHandoff);
 25    }
 26
 27    public static void PrepareFrame(
 28        bool isGuided,
 29        ref TrekRequest frameRequest,
 30        NavSteering? steering,
 31        GuidedVolumeExitHandoff? pendingVolumeExitHandoff,
 32        ref bool climbIntent,
 33        ref GuidedClimbIntentMode climbIntentMode,
 34        ref int lastSeenRouteTopologyVersion)
 35    {
 4436        if (!isGuided)
 837            return;
 38
 3639        if (TryClearInactiveClimbIntent(
 3640            ref frameRequest,
 3641            steering,
 3642            pendingVolumeExitHandoff,
 3643            ref climbIntent,
 3644            ref climbIntentMode,
 3645            ref lastSeenRouteTopologyVersion))
 46        {
 447            return;
 48        }
 49
 3250        frameRequest.IsRequestingClimb = climbIntent;
 3251    }
 52
 53    public static void SyncFromSteering(
 54        bool isGuided,
 55        ref TrekRequest frameRequest,
 56        NavSteering? steering,
 57        GuidedVolumeExitHandoff? pendingVolumeExitHandoff,
 58        bool activatedVolumeExitHandoff,
 59        bool handoffRequestedClimb,
 60        ref bool climbIntent,
 61        ref GuidedClimbIntentMode climbIntentMode,
 62        ref int lastSeenRouteTopologyVersion)
 63    {
 3664        if (!isGuided)
 065            return;
 66
 3667        if (TryClearInactiveClimbIntent(
 3668            ref frameRequest,
 3669            steering,
 3670            pendingVolumeExitHandoff,
 3671            ref climbIntent,
 3672            ref climbIntentMode,
 3673            ref lastSeenRouteTopologyVersion))
 74        {
 475            return;
 76        }
 77
 3278        if (climbIntentMode == GuidedClimbIntentMode.Auto
 3279            && steering != null
 3280            && steering.CurrentRouteTopologyVersion != lastSeenRouteTopologyVersion)
 81        {
 2582            bool resolvedRouteRequestsClimb = steering.CurrentRouteRequestsClimbIntent;
 2583            bool shouldDeferHandoffBootstrapClear =
 2584                activatedVolumeExitHandoff
 2585                && handoffRequestedClimb
 2586                && !resolvedRouteRequestsClimb;
 2587            if (!shouldDeferHandoffBootstrapClear)
 88            {
 2189                climbIntent = resolvedRouteRequestsClimb;
 2190                lastSeenRouteTopologyVersion = steering.CurrentRouteTopologyVersion;
 91            }
 92        }
 93
 3294        frameRequest.IsRequestingClimb = climbIntent;
 3295    }
 96
 97    public static bool TryActivatePendingVolumeExitHandoff(
 98        bool isGuided,
 99        TrailblazerWorldContext context,
 100        Vector3d position,
 101        Fixed64 size,
 102        ref TrekRequest frameRequest,
 103        NavSteering? steering,
 104        ref GuidedVolumeExitHandoff? pendingVolumeExitHandoff,
 105        ref bool climbIntent,
 106        GuidedClimbIntentMode climbIntentMode,
 107        ref int lastSeenRouteTopologyVersion,
 108        out bool handoffRequestedClimb)
 109    {
 44110        handoffRequestedClimb = false;
 44111        if (!isGuided
 44112            || pendingVolumeExitHandoff == null
 44113            || steering == null
 44114            || steering.ShouldMove
 44115            || steering.CurrentRequest != null)
 116        {
 32117            return false;
 118        }
 119
 12120        if (!pendingVolumeExitHandoff.TryCreateFollowupRequest(context, position, size, out IPathRequest? followupReques
 12121            || followupRequest == null)
 122        {
 1123            return false;
 124        }
 125
 11126        GuidedVolumeExitHandoff handoff = pendingVolumeExitHandoff;
 11127        pendingVolumeExitHandoff = null;
 128
 11129        steering.ApplyPathRequest(followupRequest, handoff.MovementGroupId);
 11130        CaptureRouteTopologyVersion(steering, ref lastSeenRouteTopologyVersion);
 11131        frameRequest.IsRequestingFlight = false;
 11132        frameRequest.IsRequestingSwim = false;
 11133        handoffRequestedClimb = handoff.IsRequestingClimb;
 11134        if (climbIntentMode == GuidedClimbIntentMode.Auto)
 11135            climbIntent = handoffRequestedClimb;
 136
 11137        frameRequest.IsRequestingClimb = climbIntent;
 11138        return true;
 139    }
 140
 141    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 142    public static void SetClimbIntent(
 143        ref TrekRequest frameRequest,
 144        bool status,
 145        GuidedClimbIntentMode mode,
 146        ref bool climbIntent,
 147        ref GuidedClimbIntentMode climbIntentMode)
 148    {
 1149        climbIntent = status;
 1150        climbIntentMode = mode;
 1151        frameRequest.IsRequestingClimb = status;
 1152    }
 153
 154    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 155    public static void ResetClimbIntent(
 156        ref bool climbIntent,
 157        ref GuidedClimbIntentMode climbIntentMode,
 158        ref int lastSeenRouteTopologyVersion)
 159    {
 30160        climbIntent = false;
 30161        climbIntentMode = GuidedClimbIntentMode.Auto;
 30162        lastSeenRouteTopologyVersion = 0;
 30163    }
 164
 165    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 166    public static void CaptureRouteTopologyVersion(
 167        NavSteering? steering,
 168        ref int lastSeenRouteTopologyVersion)
 169    {
 62170        lastSeenRouteTopologyVersion = steering?.CurrentRouteTopologyVersion ?? 0;
 62171    }
 172
 173    private static bool TryClearInactiveClimbIntent(
 174        ref TrekRequest frameRequest,
 175        NavSteering? steering,
 176        GuidedVolumeExitHandoff? pendingVolumeExitHandoff,
 177        ref bool climbIntent,
 178        ref GuidedClimbIntentMode climbIntentMode,
 179        ref int lastSeenRouteTopologyVersion)
 180    {
 72181        if (steering?.CurrentRequest != null
 72182            || pendingVolumeExitHandoff != null)
 183        {
 64184            return false;
 185        }
 186
 8187        ResetClimbIntent(ref climbIntent, ref climbIntentMode, ref lastSeenRouteTopologyVersion);
 8188        frameRequest.IsRequestingClimb = false;
 8189        return true;
 190    }
 191}

Methods/Properties

ResolveInitialClimbIntent(Trailblazer.Pathing.IPathRequest,Trailblazer.Navigation.GuidedVolumeExitHandoff,System.Nullable`1<System.Boolean>,Trailblazer.Navigation.GuidedClimbIntentMode&)
PrepareFrame(System.Boolean,Trailblazer.Navigation.Motor.TrekRequest&,Trailblazer.Navigation.Steering.NavSteering,Trailblazer.Navigation.GuidedVolumeExitHandoff,System.Boolean&,Trailblazer.Navigation.GuidedClimbIntentMode&,System.Int32&)
SyncFromSteering(System.Boolean,Trailblazer.Navigation.Motor.TrekRequest&,Trailblazer.Navigation.Steering.NavSteering,Trailblazer.Navigation.GuidedVolumeExitHandoff,System.Boolean,System.Boolean,System.Boolean&,Trailblazer.Navigation.GuidedClimbIntentMode&,System.Int32&)
TryActivatePendingVolumeExitHandoff(System.Boolean,Trailblazer.TrailblazerWorldContext,FixedMathSharp.Vector3d,FixedMathSharp.Fixed64,Trailblazer.Navigation.Motor.TrekRequest&,Trailblazer.Navigation.Steering.NavSteering,Trailblazer.Navigation.GuidedVolumeExitHandoff&,System.Boolean&,Trailblazer.Navigation.GuidedClimbIntentMode,System.Int32&,System.Boolean&)
SetClimbIntent(Trailblazer.Navigation.Motor.TrekRequest&,System.Boolean,Trailblazer.Navigation.GuidedClimbIntentMode,System.Boolean&,Trailblazer.Navigation.GuidedClimbIntentMode&)
ResetClimbIntent(System.Boolean&,Trailblazer.Navigation.GuidedClimbIntentMode&,System.Int32&)
CaptureRouteTopologyVersion(Trailblazer.Navigation.Steering.NavSteering,System.Int32&)
TryClearInactiveClimbIntent(Trailblazer.Navigation.Motor.TrekRequest&,Trailblazer.Navigation.Steering.NavSteering,Trailblazer.Navigation.GuidedVolumeExitHandoff,System.Boolean&,Trailblazer.Navigation.GuidedClimbIntentMode&,System.Int32&)