Simplify network connection clientOwnedObjects (#758)

* Simplify network connection clientOwnedObjects

* Whoops, missed this null check in NetworkServer. Thanks vis
This commit is contained in:
rodolphito 2019-04-07 09:57:38 -07:00 committed by vis2k
parent 146988a6bb
commit b7ae7f006c
2 changed files with 10 additions and 17 deletions

View File

@ -16,7 +16,7 @@ public class NetworkConnection : IDisposable
public string address;
public float lastMessageTime;
public NetworkIdentity playerController { get; internal set; }
public HashSet<uint> clientOwnedObjects;
public HashSet<uint> clientOwnedObjects = new HashSet<uint>();
public bool logNetworkMessages;
// this is always true for regular connections, false for local
@ -58,8 +58,6 @@ public void Dispose()
}
protected virtual void Dispose(bool disposing)
{
if (clientOwnedObjects != null)
{
foreach (uint netId in clientOwnedObjects)
{
@ -68,8 +66,7 @@ protected virtual void Dispose(bool disposing)
identity.clientAuthorityOwner = null;
}
}
}
clientOwnedObjects = null;
clientOwnedObjects.Clear();
}
public void Disconnect()
@ -278,13 +275,12 @@ public virtual bool TransportSend(int channelId, byte[] bytes, out byte error)
internal void AddOwnedObject(NetworkIdentity obj)
{
clientOwnedObjects = clientOwnedObjects ?? new HashSet<uint>();
clientOwnedObjects.Add(obj.netId);
}
internal void RemoveOwnedObject(NetworkIdentity obj)
{
clientOwnedObjects?.Remove(obj.netId);
clientOwnedObjects.Remove(obj.netId);
}
}
}

View File

@ -977,8 +977,6 @@ public static void DestroyPlayerForConnection(NetworkConnection conn)
// so we need null checks for both of them.
// => destroy what we can destroy.
if (conn.clientOwnedObjects != null)
{
HashSet<uint> tmp = new HashSet<uint>(conn.clientOwnedObjects);
foreach (uint netId in tmp)
{
@ -987,7 +985,6 @@ public static void DestroyPlayerForConnection(NetworkConnection conn)
Destroy(identity.gameObject);
}
}
}
if (conn.playerController != null)
{