breaking: NetworkTime.PingFrequency renamed to PingInterval. Makes it more obvious that we use it as interval, not as frequency in Hz.

This commit is contained in:
mischa 2023-07-06 16:45:11 +08:00
parent d64c5fb61b
commit 59e04f7902

View File

@ -4,6 +4,7 @@
// //
// however, some of the old NetworkTime code remains for ping time (rtt). // however, some of the old NetworkTime code remains for ping time (rtt).
// some users may still be using that. // some users may still be using that.
using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using UnityEngine; using UnityEngine;
#if !UNITY_2020_3_OR_NEWER #if !UNITY_2020_3_OR_NEWER
@ -15,8 +16,16 @@ namespace Mirror
/// <summary>Synchronizes server time to clients.</summary> /// <summary>Synchronizes server time to clients.</summary>
public static class NetworkTime public static class NetworkTime
{ {
/// <summary>Ping message frequency, used to calculate network time and RTT</summary> /// <summary>Ping message interval, used to calculate network time and RTT</summary>
public static float PingFrequency = 2; public static float PingInterval = 2;
// DEPRECATED 2023-07-06
[Obsolete("NetworkTime.PingFrequency was renamed to PingInterval, because we use it as seconds, not as Hz. Please rename all usages, but keep using it just as before.")]
public static float PingFrequency
{
get => PingInterval;
set => PingInterval = value;
}
/// <summary>Average out the last few results from Ping</summary> /// <summary>Average out the last few results from Ping</summary>
public static int PingWindowSize = 6; public static int PingWindowSize = 6;
@ -80,7 +89,7 @@ public static double time
[RuntimeInitializeOnLoadMethod] [RuntimeInitializeOnLoadMethod]
public static void ResetStatics() public static void ResetStatics()
{ {
PingFrequency = 2; PingInterval = 2;
PingWindowSize = 6; PingWindowSize = 6;
lastPingTime = 0; lastPingTime = 0;
_rtt = new ExponentialMovingAverage(PingWindowSize); _rtt = new ExponentialMovingAverage(PingWindowSize);
@ -92,7 +101,7 @@ public static void ResetStatics()
internal static void UpdateClient() internal static void UpdateClient()
{ {
// localTime (double) instead of Time.time for accuracy over days // localTime (double) instead of Time.time for accuracy over days
if (localTime >= lastPingTime + PingFrequency) if (localTime >= lastPingTime + PingInterval)
{ {
NetworkPingMessage pingMessage = new NetworkPingMessage(localTime); NetworkPingMessage pingMessage = new NetworkPingMessage(localTime);
NetworkClient.Send(pingMessage, Channels.Unreliable); NetworkClient.Send(pingMessage, Channels.Unreliable);