Merged master

This commit is contained in:
MrGadget1024 2023-03-16 16:21:40 -04:00
commit 5fd826071c
5 changed files with 52 additions and 17 deletions

View File

@ -540,14 +540,6 @@ void FinishStartHost()
public void StopHost() public void StopHost()
{ {
OnStopHost(); 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(); StopClient();
StopServer(); StopServer();
} }
@ -600,6 +592,12 @@ public void StopClient()
if (mode == NetworkManagerMode.Offline) if (mode == NetworkManagerMode.Offline)
return; 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. // ask client -> transport to disconnect.
// handle voluntary and involuntary disconnects in OnClientDisconnect. // handle voluntary and involuntary disconnects in OnClientDisconnect.
// //

View File

@ -335,11 +335,7 @@ public static Sprite ReadSprite(this NetworkReader reader)
return Sprite.Create(texture, reader.ReadRect(), reader.ReadVector2()); return Sprite.Create(texture, reader.ReadRect(), reader.ReadVector2());
} }
public static DateTime ReadDateTime(this NetworkReader reader) public static DateTime ReadDateTime(this NetworkReader reader) => DateTime.FromOADate(reader.ReadDouble());
{
return DateTime.FromOADate(reader.ReadDouble());
}
public static DateTime? ReadDateTimeNullable(this NetworkReader reader) => reader.ReadBool() ? ReadDateTime(reader) : default(DateTime?); public static DateTime? ReadDateTimeNullable(this NetworkReader reader) => reader.ReadBool() ? ReadDateTime(reader) : default(DateTime?);
} }
} }

View File

@ -127,8 +127,8 @@ public static double TimelineClamp(
// we define a boundary of 'bufferTime' around the target time. // we define a boundary of 'bufferTime' around the target time.
// this is where catchup / slowdown will happen. // this is where catchup / slowdown will happen.
// outside of the area, we clamp. // outside of the area, we clamp.
double lowerBound = targetTime - bufferTime; double lowerBound = targetTime - bufferTime; // how far behind we can get
double upperBound = targetTime + bufferTime; double upperBound = targetTime + bufferTime; // how far ahead we can get
return Mathd.Clamp(localTimeline, lowerBound, upperBound); return Mathd.Clamp(localTimeline, lowerBound, upperBound);
} }

View File

@ -52,6 +52,10 @@ public class ClientCube : MonoBehaviour
void Awake() 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; defaultColor = render.sharedMaterial.color;
// initialize EMA with 'emaDuration' seconds worth of history. // initialize EMA with 'emaDuration' seconds worth of history.
@ -173,14 +177,37 @@ void OnGUI()
{ {
lowFpsMode = !lowFpsMode; 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; localTimeline -= 0.1;
} }
if (GUILayout.Button("Timeline 100ms ahead"))
GUILayout.Label("|");
if (GUILayout.Button("Timeline 0.1s ahead"))
{ {
localTimeline += 0.1; localTimeline += 0.1;
} }
if (GUILayout.Button("Timeline 1s ahead"))
{
localTimeline += 1.0;
}
if (GUILayout.Button("Timeline 10s ahead"))
{
localTimeline += 10.0;
}
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
GUILayout.EndArea(); GUILayout.EndArea();

View File

@ -36,5 +36,19 @@ public void StopHostCallsOnServerDisconnectForHostClient()
manager.StopHost(); manager.StopHost();
Assert.That(manager.called, Is.EqualTo(1)); 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);
}
} }
} }