Skip to content

Commit

Permalink
breaking: remove redundant scene ready value (#325)
Browse files Browse the repository at this point in the history
* breaking: remove redundant scene ready value
BREAKING CHANGE: Remove redundant scene ready value
  • Loading branch information
uweeby committed Aug 23, 2020
1 parent 58a0f68 commit 6cc8f62
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
17 changes: 4 additions & 13 deletions Assets/Mirror/Runtime/NetworkSceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ public class NetworkSceneManager : MonoBehaviour, INetworkSceneManager
/// </remarks>
public string NetworkSceneName { get; protected set; } = "";

/// <summary>
/// Returns true when a client's connection has been set to ready.
/// <para>A client that is ready recieves state updates from the server, while a client that is not ready does not. This useful when the state of the game is not normal, such as a scene change or end-of-game.</para>
/// <para>This is read-only. To change the ready state of a client, use ClientScene.Ready(). The server is able to set the ready state of clients using NetworkServer.SetClientReady(), NetworkServer.SetClientNotReady() and NetworkServer.SetAllClientsNotReady().</para>
/// <para>This is done when changing scenes so that clients don't receive state update messages during scene loading.</para>
/// </summary>
public bool Ready { get; internal set; }

public void Start()
{
DontDestroyOnLoad(gameObject);
Expand Down Expand Up @@ -99,7 +91,6 @@ void OnClientAuthenticated(INetworkConnection conn)

void OnClientDisconnected()
{
Ready = false;
client.Authenticated.RemoveListener(OnClientAuthenticated);
client.Disconnected.RemoveListener(OnClientDisconnected);
}
Expand Down Expand Up @@ -133,7 +124,6 @@ internal void ClientNotReadyMessage(INetworkConnection conn, NotReadyMessage msg
{
logger.Log("NetworkSceneManager.OnClientNotReadyMessageInternal");

Ready = false;
OnClientNotReady(conn);
}

Expand All @@ -156,7 +146,7 @@ internal void OnClientChangeScene(string sceneName, SceneOperation sceneOperatio
internal void OnClientSceneChanged(string sceneName, SceneOperation sceneOperation)
{
//set ready after scene change has completed
if (!Ready)
if (!client.Connection.IsReady)
SetClientReady();

ClientSceneChanged.Invoke(sceneName, sceneOperation);
Expand All @@ -169,6 +159,8 @@ internal void OnClientSceneChanged(string sceneName, SceneOperation sceneOperati
/// <param name="conn">Connection to the server.</param>
internal void OnClientNotReady(INetworkConnection conn)
{
client.Connection.IsReady = false;

ClientNotReady.Invoke(conn);
}

Expand All @@ -181,14 +173,13 @@ public void SetClientReady()
if (!client || !client.Active)
throw new InvalidOperationException("Ready() called with an null or disconnected client");

if (Ready)
if (client.Connection.IsReady)
throw new InvalidOperationException("A connection has already been set as ready. There can only be one.");

if (logger.LogEnabled()) logger.Log("ClientScene.Ready() called.");

// Set these before sending the ReadyMessage, otherwise host client
// will fail in InternalAddPlayer with null readyConnection.
Ready = true;
client.Connection.IsReady = true;

// Tell server we're ready to have a player object spawned
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirror/Runtime/PlayerSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private void OnClientAuthenticated(INetworkConnection connection)
// that when we have online/offline scenes. so we need the
// clientLoadedScene flag to prevent it.
// Ready/AddPlayer is usually triggered by a scene load completing. if no scene was loaded, then Ready/AddPlayer it here instead.
if (!sceneManager.Ready)
if (!client.Connection.IsReady)
sceneManager.SetClientReady();

client.Send(new AddPlayerMessage());
Expand Down
3 changes: 1 addition & 2 deletions Assets/Mirror/Tests/Runtime/NetworkSceneManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public void ChangeServerSceneExceptionTest()
public void ReadyTest()
{
sceneManager.SetClientReady();
Assert.That(sceneManager.Ready);
Assert.That(client.Connection.IsReady);
}

Expand Down Expand Up @@ -228,7 +227,7 @@ public void ClientNotReady()
clientSceneManager.SetClientReady();
clientSceneManager.ClientNotReadyMessage(null, new NotReadyMessage());

Assert.That(clientSceneManager.Ready, Is.False);
Assert.That(client.Connection.IsReady, Is.False);
func1.Received(1).Invoke(Arg.Any<INetworkConnection>());
}

Expand Down

0 comments on commit 6cc8f62

Please sign in to comment.