Преглед изворни кода

1.修复一个释放顺序引发的报错
2.消除LSUnitViewComponentSystem UpdateSystem中的GC
3.增加一个SortedLinkList,准备后面在客户端替代SortedDictionary

tanghai пре 2 година
родитељ
комит
f4c0488026

+ 1 - 1
Unity/Assets/Resources/GlobalConfig.asset

@@ -12,5 +12,5 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: 36527db572638af47b03c805671cba75, type: 3}
   m_Name: GlobalConfig
   m_EditorClassIdentifier: 
-  CodeMode: 1
+  CodeMode: 3
   BuildType: 1

+ 11 - 7
Unity/Assets/Scripts/Core/Module/Timer/TimerComponent.cs

@@ -95,16 +95,20 @@ namespace ET
                 return;
             }
 
-            foreach (KeyValuePair<long, List<long>> kv in this.TimeId)
+            using (var enumerator = this.TimeId.GetEnumerator())
             {
-                long k = kv.Key;
-                if (k > timeNow)
+                while (enumerator.MoveNext())
                 {
-                    this.minTime = k;
-                    break;
+                    var kv = enumerator.Current;
+                    long k = kv.Key;
+                    if (k > timeNow)
+                    {
+                        this.minTime = k;
+                        break;
+                    }
+
+                    this.timeOutTime.Enqueue(k);
                 }
-
-                this.timeOutTime.Enqueue(k);
             }
 
             while (this.timeOutTime.Count > 0)

+ 6 - 1
Unity/Assets/Scripts/Core/MultiMap.cs

@@ -3,7 +3,12 @@ using System.Collections.Generic;
 
 namespace ET
 {
-    public class MultiMap<T, K>: SortedDictionary<T, List<K>>
+    public class MultiMap<T, K>:
+//#if UNITY
+//            SortedLinkList<T, List<K>>
+//#else
+            SortedDictionary<T, List<K>>
+//#endif
     {
         private readonly List<K> Empty = new();
         private readonly int maxPoolCount;

+ 14 - 0
Unity/Assets/Scripts/Core/SortedLinkList.cs

@@ -6,6 +6,15 @@ namespace ET
 {
     public class SortedLinkList<T, K>: Dictionary<T, K> where T: IComparable<T>, IEnumerable
     {
+        //public struct KeyValuePair
+        //{
+        //    public SortedLinkList<T, K> sortedLinkList;
+        //    public T Key;
+        //    public K Value;
+        //    
+        //    public KeyValuePair()
+        //}
+        
         public class Node
         {
             public Node Next;
@@ -36,6 +45,11 @@ namespace ET
             this.pool.Enqueue(node);
         }
 
+        //public new KeyValuePair GetEnumerator()
+        //{
+        //    return new 
+        //}
+
         public T FirstKey()
         {
             return this.head.Value;

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Module/Actor/MailBoxComponentSystem.cs

@@ -29,7 +29,7 @@ namespace ET.Server
     {
         protected override void Destroy(MailBoxComponent self)
         {
-            ActorMessageDispatcherComponent.Instance.Remove(self.ParentInstanceId);
+            ActorMessageDispatcherComponent.Instance?.Remove(self.ParentInstanceId);
         }
     }
 }

+ 5 - 22
Unity/Assets/Scripts/HotfixView/Client/LockStep/LSUnitViewComponentSystem.cs

@@ -14,33 +14,16 @@ namespace ET.Client
             }
         }
         
-        //public class RollbackSystem: RollbackSystem<LSUnitViewComponent>
-        //{
-        //    protected override void Rollback(LSUnitViewComponent self)
-        //    {
-        //        LSWorld lsWorld = self.GetParent<Room>().LSWorld;
-        //        foreach (LSUnitView child in self.Children.Values)
-        //        {
-        //            LSUnit unit = lsWorld.Get(child.Id) as LSUnit;
-//
-        //            Vector3 pos = child.Transform.position;
-        //            Vector3 to = unit.Position.ToVector();
-        //            float t = (to - pos).magnitude / 9f;
-//
-        //            child.Transform.position = pos;
-        //        }
-        //    }
-        //}
-        
         public class UpdateSystem: UpdateSystem<LSUnitViewComponent>
         {
             protected override void Update(LSUnitViewComponent self)
             {
-                LSWorld lsWorld = self.GetParent<Room>().LSWorld;
-                foreach (LSUnitView child in self.Children.Values)
+                Room room = self.GetParent<Room>();
+                LSWorld lsWorld = room.LSWorld;
+                foreach (long playerId in room.PlayerIds)
                 {
-                    LSUnit unit = lsWorld.Get(child.Id) as LSUnit;
-
+                    LSUnit unit = lsWorld.Get(playerId) as LSUnit;
+                    LSUnitView child = self.GetChild<LSUnitView>(playerId);
                     Vector3 pos = child.Transform.position;
                     Vector3 to = unit.Position.ToVector();
                     float distance = (to - pos).magnitude;