From c940963779d7c4ce3a4bb063a8e3c4dbce0b0213 Mon Sep 17 00:00:00 2001 From: vis2k Date: Thu, 6 Oct 2022 13:50:48 +0200 Subject: [PATCH] breaking: NetworkServer.tickRate and .tickInterval, set from exposed NetworkManager.serverTickInterval. prepares for NetworkClient time interpolation --- Assets/Mirror/Core/NetworkManager.cs | 7 +++++-- Assets/Mirror/Core/NetworkServer.cs | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Assets/Mirror/Core/NetworkManager.cs b/Assets/Mirror/Core/NetworkManager.cs index 90c7d1cbb..e932858af 100644 --- a/Assets/Mirror/Core/NetworkManager.cs +++ b/Assets/Mirror/Core/NetworkManager.cs @@ -45,8 +45,8 @@ public class NetworkManager : MonoBehaviour // send interval is 1 / sendRate. // but for tests we need a way to set it to exactly 0. // 1 / int.max would not be exactly 0, so handel that manually. - public float serverTickInterval => - serverTickRate < int.MaxValue ? 1f / serverTickRate : 0; // for 30 Hz, that's 33ms + [Obsolete("NetworkManager.serverTickInterval was moved to NetworkServer.tickInterval for consistency.")] + public float serverTickInterval => NetworkServer.tickInterval; /// Automatically switch to this scene upon going offline (on start / on disconnect / on shutdown). [Header("Scene Management")] @@ -244,6 +244,9 @@ void SetupServer() authenticator.OnServerAuthenticated.AddListener(OnServerAuthenticated); } + // copy exposed settings to static NetworkServer + NetworkServer.tickRate = serverTickRate; + ConfigureHeadlessFrameRate(); // start listening to network connections diff --git a/Assets/Mirror/Core/NetworkServer.cs b/Assets/Mirror/Core/NetworkServer.cs index d58912cea..f33f34f93 100644 --- a/Assets/Mirror/Core/NetworkServer.cs +++ b/Assets/Mirror/Core/NetworkServer.cs @@ -12,6 +12,19 @@ public static partial class NetworkServer static bool initialized; public static int maxConnections; + /// Server Update frequency, per second. Use around 60Hz for fast paced games like Counter-Strike to minimize latency. Use around 30Hz for games like WoW to minimize computations. Use around 1-10Hz for slow paced games like EVE. + // overwritten by NetworkManager (if any) + public static int tickRate = 30; + + // tick rate is in Hz. + // convert to interval in seconds for convenience where needed. + // + // send interval is 1 / sendRate. + // but for tests we need a way to set it to exactly 0. + // 1 / int.max would not be exactly 0, so handel that manually. + public static float tickInterval => + tickRate < int.MaxValue ? 1f / tickRate : 0; // for 30 Hz, that's 33ms + /// Connection to host mode client (if any) public static NetworkConnectionToClient localConnection { get; private set; }