| | | 1 | | //======================================================================= |
| | | 2 | | // GuideSampleWorkMeter.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 | | namespace Trailblazer.Pathing; |
| | | 9 | | |
| | | 10 | | /// <summary>Tracks exact bounded work shared by one or more guide samples.</summary> |
| | | 11 | | internal struct GuideSampleWorkMeter |
| | | 12 | | { |
| | | 13 | | private int _remainingCurrentNodeLookupProbes; |
| | | 14 | | private int _remainingCursorLegScans; |
| | | 15 | | private int _remainingCursorRebases; |
| | | 16 | | private int _remainingPortalChecks; |
| | | 17 | | private int _remainingPrismChecks; |
| | | 18 | | private int _remainingTraceIntervals; |
| | | 19 | | private int _remainingLocalRecoveryAttempts; |
| | | 20 | | |
| | | 21 | | internal GuideSampleWorkMeter(GuideSampleWorkBudget budget) |
| | | 22 | | { |
| | 1694 | 23 | | _remainingCurrentNodeLookupProbes = budget.MaxCurrentNodeLookupProbes; |
| | 1694 | 24 | | _remainingCursorLegScans = budget.MaxCursorLegScans; |
| | 1694 | 25 | | _remainingCursorRebases = budget.MaxCursorRebases; |
| | 1694 | 26 | | _remainingPortalChecks = budget.MaxPortalChecks; |
| | 1694 | 27 | | _remainingPrismChecks = budget.MaxPrismChecks; |
| | 1694 | 28 | | _remainingTraceIntervals = budget.MaxTraceIntervals; |
| | 1694 | 29 | | _remainingLocalRecoveryAttempts = budget.MaxLocalRecoveryAttempts; |
| | 1694 | 30 | | } |
| | | 31 | | |
| | | 32 | | internal bool TryConsumeCurrentNodeLookupProbes(int count) => |
| | 14625 | 33 | | TryConsume(ref _remainingCurrentNodeLookupProbes, count); |
| | | 34 | | |
| | | 35 | | internal bool TryConsumeCursorLegScans(int count) => |
| | 3492 | 36 | | TryConsume(ref _remainingCursorLegScans, count); |
| | | 37 | | |
| | | 38 | | internal bool TryConsumeCursorRebases(int count) => |
| | 867 | 39 | | TryConsume(ref _remainingCursorRebases, count); |
| | | 40 | | |
| | | 41 | | internal bool TryConsumePortalChecks(int count) => |
| | 3939 | 42 | | TryConsume(ref _remainingPortalChecks, count); |
| | | 43 | | |
| | | 44 | | internal bool TryConsumePrismChecks(int count) => |
| | 6043 | 45 | | TryConsume(ref _remainingPrismChecks, count); |
| | | 46 | | |
| | | 47 | | internal bool TryConsumeTraceIntervals(int count) => |
| | 1091 | 48 | | TryConsume(ref _remainingTraceIntervals, count); |
| | | 49 | | |
| | | 50 | | internal bool TryConsumeLocalRecoveryAttempts(int count) => |
| | 857 | 51 | | TryConsume(ref _remainingLocalRecoveryAttempts, count); |
| | | 52 | | |
| | | 53 | | internal readonly int GetCurrentNodeLookupAllowance() => |
| | 5896 | 54 | | _remainingCurrentNodeLookupProbes; |
| | | 55 | | |
| | | 56 | | internal readonly int GetTraceIntervalAllowance() => |
| | 744 | 57 | | _remainingTraceIntervals; |
| | | 58 | | |
| | | 59 | | internal readonly int GetCursorLegScanAllowance() => |
| | 123 | 60 | | _remainingCursorLegScans; |
| | | 61 | | |
| | | 62 | | internal readonly int GetPortalCheckAllowance() => |
| | 121 | 63 | | _remainingPortalChecks; |
| | | 64 | | |
| | | 65 | | internal readonly int GetPrismCheckAllowance() => |
| | 122 | 66 | | _remainingPrismChecks; |
| | | 67 | | |
| | | 68 | | private static bool TryConsume(ref int remaining, int count) |
| | | 69 | | { |
| | 30914 | 70 | | if (count > remaining) |
| | 84 | 71 | | return false; |
| | 30830 | 72 | | remaining -= count; |
| | 30830 | 73 | | return true; |
| | | 74 | | } |
| | | 75 | | } |