| | | 1 | | using GridForge.Grids; |
| | | 2 | | using GridForge.Spatial; |
| | | 3 | | using System; |
| | | 4 | | |
| | | 5 | | namespace Trailblazer.Pathing; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Context-owned API for host-configured raw-volume medium rules. |
| | | 9 | | /// </summary> |
| | | 10 | | public sealed class TrailblazerVolumeRulesService |
| | | 11 | | { |
| | | 12 | | private readonly TrailblazerWorldContext _context; |
| | | 13 | | private readonly PathingWorldState _state; |
| | | 14 | | |
| | 961 | 15 | | internal TrailblazerVolumeRulesService(TrailblazerWorldContext context, PathingWorldState state) |
| | | 16 | | { |
| | 961 | 17 | | _context = context; |
| | 961 | 18 | | _state = state; |
| | 961 | 19 | | } |
| | | 20 | | |
| | | 21 | | /// <inheritdoc cref="VolumeMediumRules.HasGasVoxelRule"/> |
| | | 22 | | public bool HasGasVoxelRule |
| | | 23 | | { |
| | | 24 | | get |
| | | 25 | | { |
| | 9 | 26 | | EnsureUsable(); |
| | 7 | 27 | | using (PathManager.EnterState(_state)) |
| | 7 | 28 | | return VolumeMediumRules.HasGasVoxelRule; |
| | 7 | 29 | | } |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | /// <inheritdoc cref="VolumeMediumRules.HasLiquidVoxelRule"/> |
| | | 33 | | public bool HasLiquidVoxelRule |
| | | 34 | | { |
| | | 35 | | get |
| | | 36 | | { |
| | 4 | 37 | | EnsureUsable(); |
| | 4 | 38 | | using (PathManager.EnterState(_state)) |
| | 4 | 39 | | return VolumeMediumRules.HasLiquidVoxelRule; |
| | 4 | 40 | | } |
| | | 41 | | } |
| | | 42 | | |
| | | 43 | | internal int RegistryVersion |
| | | 44 | | { |
| | | 45 | | get |
| | | 46 | | { |
| | 2 | 47 | | EnsureUsable(); |
| | 2 | 48 | | using (PathManager.EnterState(_state)) |
| | 2 | 49 | | return VolumeMediumRules.RegistryVersion; |
| | 2 | 50 | | } |
| | | 51 | | } |
| | | 52 | | |
| | | 53 | | /// <inheritdoc cref="VolumeMediumRules.SetGasVoxelPartition{TPartition}"/> |
| | | 54 | | public void SetGasVoxelPartition<TPartition>() |
| | | 55 | | where TPartition : class, IVoxelPartition |
| | | 56 | | { |
| | 1 | 57 | | EnsureUsable(); |
| | 1 | 58 | | using (PathManager.EnterState(_state)) |
| | 1 | 59 | | VolumeMediumRules.SetGasVoxelPartition<TPartition>(); |
| | 1 | 60 | | } |
| | | 61 | | |
| | | 62 | | /// <inheritdoc cref="VolumeMediumRules.SetGasVoxelRule(VolumeVoxelRule)"/> |
| | | 63 | | public void SetGasVoxelRule(VolumeVoxelRule rule) |
| | | 64 | | { |
| | 3 | 65 | | EnsureUsable(); |
| | 3 | 66 | | using (PathManager.EnterState(_state)) |
| | 3 | 67 | | VolumeMediumRules.SetGasVoxelRule(rule); |
| | 3 | 68 | | } |
| | | 69 | | |
| | | 70 | | /// <inheritdoc cref="VolumeMediumRules.ClearGasVoxelRule"/> |
| | | 71 | | public void ClearGasVoxelRule() |
| | | 72 | | { |
| | 1 | 73 | | EnsureUsable(); |
| | 1 | 74 | | using (PathManager.EnterState(_state)) |
| | 1 | 75 | | VolumeMediumRules.ClearGasVoxelRule(); |
| | 1 | 76 | | } |
| | | 77 | | |
| | | 78 | | /// <inheritdoc cref="VolumeMediumRules.SetLiquidVoxelPartition{TPartition}"/> |
| | | 79 | | public void SetLiquidVoxelPartition<TPartition>() |
| | | 80 | | where TPartition : class, IVoxelPartition |
| | | 81 | | { |
| | 1 | 82 | | EnsureUsable(); |
| | 1 | 83 | | using (PathManager.EnterState(_state)) |
| | 1 | 84 | | VolumeMediumRules.SetLiquidVoxelPartition<TPartition>(); |
| | 1 | 85 | | } |
| | | 86 | | |
| | | 87 | | /// <inheritdoc cref="VolumeMediumRules.SetLiquidVoxelRule(VolumeVoxelRule)"/> |
| | | 88 | | public void SetLiquidVoxelRule(VolumeVoxelRule rule) |
| | | 89 | | { |
| | 1 | 90 | | EnsureUsable(); |
| | 1 | 91 | | using (PathManager.EnterState(_state)) |
| | 1 | 92 | | VolumeMediumRules.SetLiquidVoxelRule(rule); |
| | 1 | 93 | | } |
| | | 94 | | |
| | | 95 | | /// <inheritdoc cref="VolumeMediumRules.ClearLiquidVoxelRule"/> |
| | | 96 | | public void ClearLiquidVoxelRule() |
| | | 97 | | { |
| | 1 | 98 | | EnsureUsable(); |
| | 1 | 99 | | using (PathManager.EnterState(_state)) |
| | 1 | 100 | | VolumeMediumRules.ClearLiquidVoxelRule(); |
| | 1 | 101 | | } |
| | | 102 | | |
| | | 103 | | internal bool IsConfigured(TraversalMedium medium) |
| | | 104 | | { |
| | 3 | 105 | | EnsureUsable(); |
| | 3 | 106 | | using (PathManager.EnterState(_state)) |
| | 3 | 107 | | return VolumeMediumRules.IsConfigured(medium); |
| | 3 | 108 | | } |
| | | 109 | | |
| | | 110 | | internal bool Matches(Voxel voxel, TraversalMedium medium) |
| | | 111 | | { |
| | 4 | 112 | | EnsureUsable(); |
| | 4 | 113 | | using (PathManager.EnterState(_state)) |
| | 4 | 114 | | return VolumeMediumRules.Matches(voxel, medium); |
| | 4 | 115 | | } |
| | | 116 | | |
| | | 117 | | private void EnsureUsable() |
| | | 118 | | { |
| | 30 | 119 | | if (_context.IsDisposed) |
| | 1 | 120 | | throw new ObjectDisposedException(nameof(TrailblazerWorldContext)); |
| | 29 | 121 | | if (!_context.World.IsActive) |
| | 1 | 122 | | throw new InvalidOperationException("TrailblazerVolumeRulesService is bound to an inactive GridWorld."); |
| | 28 | 123 | | } |
| | | 124 | | } |