| | | 1 | | //======================================================================= |
| | | 2 | | // AreaBlocker.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 FixedMathSharp; |
| | | 9 | | using FixedMathSharp.Geometry; |
| | | 10 | | using GridForge.Grids; |
| | | 11 | | using GridForge.Spatial; |
| | | 12 | | |
| | | 13 | | namespace GridForge.Blockers; |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// A manually placed blocker that obstructs a two-dimensional XZ-plane area on one world Y layer. |
| | | 17 | | /// </summary> |
| | | 18 | | public class AreaBlocker : Blocker |
| | | 19 | | { |
| | | 20 | | private readonly FixedBoundArea _blockArea; |
| | | 21 | | private readonly Fixed64 _layerY; |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Initializes a new area blocker bound to the supplied world. |
| | | 25 | | /// </summary> |
| | | 26 | | /// <param name="world">The world whose grids this blocker should affect.</param> |
| | | 27 | | /// <param name="blockArea">The XZ-plane area to block.</param> |
| | | 28 | | /// <param name="layerY">The world Y layer to block. Defaults to zero.</param> |
| | | 29 | | /// <param name="isActive">Flag whether or not blocker is active.</param> |
| | | 30 | | /// <param name="cacheCoveredVoxels">Flag whether or not to cache covered voxels.</param> |
| | | 31 | | public AreaBlocker( |
| | | 32 | | GridWorld world, |
| | | 33 | | FixedBoundArea blockArea, |
| | | 34 | | Fixed64 layerY = default, |
| | | 35 | | bool isActive = true, |
| | 2 | 36 | | bool cacheCoveredVoxels = false) : base(world, isActive, cacheCoveredVoxels) |
| | | 37 | | { |
| | 2 | 38 | | _blockArea = blockArea; |
| | 2 | 39 | | _layerY = layerY; |
| | 2 | 40 | | } |
| | | 41 | | |
| | | 42 | | /// <summary> |
| | | 43 | | /// Initializes a new area blocker from XZ-plane min/max bounds. |
| | | 44 | | /// </summary> |
| | | 45 | | /// <param name="world">The world whose grids this blocker should affect.</param> |
| | | 46 | | /// <param name="boundsMin">The 2D minimum bound whose X component maps to world X and Y component maps to world Z.< |
| | | 47 | | /// <param name="boundsMax">The 2D maximum bound whose X component maps to world X and Y component maps to world Z.< |
| | | 48 | | /// <param name="layerY">The world Y layer to block. Defaults to zero.</param> |
| | | 49 | | /// <param name="isActive">Flag whether or not blocker is active.</param> |
| | | 50 | | /// <param name="cacheCoveredVoxels">Flag whether or not to cache covered voxels.</param> |
| | | 51 | | public AreaBlocker( |
| | | 52 | | GridWorld world, |
| | | 53 | | Vector2d boundsMin, |
| | | 54 | | Vector2d boundsMax, |
| | | 55 | | Fixed64 layerY = default, |
| | | 56 | | bool isActive = true, |
| | | 57 | | bool cacheCoveredVoxels = false) |
| | 1 | 58 | | : this( |
| | 1 | 59 | | world, |
| | 1 | 60 | | FixedBoundArea.FromMinMax(boundsMin, boundsMax), |
| | 1 | 61 | | layerY, |
| | 1 | 62 | | isActive, |
| | 1 | 63 | | cacheCoveredVoxels) |
| | 1 | 64 | | { } |
| | | 65 | | |
| | | 66 | | /// <inheritdoc cref="Blocker.GetBoundsMin"/> |
| | 4 | 67 | | protected override Vector3d GetBoundsMin() => GridPlane2d.ToWorld(_blockArea.Min, _layerY); |
| | | 68 | | |
| | | 69 | | /// <inheritdoc cref="Blocker.GetBoundsMax"/> |
| | 4 | 70 | | protected override Vector3d GetBoundsMax() => GridPlane2d.ToWorld(_blockArea.Max, _layerY); |
| | | 71 | | } |