using FishNet.Serializing; using GameKit.Utilities; namespace FishNet.Managing.Timing { public struct PreciseTick { /// /// The current tick. /// public uint Tick; /// /// Percentage into the next tick. /// public double Percent; public PreciseTick(uint tick, double percent) { Tick = tick; Percent = percent; } /// /// Prints PreciseTick information as a string. /// /// public override string ToString() => $"Tick {Tick}, Percent {Percent.ToString("000")}"; } public static class PreciseTickSerializer { public static void WritePreciseTick(this Writer writer, PreciseTick value) { writer.WriteTickUnpacked(value.Tick); /* No reason percent should exist beyond these values, but better to be safe. * There is also no double clamp in Unity so... */ double percent = Maths.ClampDouble(value.Percent, 0d, 1f); byte percentByte = (byte)(percent * 100); writer.WriteByte(percentByte); } public static PreciseTick ReadPreciseTick(this Reader reader) { uint tick = reader.ReadTickUnpacked(); byte percentByte = reader.ReadByte(); double percent = Maths.ClampDouble((percentByte / 100f), 0d, 1d); return new PreciseTick(tick, percent); } } }