From 5c48971d8e5305994c278d3ed0cb3b4f2fda0057 Mon Sep 17 00:00:00 2001 From: MrGadget <9826063+MrGadget1024@users.noreply.github.com> Date: Sat, 22 Jan 2022 19:35:56 -0500 Subject: [PATCH] Updated SyncListWithUserData --- Assets/Mirror/Runtime/SyncListWithUserData.cs | 46 ++++++------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/Assets/Mirror/Runtime/SyncListWithUserData.cs b/Assets/Mirror/Runtime/SyncListWithUserData.cs index ad7f4b5f1..529001e38 100644 --- a/Assets/Mirror/Runtime/SyncListWithUserData.cs +++ b/Assets/Mirror/Runtime/SyncListWithUserData.cs @@ -243,14 +243,10 @@ public override void OnDeserializeDelta(NetworkReader reader) } if (apply) - { Callback?.Invoke(operation, index, oldItem, newItem, default); - } - // we just skipped this change else - { + // we just skipped this change changesAhead--; - } } } @@ -311,13 +307,6 @@ public List FindAll(Predicate match) return results; } - public void Insert(int index, T item) - { - objects.Insert(index, item); - InternalUserData.Insert(index, default); - AddOperation(Operation.OP_INSERT, index, default, item, default); - } - public void InsertRange(int index, IEnumerable range) { foreach (T entry in range) @@ -327,14 +316,11 @@ public void InsertRange(int index, IEnumerable range) } } - public bool Remove(T item) + public void Insert(int index, T item) { - int index = IndexOf(item); - bool result = index >= 0; - if (result) - RemoveAt(index); - - return result; + objects.Insert(index, item); + InternalUserData.Insert(index, default); + AddOperation(Operation.OP_INSERT, index, default, item, default); } public int RemoveAll(Predicate match) @@ -350,13 +336,21 @@ public int RemoveAll(Predicate match) return toRemove.Count; } + public bool Remove(T item) + { + int index = IndexOf(item); + bool result = index >= 0; + if (result) + RemoveAt(index); + + return result; + } + public void RemoveAt(int index) { T oldItem = objects[index]; TUserData userData = InternalUserData[index]; - UnityEngine.Debug.LogWarning($"objects RemoveAt {index}"); objects.RemoveAt(index); - UnityEngine.Debug.LogWarning($"InternalUserData RemoveAt {index}"); InternalUserData.RemoveAt(index); AddOperation(Operation.OP_REMOVEAT, index, oldItem, default, userData); } @@ -388,16 +382,6 @@ public T this[int i] IEnumerator IEnumerable.GetEnumerator() => new Enumerator(this); - // default Enumerator allocates. we need a custom struct Enumerator to - // not allocate on the heap. - // (System.Collections.Generic.List source code does the same) - // - // benchmark: - // uMMORPG with 800 monsters, Skills.GetHealthBonus() which runs a - // foreach on skills SyncList: - // before: 81.2KB GC per frame - // after: 0KB GC per frame - // => this is extremely important for MMO scale networking public struct Enumerator : IEnumerator { readonly SyncListWithUserData list;