From be8857a5096004c72fbd3e599384a9057525ea29 Mon Sep 17 00:00:00 2001 From: vis2k Date: Thu, 16 Mar 2023 11:20:19 +0800 Subject: [PATCH 1/5] TimelineClamp: add comments --- .../Core/SnapshotInterpolation/SnapshotInterpolation.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Mirror/Core/SnapshotInterpolation/SnapshotInterpolation.cs b/Assets/Mirror/Core/SnapshotInterpolation/SnapshotInterpolation.cs index adf058995..0fbe095ce 100644 --- a/Assets/Mirror/Core/SnapshotInterpolation/SnapshotInterpolation.cs +++ b/Assets/Mirror/Core/SnapshotInterpolation/SnapshotInterpolation.cs @@ -127,8 +127,8 @@ public static double TimelineClamp( // we define a boundary of 'bufferTime' around the target time. // this is where catchup / slowdown will happen. // outside of the area, we clamp. - double lowerBound = targetTime - bufferTime; - double upperBound = targetTime + bufferTime; + double lowerBound = targetTime - bufferTime; // how far behind we can get + double upperBound = targetTime + bufferTime; // how far ahead we can get return Mathd.Clamp(localTimeline, lowerBound, upperBound); } From d63af8d22ccbaa10d19e14f80e10918f625d7cc0 Mon Sep 17 00:00:00 2001 From: vis2k Date: Thu, 16 Mar 2023 18:15:31 +0800 Subject: [PATCH 2/5] Snapshot Interpolation Demo: add more buttons for testing --- .../Snapshot Interpolation/ClientCube.cs | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Assets/Mirror/Examples/Snapshot Interpolation/ClientCube.cs b/Assets/Mirror/Examples/Snapshot Interpolation/ClientCube.cs index 94cddea1e..fc74129be 100644 --- a/Assets/Mirror/Examples/Snapshot Interpolation/ClientCube.cs +++ b/Assets/Mirror/Examples/Snapshot Interpolation/ClientCube.cs @@ -173,14 +173,37 @@ void OnGUI() { lowFpsMode = !lowFpsMode; } - if (GUILayout.Button("Timeline 100ms behind")) + + GUILayout.Label("|"); + + if (GUILayout.Button("Timeline 10s behind")) + { + localTimeline -= 10.0; + } + if (GUILayout.Button("Timeline 1s behind")) + { + localTimeline -= 1.0; + } + if (GUILayout.Button("Timeline 0.1s behind")) { localTimeline -= 0.1; } - if (GUILayout.Button("Timeline 100ms ahead")) + + GUILayout.Label("|"); + + if (GUILayout.Button("Timeline 0.1s ahead")) { localTimeline += 0.1; } + if (GUILayout.Button("Timeline 1s ahead")) + { + localTimeline += 1.0; + } + if (GUILayout.Button("Timeline 10s ahead")) + { + localTimeline += 10.0; + } + GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.EndArea(); From a9b216d2e65a721a19b1f6ef3c56b88f6da3ad59 Mon Sep 17 00:00:00 2001 From: vis2k Date: Thu, 16 Mar 2023 19:23:53 +0800 Subject: [PATCH 3/5] snapshot interpolation demo: vsync reminder. it's too easy to forget. --- Assets/Mirror/Examples/Snapshot Interpolation/ClientCube.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Assets/Mirror/Examples/Snapshot Interpolation/ClientCube.cs b/Assets/Mirror/Examples/Snapshot Interpolation/ClientCube.cs index fc74129be..fb1f29c8e 100644 --- a/Assets/Mirror/Examples/Snapshot Interpolation/ClientCube.cs +++ b/Assets/Mirror/Examples/Snapshot Interpolation/ClientCube.cs @@ -52,6 +52,10 @@ public class ClientCube : MonoBehaviour void Awake() { + // show vsync reminder. too easy to forget. + Debug.Log("Reminder: Snapshot interpolation is smoothest & easiest to debug with Vsync off."); + + defaultColor = render.sharedMaterial.color; // initialize EMA with 'emaDuration' seconds worth of history. From ff5115e04a10af2219d3d64cb8ddb489862d6e47 Mon Sep 17 00:00:00 2001 From: MrGadget <9826063+MrGadget1024@users.noreply.github.com> Date: Thu, 16 Mar 2023 08:27:49 -0400 Subject: [PATCH 4/5] fix(NetworkManager): Call OnServerDisconnect for Host Client (#3419) --- Assets/Mirror/Core/NetworkManager.cs | 14 ++++++-------- ...NetworkManagerStopHostOnServerDisconnectTest.cs | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Assets/Mirror/Core/NetworkManager.cs b/Assets/Mirror/Core/NetworkManager.cs index 89329ca74..471d521d4 100644 --- a/Assets/Mirror/Core/NetworkManager.cs +++ b/Assets/Mirror/Core/NetworkManager.cs @@ -540,14 +540,6 @@ void FinishStartHost() public void StopHost() { OnStopHost(); - - // calling OnTransportDisconnected was needed to fix - // https://github.com/vis2k/Mirror/issues/1515 - // so that the host client receives a DisconnectMessage - // TODO reevaluate if this is still needed after all the disconnect - // fixes, and try to put this into LocalConnection.Disconnect! - NetworkServer.OnTransportDisconnected(NetworkConnection.LocalConnectionId); - StopClient(); StopServer(); } @@ -600,6 +592,12 @@ public void StopClient() if (mode == NetworkManagerMode.Offline) return; + // For Host client, call OnServerDisconnect before NetworkClient.Disconnect + // because we need NetworkServer.localConnection to not be null + // NetworkClient.Disconnect will set it null. + if (mode == NetworkManagerMode.Host) + OnServerDisconnect(NetworkServer.localConnection); + // ask client -> transport to disconnect. // handle voluntary and involuntary disconnects in OnClientDisconnect. // diff --git a/Assets/Mirror/Tests/Editor/NetworkManagerStopHostOnServerDisconnectTest.cs b/Assets/Mirror/Tests/Editor/NetworkManagerStopHostOnServerDisconnectTest.cs index 94c781714..42f0f326c 100644 --- a/Assets/Mirror/Tests/Editor/NetworkManagerStopHostOnServerDisconnectTest.cs +++ b/Assets/Mirror/Tests/Editor/NetworkManagerStopHostOnServerDisconnectTest.cs @@ -36,5 +36,19 @@ public void StopHostCallsOnServerDisconnectForHostClient() manager.StopHost(); Assert.That(manager.called, Is.EqualTo(1)); } + + [Test] + public void StopClientCallsOnServerDisconnectForHostClient() + { + // OnServerDisconnect is always called when a client disconnects. + // it should also be called for the host client when we stop the host + Assert.That(manager.called, Is.EqualTo(0)); + manager.StartHost(); + manager.StopClient(); + Assert.That(manager.called, Is.EqualTo(1)); + Assert.That(NetworkServer.connections.Count, Is.EqualTo(0)); + Assert.That(NetworkServer.localConnection, Is.Null); + Assert.That(NetworkClient.connection, Is.Null); + } } } From ef86df8454b3c52ae04fc39760b350d871dc18c0 Mon Sep 17 00:00:00 2001 From: MrGadget1024 <9826063+MrGadget1024@users.noreply.github.com> Date: Thu, 16 Mar 2023 15:26:05 -0400 Subject: [PATCH 5/5] NetworkReaderExtensions - syntax --- Assets/Mirror/Core/NetworkReaderExtensions.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Assets/Mirror/Core/NetworkReaderExtensions.cs b/Assets/Mirror/Core/NetworkReaderExtensions.cs index 580490672..82424d3c6 100644 --- a/Assets/Mirror/Core/NetworkReaderExtensions.cs +++ b/Assets/Mirror/Core/NetworkReaderExtensions.cs @@ -335,11 +335,7 @@ public static Sprite ReadSprite(this NetworkReader reader) return Sprite.Create(texture, reader.ReadRect(), reader.ReadVector2()); } - public static DateTime ReadDateTime(this NetworkReader reader) - { - return DateTime.FromOADate(reader.ReadDouble()); - } - + public static DateTime ReadDateTime(this NetworkReader reader) => DateTime.FromOADate(reader.ReadDouble()); public static DateTime? ReadDateTimeNullable(this NetworkReader reader) => reader.ReadBool() ? ReadDateTime(reader) : default(DateTime?); } }