mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
fix: NetworkConnection.observing changed back to regular HashSet instead of SortedSet. fixes identities with same distance being dropped
This commit is contained in:
parent
2362ae8db7
commit
0600478e69
@ -9,11 +9,17 @@ public abstract class NetworkConnection
|
||||
{
|
||||
public const int LocalConnectionId = 0;
|
||||
|
||||
// NetworkIdentities that this connection can see
|
||||
// sorted by distance to the main player object,
|
||||
// which is necessary for priority based WorldState sync
|
||||
// NetworkIdentities that this connection can see.
|
||||
// IMPORTANT: priority WorldState needs them sorted, but we can NOT
|
||||
// store them sorted for two reasons:
|
||||
// - they are only sorted during insertion, but
|
||||
// entities still move around after
|
||||
// - SortedSet uses comparer as key so entities with the same
|
||||
// distance would be dropped
|
||||
// => keep this unsorted. sort when needed.
|
||||
// TODO move to server's NetworkConnectionToClient?
|
||||
internal readonly SortedSet<NetworkIdentity> observing;
|
||||
internal readonly HashSet<NetworkIdentity> observing =
|
||||
new HashSet<NetworkIdentity>();
|
||||
|
||||
// TODO this is NetworkServer.handlers on server and NetworkClient.handlers on client.
|
||||
// maybe use them directly. avoid extra state.
|
||||
@ -54,9 +60,6 @@ public abstract class NetworkConnection
|
||||
|
||||
internal NetworkConnection()
|
||||
{
|
||||
// initialize 'observing' with the custom comparer
|
||||
observing = new SortedSet<NetworkIdentity>(new ObservingComparer(this));
|
||||
|
||||
// set lastTime to current time when creating connection to make
|
||||
// sure it isn't instantly kicked for inactivity
|
||||
lastMessageTime = Time.time;
|
||||
|
@ -1467,6 +1467,15 @@ internal static void NetworkLateUpdate()
|
||||
PartialWorldStateMessage world = new PartialWorldStateMessage();
|
||||
using (PooledNetworkWriter writer = NetworkWriterPool.GetWriter())
|
||||
{
|
||||
// we want to fill WorldState by priority.
|
||||
// we can't store .observing as sorted because that
|
||||
// guarantee would only exist during insertion since
|
||||
// entities still move around after.
|
||||
// => so let's sorted here
|
||||
// TODO nonalloc
|
||||
List<NetworkIdentity> sorted = connection.observing.ToList();
|
||||
sorted.Sort(new ObservingComparer(connection));
|
||||
|
||||
// for each entity that this connection is seeing,
|
||||
// sorted by priority (see NetworkConnection.observing)
|
||||
foreach (NetworkIdentity identity in connection.observing)
|
||||
|
Loading…
Reference in New Issue
Block a user