| | | 1 | | //======================================================================= |
| | | 2 | | // GridDiagnosticQuery.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 GridForge.Grids.Storage; |
| | | 10 | | using GridForge.Grids.Topology; |
| | | 11 | | |
| | | 12 | | namespace GridForge.Diagnostics; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Immutable filter and budget settings for a diagnostic cell query. |
| | | 16 | | /// </summary> |
| | | 17 | | public readonly struct GridDiagnosticQuery |
| | | 18 | | { |
| | | 19 | | /// <summary> |
| | | 20 | | /// Default maximum number of diagnostic cells returned by a single query. |
| | | 21 | | /// </summary> |
| | | 22 | | public const int DefaultMaxCells = 65536; |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Optional world-local grid slot filter. |
| | | 26 | | /// </summary> |
| | | 27 | | public readonly ushort? GridIndex; |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Optional topology filter. |
| | | 31 | | /// </summary> |
| | | 32 | | public readonly GridTopologyKind? TopologyKind; |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Optional storage-kind filter. |
| | | 36 | | /// </summary> |
| | | 37 | | public readonly GridStorageKind? StorageKind; |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Selects whether the query should return physical cells, missing sparse |
| | | 41 | | /// address cells, or both. |
| | | 42 | | /// </summary> |
| | | 43 | | public readonly GridDiagnosticAddressMode AddressMode; |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// State flags that a returned cell must contain. |
| | | 47 | | /// </summary> |
| | | 48 | | public readonly GridDiagnosticCellState RequiredStates; |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// State flags that exclude a cell from the result. |
| | | 52 | | /// </summary> |
| | | 53 | | public readonly GridDiagnosticCellState ExcludedStates; |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Optional world-space minimum bounds for the query. |
| | | 57 | | /// </summary> |
| | | 58 | | public readonly Vector3d? BoundsMin; |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Optional world-space maximum bounds for the query. |
| | | 62 | | /// </summary> |
| | | 63 | | public readonly Vector3d? BoundsMax; |
| | | 64 | | |
| | | 65 | | /// <summary> |
| | | 66 | | /// Maximum number of cells this query may return before it is stopped. |
| | | 67 | | /// </summary> |
| | | 68 | | public readonly int MaxCells; |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// Allows missing sparse address-space queries to scan the whole grid |
| | | 72 | | /// address space when no bounds are supplied. |
| | | 73 | | /// </summary> |
| | | 74 | | public readonly bool AllowFullAddressSpaceScan; |
| | | 75 | | |
| | | 76 | | /// <summary> |
| | | 77 | | /// Initializes a diagnostic query. |
| | | 78 | | /// </summary> |
| | | 79 | | public GridDiagnosticQuery( |
| | | 80 | | ushort? gridIndex = null, |
| | | 81 | | GridTopologyKind? topologyKind = null, |
| | | 82 | | GridStorageKind? storageKind = null, |
| | | 83 | | GridDiagnosticAddressMode addressMode = GridDiagnosticAddressMode.PhysicalOnly, |
| | | 84 | | GridDiagnosticCellState requiredStates = GridDiagnosticCellState.None, |
| | | 85 | | GridDiagnosticCellState excludedStates = GridDiagnosticCellState.None, |
| | | 86 | | Vector3d? boundsMin = null, |
| | | 87 | | Vector3d? boundsMax = null, |
| | | 88 | | int maxCells = DefaultMaxCells, |
| | | 89 | | bool allowFullAddressSpaceScan = false) |
| | | 90 | | { |
| | 67 | 91 | | GridIndex = gridIndex; |
| | 67 | 92 | | TopologyKind = topologyKind; |
| | 67 | 93 | | StorageKind = storageKind; |
| | 67 | 94 | | AddressMode = addressMode; |
| | 67 | 95 | | RequiredStates = requiredStates; |
| | 67 | 96 | | ExcludedStates = excludedStates; |
| | 67 | 97 | | BoundsMin = boundsMin; |
| | 67 | 98 | | BoundsMax = boundsMax; |
| | 67 | 99 | | MaxCells = maxCells > 0 ? maxCells : DefaultMaxCells; |
| | 67 | 100 | | AllowFullAddressSpaceScan = allowFullAddressSpaceScan; |
| | 67 | 101 | | } |
| | | 102 | | |
| | | 103 | | /// <summary> |
| | | 104 | | /// Creates a query that returns physical cells from all active grids. |
| | | 105 | | /// </summary> |
| | 39 | 106 | | public static GridDiagnosticQuery AllPhysical() => new GridDiagnosticQuery(maxCells: DefaultMaxCells); |
| | | 107 | | |
| | | 108 | | /// <summary> |
| | | 109 | | /// Creates a physical-cell query for one world-local grid slot. |
| | | 110 | | /// </summary> |
| | 3 | 111 | | public static GridDiagnosticQuery ForGrid(ushort gridIndex) => new(gridIndex: gridIndex); |
| | | 112 | | |
| | | 113 | | /// <summary> |
| | | 114 | | /// Creates a physical-cell query clipped to world-space bounds. |
| | | 115 | | /// </summary> |
| | 4 | 116 | | public static GridDiagnosticQuery ForBounds(Vector3d min, Vector3d max) => new( |
| | 4 | 117 | | boundsMin: min, |
| | 4 | 118 | | boundsMax: max); |
| | | 119 | | } |