< Summary

Information
Class: Trailblazer.Pathing.NavigationWorkMeter
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Query/NavigationWorkMeter.cs
Line coverage
100%
Covered lines: 135
Uncovered lines: 0
Coverable lines: 135
Total lines: 279
Line coverage: 100%
Branch coverage
100%
Covered branches: 68
Total branches: 68
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Query/NavigationWorkMeter.cs

#LineLine coverage
 1//=======================================================================
 2// NavigationWorkMeter.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;
 9
 10namespace Trailblazer.Pathing;
 11
 12/// <summary>Tracks deterministic work consumed by one complete navigation query.</summary>
 13internal sealed class NavigationWorkMeter
 14{
 15    private NavigationWorkBudget _budget;
 16    private int _lookupReservationFloor;
 17    private int _guideLookupAndCoveredLimit;
 18    private int _guideEdgeAndConnectionLimit;
 19    private int _guidePortalLimit;
 20    private int _guidePrismLimit;
 21
 3617222    internal NavigationWorkMeter(NavigationWorkBudget budget) => Reset(budget);
 23
 24    internal int LookupProbes { get; private set; }
 25
 26    internal int EndpointCandidates { get; private set; }
 27
 28    internal int ExpandedNodes { get; private set; }
 29
 30    internal int EvaluatedEdges { get; private set; }
 31
 32    internal int ConnectionLegs { get; private set; }
 33
 34    internal int TransitionCandidates { get; private set; }
 35
 36    internal int TransitionPairs { get; private set; }
 37
 38    internal int PrimaryVolumeCandidates { get; private set; }
 39
 40    internal int ShortcutVolumeCandidates { get; private set; }
 41
 42    internal long VolumeUnionChecks { get; private set; }
 43
 44    internal int SuccessfulDependencyMerges { get; private set; }
 45
 46    internal int TraceIntervals { get; private set; }
 47
 48    internal int CoveredVoxelIntervals { get; private set; }
 49
 50    internal int SimplificationRays { get; private set; }
 51
 4512852    internal int RemainingLookupProbes => IsGuideSampleBridge
 4512853        ? Math.Min(
 4512854            _budget.MaxLookupProbes - LookupProbes - _lookupReservationFloor,
 4512855            _guideLookupAndCoveredLimit - LookupProbes - CoveredVoxelIntervals)
 4512856        : _budget.MaxLookupProbes - LookupProbes - _lookupReservationFloor;
 57
 58    internal int RemainingEndpointCandidates =>
 537859        _budget.MaxEndpointCandidates - EndpointCandidates;
 60
 690261    internal int RemainingExpandedNodes => _budget.MaxExpandedNodes - ExpandedNodes;
 62
 3899463    internal int RemainingEvaluatedEdges => IsGuideSampleBridge
 3899464        ? Math.Min(
 3899465            _budget.MaxEvaluatedEdges - EvaluatedEdges,
 3899466            _guideEdgeAndConnectionLimit - EvaluatedEdges - ConnectionLegs)
 3899467        : _budget.MaxEvaluatedEdges - EvaluatedEdges;
 68
 65069    internal int RemainingConnectionLegs => IsGuideSampleBridge
 65070        ? Math.Min(
 65071            _budget.MaxConnectionLegs - ConnectionLegs,
 65072            _guideEdgeAndConnectionLimit - EvaluatedEdges - ConnectionLegs)
 65073        : _budget.MaxConnectionLegs - ConnectionLegs;
 74
 75    internal int RemainingTransitionCandidates =>
 178676        _budget.MaxTransitionCandidates - TransitionCandidates;
 77
 22478    internal int RemainingTransitionPairs => _budget.MaxTransitionPairs - TransitionPairs;
 79
 266680    internal int RemainingTraceIntervals => _budget.MaxTraceIntervals - TraceIntervals;
 81
 990082    internal int RemainingCoveredVoxelIntervals => IsGuideSampleBridge
 990083        ? Math.Min(
 990084            _budget.MaxCoveredVoxelIntervals - CoveredVoxelIntervals,
 990085            _guideLookupAndCoveredLimit - LookupProbes - CoveredVoxelIntervals)
 990086        : _budget.MaxCoveredVoxelIntervals - CoveredVoxelIntervals;
 87
 343288    internal long RemainingGridCandidateWork => IsGuideSampleBridge
 343289        ? (long)_guideLookupAndCoveredLimit - LookupProbes - CoveredVoxelIntervals
 343290        : checked((long)RemainingLookupProbes + RemainingCoveredVoxelIntervals);
 91
 10766992    internal bool IsGuideSampleBridge => _guideLookupAndCoveredLimit >= 0;
 93
 94    internal int GuidePortalChecks { get; private set; }
 95
 96    internal int GuidePrismChecks { get; private set; }
 97
 98    internal int RemainingSimplificationRays =>
 32699        _budget.MaxSimplificationRays - SimplificationRays;
 100
 101    internal bool TryConsumeLookupProbes(int count)
 102    {
 32928103        if (count < 0 || count > RemainingLookupProbes)
 16104            return false;
 32912105        LookupProbes += count;
 32912106        return true;
 107    }
 108
 109    internal bool TrySetLookupReservationFloor(int count)
 110    {
 117111        if (count < 0 || count > _budget.MaxLookupProbes - LookupProbes)
 5112            return false;
 112113        _lookupReservationFloor = count;
 112114        return true;
 115    }
 116
 694117    internal void ReleaseLookupReservationFloor() => _lookupReservationFloor = 0;
 118
 119    internal bool TryConsumeEndpointCandidates(int count)
 120    {
 3256121        if (count < 0 || count > RemainingEndpointCandidates)
 2122            return false;
 3254123        EndpointCandidates += count;
 3254124        return true;
 125    }
 126
 127    internal bool TryConsumeExpandedNodes(int count)
 128    {
 6478129        if (count < 0 || count > RemainingExpandedNodes)
 5130            return false;
 6473131        ExpandedNodes += count;
 6473132        return true;
 133    }
 134
 135    internal bool TryConsumeEvaluatedEdges(int count)
 136    {
 38632137        if (count < 0 || count > RemainingEvaluatedEdges)
 12138            return false;
 38620139        EvaluatedEdges += count;
 38620140        return true;
 141    }
 142
 143    internal bool TryConsumeConnectionLegs(int count)
 144    {
 447145        if (count < 0 || count > RemainingConnectionLegs)
 6146            return false;
 441147        ConnectionLegs += count;
 441148        return true;
 149    }
 150
 151    internal bool TryConsumeTransitionCandidates(int count)
 152    {
 1598153        if (count < 0 || count > RemainingTransitionCandidates)
 6154            return false;
 1592155        TransitionCandidates += count;
 1592156        return true;
 157    }
 158
 159    internal bool TryConsumeTransitionPairs(int count)
 160    {
 219161        if (count < 0 || count > RemainingTransitionPairs)
 3162            return false;
 216163        TransitionPairs += count;
 216164        return true;
 165    }
 166
 167    internal void RecordVolumeCandidate(bool isPrimary)
 168    {
 2647169        if (isPrimary)
 1440170            PrimaryVolumeCandidates++;
 171        else
 1207172            ShortcutVolumeCandidates++;
 1207173    }
 174
 2100175    internal void RecordVolumeUnionCheck() => VolumeUnionChecks++;
 176
 177    internal void RecordSuccessfulDependencyMerge() =>
 26178        SuccessfulDependencyMerges++;
 179
 180    internal bool TryConsumeTraceIntervals(int count)
 181    {
 1336182        if (count < 0 || count > RemainingTraceIntervals)
 3183            return false;
 1333184        TraceIntervals += count;
 1333185        return true;
 186    }
 187
 188    internal bool TryConsumeCoveredVoxelIntervals(int count)
 189    {
 3436190        if (count < 0 || count > RemainingCoveredVoxelIntervals)
 3191            return false;
 3433192        CoveredVoxelIntervals += count;
 3433193        return true;
 194    }
 195
 196    internal bool TryConsumeSimplificationRays(int count)
 197    {
 38198        if (count < 0 || count > RemainingSimplificationRays)
 3199            return false;
 35200        SimplificationRays += count;
 35201        return true;
 202    }
 203
 204    internal bool TryConsumeGuidePortalChecks(int count)
 205    {
 87206        if (!IsGuideSampleBridge
 87207            || count < 0
 87208            || count > _guidePortalLimit - GuidePortalChecks)
 209        {
 3210            return false;
 211        }
 84212        GuidePortalChecks += count;
 84213        return true;
 214    }
 215
 216    internal bool TryConsumeGuidePrismChecks(int count)
 217    {
 14218        if (!IsGuideSampleBridge
 14219            || count < 0
 14220            || count > _guidePrismLimit - GuidePrismChecks)
 221        {
 3222            return false;
 223        }
 11224        GuidePrismChecks += count;
 11225        return true;
 226    }
 227
 228    internal void ResetForGuideSample(
 229        int lookupAndCoveredLimit,
 230        int edgeAndConnectionLimit,
 231        int portalLimit,
 232        int prismLimit,
 233        int traceIntervalLimit)
 234    {
 124235        var budget = new NavigationWorkBudget(
 124236            lookupAndCoveredLimit,
 124237            maxEndpointCandidates: 0,
 124238            maxExpandedNodes: 0,
 124239            edgeAndConnectionLimit,
 124240            edgeAndConnectionLimit,
 124241            maxTransitionCandidates: 0,
 124242            maxTransitionPairs: 0,
 124243            maxStagedLegAttempts: 0,
 124244            traceIntervalLimit,
 124245            lookupAndCoveredLimit,
 124246            maxSimplificationRays: 0);
 124247        Reset(budget);
 124248        _guideLookupAndCoveredLimit = lookupAndCoveredLimit;
 124249        _guideEdgeAndConnectionLimit = edgeAndConnectionLimit;
 124250        _guidePortalLimit = portalLimit;
 124251        _guidePrismLimit = prismLimit;
 124252    }
 253
 254    internal void Reset(NavigationWorkBudget budget)
 255    {
 20141256        _budget = budget;
 20141257        LookupProbes = 0;
 20141258        EndpointCandidates = 0;
 20141259        ExpandedNodes = 0;
 20141260        EvaluatedEdges = 0;
 20141261        ConnectionLegs = 0;
 20141262        TransitionCandidates = 0;
 20141263        TransitionPairs = 0;
 20141264        PrimaryVolumeCandidates = 0;
 20141265        ShortcutVolumeCandidates = 0;
 20141266        VolumeUnionChecks = 0;
 20141267        SuccessfulDependencyMerges = 0;
 20141268        TraceIntervals = 0;
 20141269        CoveredVoxelIntervals = 0;
 20141270        SimplificationRays = 0;
 20141271        GuidePortalChecks = 0;
 20141272        GuidePrismChecks = 0;
 20141273        _lookupReservationFloor = 0;
 20141274        _guideLookupAndCoveredLimit = -1;
 20141275        _guideEdgeAndConnectionLimit = -1;
 20141276        _guidePortalLimit = 0;
 20141277        _guidePrismLimit = 0;
 20141278    }
 279}