diff --git a/source/InterpolationTime.cs b/source/InterpolationTime.cs index a8fb1e6..fef5543 100644 --- a/source/InterpolationTime.cs +++ b/source/InterpolationTime.cs @@ -165,7 +165,10 @@ public void OnUpdate(float deltaTime) /// public void OnMessage(float serverTime) { - logger.Assert(serverTime > _latestServerTime, $"Received message out of order. Server Time: {serverTime} vs New Time: {_latestServerTime}"); + // only check this if we are intialized + if (intialized) + logger.Assert(serverTime > _latestServerTime, $"Received message out of order. Server Time: {serverTime} vs New Time: {_latestServerTime}"); + _latestServerTime = serverTime; // If this is the first message, set the client time to the server difference. @@ -198,6 +201,16 @@ public void OnMessage(float serverTime) if (logger.LogEnabled()) logger.Log($"st: {serverTime:0.00}, ct: {_clientTime:0.00}, diff: {diff * 1000:0.0}, wanted: {diffAvg.Value * 1000:0.0}, scale: {clientScaleTime}"); } + /// + /// Call this when start new client to reset timer + /// + public void Reset() + { + // mark this so first server method will call InitNew + intialized = false; + _latestServerTime = 0; + } + /// /// Initializes and resets the system. /// diff --git a/source/SyncPositionSystem.cs b/source/SyncPositionSystem.cs index 5b8e2d2..a264d0f 100644 --- a/source/SyncPositionSystem.cs +++ b/source/SyncPositionSystem.cs @@ -187,6 +187,8 @@ private void ClientStarted() if (!ServerActive) timer = new Timer(); + // reset time incase this is 2nd time client starts + _timeSync.Reset(); Client.MessageHandler.RegisterHandler(ClientHandleNetworkPositionMessage); }