| | | 1 | | //======================================================================= |
| | | 2 | | // OccupantTicket.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 SwiftCollections.Utility; |
| | | 10 | | |
| | | 11 | | namespace GridForge; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Identifies one occupant registration in a scan-cell bucket. |
| | | 15 | | /// </summary> |
| | | 16 | | public readonly struct OccupantTicket : IEquatable<OccupantTicket> |
| | | 17 | | { |
| | | 18 | | /// <summary> |
| | | 19 | | /// The O(1) lookup slot within the voxel's occupant bucket. |
| | | 20 | | /// </summary> |
| | | 21 | | public int Slot { get; } |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// The process-unique generation assigned to this registration lifetime. |
| | | 25 | | /// </summary> |
| | | 26 | | public long Generation { get; } |
| | | 27 | | |
| | | 28 | | internal OccupantTicket(int slot, long generation) |
| | | 29 | | { |
| | 704 | 30 | | Slot = slot; |
| | 704 | 31 | | Generation = generation; |
| | 704 | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Indicates whether this ticket identifies an allocated occupant registration. |
| | | 36 | | /// </summary> |
| | 8383 | 37 | | public bool IsValid => Slot >= 0 && Generation > 0; |
| | | 38 | | |
| | | 39 | | /// <inheritdoc /> |
| | 17 | 40 | | public bool Equals(OccupantTicket other) => Slot == other.Slot && Generation == other.Generation; |
| | | 41 | | |
| | | 42 | | /// <inheritdoc /> |
| | 2 | 43 | | public override bool Equals(object? obj) => obj is OccupantTicket other && Equals(other); |
| | | 44 | | |
| | | 45 | | /// <inheritdoc /> |
| | 2 | 46 | | public override int GetHashCode() => SwiftHashTools.CombineHashCodes(Slot, Generation.GetHashCode()); |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Compares two occupant tickets for equality. |
| | | 50 | | /// </summary> |
| | 1 | 51 | | public static bool operator ==(OccupantTicket left, OccupantTicket right) => left.Equals(right); |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// Compares two occupant tickets for inequality. |
| | | 55 | | /// </summary> |
| | 1 | 56 | | public static bool operator !=(OccupantTicket left, OccupantTicket right) => !left.Equals(right); |
| | | 57 | | } |