Skip to content

Commit cb23eea

Browse files
committed
changed how we build the receiver array
1 parent 3c84dd3 commit cb23eea

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

Basis/Packages/com.basis.framework/Networking/BasisNetworkLifeCycle.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ public static void Initalize(BasisNetworkManagement Management)
4040

4141
Management.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity);
4242
BasisNetworkManagement.OnEnableInstanceCreate?.Invoke();
43-
44-
BasisNetworkPlayers.PublishReceiversSnapshot();
4543
BasisNetworkManagement.NetworkRunning = true;
4644
}
4745
public static bool GoingThroughReboot = false;

Basis/Packages/com.basis.framework/Networking/BasisNetworkManagement.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ public static bool IsMainThread()
151151
public static float Beta = 2;
152152
// [Header("DerivativeCutoff This controls how noisy the speed estimate itself is.Before the filter adapts, it estimates velocity:")]
153153
public static float DerivativeCutoff = 2;
154-
public static BasisNetworkReceiver[] snapshot;
155-
public static int Length;
156154
/// <summary>
157155
/// Simulates network computation step (state updates, bone drivers, profiler update).
158156
/// </summary>
@@ -164,12 +162,12 @@ public static void SimulateNetworkCompute(float UnscaledDeltaTime)
164162
return;
165163
}
166164

167-
snapshot = BasisNetworkPlayers.ReceiversSnapshot;
165+
BasisNetworkPlayers.PublishReceiversSnapshot();
166+
168167
BoneJobSystem = RemoteBoneJobSystem.Schedule(); // will always be a frame behind
169-
Length = snapshot.Length;
170-
for (int Index = 0; Index < Length; Index++)
168+
for (int Index = 0; Index < BasisNetworkPlayers.ReceiverCount; Index++)
171169
{
172-
snapshot[Index].Compute(UnscaledDeltaTime);
170+
BasisNetworkPlayers.ReceiversSnapshot[Index].Compute(UnscaledDeltaTime);
173171
}
174172
BasisRemoteNetworkDriver.Compute();
175173
BasisNetworkProfiler.Update();
@@ -197,9 +195,9 @@ public static void SimulateNetworkApply()
197195
}
198196

199197
BasisRemoteNetworkDriver.Apply();
200-
for (int Index = 0; Index < Length; Index++)
198+
for (int Index = 0; Index < BasisNetworkPlayers.ReceiverCount; Index++)
201199
{
202-
snapshot[Index].Apply();
200+
BasisNetworkPlayers.ReceiversSnapshot[Index].Apply();
203201
}
204202
}
205203

Basis/Packages/com.basis.framework/Networking/BasisNetworkPlayers.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ public static class BasisNetworkPlayers
2121
public static readonly ConcurrentDictionary<string, ushort> OwnershipPairing = new();
2222

2323
// Receiver snapshot for multi-threaded compute/apply phases.
24-
private static volatile BasisNetworkReceiver[] _receiversSnapshot = Array.Empty<BasisNetworkReceiver>();
25-
public static BasisNetworkReceiver[] ReceiversSnapshot => _receiversSnapshot;
26-
public static int ReceiverCount => _receiversSnapshot.Length;
24+
public static BasisNetworkReceiver[] ReceiversSnapshot = Array.Empty<BasisNetworkReceiver>();
25+
public static int ReceiverCount;
2726

2827
// --- Lifecycle helpers ---------------------------------------------
2928
public static void ClearAllRegistries()
@@ -36,11 +35,11 @@ public static void ClearAllRegistries()
3635
RemotePlayers.Clear();
3736
JoiningPlayers.Clear();
3837
OwnershipPairing.Clear();
39-
PublishReceiversSnapshot();
4038
}
4139
public static void PublishReceiversSnapshot()
4240
{
43-
_receiversSnapshot = RemotePlayers.Count == 0 ? Array.Empty<BasisNetworkReceiver>() : RemotePlayers.Values.ToArray();
41+
ReceiversSnapshot = RemotePlayers.Count == 0 ? Array.Empty<BasisNetworkReceiver>() : RemotePlayers.Values.ToArray();
42+
ReceiverCount = ReceiversSnapshot.Length;
4443
}
4544

4645
// --- Registry APIs --------------------------------------------------
@@ -84,8 +83,6 @@ public static bool AddPlayer(BasisNetworkPlayer netPlayer)
8483
BasisDebug.LogError($"Failed to add remote player {netPlayer.playerId} to RemotePlayers. Rolled back from Players.");
8584
return false;
8685
}
87-
88-
PublishReceiversSnapshot();
8986
}
9087

9188
return true;
@@ -102,7 +99,6 @@ public static bool RemovePlayer(ushort netId, out BasisNetworkPlayer player)
10299

103100
Players.TryRemove(netId, out player);
104101
RemotePlayers.TryRemove(netId, out _);
105-
PublishReceiversSnapshot();
106102
return true;
107103
}
108104

0 commit comments

Comments
 (0)