From 50c2eab81ae0f3826bd529c9162b6ce06e957b19 Mon Sep 17 00:00:00 2001 From: vis2k Date: Thu, 28 Apr 2022 19:08:41 +0800 Subject: [PATCH] breaking: InterestManagement.OnRebuildObservers: HashSet changed to ISet to also support passing a SortedSet --- .../InterestManagement/Distance/DistanceInterestManagement.cs | 2 +- .../InterestManagement/Match/MatchInterestManagement.cs | 2 +- .../InterestManagement/Scene/SceneInterestManagement.cs | 2 +- .../SpatialHashing/SpatialHashingInterestManagement.cs | 2 +- .../InterestManagement/Team/TeamInterestManagement.cs | 4 ++-- Assets/Mirror/Runtime/InterestManagement.cs | 4 +++- 6 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Assets/Mirror/Components/InterestManagement/Distance/DistanceInterestManagement.cs b/Assets/Mirror/Components/InterestManagement/Distance/DistanceInterestManagement.cs index 116051b8a..c94c35a3a 100644 --- a/Assets/Mirror/Components/InterestManagement/Distance/DistanceInterestManagement.cs +++ b/Assets/Mirror/Components/InterestManagement/Distance/DistanceInterestManagement.cs @@ -32,7 +32,7 @@ public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnection return Vector3.Distance(identity.transform.position, newObserver.identity.transform.position) < range; } - public override void OnRebuildObservers(NetworkIdentity identity, HashSet newObservers) + public override void OnRebuildObservers(NetworkIdentity identity, ISet newObservers) { // cache range and .transform because both call GetComponent. int range = GetVisRange(identity); diff --git a/Assets/Mirror/Components/InterestManagement/Match/MatchInterestManagement.cs b/Assets/Mirror/Components/InterestManagement/Match/MatchInterestManagement.cs index ff2eadc13..2c50a7ad2 100644 --- a/Assets/Mirror/Components/InterestManagement/Match/MatchInterestManagement.cs +++ b/Assets/Mirror/Components/InterestManagement/Match/MatchInterestManagement.cs @@ -137,7 +137,7 @@ public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnection return identityNetworkMatch.matchId == newObserverNetworkMatch.matchId; } - public override void OnRebuildObservers(NetworkIdentity identity, HashSet newObservers) + public override void OnRebuildObservers(NetworkIdentity identity, ISet newObservers) { if (!identity.TryGetComponent(out NetworkMatch networkMatch)) return; diff --git a/Assets/Mirror/Components/InterestManagement/Scene/SceneInterestManagement.cs b/Assets/Mirror/Components/InterestManagement/Scene/SceneInterestManagement.cs index 8cbfa3bb8..079808568 100644 --- a/Assets/Mirror/Components/InterestManagement/Scene/SceneInterestManagement.cs +++ b/Assets/Mirror/Components/InterestManagement/Scene/SceneInterestManagement.cs @@ -94,7 +94,7 @@ public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnection return identity.gameObject.scene == newObserver.identity.gameObject.scene; } - public override void OnRebuildObservers(NetworkIdentity identity, HashSet newObservers) + public override void OnRebuildObservers(NetworkIdentity identity, ISet newObservers) { if (!sceneObjects.TryGetValue(identity.gameObject.scene, out HashSet objects)) return; diff --git a/Assets/Mirror/Components/InterestManagement/SpatialHashing/SpatialHashingInterestManagement.cs b/Assets/Mirror/Components/InterestManagement/SpatialHashing/SpatialHashingInterestManagement.cs index eb4c2c562..54cf2f1c7 100644 --- a/Assets/Mirror/Components/InterestManagement/SpatialHashing/SpatialHashingInterestManagement.cs +++ b/Assets/Mirror/Components/InterestManagement/SpatialHashing/SpatialHashingInterestManagement.cs @@ -52,7 +52,7 @@ public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnection return (projected - observerProjected).sqrMagnitude <= 2; } - public override void OnRebuildObservers(NetworkIdentity identity, HashSet newObservers) + public override void OnRebuildObservers(NetworkIdentity identity, ISet newObservers) { // add everyone in 9 neighbour grid // -> pass observers to GetWithNeighbours directly to avoid allocations diff --git a/Assets/Mirror/Components/InterestManagement/Team/TeamInterestManagement.cs b/Assets/Mirror/Components/InterestManagement/Team/TeamInterestManagement.cs index 22b4ace33..0847b6370 100644 --- a/Assets/Mirror/Components/InterestManagement/Team/TeamInterestManagement.cs +++ b/Assets/Mirror/Components/InterestManagement/Team/TeamInterestManagement.cs @@ -148,7 +148,7 @@ public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnection return identityNetworkTeam.teamId == newObserverNetworkTeam.teamId; } - public override void OnRebuildObservers(NetworkIdentity identity, HashSet newObservers) + public override void OnRebuildObservers(NetworkIdentity identity, ISet newObservers) { // If this object doesn't have a NetworkTeam then it's visible to all clients if (!identity.TryGetComponent(out NetworkTeam networkTeam)) @@ -178,7 +178,7 @@ public override void OnRebuildObservers(NetworkIdentity identity, HashSet newObservers) + void AddAllConnections(ISet newObservers) { foreach (NetworkConnectionToClient conn in NetworkServer.connections.Values) { diff --git a/Assets/Mirror/Runtime/InterestManagement.cs b/Assets/Mirror/Runtime/InterestManagement.cs index ab149c324..1a22d8160 100644 --- a/Assets/Mirror/Runtime/InterestManagement.cs +++ b/Assets/Mirror/Runtime/InterestManagement.cs @@ -54,7 +54,9 @@ public virtual void Reset() {} // // Mirror maintains .observing automatically in the background. best of // both worlds without any worrying now! - public abstract void OnRebuildObservers(NetworkIdentity identity, HashSet newObservers); + // + // ISet to support both HashSet and SortedSet. + public abstract void OnRebuildObservers(NetworkIdentity identity, ISet newObservers); // helper function to trigger a full rebuild. // most implementations should call this in a certain interval.