mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
Interest Management: NetworkConnection.visList renamed to observing
This commit is contained in:
parent
bd4fa37cd5
commit
650231025f
@ -18,8 +18,8 @@ public abstract class NetworkConnection
|
||||
{
|
||||
public const int LocalConnectionId = 0;
|
||||
|
||||
// internal so it can be tested
|
||||
internal readonly HashSet<NetworkIdentity> visList = new HashSet<NetworkIdentity>();
|
||||
// NetworkIdentities that this connection can see
|
||||
internal readonly HashSet<NetworkIdentity> observing = new HashSet<NetworkIdentity>();
|
||||
|
||||
Dictionary<int, NetworkMessageDelegate> messageHandlers;
|
||||
|
||||
@ -156,17 +156,17 @@ public override string ToString()
|
||||
return $"connection({connectionId})";
|
||||
}
|
||||
|
||||
internal void AddToVisList(NetworkIdentity identity)
|
||||
internal void AddToObserving(NetworkIdentity identity)
|
||||
{
|
||||
visList.Add(identity);
|
||||
observing.Add(identity);
|
||||
|
||||
// spawn identity for this conn
|
||||
NetworkServer.ShowForConnection(identity, this);
|
||||
}
|
||||
|
||||
internal void RemoveFromVisList(NetworkIdentity identity, bool isDestroyed)
|
||||
internal void RemoveFromObserving(NetworkIdentity identity, bool isDestroyed)
|
||||
{
|
||||
visList.Remove(identity);
|
||||
observing.Remove(identity);
|
||||
|
||||
if (!isDestroyed)
|
||||
{
|
||||
@ -177,11 +177,11 @@ internal void RemoveFromVisList(NetworkIdentity identity, bool isDestroyed)
|
||||
|
||||
internal void RemoveObservers()
|
||||
{
|
||||
foreach (NetworkIdentity identity in visList)
|
||||
foreach (NetworkIdentity identity in observing)
|
||||
{
|
||||
identity.RemoveObserverInternal(this);
|
||||
}
|
||||
visList.Clear();
|
||||
observing.Clear();
|
||||
}
|
||||
|
||||
// helper function
|
||||
|
@ -1143,7 +1143,7 @@ internal void ClearObservers()
|
||||
{
|
||||
foreach (NetworkConnection conn in observers.Values)
|
||||
{
|
||||
conn.RemoveFromVisList(this, true);
|
||||
conn.RemoveFromObserving(this, true);
|
||||
}
|
||||
observers.Clear();
|
||||
}
|
||||
@ -1167,7 +1167,7 @@ internal void AddObserver(NetworkConnection conn)
|
||||
// Debug.Log("Added observer " + conn.address + " added for " + gameObject);
|
||||
|
||||
observers[conn.connectionId] = conn;
|
||||
conn.AddToVisList(this);
|
||||
conn.AddToObserving(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1264,7 +1264,7 @@ public void RebuildObservers(bool initialize)
|
||||
if (initialize || !observers.ContainsKey(conn.connectionId))
|
||||
{
|
||||
// new observer
|
||||
conn.AddToVisList(this);
|
||||
conn.AddToObserving(this);
|
||||
// Debug.Log("New Observer for " + gameObject + " " + conn);
|
||||
changed = true;
|
||||
}
|
||||
@ -1277,7 +1277,7 @@ public void RebuildObservers(bool initialize)
|
||||
if (!newObservers.Contains(conn))
|
||||
{
|
||||
// removed observer
|
||||
conn.RemoveFromVisList(this, false);
|
||||
conn.RemoveFromObserving(this, false);
|
||||
// Debug.Log("Removed Observer for " + gameObject + " " + conn);
|
||||
changed = true;
|
||||
}
|
||||
|
@ -1628,9 +1628,9 @@ public void RebuildObserversDoesNotAddServerConnectionsIfImplemented()
|
||||
}
|
||||
|
||||
// RebuildObservers is complex. let's do one full test where we check
|
||||
// add, remove and vislist.
|
||||
// add, remove and observing.
|
||||
[Test]
|
||||
public void RebuildObserversAddRemoveAndVisListTest()
|
||||
public void RebuildObserversAddRemoveAndObservingTest()
|
||||
{
|
||||
// add observer component with ready observer
|
||||
RebuildObserversNetworkBehaviour comp = gameObject.AddComponent<RebuildObserversNetworkBehaviour>();
|
||||
@ -1645,9 +1645,9 @@ public void RebuildObserversAddRemoveAndVisListTest()
|
||||
Assert.That(identity.observers.Count, Is.EqualTo(1));
|
||||
Assert.That(identity.observers.ContainsKey(observerA.connectionId));
|
||||
|
||||
// identity should have added itself to the observer's visList
|
||||
Assert.That(observerA.visList.Count, Is.EqualTo(1));
|
||||
Assert.That(observerA.visList.Contains(identity), Is.True);
|
||||
// identity should have added itself to the observer's observing
|
||||
Assert.That(observerA.observing.Count, Is.EqualTo(1));
|
||||
Assert.That(observerA.observing.Contains(identity), Is.True);
|
||||
|
||||
// let the component find another observer
|
||||
NetworkConnectionToClient observerB = new NetworkConnectionToClient(43, false, 0) { isReady = true };
|
||||
@ -1658,11 +1658,11 @@ public void RebuildObserversAddRemoveAndVisListTest()
|
||||
Assert.That(identity.observers.Count, Is.EqualTo(1));
|
||||
Assert.That(identity.observers.ContainsKey(observerB.connectionId));
|
||||
|
||||
// identity should have removed itself from the old observer's visList
|
||||
// and added itself to new observer's vislist
|
||||
Assert.That(observerA.visList.Count, Is.EqualTo(0));
|
||||
Assert.That(observerB.visList.Count, Is.EqualTo(1));
|
||||
Assert.That(observerB.visList.Contains(identity), Is.True);
|
||||
// identity should have removed itself from the old observer's observing
|
||||
// and added itself to new observer's observing
|
||||
Assert.That(observerA.observing.Count, Is.EqualTo(0));
|
||||
Assert.That(observerB.observing.Count, Is.EqualTo(1));
|
||||
Assert.That(observerB.observing.Contains(identity), Is.True);
|
||||
|
||||
// clean up
|
||||
NetworkServer.Shutdown();
|
||||
|
Loading…
Reference in New Issue
Block a user