revert previous commit NetworkTime modifications. keep TimeAsDouble

This commit is contained in:
vis2k 2023-03-27 10:56:13 +08:00
parent 70e972aeb5
commit 527dda561a

View File

@ -6,7 +6,9 @@
// some users may still be using that. // some users may still be using that.
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using UnityEngine; using UnityEngine;
#if !UNITY_2020_3_OR_NEWER
using Stopwatch = System.Diagnostics.Stopwatch; using Stopwatch = System.Diagnostics.Stopwatch;
#endif
namespace Mirror namespace Mirror
{ {
@ -23,15 +25,21 @@ public static class NetworkTime
static ExponentialMovingAverage _rtt = new ExponentialMovingAverage(PingWindowSize); static ExponentialMovingAverage _rtt = new ExponentialMovingAverage(PingWindowSize);
/// <summary>Returns double precision clock time _in this system_, unaffected by the network.</summary>
#if UNITY_2020_3_OR_NEWER
public static double localTime
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => Time.timeAsDouble;
}
#else
// need stopwatch for older Unity versions, but it's quite slow. // need stopwatch for older Unity versions, but it's quite slow.
// CAREFUL: unlike Time.time, this is not a FRAME time. // CAREFUL: unlike Time.time, this is not a FRAME time.
// it changes during the frame too. // it changes during the frame too.
static readonly Stopwatch stopwatch = new Stopwatch(); static readonly Stopwatch stopwatch = new Stopwatch();
static NetworkTime() => stopwatch.Start(); static NetworkTime() => stopwatch.Start();
/// <summary>Returns double precision clock time _in this system_, unaffected by the network.</summary>
public static double localTime => stopwatch.Elapsed.TotalSeconds; public static double localTime => stopwatch.Elapsed.TotalSeconds;
#endif
/// <summary>The time in seconds since the server started.</summary> /// <summary>The time in seconds since the server started.</summary>
// via global NetworkClient snapshot interpolated timeline (if client). // via global NetworkClient snapshot interpolated timeline (if client).
@ -69,7 +77,9 @@ public static void ResetStatics()
PingWindowSize = 6; PingWindowSize = 6;
lastPingTime = 0; lastPingTime = 0;
_rtt = new ExponentialMovingAverage(PingWindowSize); _rtt = new ExponentialMovingAverage(PingWindowSize);
#if !UNITY_2020_3_OR_NEWER
stopwatch.Restart(); stopwatch.Restart();
#endif
} }
internal static void UpdateClient() internal static void UpdateClient()