| | | 1 | | //======================================================================= |
| | | 2 | | // GridCoveredAddressGeneration.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 System; |
| | | 9 | | using GridForge.Configuration; |
| | | 10 | | |
| | | 11 | | namespace GridForge.Grids.Topology; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Identifies one exact active grid generation eligible for a covered-address query. |
| | | 15 | | /// </summary> |
| | | 16 | | public readonly struct GridCoveredAddressGeneration : IComparable<GridCoveredAddressGeneration> |
| | | 17 | | { |
| | | 18 | | /// <summary>The durable normalized grid identity.</summary> |
| | | 19 | | public GridConfigurationKey ConfigurationKey { get; } |
| | | 20 | | |
| | | 21 | | /// <summary>The recyclable world-local grid slot.</summary> |
| | | 22 | | public ushort GridIndex { get; } |
| | | 23 | | |
| | | 24 | | /// <summary>The exact process-unique grid allocation identity.</summary> |
| | | 25 | | public long GridSpawnToken { get; } |
| | | 26 | | |
| | | 27 | | /// <summary>The last committed sequence applied to this grid generation.</summary> |
| | | 28 | | public ulong GridLastChangeSequence { get; } |
| | | 29 | | |
| | | 30 | | /// <summary>Initializes an exact eligible grid-generation identity.</summary> |
| | | 31 | | public GridCoveredAddressGeneration( |
| | | 32 | | GridConfigurationKey configurationKey, |
| | | 33 | | ushort gridIndex, |
| | | 34 | | long gridSpawnToken, |
| | | 35 | | ulong gridLastChangeSequence) |
| | | 36 | | { |
| | 77 | 37 | | ConfigurationKey = configurationKey; |
| | 77 | 38 | | GridIndex = gridIndex; |
| | 77 | 39 | | GridSpawnToken = gridSpawnToken; |
| | 77 | 40 | | GridLastChangeSequence = gridLastChangeSequence; |
| | 77 | 41 | | } |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Compares durable configuration identity only. Eligible inputs must be strictly ascending by this order. |
| | | 45 | | /// </summary> |
| | | 46 | | public int CompareTo(GridCoveredAddressGeneration other) => |
| | 59 | 47 | | CompareConfigurationKeys(ConfigurationKey, other.ConfigurationKey); |
| | | 48 | | |
| | | 49 | | internal static int CompareConfigurationKeys( |
| | | 50 | | GridConfigurationKey left, |
| | | 51 | | GridConfigurationKey right) |
| | | 52 | | { |
| | 59 | 53 | | int value = left.BoundsMin.X.CompareTo(right.BoundsMin.X); |
| | 94 | 54 | | if (value != 0) return value; |
| | 24 | 55 | | value = left.BoundsMin.Y.CompareTo(right.BoundsMin.Y); |
| | 26 | 56 | | if (value != 0) return value; |
| | 22 | 57 | | value = left.BoundsMin.Z.CompareTo(right.BoundsMin.Z); |
| | 24 | 58 | | if (value != 0) return value; |
| | 20 | 59 | | value = left.BoundsMax.X.CompareTo(right.BoundsMax.X); |
| | 22 | 60 | | if (value != 0) return value; |
| | 18 | 61 | | value = left.BoundsMax.Y.CompareTo(right.BoundsMax.Y); |
| | 20 | 62 | | if (value != 0) return value; |
| | 16 | 63 | | value = left.BoundsMax.Z.CompareTo(right.BoundsMax.Z); |
| | 18 | 64 | | if (value != 0) return value; |
| | 14 | 65 | | value = left.TopologyKind.CompareTo(right.TopologyKind); |
| | 16 | 66 | | if (value != 0) return value; |
| | 12 | 67 | | value = left.TopologyMetrics.CellRadius.CompareTo(right.TopologyMetrics.CellRadius); |
| | 14 | 68 | | if (value != 0) return value; |
| | 10 | 69 | | value = left.TopologyMetrics.CellWidth.CompareTo(right.TopologyMetrics.CellWidth); |
| | 12 | 70 | | if (value != 0) return value; |
| | 8 | 71 | | value = left.TopologyMetrics.LayerHeight.CompareTo(right.TopologyMetrics.LayerHeight); |
| | 10 | 72 | | if (value != 0) return value; |
| | 6 | 73 | | value = left.TopologyMetrics.CellLength.CompareTo(right.TopologyMetrics.CellLength); |
| | 6 | 74 | | return value != 0 |
| | 6 | 75 | | ? value |
| | 6 | 76 | | : left.TopologyMetrics.HexOrientation.CompareTo(right.TopologyMetrics.HexOrientation); |
| | | 77 | | } |
| | | 78 | | } |