using FishNet.Serializing; using GameKit.Dependencies.Utilities; namespace FishNet.Managing.Timing { public struct PreciseTick { /// /// The current tick. /// public uint Tick; /// /// Percentage of the tick returned between 0d and 1d. /// public double PercentAsDouble; /// /// Percentage of the tick returned between 0 and 100. /// public byte PercentAsByte; /// /// Creates a precise tick where the percentage is a byte between 0 and 100. /// public PreciseTick(uint tick, byte percentAsByte) { Tick = tick; PercentAsByte = percentAsByte; PercentAsDouble = (percentAsByte / 100d); } /// /// Creates a precise tick where the percentage is a double between 0d and 1d. /// public PreciseTick(uint tick, double percent) { Tick = tick; PercentAsByte = (byte)(percent * 100d); PercentAsDouble = percent; } /// /// Prints PreciseTick information as a string. /// /// public override string ToString() => $"Tick {Tick}, Percent {PercentAsByte.ToString("000")}"; } public static class PreciseTickSerializer { public static void WritePreciseTick(this Writer writer, PreciseTick value) { writer.WriteTickUnpacked(value.Tick); writer.WriteByte(value.PercentAsByte); } public static PreciseTick ReadPreciseTick(this Reader reader) { uint tick = reader.ReadTickUnpacked(); byte percentByte = reader.ReadByte(); return new PreciseTick(tick, percentByte); } } }