Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
fa0fef6
Added delegate types and appropriate events in NetworkSceneManager.
pdeschain Apr 20, 2021
adf18e3
Added a new internal message that is sent out to all the clients when…
pdeschain Apr 21, 2021
d10910b
Added comments and an array of timed out client IDs to the OnAllClien…
pdeschain Apr 21, 2021
c802347
Noticed that I was trying to check the list of connected clients on t…
pdeschain Apr 22, 2021
ffb06da
Added automated tests for introduced callbacks.
pdeschain Apr 26, 2021
6dfbebb
More work on tests
pdeschain Apr 27, 2021
d23e199
More work on tests
pdeschain Apr 28, 2021
16468ef
Merge branch 'develop' of https://github.com/Unity-Technologies/com.u…
pdeschain Apr 28, 2021
9fb4a8c
Merge branch 'develop' into feature/onclientready-mtt588
NoelStephensUnity Apr 28, 2021
531ebdb
Moved scenes used for OnClientReady tests under the Assets/ directory
pdeschain Apr 30, 2021
4f0b4e3
Moved OnAllClientsReady scenes back into package, testing how Yamato …
pdeschain Apr 30, 2021
b8280e2
Moved the test scenes back under Assets/ folder, tweaked the code tha…
pdeschain Apr 30, 2021
1e2c31a
More of the same attempts to placate Yamato
pdeschain Apr 30, 2021
e3beeb1
#
pdeschain Apr 30, 2021
fcd7f42
Due to current limitations in our ability to reference scenes in Asse…
pdeschain Apr 30, 2021
73efb2e
Renamed the message and added events and delegates to be more underst…
pdeschain May 3, 2021
007719f
Merge branch 'develop' of https://github.com/Unity-Technologies/com.u…
pdeschain May 3, 2021
cf3d516
doc tweaks
pdeschain May 3, 2021
a7f9add
Yamato taming
pdeschain May 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added a new internal message that is sent out to all the clients when…
… the server recieves acknowledgement that all clients have successfully loaded the scene (or timed out)
  • Loading branch information
pdeschain committed Apr 21, 2021
commit adf18e3afe63f6b5175dc5e623ec4d21daaf4c40
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal static class NetworkConstants
internal const byte TIME_SYNC = 11;
internal const byte NETWORK_VARIABLE_DELTA = 12;
internal const byte NETWORK_VARIABLE_UPDATE = 13;
internal const byte ALL_CLIENTS_SWITCH_SCENE_COMPLETED = 14;
internal const byte UNNAMED_MESSAGE = 20;
internal const byte DESTROY_OBJECTS = 21;
internal const byte NAMED_MESSAGE = 22;
Expand All @@ -42,7 +43,7 @@ internal static class NetworkConstants
"TIME_SYNC",
"NETWORK_VARIABLE_DELTA",
"NETWORK_VARIABLE_UPDATE",
"",
"ALL_CLIENTS_SWITCH_SCENE_COMPLETED",
"",
"", // 16
"",
Expand Down
7 changes: 7 additions & 0 deletions com.unity.multiplayer.mlapi/Runtime/Core/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,13 @@ internal void HandleIncomingData(ulong clientId, NetworkChannel networkChannel,
NetworkLog.LogWarning($"Server received {nameof(NetworkConstants.CLIENT_SWITCH_SCENE_COMPLETED)} from client id {clientId}");
}

break;
case NetworkConstants.ALL_CLIENTS_SWITCH_SCENE_COMPLETED:
if (IsClient)
{
MessageHandler.HandleAllClientsSwitchSceneCompleted(clientId, messageStream);
}

break;
case NetworkConstants.SERVER_LOG:
if (IsServer && NetworkConfig.EnableNetworkLogs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ internal interface IInternalMessageHandler
void HandleUnnamedMessage(ulong clientId, Stream stream);
void HandleNamedMessage(ulong clientId, Stream stream);
void HandleNetworkLog(ulong clientId, Stream stream);
void HandleAllClientsSwitchSceneCompleted(ulong clientId, Stream stream);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal class InternalMessageHandler : IInternalMessageHandler
private static ProfilerMarker s_HandleNetworkLog = new ProfilerMarker($"{nameof(InternalMessageHandler)}.{nameof(HandleNetworkLog)}");
private static ProfilerMarker s_RpcReceiveQueueItemServerRpc = new ProfilerMarker($"{nameof(InternalMessageHandler)}.{nameof(RpcReceiveQueueItem)}.{nameof(RpcQueueContainer.QueueItemType.ServerRpc)}");
private static ProfilerMarker s_RpcReceiveQueueItemClientRpc = new ProfilerMarker($"{nameof(InternalMessageHandler)}.{nameof(RpcReceiveQueueItem)}.{nameof(RpcQueueContainer.QueueItemType.ClientRpc)}");
private static ProfilerMarker s_HandleAllClientsSwitchSceneCompleted = new ProfilerMarker($"{nameof(InternalMessageHandler)}.{nameof(HandleAllClientsSwitchSceneCompleted)}");
#endif

public NetworkManager NetworkManager => m_NetworkManager;
Expand Down Expand Up @@ -606,6 +607,22 @@ public void HandleNetworkLog(ulong clientId, Stream stream)
}
#if DEVELOPMENT_BUILD || UNITY_EDITOR
s_HandleNetworkLog.End();
#endif
}

public void HandleAllClientsSwitchSceneCompleted(ulong clientId, Stream stream)
{
#if DEVELOPMENT_BUILD || UNITY_EDITOR
s_HandleAllClientsSwitchSceneCompleted.Begin();
#endif
using (var reader = PooledNetworkReader.Get(stream))
{
var clientIds = reader.ReadULongArray();

NetworkManager.SceneManager.AllClientsReady(clientIds);
}
#if DEVELOPMENT_BUILD || UNITY_EDITOR
s_HandleAllClientsSwitchSceneCompleted.End();
#endif
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class NetworkSceneManager

public delegate void OnAllClientsLoadedSceneDelegate(SceneSwitchProgress progress, bool timedOut);

public delegate void AllClientsReadyDelegate(ulong[] clientIds);

/// <summary>
/// Event that is invoked when the scene is switched
/// </summary>
Expand All @@ -43,10 +45,21 @@ public class NetworkSceneManager
/// </summary>
public event SceneSwitchStartedDelegate OnSceneSwitchStarted;

/// <summary>
/// Event that is invoked on the server when a client completes scene transition
/// </summary>
public event OnClientLoadedSceneDelegate OnClientLoadedScene;

/// <summary>
/// Event that is invoked on the server when all clients have reported that they have completed scene transition
/// </summary>
public event OnAllClientsLoadedSceneDelegate OnAllClientsLoadedScene;

/// <summary>
/// Event that is invoked on the client after all clients have successfully completed scene transition
/// </summary>
public event AllClientsReadyDelegate OnAllClientsReady;

internal readonly HashSet<string> RegisteredSceneNames = new HashSet<string>();
internal readonly Dictionary<string, uint> SceneNameToIndex = new Dictionary<string, uint>();
internal readonly Dictionary<uint, string> SceneIndexToString = new Dictionary<uint, string>();
Expand Down Expand Up @@ -149,7 +162,17 @@ public SceneSwitchProgress SwitchScene(string sceneName)
CurrentSceneSwitchProgressGuid = switchSceneProgress.Guid;

switchSceneProgress.OnClientLoadedScene += clientId => { OnClientLoadedScene?.Invoke(switchSceneProgress, clientId); };
switchSceneProgress.OnComplete += timedOut => { OnAllClientsLoadedScene?.Invoke(switchSceneProgress, timedOut); };
switchSceneProgress.OnComplete += timedOut =>
{
OnAllClientsLoadedScene?.Invoke(switchSceneProgress, timedOut);

using (var buffer = PooledNetworkBuffer.Get())
using (var writer = PooledNetworkWriter.Get(buffer))
{
writer.WriteULongArray(switchSceneProgress.DoneClients.ToArray(), switchSceneProgress.DoneClients.Count);
m_NetworkManager.MessageSender.Send(NetworkManager.Singleton.ServerClientId, NetworkConstants.ALL_CLIENTS_SWITCH_SCENE_COMPLETED, NetworkChannel.Internal, buffer);
}
};

// Move ALL NetworkObjects to the temp scene
MoveObjectsToDontDestroyOnLoad();
Expand Down Expand Up @@ -490,5 +513,10 @@ private void MoveObjectsToScene(Scene scene)
SceneManager.MoveGameObjectToScene(sobj.gameObject, scene);
}
}

internal void AllClientsReady(ulong[] clientIds)
{
OnAllClientsReady?.Invoke(clientIds);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ internal class DummyMessageHandler : IInternalMessageHandler
public void HandleNamedMessage(ulong clientId, Stream stream) => VerifyCalled(nameof(HandleNamedMessage));

public void HandleNetworkLog(ulong clientId, Stream stream) => VerifyCalled(nameof(HandleNetworkLog));

public void HandleAllClientsSwitchSceneCompleted(ulong clientId, Stream stream) => VerifyCalled(nameof(HandleAllClientsSwitchSceneCompleted));

private void VerifyCalled(string method)
{
Expand Down