From de32fc785d0a074572d6377b618ea659646d0d84 Mon Sep 17 00:00:00 2001 From: mischa Date: Thu, 17 Oct 2024 13:38:19 +0200 Subject: [PATCH] perf: only grab NetworkTime.localTime property once. --- .../NetworkTransformHybrid2022.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Assets/Mirror/Components/NetworkTransform/NetworkTransformHybrid2022.cs b/Assets/Mirror/Components/NetworkTransform/NetworkTransformHybrid2022.cs index fa054a696..75716f44e 100644 --- a/Assets/Mirror/Components/NetworkTransform/NetworkTransformHybrid2022.cs +++ b/Assets/Mirror/Components/NetworkTransform/NetworkTransformHybrid2022.cs @@ -496,10 +496,10 @@ protected virtual void OnServerToClientDeltaSync(byte baselineTick, Vector3? pos // update ////////////////////////////////////////////////////////////// bool baselineDirty = true; - void UpdateServerBaseline() + void UpdateServerBaseline(double localTime) { // send a reliable baseline every 1 Hz - if (NetworkTime.localTime >= lastServerBaselineTime + baselineInterval) + if (localTime >= lastServerBaselineTime + baselineInterval) { // perf: get position/rotation directly. TransformSnapshot is too expensive. // TransformSnapshot snapshot = ConstructSnapshot(); @@ -529,7 +529,7 @@ void UpdateServerBaseline() } } - void UpdateServerDelta() + void UpdateServerDelta(double localTime) { // broadcast to all clients each 'sendInterval' // (client with authority will drop the rpc) @@ -567,7 +567,7 @@ void UpdateServerDelta() // if baseline is dirty, send unreliables every sendInterval until baseline is not dirty anymore. if (onlySyncOnChange && !baselineDirty) return; - if (NetworkTime.localTime >= lastServerSendTime + sendInterval) // CUSTOM CHANGE: allow custom sendRate + sendInterval again + if (localTime >= lastServerSendTime + sendInterval) // CUSTOM CHANGE: allow custom sendRate + sendInterval again { // perf: get position/rotation directly. TransformSnapshot is too expensive. // TransformSnapshot snapshot = ConstructSnapshot(); @@ -591,7 +591,7 @@ void UpdateServerDelta() RpcServerToClientDeltaSync(writer); } - lastServerSendTime = NetworkTime.localTime; + lastServerSendTime = localTime; } } @@ -632,8 +632,10 @@ void UpdateServer() // broadcasting if (syncDirection == SyncDirection.ServerToClient || IsClientWithAuthority) { - UpdateServerBaseline(); - UpdateServerDelta(); + // perf: only grab NetworkTime.localTime property once. + double localTime = NetworkTime.localTime; + UpdateServerBaseline(localTime); + UpdateServerDelta(localTime); } // interpolate remote clients