using System; using Robust.Shared.Serialization; namespace Robust.Shared.Timing { /// /// Wraps a game tick value. /// [Serializable, NetSerializable] public readonly struct GameTick : IEquatable, IComparable { public static readonly GameTick Zero = new(0); public static readonly GameTick First = new(1); public static readonly GameTick MaxValue = new(uint.MaxValue); public readonly uint Value; /// /// Constructs a new instance of GameTick. /// /// public GameTick(uint value) { Value = value; } /// public bool Equals(GameTick other) { return Value == other.Value; } /// public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) return false; return obj is GameTick other && Equals(other); } /// public override int GetHashCode() { return (int) Value; } /// /// Check for equality by value between two objects. /// public static bool operator ==(GameTick a, GameTick b) { return a.Value == b.Value; } /// /// Check for inequality by value between two objects. /// public static bool operator !=(GameTick a, GameTick b) { return a.Value != b.Value; } /// public int CompareTo(GameTick other) { return Value.CompareTo(other.Value); } public static bool operator >(GameTick a, GameTick b) => a.Value > b.Value; public static bool operator >=(GameTick a, GameTick b) => a.Value >= b.Value; public static bool operator <(GameTick a, GameTick b) => a.Value < b.Value; public static bool operator <=(GameTick a, GameTick b) => a.Value <= b.Value; public static GameTick operator +(GameTick a, uint b) { return new(a.Value + b); } public static GameTick operator -(GameTick a, uint b) { return new(a.Value - b); } /// public override string ToString() { return Value.ToString(); } } }