| | | 1 | | using GridForge.Spatial; |
| | | 2 | | using SwiftCollections; |
| | | 3 | | using System; |
| | | 4 | | using System.Threading; |
| | | 5 | | |
| | | 6 | | namespace Trailblazer.Pathing; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Stores traversal transition registrations and lookup indexes for one pathing context. |
| | | 10 | | /// </summary> |
| | | 11 | | internal sealed class TraversalTransitionRegistryState : IDisposable |
| | | 12 | | { |
| | | 13 | | private bool _disposed; |
| | | 14 | | |
| | | 15 | | internal SwiftDictionary<string, RegisteredTraversalTransition> Transitions { get; } = |
| | 961 | 16 | | new(8, StringComparer.Ordinal); |
| | | 17 | | |
| | | 18 | | internal SwiftHashSet<string> ActiveTransitionIds { get; } = new(); |
| | | 19 | | |
| | | 20 | | internal SwiftHashSet<string> SuppressedManagedTransitionIds { get; } = new(); |
| | | 21 | | |
| | | 22 | | internal SwiftDictionary<WorldVoxelIndex, SwiftHashSet<string>> ManagedManualTransitionIdsByVoxel { get; } = new(); |
| | | 23 | | |
| | | 24 | | internal SwiftDictionary<WorldVoxelIndex, SwiftHashSet<string>> OutgoingTransitionIdsByVoxel { get; } = new(); |
| | | 25 | | |
| | | 26 | | internal SwiftDictionary<WorldVoxelIndex, SwiftHashSet<string>> IncomingTransitionIdsByVoxel { get; } = new(); |
| | | 27 | | |
| | | 28 | | internal SwiftDictionary<int, SwiftHashSet<string>> TransitionIdsBySourceGrid { get; } = new(); |
| | | 29 | | |
| | | 30 | | internal SwiftDictionary<int, SwiftHashSet<string>> TransitionIdsByDestinationGrid { get; } = new(); |
| | | 31 | | |
| | | 32 | | internal ReaderWriterLockSlim TransitionLock { get; } = new(); |
| | | 33 | | |
| | | 34 | | internal int RegistryVersion; |
| | | 35 | | |
| | | 36 | | internal int RegistrationOrder; |
| | | 37 | | |
| | 961 | 38 | | internal TraversalTransition[] AllTransitionsSnapshot = Array.Empty<TraversalTransition>(); |
| | | 39 | | |
| | | 40 | | internal void IncrementRegistryVersion() |
| | | 41 | | { |
| | 1898 | 42 | | Interlocked.Increment(ref RegistryVersion); |
| | 1898 | 43 | | } |
| | | 44 | | |
| | | 45 | | public void Dispose() |
| | | 46 | | { |
| | 961 | 47 | | if (_disposed) |
| | 0 | 48 | | return; |
| | | 49 | | |
| | 961 | 50 | | _disposed = true; |
| | 961 | 51 | | TransitionLock.Dispose(); |
| | 961 | 52 | | } |
| | | 53 | | } |