< Summary

Information
Class: Trailblazer.Pathing.TrailblazerGuideService
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Search/Guide/TrailblazerGuideService.cs
Line coverage
100%
Covered lines: 92
Uncovered lines: 0
Coverable lines: 92
Total lines: 242
Line coverage: 100%
Branch coverage
91%
Covered branches: 11
Total branches: 12
Branch coverage: 91.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Pathing/Search/Guide/TrailblazerGuideService.cs

#LineLine coverage
 1using System;
 2using System.Diagnostics.CodeAnalysis;
 3
 4namespace Trailblazer.Pathing;
 5
 6/// <summary>
 7/// Context-owned API for guide request, return, cache invalidation, and cache diagnostics.
 8/// </summary>
 9public sealed class TrailblazerGuideService
 10{
 11    private readonly TrailblazerWorldContext _context;
 12    private readonly PathingWorldState _state;
 13
 96114    internal TrailblazerGuideService(TrailblazerWorldContext context, PathingWorldState state)
 15    {
 96116        _context = context;
 96117        _state = state;
 96118    }
 19
 20    /// <inheritdoc cref="PathGuideFactory.TotalAStarGuideCount"/>
 21    public int TotalAStarGuideCount
 22    {
 23        get
 24        {
 925            using (EnterUsableState())
 726                return PathGuideFactory.TotalAStarGuideCount;
 727        }
 28    }
 29
 30    /// <inheritdoc cref="PathGuideFactory.InUseAStarGuideCount"/>
 31    public int InUseAStarGuideCount
 32    {
 33        get
 34        {
 835            using (EnterUsableState())
 836                return PathGuideFactory.InUseAStarGuideCount;
 837        }
 38    }
 39
 40    /// <inheritdoc cref="PathGuideFactory.TotalFlowGuideCount"/>
 41    public int TotalFlowGuideCount
 42    {
 43        get
 44        {
 245            using (EnterUsableState())
 246                return PathGuideFactory.TotalFlowGuideCount;
 247        }
 48    }
 49
 50    /// <inheritdoc cref="PathGuideFactory.InUseFlowGuideCount"/>
 51    public int InUseFlowGuideCount
 52    {
 53        get
 54        {
 155            using (EnterUsableState())
 156                return PathGuideFactory.InUseFlowGuideCount;
 157        }
 58    }
 59
 60    /// <inheritdoc cref="PathGuideFactory.TotalVolumeGuideCount"/>
 61    public int TotalVolumeGuideCount
 62    {
 63        get
 64        {
 665            using (EnterUsableState())
 666                return PathGuideFactory.TotalVolumeGuideCount;
 667        }
 68    }
 69
 70    /// <inheritdoc cref="PathGuideFactory.InUseVolumeGuideCount"/>
 71    public int InUseVolumeGuideCount
 72    {
 73        get
 74        {
 175            using (EnterUsableState())
 176                return PathGuideFactory.InUseVolumeGuideCount;
 177        }
 78    }
 79
 80    /// <inheritdoc cref="PathGuideFactory.TotalHybridRoutePlanCount"/>
 81    public int TotalHybridRoutePlanCount
 82    {
 83        get
 84        {
 285            using (EnterUsableState())
 286                return PathGuideFactory.TotalHybridRoutePlanCount;
 287        }
 88    }
 89
 90    /// <inheritdoc cref="PathGuideFactory.InUseHybridRoutePlanCount"/>
 91    public int InUseHybridRoutePlanCount
 92    {
 93        get
 94        {
 195            using (EnterUsableState())
 196                return PathGuideFactory.InUseHybridRoutePlanCount;
 197        }
 98    }
 99
 100    /// <inheritdoc cref="PathGuideFactory.IsPooling"/>
 101    public bool IsPooling
 102    {
 103        get
 104        {
 1105            using (EnterUsableState())
 1106                return PathGuideFactory.IsPooling;
 1107        }
 108    }
 109
 110    /// <inheritdoc cref="PathGuideFactory.AnyInUse"/>
 111    public bool AnyInUse
 112    {
 113        get
 114        {
 2115            using (EnterUsableState())
 2116                return PathGuideFactory.AnyInUse;
 2117        }
 118    }
 119
 120    /// <summary>
 121    /// Requests a typed guide for the supplied validated path request.
 122    /// </summary>
 123    public bool RequestGuide<T>(IPathRequest request, [NotNullWhen(true)] out T? result)
 124        where T : class, IGuide
 125    {
 21126        if (!IsRequestOwnedByThisContext(request))
 127        {
 1128            result = null;
 1129            return false;
 130        }
 131
 20132        using (EnterUsableState())
 20133            return PathGuideFactory.RequestGuide(request, out result);
 20134    }
 135
 136    /// <inheritdoc cref="PathGuideFactory.RequestGuide(IPathRequest,out IGuide?)"/>
 137    public bool RequestGuide(IPathRequest request, [NotNullWhen(true)] out IGuide? result)
 138    {
 66139        if (!IsRequestOwnedByThisContext(request))
 140        {
 2141            result = null;
 2142            return false;
 143        }
 144
 64145        using (EnterUsableState())
 64146            return PathGuideFactory.RequestGuide(request, out result);
 64147    }
 148
 149    /// <inheritdoc cref="PathGuideFactory.ReturnGuide(IGuide?,bool)"/>
 150    public void ReturnGuide(IGuide? guide, bool dispose = false)
 151    {
 30152        if (guide == null)
 1153            return;
 154
 29155        using (EnterUsableState())
 29156            PathGuideFactory.ReturnGuide(guide, dispose);
 28157    }
 158
 159    /// <inheritdoc cref="PathGuideFactory.InvalidateCacheFor(string)"/>
 160    public void InvalidateCacheFor(string chartKey)
 161    {
 2162        using (EnterUsableState())
 2163            PathGuideFactory.InvalidateCacheFor(chartKey);
 2164    }
 165
 166    /// <inheritdoc cref="PathGuideFactory.FlushCache(bool)"/>
 167    public void FlushCache(bool force = false)
 168    {
 1169        using (EnterUsableState())
 1170            PathGuideFactory.FlushCache(force);
 1171    }
 172
 173    internal void CullExpiredGuides(int currentFrame)
 174    {
 2299175        using (EnterUsableState())
 2299176            PathGuideFactory.CullExpiredGuides(currentFrame);
 2299177    }
 178
 179    internal void InvalidateVolumeCache()
 180    {
 2181        using (EnterUsableState())
 2182            PathGuideFactory.InvalidateVolumeCache();
 2183    }
 184
 185    internal SolidPartitionReachability.SolidPartitionReachabilityStats CaptureReachabilityStats()
 186    {
 8187        using (EnterUsableState())
 8188            return SolidPartitionReachability.CaptureStats();
 8189    }
 190
 191    internal bool TrySeedAStarCacheForBenchmark(int requestKey, string[] chartKeys, bool checkout)
 192    {
 5193        using (EnterUsableState())
 5194            return PathGuideFactory.TrySeedAStarCacheForBenchmark(requestKey, chartKeys, checkout);
 5195    }
 196
 197    internal bool TrySeedFlowFieldCacheForBenchmark(int requestKey, string[] chartKeys, bool checkout)
 198    {
 1199        using (EnterUsableState())
 1200            return PathGuideFactory.TrySeedFlowFieldCacheForBenchmark(requestKey, chartKeys, checkout);
 1201    }
 202
 203    internal bool TrySeedVolumeCacheForBenchmark(int requestKey, string[] chartKeys, bool checkout)
 204    {
 3205        using (EnterUsableState())
 3206            return PathGuideFactory.TrySeedVolumeCacheForBenchmark(requestKey, chartKeys, checkout);
 3207    }
 208
 209    internal bool TrySeedHybridRoutePlanCacheForBenchmark(int requestKey, string[] chartKeys, bool checkout)
 210    {
 1211        using (EnterUsableState())
 212        {
 1213            return PathGuideFactory.TrySeedHybridRoutePlanCacheForBenchmark(
 1214                requestKey,
 1215                chartKeys,
 1216                checkout);
 217        }
 1218    }
 219
 220    internal int CountIndexedCacheEntriesForBenchmark(string chartKey)
 221    {
 1222        using (EnterUsableState())
 1223            return PathGuideFactory.CountIndexedCacheEntriesForBenchmark(chartKey);
 1224    }
 225
 226    private IDisposable EnterUsableState()
 227    {
 2469228        EnsureUsable();
 2467229        return PathManager.EnterState(_state);
 230    }
 231
 232    private void EnsureUsable()
 233    {
 2469234        if (_context.IsDisposed)
 1235            throw new ObjectDisposedException(nameof(TrailblazerWorldContext));
 2468236        if (!_context.World.IsActive)
 1237            throw new InvalidOperationException("TrailblazerGuideService is bound to an inactive GridWorld.");
 2467238    }
 239
 240    private bool IsRequestOwnedByThisContext(IPathRequest request) =>
 87241        request != null && ReferenceEquals(request.Context, _context);
 242}