From a8630abbf6c63f0c187e47fb9da0e8ef307587ed Mon Sep 17 00:00:00 2001 From: vis2k Date: Wed, 26 May 2021 17:51:15 +0800 Subject: [PATCH] NetworkServer: CleanupSerializations helper function --- Assets/Mirror/Runtime/NetworkServer.cs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Assets/Mirror/Runtime/NetworkServer.cs b/Assets/Mirror/Runtime/NetworkServer.cs index 01ed93118..1772d0cb6 100644 --- a/Assets/Mirror/Runtime/NetworkServer.cs +++ b/Assets/Mirror/Runtime/NetworkServer.cs @@ -1438,6 +1438,20 @@ static Serialization GetEntitySerialization(NetworkIdentity identity) return serializations[identity]; } + // helper function to clean up cached serializations + static void CleanupSerializations() + { + // return serialized writers to pool, clear set + // TODO this is for feature parity before push->pull change. + // make this more simple / unnecessary later. + foreach (Serialization entry in serializations.Values) + { + NetworkWriterPool.Recycle(entry.ownerWriter); + NetworkWriterPool.Recycle(entry.observersWriter); + } + serializations.Clear(); + } + // helper function to broadcast the world to a connection static void BroadcastToConnection(NetworkConnectionToClient connection) { @@ -1542,15 +1556,8 @@ internal static void NetworkLateUpdate() connection.Update(); } - // return serialized writers to pool, clear set - // TODO this is for feature parity before push->pull change. - // make this more simple / unnecessary later. - foreach (Serialization entry in serializations.Values) - { - NetworkWriterPool.Recycle(entry.ownerWriter); - NetworkWriterPool.Recycle(entry.observersWriter); - } - serializations.Clear(); + // return serialized writers to pool + CleanupSerializations(); // TODO this unfortunately means we still need to iterate ALL // spawned and not just the ones with observers. figure