Skip to content

Commit 443a93c

Browse files
fix - wip
First pass POC of deferring synchronization when more than one client is wanting to be synchronized in a very small period of time.
1 parent c577a01 commit 443a93c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

com.unity.netcode.gameobjects/Runtime/Messaging/Messages/ClientConnectedMessage.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public void Handle(ref NetworkContext context)
7373
/// DANGO-TODO: Determine if this needs to be removed once the service handles object distribution
7474
networkManager.RedistributeToClients = true;
7575
networkManager.ClientsToRedistribute.Add(ClientId);
76+
77+
// TODO: We need a client synchronized message or something like that here
7678
}
7779
}
7880
}

com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,8 @@ private void OnClientLoadedScene(uint sceneEventId, Scene scene)
19861986
/// </summary>
19871987
internal Func<Scene, bool> ExcludeSceneFromSychronization;
19881988

1989+
internal List<ulong> ClientConnectionQueue = new List<ulong>();
1990+
19891991
/// <summary>
19901992
/// Server Side:
19911993
/// This is used for players that have just had their connection approved and will assure they are synchronized
@@ -1994,8 +1996,21 @@ private void OnClientLoadedScene(uint sceneEventId, Scene scene)
19941996
/// synchronized.
19951997
/// </summary>
19961998
/// <param name="clientId">newly joined client identifier</param>
1997-
internal void SynchronizeNetworkObjects(ulong clientId)
1999+
internal void SynchronizeNetworkObjects(ulong clientId, bool synchronizingService = false)
19982000
{
2001+
// If this is a newly connecting client, add it to the connecting client queue
2002+
if (!synchronizingService && !ClientConnectionQueue.Contains(clientId))
2003+
{
2004+
ClientConnectionQueue.Add(clientId);
2005+
// If we are already synchronizing a client, then add this client to the queue and exit.
2006+
if (ClientConnectionQueue.Count > 1)
2007+
{
2008+
Debug.Log($"Deferring Client-{clientId} synchrnization.");
2009+
return;
2010+
}
2011+
}
2012+
2013+
19992014
// Update the clients
20002015
NetworkManager.SpawnManager.UpdateObservedNetworkObjects(clientId);
20012016

@@ -2623,6 +2638,13 @@ private void HandleSessionOwnerEvent(uint sceneEventId, ulong clientId)
26232638
// DANGO-EXP TODO: Remove this once service distributes objects
26242639
NetworkManager.SpawnManager.DistributeNetworkObjects(clientId);
26252640
EndSceneEvent(sceneEventId);
2641+
ClientConnectionQueue.Remove(clientId);
2642+
Debug.Log($"Client-{clientId} synchronized.");
2643+
if (ClientConnectionQueue.Count > 0)
2644+
{
2645+
Debug.Log($"Synchronizing Client-{ClientConnectionQueue[0]}...");
2646+
SynchronizeNetworkObjects(ClientConnectionQueue[0]);
2647+
}
26262648
break;
26272649
}
26282650
default:

0 commit comments

Comments
 (0)