Explorar o código

生成存档数据,每隔一分钟保存LSWorld

tanghai %!s(int64=2) %!d(string=hai) anos
pai
achega
a80528b768

+ 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: 3
+  CodeMode: 1
   BuildType: 1

+ 20 - 1
Unity/Assets/Scripts/Hotfix/Share/LockStep/RoomSystem.cs

@@ -1,4 +1,5 @@
 using System;
+using System.IO;
 
 namespace ET
 {
@@ -27,7 +28,12 @@ namespace ET
             LSWorld lsWorld = self.GetComponent<LSWorld>();
             // 保存当前帧场景数据
             self.FrameBuffer.SaveLSWorld(frame, lsWorld);
-            
+
+            if (frame <= self.RealFrame) // 只有Real帧才保存录像数据
+            {
+                self.SaveData(frame);
+            }
+
             // 设置输入到每个LSUnit身上
             LSUnitComponent unitComponent = lsWorld.GetComponent<LSUnitComponent>();
             foreach (var kv in oneFrameMessages.Inputs)
@@ -39,5 +45,18 @@ namespace ET
             
             lsWorld.Update();
         }
+
+        public static void SaveData(this Room self, int frame)
+        {
+            OneFrameMessages oneFrameMessages = self.FrameBuffer[frame];
+            OneFrameMessages saveMessage = new();
+            oneFrameMessages.CopyTo(saveMessage);
+            self.SaveData.MessagesList.Add(saveMessage);
+            if (frame % LSConstValue.SaveLSWorldFrameCount == 0)
+            {
+                MemoryBuffer memoryBuffer = self.FrameBuffer.GetMemoryBuffer(frame);
+                self.SaveData.LSWorlds.Add(memoryBuffer.ToArray());   
+            }
+        }
     }
 }

+ 1 - 1
Unity/Assets/Scripts/HotfixView/Client/LockStep/LSUnitViewSystem.cs

@@ -38,7 +38,7 @@ namespace ET.Client
                 self.Position = unit.Position.ToVector();
                 self.Rotation = unit.Rotation.ToQuaternion();
             }
-
+            
             LSInput input = unit.GetComponent<LSInputComponent>().LSInput;
             if (input.V != TSVector2.zero)
             {

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

@@ -60,9 +60,24 @@ namespace ET
             oneFrameMessages.Frame = 0;
         }
 
-        public LSWorld GetLSWorld(int frame)
+        public MemoryBuffer GetMemoryBuffer(int frame)
         {
+            if (frame < 0)
+            {
+                return null;
+            }
+
+            if (frame > this.MaxFrame)
+            {
+                return null;
+            }
             MemoryBuffer memoryBuffer = this.dataBuffer[frame % this.dataBuffer.Capacity];
+            return memoryBuffer;
+        }
+
+        public LSWorld GetLSWorld(int frame)
+        {
+            MemoryBuffer memoryBuffer = GetMemoryBuffer(frame);
             return MongoHelper.Deserialize(typeof (LSWorld), memoryBuffer) as LSWorld;
         }
 

+ 2 - 1
Unity/Assets/Scripts/Model/Share/LockStep/LSConstValue.cs

@@ -2,8 +2,9 @@ namespace ET
 {
     public static class LSConstValue
     {
-        public const int MatchCount = 1;
+        public const int MatchCount = 2;
         public const int UpdateInterval = 50;
         public const int FrameCountPerSecond = 1000 / UpdateInterval;
+        public const int SaveLSWorldFrameCount = 60 * FrameCountPerSecond;
     }
 }

+ 8 - 0
Unity/Assets/Scripts/Model/Share/LockStep/LSWorld.cs

@@ -54,6 +54,13 @@ namespace ET
         public TSRandom Random { get; set; }
         
         public SceneType SceneType { get; set; }
+        
+        public int Frame { get; set; }
+
+        public long TimeNow()
+        {
+            return LSConstValue.UpdateInterval * this.Frame;
+        }
 
         public void AddToUpdater(LSEntity lsEntity)
         {
@@ -63,6 +70,7 @@ namespace ET
         public void Update()
         {
             this.updater.Update();
+            ++this.Frame;
         }
     }
 }

+ 2 - 0
Unity/Assets/Scripts/Model/Share/LockStep/Room.cs

@@ -21,5 +21,7 @@ namespace ET
         public int PredictionFrame { get; set; } = -1;
 
         public int RealFrame { get; set; } = -1;
+
+        public SaveData SaveData = new();
     }
 }

+ 15 - 0
Unity/Assets/Scripts/Model/Share/LockStep/SaveData.cs

@@ -0,0 +1,15 @@
+using System.Collections.Generic;
+using MemoryPack;
+
+namespace ET
+{
+    [MemoryPackable]
+    public class SaveData
+    {
+        [MemoryPackOrder(1)]
+        public List<OneFrameMessages> MessagesList = new();
+        
+        [MemoryPackOrder(2)]
+        public List<byte[]> LSWorlds = new();
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Model/Share/LockStep/SaveData.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 1775219934ec64b409ed64cb2aab6fbd
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: