Skip to content

Commit

Permalink
Merge branch 'develop' into fix/fixing-connection-management-test
Browse files Browse the repository at this point in the history
  • Loading branch information
LPLafontaineB authored Apr 26, 2023
2 parents 7ebe629 + 32f4732 commit 68fc9af
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Threading.Tasks;
using Unity.Multiplayer.Samples.Utilities;
using UnityEngine;

namespace Unity.BossRoom.ConnectionManagement
Expand Down Expand Up @@ -68,8 +67,6 @@ internal async Task ConnectClientAsync()
{
throw new Exception("NetworkManager StartClient failed");
}

SceneLoaderWrapper.Instance.AddOnSceneEventCallback();
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using Unity.BossRoom.Infrastructure;
using Unity.BossRoom.UnityServices.Lobbies;
using Unity.Multiplayer.Samples.BossRoom;
Expand All @@ -26,8 +25,6 @@ class HostingState : OnlineState

public override void Enter()
{
SceneLoaderWrapper.Instance.AddOnSceneEventCallback();

//The "BossRoom" server always advances to CharSelect immediately on start. Different games
//may do this differently.
SceneLoaderWrapper.Instance.LoadScene("CharSelect", useNetworkSceneManager: true);
Expand Down
2 changes: 0 additions & 2 deletions Assets/Tests/Runtime/ConnectionManagementTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ public override void Awake()

public override void Start() { }

public override void AddOnSceneEventCallback() { }

public override void LoadScene(string sceneName, bool useNetworkSceneManager, LoadSceneMode loadSceneMode = LoadSceneMode.Single) { }
}

Expand Down
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Additional documentation and release notes are available at [Multiplayer Documen
### Changed
* Replaced our polling for lobby updates with a subscription to the new Websocket based LobbyEvents (#805). This saves up a significant amount of bandwidth usage to and from the service, since updates are infrequent in this game. Now clients and hosts only use up bandwidth on the Lobby service when it is needed. With polling, we used to send a GET request per client once every 2s. The responses were between ~550 bytes and 900 bytes, so if we suppose an average of 725 bytes and 100 000 concurrent users (CCU), this amounted to around 725B * 30 calls per minute * 100 000 CCU = 2.175 GB per minute. Scaling this to a month would get us 93.96 TB per month. In our case, since the only changes to the lobbies happen when a user connects or disconnects, most of that data was not necessary and can be saved to reduce bandwidth usage. Since the cost of using the Lobby service depends on bandwidth usage, this would also save money on an actual game.
* Simplified reconnection flow by offloading responsibility to ConnectionMethod (#804). Now the ClientReconnectingState uses the ConnectionMethod it is configured with to handle setting up reconnection (i.e. reconnecting to the Lobby before trying to reconnect to the Relay server if it is using Relay and Lobby). It can now also fail early and stop retrying if the lobby doesn't exist anymore.
* Replaced our custom pool implementation using queues with ObjectPool (#824)
* Upgraded Boss Room to NGO 1.3.1 (#828) NetworkPrefabs inside NetworkManager's NetworkPrefabs list have been converted to NetworkPrefabsList ScriptableObject.
* Replaced our custom pool implementation using queues with ObjectPool (#824)(#827)
* Upgraded Boss Room to NGO 1.3.1 (#828) NetworkPrefabs inside NetworkManager's NetworkPrefabs list have been converted to NetworkPrefabsList ScriptableObject.
* Upgraded Boss Room to NGO 1.4.0 (#829)
* Profile names generated are now only 30 characters or under to fit Authentication Service requirements (#831)

Expand All @@ -31,6 +31,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
* UpdateRunner now sends the right value for deltaTime when updating its subscribers (#805)
* Inputs are better sanitized when entering IP address and port (#821). Now all invalid characters are prevented, and UnityTransport's NetworkEndpoint.TryParse is used to verify the validity of the IP address and port that are entered before making the join/host button interactable.
* Fixed failing connection management test (#826). This test had to be ignored previously because there was no mechanism to detect unexpected server shutdowns. With the OnServerStopped callback introduced in NGO 1.4.0, this is no longer an issue.
* Decoupled SceneLoaderWrapper and ConnectionStates (#830). The OnServerStarted and OnClientStarted callbacks available in NGO 1.4.0 allows us to remove the need for an external method to initialize the SceneLoaderWrapper after starting a NetworkingSession.

## [2.0.4] - 2022-12-13
### Changed
Expand Down
3 changes: 3 additions & 0 deletions Packages/com.unity.multiplayer.samples.coop/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [unreleased] - yyyy-mm-dd

### Changed
* Removed need for SceneLoaderWrapper.AddOnSceneEventCallback (#830). The OnServerStarted and OnClientStarted callbacks available in NGO 1.4.0 allows us to remove the need for an external method to initialize the SceneLoaderWrapper after starting a NetworkingSession.

## [1.5.1] - 2022-12-13
### Changed
* Bumped RNSM to 1.1.0: Switched x axis units to seconds instead of frames now that it's available. This means adjusting the sample count to a lower value as well to 30 seconds, since the x axis was moving too slowly. (#788)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class SceneLoaderWrapper : NetworkBehaviour

bool IsNetworkSceneManagementEnabled => NetworkManager != null && NetworkManager.SceneManager != null && NetworkManager.NetworkConfig.EnableSceneManagement;

bool m_IsInitialized;

public static SceneLoaderWrapper Instance { get; protected set; }

public virtual void Awake()
Expand All @@ -39,32 +41,50 @@ public virtual void Awake()
public virtual void Start()
{
SceneManager.sceneLoaded += OnSceneLoaded;
NetworkManager.OnServerStarted += OnNetworkingSessionStarted;
NetworkManager.OnClientStarted += OnNetworkingSessionStarted;
NetworkManager.OnServerStopped += OnNetworkingSessionEnded;
NetworkManager.OnClientStopped += OnNetworkingSessionEnded;
}

public override void OnDestroy()
void OnNetworkingSessionStarted()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
base.OnDestroy();
// This prevents this to be called twice on a host, which receives both OnServerStarted and OnClientStarted callbacks
if (!m_IsInitialized)
{
if (IsNetworkSceneManagementEnabled)
{
NetworkManager.SceneManager.OnSceneEvent += OnSceneEvent;
}

m_IsInitialized = true;
}
}

public override void OnNetworkDespawn()
void OnNetworkingSessionEnded(bool unused)
{
if (NetworkManager != null && NetworkManager.SceneManager != null)
if (m_IsInitialized)
{
NetworkManager.SceneManager.OnSceneEvent -= OnSceneEvent;
if (IsNetworkSceneManagementEnabled)
{
NetworkManager.SceneManager.OnSceneEvent -= OnSceneEvent;
}

m_IsInitialized = false;
}
}

/// <summary>
/// Initializes the callback on scene events. This needs to be called right after initializing NetworkManager
/// (after StartHost, StartClient or StartServer)
/// </summary>
public virtual void AddOnSceneEventCallback()
public override void OnDestroy()
{
if (IsNetworkSceneManagementEnabled)
SceneManager.sceneLoaded -= OnSceneLoaded;
if (NetworkManager != null)
{
NetworkManager.SceneManager.OnSceneEvent += OnSceneEvent;
NetworkManager.OnServerStarted -= OnNetworkingSessionStarted;
NetworkManager.OnClientStarted -= OnNetworkingSessionStarted;
NetworkManager.OnServerStopped -= OnNetworkingSessionEnded;
NetworkManager.OnClientStopped -= OnNetworkingSessionEnded;
}
base.OnDestroy();
}

/// <summary>
Expand Down

0 comments on commit 68fc9af

Please sign in to comment.