NetworkIdentity.RebuildObservers: GetNewObservers code split into separate function

This commit is contained in:
vis2k 2020-03-03 22:12:34 +01:00
parent e00e8195bb
commit 01f5fb4a94

View File

@ -971,6 +971,21 @@ internal void AddObserver(NetworkConnection conn)
conn.AddToVisList(this);
}
// helper function to call OnRebuildObservers in all components
// -> HashSet is passed in so we can cache it!
internal bool GetNewObservers(HashSet<NetworkConnection> observersSet, bool initialize)
{
bool result = false;
observersSet.Clear();
foreach (NetworkBehaviour comp in NetworkBehaviours)
{
result |= comp.OnRebuildObservers(observersSet, initialize);
}
return result;
}
static readonly HashSet<NetworkConnection> newObservers = new HashSet<NetworkConnection>();
/// <summary>
@ -983,15 +998,9 @@ public void RebuildObservers(bool initialize)
return;
bool changed = false;
bool result = false;
newObservers.Clear();
// call OnRebuildObservers function in components
foreach (NetworkBehaviour comp in NetworkBehaviours)
{
result |= comp.OnRebuildObservers(newObservers, initialize);
}
// call OnRebuildObservers function in all components
bool result = GetNewObservers(newObservers, initialize);
// if player connection: ensure player always see himself no matter what.
// -> fixes https://github.com/vis2k/Mirror/issues/692 where a