Skip to content

feat: OnAllClientsReady #755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
May 3, 2021
Merged

feat: OnAllClientsReady #755

merged 19 commits into from
May 3, 2021

Conversation

pdeschain
Copy link
Contributor

@pdeschain pdeschain commented Apr 21, 2021

Summary:

Users need a simplified way to determine when all clients have finished transitioning to a newly loaded scene so net-code related logic (i.e. sending messages, detecting network variable states, etc) can safely begin.

Technical Notes:

On the server-side currently not much needed to be done - we already have SceneSwitchProgress object created for any scene switches. The only hindrance here is that the user has to cache SceneSwitchProgress in order to be able to listen to it's events. We can capture these events in NetworkSceneManager and provide a unified set of events one can listen to without needing to re-subscribe to the events any time a new scene is being loaded.

Two events are added to the NetworkSceneManager that forward the SceneSwitchProgress events (those happen only on the server):

OnClientLoadedScene - invoked when a client concludes scene loading
OnAllClientsLoadedScene - invoked when all clients have concluded scene loading

On the client-side this can be accomplished by implementing a new internal MLAPI message event (NetworkConstants.ALL_CLIENTS_SWITCH_SCENE_COMPLETED).

This message is sent (along with lists of all connected and timed-out clients) to the clients as soon as the server knows that all clients have concluded their scene transitions. The message is then handled in InternalMessageHandler.HandleAllClientsSwitchSceneCompleted, which triggers NetworkSceneManager.OnAllClientsReady event on all the clients.

Acceptance Criteria:

Nothing should break - the change is purely additive.

It should be simpler to implement scene switching logic on the client and on the server and it should eliminate the need for custom messaging that the users will have to implement to achieve the same functionality.

Acceptance Tests:

[Manual] `OnClientLoadedScene` and  `OnAllClientsLoadedScene` callbacks can be currently tested via a manual test `NetworkSceneManager callback tests` available from the ManualTests scene.

After we have a way to test scenarios that rely on having multiple peers it would be possible to automate `OnAllClilentsReady` - currently it's impossible to test automatically because Host doesn't receive messages the same way a pure client would.

These events forward the events from any individual SceneSwitchProgress to a single endpoint.
… the server recieves acknowledgement that all clients have successfully loaded the scene (or timed out)
@unity-cla-assistant
Copy link

unity-cla-assistant commented Apr 21, 2021

CLA assistant check
All committers have signed the CLA.

@pdeschain pdeschain changed the title Feature - OnAllClientsReady feat: OnAllClientsReady Apr 21, 2021
…tsReady callback - this way we can know specifically, which users failed to load the scene before the transition timed out
…he client, switched it over so that the array of timedout client IDs is properly computed on the server.
…nity.multiplayer.mlapi into feature/onclientready-mtt588

# Conflicts:
#	com.unity.multiplayer.mlapi/Tests/Runtime/NetworkManagerHelper.cs
#	testproject/ProjectSettings/EditorBuildSettings.asset
@pdeschain pdeschain marked this pull request as ready for review April 28, 2021 05:04
var timedOutClientIds = m_NetworkManager.ConnectedClients.Keys.Except(doneClientIds).ToArray();

writer.WriteULongArray(doneClientIds, doneClientIds.Length);
writer.WriteULongArray(timedOutClientIds, timedOutClientIds.Length);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Both active and timed out clients!
Very useful!

/// <returns>true if it was instantiated or is already instantiate otherwise false means it failed to instantiate</returns>
public static bool StartNetworkManager(out NetworkManager networkManager, NetworkManagerOperatingMode managerMode = NetworkManagerOperatingMode.Host)
public static bool StartNetworkManager(out NetworkManager networkManager, NetworkManagerOperatingMode managerMode = NetworkManagerOperatingMode.Host, NetworkConfig networkConfig = null)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding NetworkConfig will come in handy.

Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks real good Philipp!

Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some issues with the NetworkManagerHelper and the way you are loading scenes.
Grab me when you have a second to discuss.

@NoelStephensUnity NoelStephensUnity self-requested a review April 28, 2021 21:45
…t locates the full path to a scene for the Setup stage.
…ts/.. and in SceneManager list from the package dll on Yamato, the automated tests were removed and a manual test was created instead.
Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will fix the NetworkSceneManager issue in the very near future.
The rest looks good to go!

@mattwalsh-unity mattwalsh-unity self-requested a review April 30, 2021 19:41
pdeschain added 2 commits May 3, 2021 14:38
…nity.multiplayer.mlapi into feature/onclientready-mtt588

# Conflicts:
#	testproject/Assets/ManualTests/ManualTestsMenu.unity
Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The adjusted event names look good.
Very clear what each one does at this point

@pdeschain pdeschain merged commit e864e8e into develop May 3, 2021
@pdeschain pdeschain deleted the feature/onclientready-mtt588 branch May 3, 2021 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants