Kaynağa Gözat

优化了帧同步的日志,修复了更改Entity导致的一个bug

tanghai 1 yıl önce
ebeveyn
işleme
5a223ed3bf

+ 1 - 0
Unity/Assets/Config/Proto/LockStepOuter_C_11001.proto

@@ -51,6 +51,7 @@ message FrameMessage // IMessage
 
 message OneFrameInputs // IMessage
 {
+	int32 Frame = 1;
 	map<int64, LSInput> Inputs = 2;
 }
 

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

@@ -15,5 +15,5 @@ MonoBehaviour:
   CodeMode: 3
   EnableDll: 1
   BuildType: 0
-  AppType: 7
+  AppType: 8
   EPlayMode: 0

+ 2 - 19
Unity/Assets/Scripts/Core/Entity/Entity.cs

@@ -341,8 +341,8 @@ namespace ET
                         foreach ((long _, Entity component) in this.components)
                         {
                             component.IsComponent = true;
-                            this.Components.Add(GetLongHashCodeByType(component.GetType()), component);
                             component.parent = this;
+                            component.IScene = this.iScene;
                         }
                     }
 
@@ -351,29 +351,12 @@ namespace ET
                         foreach ((long _, Entity child) in this.children)
                         {
                             child.IsComponent = false;
-                            this.Children.Add(child.Id, child);
                             child.parent = this;
+                            child.IScene = this.iScene;
                         }
                     }
                 }
 
-                // 递归设置孩子的Domain
-                if (this.children != null)
-                {
-                    foreach (Entity entity in this.children.Values)
-                    {
-                        entity.IScene = this.iScene;
-                    }
-                }
-
-                if (this.components != null)
-                {
-                    foreach (Entity component in this.components.Values)
-                    {
-                        component.IScene = this.iScene;
-                    }
-                }
-
                 if (!this.IsNew)
                 {
                     this.IsNew = true;

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Client/LockStep/LSClientUpdaterSystem.cs

@@ -37,7 +37,7 @@ namespace ET.Client
 
                 ++room.PredictionFrame;
                 OneFrameInputs oneFrameInputs = self.GetOneFrameMessages(room.PredictionFrame);
-                
+                Log.Debug($"predictionFrame: {MongoHelper.ToJson(oneFrameInputs)}");
                 room.Update(oneFrameInputs);
                 room.SendHash(room.PredictionFrame);
                 
@@ -76,7 +76,7 @@ namespace ET.Client
                 authorityFrame.CopyTo(predictionFrame);
             }
             predictionFrame.Inputs[self.MyId] = self.Input;
-            
+            predictionFrame.Frame = frame;
             return predictionFrame;
         }
     }

+ 2 - 1
Unity/Assets/Scripts/Hotfix/Server/LockStep/Room/LSServerUpdaterSystem.cs

@@ -31,7 +31,7 @@ namespace ET.Server
 
             OneFrameInputs sendInput = OneFrameInputs.Create();
             oneFrameInputs.CopyTo(sendInput);
-
+            Log.Debug($"server broadcast: {sendInput}");
             RoomMessageHelper.BroadCast(room, sendInput);
 
             room.Update(oneFrameInputs);
@@ -72,6 +72,7 @@ namespace ET.Server
                 {
                     oneFrameInputs.Inputs[playerId] = new LSInput();
                 }
+                Log.Debug($"use last input, current frame: {frame} {playerId}:{oneFrameInputs.Inputs[playerId]}");
             }
 
             return oneFrameInputs;

+ 4 - 0
Unity/Assets/Scripts/Model/Generate/Client/Message/LockStepOuter_C_11001.cs

@@ -232,6 +232,9 @@ namespace ET
             return ObjectPool.Instance.Fetch(typeof(OneFrameInputs), isFromPool) as OneFrameInputs;
         }
 
+        [MemoryPackOrder(0)]
+        public int Frame { get; set; }
+
         [MongoDB.Bson.Serialization.Attributes.BsonDictionaryOptions(MongoDB.Bson.Serialization.Options.DictionaryRepresentation.ArrayOfArrays)]
         [MemoryPackOrder(1)]
         public Dictionary<long, LSInput> Inputs { get; set; } = new();
@@ -242,6 +245,7 @@ namespace ET
                 return;
             }
 
+            this.Frame = default;
             this.Inputs.Clear();
 
             ObjectPool.Instance.Recycle(this);

+ 4 - 0
Unity/Assets/Scripts/Model/Generate/ClientServer/Message/LockStepOuter_C_11001.cs

@@ -232,6 +232,9 @@ namespace ET
             return ObjectPool.Instance.Fetch(typeof(OneFrameInputs), isFromPool) as OneFrameInputs;
         }
 
+        [MemoryPackOrder(0)]
+        public int Frame { get; set; }
+
         [MongoDB.Bson.Serialization.Attributes.BsonDictionaryOptions(MongoDB.Bson.Serialization.Options.DictionaryRepresentation.ArrayOfArrays)]
         [MemoryPackOrder(1)]
         public Dictionary<long, LSInput> Inputs { get; set; } = new();
@@ -242,6 +245,7 @@ namespace ET
                 return;
             }
 
+            this.Frame = default;
             this.Inputs.Clear();
 
             ObjectPool.Instance.Recycle(this);

+ 4 - 0
Unity/Assets/Scripts/Model/Generate/Server/Message/LockStepOuter_C_11001.cs

@@ -232,6 +232,9 @@ namespace ET
             return ObjectPool.Instance.Fetch(typeof(OneFrameInputs), isFromPool) as OneFrameInputs;
         }
 
+        [MemoryPackOrder(0)]
+        public int Frame { get; set; }
+
         [MongoDB.Bson.Serialization.Attributes.BsonDictionaryOptions(MongoDB.Bson.Serialization.Options.DictionaryRepresentation.ArrayOfArrays)]
         [MemoryPackOrder(1)]
         public Dictionary<long, LSInput> Inputs { get; set; } = new();
@@ -242,6 +245,7 @@ namespace ET
                 return;
             }
 
+            this.Frame = default;
             this.Inputs.Clear();
 
             ObjectPool.Instance.Recycle(this);

+ 1 - 0
Unity/Assets/Scripts/Model/Share/LockStep/FrameBuffer.cs

@@ -68,6 +68,7 @@ namespace ET
         {
             EnsureFrame(frame);
             OneFrameInputs oneFrameInputs = this.frameInputs[frame % this.frameInputs.Capacity];
+            oneFrameInputs.Frame = frame;
             return oneFrameInputs;
         }
 

+ 6 - 0
Unity/Assets/Scripts/Model/Share/LockStep/OneFrameInputs.cs

@@ -12,6 +12,7 @@ namespace ET
 
         public void CopyTo(OneFrameInputs to)
         {
+            to.Frame = this.Frame;
             to.Inputs.Clear();
             foreach (var kv in this.Inputs)
             {
@@ -54,6 +55,11 @@ namespace ET
                 }
                 return false;
             }
+
+            if (a.Frame != b.Frame)
+            {
+                return false;
+            }
             
             if (a.Inputs.Count != b.Inputs.Count)
             {