| | | 1 | | //======================================================================= |
| | | 2 | | // NavigationAStarPayloadLease.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 | | using System; |
| | | 9 | | using System.Threading; |
| | | 10 | | |
| | | 11 | | namespace Trailblazer.Pathing; |
| | | 12 | | |
| | | 13 | | /// <summary>Owns one active reference to an immutable A* payload.</summary> |
| | | 14 | | internal sealed class NavigationAStarPayloadLease : IDisposable |
| | | 15 | | { |
| | | 16 | | private readonly NavigationAStarPayloadCache _owner; |
| | | 17 | | private NavigationAStarPayloadCache.CacheEntry? _entry; |
| | | 18 | | |
| | 110 | 19 | | internal NavigationAStarPayloadLease(NavigationAStarPayloadCache owner) |
| | | 20 | | { |
| | 110 | 21 | | _owner = owner; |
| | 110 | 22 | | } |
| | | 23 | | |
| | 6594 | 24 | | internal NavigationAStarPayload Payload => _entry?.Payload |
| | 6594 | 25 | | ?? throw new ObjectDisposedException(nameof(NavigationAStarPayloadLease)); |
| | | 26 | | |
| | | 27 | | internal NavigationAStarPayloadLease? NextPooled { get; set; } |
| | | 28 | | |
| | | 29 | | internal void Bind(NavigationAStarPayloadCache.CacheEntry entry) |
| | | 30 | | { |
| | 1093 | 31 | | _entry = entry; |
| | 1093 | 32 | | } |
| | | 33 | | |
| | | 34 | | internal NavigationAStarPayloadCache.CacheEntry? DetachEntry() => |
| | 1074 | 35 | | Interlocked.Exchange(ref _entry, null); |
| | | 36 | | |
| | 1074 | 37 | | public void Dispose() => _owner.Return(this); |
| | | 38 | | } |