Skip to content

Commit

Permalink
fix(NetworkRoomManager): Hashset instead of List
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGadget1024 committed May 19, 2024
1 parent 1721b56 commit c573936
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions Assets/Mirror/Components/NetworkRoomManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public struct PendingPlayer
/// List of players that are in the Room
/// </summary>
[FormerlySerializedAs("m_PendingPlayers")]
public List<PendingPlayer> pendingPlayers = new List<PendingPlayer>();
public HashSet<PendingPlayer> pendingPlayers = new HashSet<PendingPlayer>();

[Header("Diagnostics")]
/// <summary>
Expand All @@ -71,7 +71,7 @@ public struct PendingPlayer
/// <para>The slotId on players is global to the game - across all players.</para>
/// </summary>
[ReadOnly, Tooltip("List of Room Player objects")]
public List<NetworkRoomPlayer> roomSlots = new List<NetworkRoomPlayer>();
public HashSet<NetworkRoomPlayer> roomSlots = new HashSet<NetworkRoomPlayer>();

public bool allPlayersReady
{
Expand Down Expand Up @@ -251,11 +251,10 @@ public override void OnServerDisconnect(NetworkConnectionToClient conn)
OnRoomServerDisconnect(conn);
base.OnServerDisconnect(conn);

if (Utils.IsHeadless())
{
if (numPlayers < 1)
StopServer();
}
// Restart the server if we're headless and no players are connected.
// This will send server to offline scene, where auto-start will run.
if (Utils.IsHeadless() && numPlayers < 1)
StopServer();
}

// Sequential index used in round-robin deployment of players into instances and score positioning
Expand Down Expand Up @@ -316,10 +315,9 @@ public void RecalculateRoomPlayerIndices()
{
if (roomSlots.Count > 0)
{
for (int i = 0; i < roomSlots.Count; i++)
{
roomSlots[i].index = i;
}
int i = 0;
foreach (NetworkRoomPlayer player in roomSlots)
player.index = i++;
}
}

Expand Down

0 comments on commit c573936

Please sign in to comment.