| | | 1 | | //======================================================================= |
| | | 2 | | // GridEventInfo.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.Configuration; |
| | | 10 | | using GridForge.Spatial; |
| | | 11 | | |
| | | 12 | | namespace GridForge.Grids; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Immutable snapshot describing a grid at the time a world grid notification is raised. |
| | | 16 | | /// </summary> |
| | | 17 | | public readonly struct GridEventInfo |
| | | 18 | | { |
| | | 19 | | /// <summary> |
| | | 20 | | /// The runtime token of the owning <see cref="GridWorld"/> instance. |
| | | 21 | | /// </summary> |
| | | 22 | | public readonly int WorldSpawnToken; |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// The stable slot index assigned to the grid within <see cref="GridWorld.ActiveGrids"/>. |
| | | 26 | | /// </summary> |
| | | 27 | | public readonly ushort GridIndex; |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// The unique spawn token for the specific grid instance occupying <see cref="GridIndex"/>. |
| | | 31 | | /// </summary> |
| | | 32 | | public readonly int GridSpawnToken; |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// The snapped configuration for the grid when the notification was raised. |
| | | 36 | | /// </summary> |
| | | 37 | | public readonly GridConfiguration Configuration; |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// The per-grid version recorded when the notification was raised. |
| | | 41 | | /// </summary> |
| | | 42 | | public readonly uint GridVersion; |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// The reason this grid event was raised. |
| | | 46 | | /// </summary> |
| | | 47 | | public readonly GridEventKind ChangeKind; |
| | | 48 | | |
| | | 49 | | /// <summary> |
| | | 50 | | /// The changed voxel index for voxel-scoped grid events. |
| | | 51 | | /// </summary> |
| | | 52 | | public readonly VoxelIndex VoxelIndex; |
| | | 53 | | |
| | | 54 | | /// <summary> |
| | | 55 | | /// The minimum world-space bounds affected by this event. |
| | | 56 | | /// </summary> |
| | | 57 | | public readonly Vector3d AffectedBoundsMin; |
| | | 58 | | |
| | | 59 | | /// <summary> |
| | | 60 | | /// The maximum world-space bounds affected by this event. |
| | | 61 | | /// </summary> |
| | | 62 | | public readonly Vector3d AffectedBoundsMax; |
| | | 63 | | |
| | | 64 | | /// <summary> |
| | | 65 | | /// The minimum snapped bounds of the grid. |
| | | 66 | | /// </summary> |
| | 13 | 67 | | public readonly Vector3d BoundsMin => Configuration.BoundsMin; |
| | | 68 | | |
| | | 69 | | /// <summary> |
| | | 70 | | /// The maximum snapped bounds of the grid. |
| | | 71 | | /// </summary> |
| | 13 | 72 | | public readonly Vector3d BoundsMax => Configuration.BoundsMax; |
| | | 73 | | |
| | | 74 | | /// <summary> |
| | | 75 | | /// Initializes a new immutable grid event snapshot. |
| | | 76 | | /// </summary> |
| | | 77 | | public GridEventInfo( |
| | | 78 | | int worldSpawnToken, |
| | | 79 | | ushort gridIndex, |
| | | 80 | | int gridSpawnToken, |
| | | 81 | | GridConfiguration configuration, |
| | | 82 | | uint gridVersion, |
| | | 83 | | GridEventKind changeKind = GridEventKind.Unspecified, |
| | | 84 | | VoxelIndex voxelIndex = default, |
| | | 85 | | Vector3d affectedBoundsMin = default, |
| | | 86 | | Vector3d affectedBoundsMax = default) |
| | | 87 | | { |
| | 1851 | 88 | | WorldSpawnToken = worldSpawnToken; |
| | 1851 | 89 | | GridIndex = gridIndex; |
| | 1851 | 90 | | GridSpawnToken = gridSpawnToken; |
| | 1851 | 91 | | Configuration = configuration; |
| | 1851 | 92 | | GridVersion = gridVersion; |
| | 1851 | 93 | | ChangeKind = changeKind; |
| | 1851 | 94 | | VoxelIndex = voxelIndex; |
| | 1851 | 95 | | AffectedBoundsMin = !voxelIndex.IsAllocated && affectedBoundsMin == default && affectedBoundsMax == default |
| | 1851 | 96 | | ? configuration.BoundsMin |
| | 1851 | 97 | | : affectedBoundsMin; |
| | 1851 | 98 | | AffectedBoundsMax = !voxelIndex.IsAllocated && affectedBoundsMin == default && affectedBoundsMax == default |
| | 1851 | 99 | | ? configuration.BoundsMax |
| | 1851 | 100 | | : affectedBoundsMax; |
| | 1851 | 101 | | } |
| | | 102 | | |
| | | 103 | | /// <summary> |
| | | 104 | | /// Creates an exact bounds key from the stored grid configuration. |
| | | 105 | | /// </summary> |
| | 1 | 106 | | public readonly BoundsKey ToBoundsKey() => Configuration.ToBoundsKey(); |
| | | 107 | | } |