From c6633bccbe51690a9f228a2e66a0404d3d61f5fb Mon Sep 17 00:00:00 2001 From: mischa Date: Fri, 18 Oct 2024 13:33:47 +0200 Subject: [PATCH] clientdelta wip --- .../NetworkTransformHybrid2022.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Assets/Mirror/Components/NetworkTransform/NetworkTransformHybrid2022.cs b/Assets/Mirror/Components/NetworkTransform/NetworkTransformHybrid2022.cs index 223a3add2..cf490b44e 100644 --- a/Assets/Mirror/Components/NetworkTransform/NetworkTransformHybrid2022.cs +++ b/Assets/Mirror/Components/NetworkTransform/NetworkTransformHybrid2022.cs @@ -688,11 +688,11 @@ void UpdateClientBaseline(double localTime) void UpdateClientDelta(double localTime) { - // TODO - } + // only sync on change: + // unreliable isn't guaranteed to be delivered so this depends on reliable baseline. + // if baseline is dirty, send unreliables every sendInterval until baseline is not dirty anymore. + if (onlySyncOnChange && !baselineDirty) return; - void UpdateClientBroadcast(double localTime) - { // send to server each 'sendInterval' // NetworkTime.localTime for double precision until Unity has it too // @@ -715,14 +715,14 @@ void UpdateClientBroadcast(double localTime) // received successfully. if (localTime >= lastClientSendTime + sendInterval) // CUSTOM CHANGE: allow custom sendRate + sendInterval again { - // send snapshot without timestamp. - // receiver gets it from batch timestamp to save bandwidth. - TransformSnapshot snapshot = ConstructSnapshot(); + // perf: get position/rotation directly. TransformSnapshot is too expensive. + // TransformSnapshot snapshot = ConstructSnapshot(); + target.GetLocalPositionAndRotation(out Vector3 position, out Quaternion rotation); CmdClientToServerSync( // only sync what the user wants to sync - syncPosition ? snapshot.position : default(Vector3?), - syncRotation ? snapshot.rotation : default(Quaternion?)//, + syncPosition ? position : default(Vector3?), + syncRotation ? rotation : default(Quaternion?)//, // syncScale ? snapshot.scale : default(Vector3?) ); @@ -766,7 +766,7 @@ void UpdateClient() double localTime = NetworkTime.localTime; UpdateClientBaseline(localTime); - UpdateClientBroadcast(localTime); + UpdateClientDelta(localTime); } // for all other clients (and for local player if !authority), // we need to apply snapshots from the buffer