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