Skip to content

Commit

Permalink
NetworkTime creates it's own frame time in 2019
Browse files Browse the repository at this point in the history
Since we don't have double time there yet and the stopwatch will change during the frame which causes jitter and other artifacts
supersedes #3623
See also #2838
  • Loading branch information
imerr committed Oct 6, 2023
1 parent c312b6b commit 59cda4b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Assets/Mirror/Core/NetworkLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ static void NetworkEarlyUpdate()
// loop functions run in edit mode and in play mode.
// however, we only want to call NetworkServer/Client in play mode.
if (!Application.isPlaying) return;


NetworkTime.EarlyUpdate();
//Debug.Log($"NetworkEarlyUpdate {Time.time}");
NetworkServer.NetworkEarlyUpdate();
NetworkClient.NetworkEarlyUpdate();
Expand Down
10 changes: 9 additions & 1 deletion Assets/Mirror/Core/NetworkTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public static double localTime
// it changes during the frame too.
static readonly Stopwatch stopwatch = new Stopwatch();
static NetworkTime() => stopwatch.Start();
public static double localTime => stopwatch.Elapsed.TotalSeconds;
static double localFrameTime = 0;
public static double localTime => localFrameTime;
#endif

/// <summary>The time in seconds since the server started.</summary>
Expand Down Expand Up @@ -231,5 +232,12 @@ internal static void OnServerPong(NetworkConnectionToClient conn, NetworkPongMes
double newRtt = localTime - message.localTime;
conn._rtt.Add(newRtt);
}

internal static void EarlyUpdate()
{
#if !UNITY_2020_3_OR_NEWER
localFrameTime = stopwatch.Elapsed.TotalSeconds;
#endif
}
}
}

0 comments on commit 59cda4b

Please sign in to comment.