Ver código fonte

保存一下

tanghai 2 anos atrás
pai
commit
364c06300a
38 arquivos alterados com 294 adições e 360 exclusões
  1. 11 6
      Unity/Assets/Config/Proto/LockStepOuter_C_11001.proto
  2. 68 7
      Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/BattleSceneClientUpdaterSystem.cs
  3. 5 1
      Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/OneFrameMessagesHandler.cs
  4. 2 2
      Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/Room2C_EnterMapHandler.cs
  5. 7 7
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/C2Room_ChangeSceneFinishHandler.cs
  6. 3 1
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/FrameMessageHandler.cs
  7. 2 0
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomServerComponentSystem.cs
  8. 0 24
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Room/BattleSceneServerUpdaterSystem.cs
  9. 0 3
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Room/BattleSceneServerUpdaterSystem.cs.meta
  10. 3 3
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Room/ServerFrameRecvComponentSystem.cs
  11. 8 25
      Unity/Assets/Scripts/Codes/Hotfix/Share/LockStep/BattleSceneSystem.cs
  12. 5 1
      Unity/Assets/Scripts/Codes/HotfixView/Client/LockStep/LockStepOperaComponentSystem.cs
  13. 1 1
      Unity/Assets/Scripts/Codes/Model/Client/Demo/Ping/PingComponent.cs
  14. 7 1
      Unity/Assets/Scripts/Codes/Model/Client/LockStep/BattleSceneClientUpdater.cs
  15. 1 1
      Unity/Assets/Scripts/Codes/Model/Client/LockStep/WaitType.cs
  16. 22 12
      Unity/Assets/Scripts/Codes/Model/Generate/Client/Message/LockStepOuter_C_11001.cs
  17. 0 11
      Unity/Assets/Scripts/Codes/Model/Generate/Client/Message/LockStepOuter_C_11001.cs.meta
  18. 0 11
      Unity/Assets/Scripts/Codes/Model/Generate/Client/Message/OuterMessage_C_10001.cs.meta
  19. 0 11
      Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/InnerMessage_S_20001.cs.meta
  20. 0 11
      Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/LockStepInner_S_21001.cs.meta
  21. 22 12
      Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/LockStepOuter_C_11001.cs
  22. 0 11
      Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/LockStepOuter_C_11001.cs.meta
  23. 0 11
      Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/OuterMessage_C_10001.cs.meta
  24. 0 11
      Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/InnerMessage_S_20001.cs.meta
  25. 0 11
      Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/LockStepInner_S_21001.cs.meta
  26. 22 12
      Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/LockStepOuter_C_11001.cs
  27. 0 11
      Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/LockStepOuter_C_11001.cs.meta
  28. 0 11
      Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/OuterMessage_C_10001.cs.meta
  29. 1 0
      Unity/Assets/Scripts/Codes/Model/Server/LockStep/Map/RoomPlayer.cs
  30. 0 8
      Unity/Assets/Scripts/Codes/Model/Server/LockStep/Room/BattleSceneServerUpdater.cs
  31. 0 3
      Unity/Assets/Scripts/Codes/Model/Server/LockStep/Room/BattleSceneServerUpdater.cs.meta
  32. 29 2
      Unity/Assets/Scripts/Codes/Model/Share/LockStep/BattleScene.cs
  33. 28 14
      Unity/Assets/Scripts/Codes/Model/Share/LockStep/FrameBuffer.cs
  34. 0 0
      Unity/Assets/Scripts/Codes/Model/Share/LockStep/LSConstValue.cs
  35. 0 0
      Unity/Assets/Scripts/Codes/Model/Share/LockStep/LSConstValue.cs.meta
  36. 27 0
      Unity/Assets/Scripts/Codes/Model/Share/LockStep/LSInputInfo.cs
  37. 3 0
      Unity/Assets/Scripts/Codes/Model/Share/LockStep/LSInputInfo.cs.meta
  38. 17 104
      Unity/Assets/Scripts/Codes/Model/Share/LockStep/OneFrameMessage.cs

+ 11 - 6
Unity/Assets/Config/Proto/LockStepOuter_C_11001.proto

@@ -36,23 +36,28 @@ message LockStepUnitInfo
 }
 
 // 房间通知客户端进入战斗
-message Room2C_EnterMap // IActorMessage
+message Room2C_BattleStart // IActorMessage
 {
 	int64 StartTime = 1;
 	repeated LockStepUnitInfo UnitInfo = 2;
 }
 
+message LSInputInfo
+{
+	TrueSync.TSVector2 V = 1;
+	int32 Button = 2;
+}
+
 message FrameMessage // IActorMessage
 {
-	int64 PlayerId = 1;
-	int32 Frame = 2;
-	TrueSync.TSVector2 V = 3;
-	int32 Button = 4;
+	int32 Frame = 1;
+	int64 PlayerId = 2;
+	LSInputInfo InputInfo = 3;
 }
 
 message OneFrameMessages // IActorMessage
 {
 	int32 Frame = 1;
-	map<int64, FrameMessage> Messages = 2;
+	map<int64, LSInputInfo> InputInfos = 2;
 }
 

+ 68 - 7
Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/BattleSceneClientUpdaterSystem.cs

@@ -2,23 +2,84 @@ using System;
 
 namespace ET.Client
 {
-    [FriendOf(typeof(BattleScene))]
+    [FriendOf(typeof (BattleSceneClientUpdater))]
     public static class BattleSceneClientUpdaterSystem
     {
-        [FriendOf(typeof(BattleScene))]
+        [FriendOf(typeof (BattleScene))]
         public class UpdateSystem: UpdateSystem<BattleSceneClientUpdater>
         {
             protected override void Update(BattleSceneClientUpdater self)
             {
-                BattleScene battleScene = self.GetParent<BattleScene>();
-                long timeNow = TimeHelper.ServerFrameTime();
-                if (timeNow > battleScene.StartTime + battleScene.Frame * LSConstValue.UpdateInterval)
+                self.Update();
+            }
+        }
+
+        private static void Update(this BattleSceneClientUpdater self)
+        {
+            BattleScene battleScene = self.GetParent<BattleScene>();
+
+            FrameBuffer frameBuffer = battleScene.FrameBuffer;
+
+            long timeNow = TimeHelper.ServerFrameTime();
+            if (timeNow < battleScene.StartTime + battleScene.FrameBuffer.NowFrame * LSConstValue.UpdateInterval)
+            {
+                return;
+            }
+
+            // 执行到PredictionFrame, 每次update最多执行5帧
+            if (frameBuffer.NowFrame < frameBuffer.RealFrame + frameBuffer.PredictionCount)
+            {
+                int j = 0;
+                for (int i = frameBuffer.NowFrame; i < frameBuffer.RealFrame + frameBuffer.PredictionCount; ++i)
                 {
-                    OneFrameMessages oneFrameMessages = battleScene.FrameBuffer.GetFrameMessage(battleScene.Frame);
+                    if (++j % 5 == 0)
+                    {
+                        break;
+                    }
+
+                    ++frameBuffer.NowFrame;
+                    OneFrameMessages oneFrameMessages = GetOneFrameMessages(self, i);
                     battleScene.Update(oneFrameMessages);
-                    ++battleScene.Frame;
                 }
             }
         }
+
+        private static OneFrameMessages GetOneFrameMessages(this BattleSceneClientUpdater self, int frame)
+        {
+            BattleScene battleScene = self.GetParent<BattleScene>();
+            FrameBuffer frameBuffer = battleScene.FrameBuffer;
+            if (frame != frameBuffer.NowFrame + 1)
+            {
+                throw new Exception($"get frame error: {frame} {frameBuffer.NowFrame} {frameBuffer.RealFrame}");
+            }
+
+            if (frame <= frameBuffer.RealFrame)
+            {
+                return frameBuffer.GetFrame(frame);
+            }
+
+            // predict
+            return GetPredictionOneFrameMessage(self, frame);
+        }
+
+        // 获取预测一帧的消息
+        private static OneFrameMessages GetPredictionOneFrameMessage(this BattleSceneClientUpdater self, int frame)
+        {
+            BattleScene battleScene = self.GetParent<BattleScene>();
+            OneFrameMessages preFrame = battleScene.FrameBuffer.GetFrame(frame - 1);
+            if (preFrame == null)
+            {
+                return null;
+            }
+
+            OneFrameMessages predictionFrame = MongoHelper.Clone(preFrame);
+
+            predictionFrame.Frame = frame;
+
+            PlayerComponent playerComponent = battleScene.GetParent<Scene>().GetComponent<PlayerComponent>();
+            long myId = playerComponent.MyId;
+            predictionFrame.InputInfos[myId] = self.InputInfo;
+            return predictionFrame;
+        }
     }
 }

+ 5 - 1
Unity/Assets/Scripts/Codes/Hotfix/Client/LockStep/OneFrameMessagesHandler.cs

@@ -5,7 +5,11 @@ namespace ET.Client
     {
         protected override async ETTask Run(Session session, OneFrameMessages message)
         {
-            session.DomainScene().GetComponent<BattleScene>().FrameBuffer.AddFrameMessage(message);
+            FrameBuffer frameBuffer = session.DomainScene().GetComponent<BattleScene>().FrameBuffer;
+            frameBuffer.AddRealFrame(message);
+            
+            PingComponent pingComponent = session.GetComponent<PingComponent>();
+            frameBuffer.PredictionCount = (int) (pingComponent.Ping / 2f / LSConstValue.UpdateInterval) + 1;
             await ETTask.CompletedTask;
         }
     }

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

@@ -1,9 +1,9 @@
 namespace ET.Client
 {
     [MessageHandler(SceneType.Client)]
-    public class Room2C_EnterMapHandler: AMHandler<Room2C_EnterMap>
+    public class Room2C_EnterMapHandler: AMHandler<Room2C_BattleStart>
     {
-        protected override async ETTask Run(Session session, Room2C_EnterMap message)
+        protected override async ETTask Run(Session session, Room2C_BattleStart message)
         {
             session.DomainScene().GetComponent<ObjectWait>().Notify(new WaitType.Wait_Room2C_EnterMap() {Message = message});
             await ETTask.CompletedTask;

+ 7 - 7
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/C2Room_ChangeSceneFinishHandler.cs

@@ -23,20 +23,20 @@ namespace ET.Server
             {
                 await TimerComponent.Instance.WaitAsync(1000);
 
-                Room2C_EnterMap room2CEnterMap = new Room2C_EnterMap() {StartTime = TimeHelper.ServerFrameTime(), UnitInfo = new List<LockStepUnitInfo>()};
-                foreach (var kv in roomServerComponent.Children)
+                Room2C_BattleStart room2CBattleStart = new() {StartTime = TimeHelper.ServerFrameTime()};
+                foreach (RoomPlayer rp in roomServerComponent.Children.Values)
                 {
-                    room2CEnterMap.UnitInfo.Add(new LockStepUnitInfo()
+                    room2CBattleStart.UnitInfo[rp.Slot] = new LockStepUnitInfo()
                     {
-                        PlayerId = kv.Key, 
+                        PlayerId = rp.Id, 
                         Position = new TSVector(10, 0, 10), 
                         Rotation = TSQuaternion.identity
-                    });
+                    };
                 }
                 
-                roomScene.GetComponent<BattleScene>().Init(room2CEnterMap);
+                roomScene.GetComponent<BattleScene>().Init(room2CBattleStart);
 
-                RoomMessageHelper.BroadCast(roomScene, room2CEnterMap);
+                RoomMessageHelper.BroadCast(roomScene, room2CBattleStart);
             }
 
             await ETTask.CompletedTask;

+ 3 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/FrameMessageHandler.cs

@@ -1,3 +1,5 @@
+using System.Collections.Generic;
+
 namespace ET.Server
 {
     [ActorMessageHandler(SceneType.Room)]
@@ -9,7 +11,7 @@ namespace ET.Server
             if (oneFrameMessages != null)
             {
                 BattleScene battleScene = roomScene.GetComponent<BattleScene>();
-                battleScene.FrameBuffer.AddFrameMessage(oneFrameMessages);
+                battleScene.FrameBuffer.AddRealFrame(oneFrameMessages);
             }
             
             RoomMessageHelper.BroadCast(roomScene, oneFrameMessages);

+ 2 - 0
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomServerComponentSystem.cs

@@ -10,9 +10,11 @@ namespace ET.Server
         {
             protected override void Awake(RoomServerComponent self, Match2Map_GetRoom match2MapGetRoom)
             {
+                int slot = 0;
                 foreach (long id in match2MapGetRoom.PlayerIds)
                 {
                     RoomPlayer roomPlayer = self.AddChildWithId<RoomPlayer>(id);
+                    roomPlayer.Slot = slot++;
                 }
             }
         }

+ 0 - 24
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Room/BattleSceneServerUpdaterSystem.cs

@@ -1,24 +0,0 @@
-using System;
-
-namespace ET.Server
-{
-    [FriendOf(typeof(BattleScene))]
-    public static class BattleSceneServerUpdaterSystem
-    {
-        [FriendOf(typeof(BattleScene))]
-        public class UpdateSystem: UpdateSystem<BattleSceneServerUpdater>
-        {
-            protected override void Update(BattleSceneServerUpdater self)
-            {
-                BattleScene battleScene = self.GetParent<BattleScene>();
-                long timeNow = TimeHelper.ServerFrameTime();
-                if (timeNow > battleScene.StartTime + battleScene.Frame * LSConstValue.UpdateInterval)
-                {
-                    OneFrameMessages oneFrameMessages = battleScene.FrameBuffer.GetFrameMessage(battleScene.Frame);
-                    battleScene.Update(oneFrameMessages);
-                    ++battleScene.Frame;
-                }
-            }
-        }
-    }
-}

+ 0 - 3
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Room/BattleSceneServerUpdaterSystem.cs.meta

@@ -1,3 +0,0 @@
-fileFormatVersion: 2
-guid: e7204b22c39249aaa9763c2384d66436
-timeCreated: 1681820700

+ 3 - 3
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Room/ServerFrameRecvComponentSystem.cs

@@ -19,18 +19,18 @@ namespace ET.Server
                 oneFrameMessages = new OneFrameMessages
                 {
                     Frame = message.Frame,
-                    Messages = new Dictionary<long, FrameMessage>()
                 };
                 self.FrameMessages.Add(oneFrameMessages.Frame, oneFrameMessages);
             }
-            oneFrameMessages.Messages.Add(message.PlayerId, message);
+
+            oneFrameMessages.InputInfos[message.PlayerId] = message.InputInfo;
 
             if (oneFrameMessages.Frame > self.NowFrame)
             {
                 return null;   
             }
 
-            if (oneFrameMessages.Messages.Count != LSConstValue.MatchCount)
+            if (oneFrameMessages.InputInfos.Count != LSConstValue.MatchCount)
             {
                 return null;
             }

+ 8 - 25
Unity/Assets/Scripts/Codes/Hotfix/Share/LockStep/BattleSceneSystem.cs

@@ -1,42 +1,25 @@
-using System;
-using System.Collections.Generic;
-using NUnit.Framework.Constraints;
-
 namespace ET
 {
     [FriendOf(typeof(BattleScene))]
     public static class BattleSceneSystem
     {
-        [ObjectSystem]
-        public class UpdateSystem : UpdateSystem<BattleScene>
+        public static void Init(this BattleScene self, Room2C_BattleStart room2CBattleStart)
         {
-            protected override void Update(BattleScene self)
-            {
-                long timeNow = TimeHelper.ServerFrameTime();
-                if (timeNow > self.StartTime + self.Frame * 50)
-                {
-                    OneFrameMessages oneFrameMessages = self.FrameBuffer.GetFrameMessage(self.Frame);
-                    self.Update(oneFrameMessages);
-                    ++self.Frame;
-                }
-            }
-        }
-        
+            self.StartTime = room2CBattleStart.StartTime;
 
-        public static void Init(this BattleScene self, Room2C_EnterMap room2CEnterMap)
-        {
-            self.StartTime = room2CEnterMap.StartTime;
-            
-            foreach (LockStepUnitInfo lockStepUnitInfo in room2CEnterMap.UnitInfo)
+            for (int i = 0; i < room2CBattleStart.UnitInfo.Count; ++i)
             {
-                UnitFFactory.Init(self.LSWorld, lockStepUnitInfo);
+                LockStepUnitInfo unitInfo = room2CBattleStart.UnitInfo[i];
+                UnitFFactory.Init(self.LSWorld, unitInfo);
+                self.SlotIds.Add(i, unitInfo.PlayerId);
             }
         }
 
+
         public static void Update(this BattleScene self, OneFrameMessages oneFrameMessages)
         {
             // 保存当前帧场景数据
-            self.FrameBuffer.SaveDate(self.Frame, MongoHelper.Serialize(self.LSWorld));
+            self.FrameBuffer.SaveDate(self.FrameBuffer.NowFrame, MongoHelper.Serialize(self.LSWorld));
             
             
             // 处理Message

+ 5 - 1
Unity/Assets/Scripts/Codes/HotfixView/Client/LockStep/LockStepOperaComponentSystem.cs

@@ -3,9 +3,10 @@ using UnityEngine;
 
 namespace ET.Client
 {
+    [FriendOf(typeof(BattleSceneClientUpdater))]
     public static class LockStepOperaComponentSystem
     {
-        [ObjectSystem]
+        [FriendOf(typeof(BattleSceneClientUpdater))]
         public class UpdateSystem: UpdateSystem<LockStepOperaComponent>
         {
             protected override void Update(LockStepOperaComponent self)
@@ -30,6 +31,9 @@ namespace ET.Client
                 {
                     v.x += 1;
                 }
+
+                BattleSceneClientUpdater battleSceneClientUpdater = self.GetParent<BattleScene>().GetComponent<BattleSceneClientUpdater>();
+                battleSceneClientUpdater.InputInfo.V = v;
             }
         }
     }

+ 1 - 1
Unity/Assets/Scripts/Codes/Model/Client/Demo/Ping/PingComponent.cs

@@ -3,6 +3,6 @@ namespace ET.Client
     [ComponentOf(typeof(Session))]
     public class PingComponent: Entity, IAwake, IDestroy
     {
-        public long Ping; //延迟值
+        public long Ping { get; set; } //延迟值
     }
 }

+ 7 - 1
Unity/Assets/Scripts/Codes/Model/Client/LockStep/BattleSceneClientUpdater.cs

@@ -1,8 +1,14 @@
+using TrueSync;
+
 namespace ET.Client
 {
     [ComponentOf(typeof(BattleScene))]
     public class BattleSceneClientUpdater: Entity, IAwake, IUpdate
     {
-        
+        public LSInputInfo InputInfo;
+
+        public int PreditionFrameCount;
+
+        public FrameBuffer PreditionFrame;
     }
 }

+ 1 - 1
Unity/Assets/Scripts/Codes/Model/Client/LockStep/WaitType.cs

@@ -6,7 +6,7 @@ namespace ET
         {
             public int Error { get; set; }
 
-            public Room2C_EnterMap Message;
+            public Room2C_BattleStart Message;
         }
     }
 }

+ 22 - 12
Unity/Assets/Scripts/Codes/Model/Generate/Client/Message/LockStepOuter_C_11001.cs

@@ -68,9 +68,9 @@ namespace ET
 	}
 
 // 房间通知客户端进入战斗
-	[Message(LockStepOuter.Room2C_EnterMap)]
+	[Message(LockStepOuter.Room2C_BattleStart)]
 	[ProtoContract]
-	public partial class Room2C_EnterMap: ProtoObject, IActorMessage
+	public partial class Room2C_BattleStart: ProtoObject, IActorMessage
 	{
 		[ProtoMember(1)]
 		public long StartTime { get; set; }
@@ -80,21 +80,30 @@ namespace ET
 
 	}
 
+	[Message(LockStepOuter.LSInputInfo)]
+	[ProtoContract]
+	public partial class LSInputInfo: ProtoObject
+	{
+		[ProtoMember(1)]
+		public TrueSync.TSVector2 V { get; set; }
+
+		[ProtoMember(2)]
+		public int Button { get; set; }
+
+	}
+
 	[Message(LockStepOuter.FrameMessage)]
 	[ProtoContract]
 	public partial class FrameMessage: ProtoObject, IActorMessage
 	{
 		[ProtoMember(1)]
-		public long PlayerId { get; set; }
+		public int Frame { get; set; }
 
 		[ProtoMember(2)]
-		public int Frame { get; set; }
+		public long PlayerId { get; set; }
 
 		[ProtoMember(3)]
-		public TrueSync.TSVector2 V { get; set; }
-
-		[ProtoMember(4)]
-		public int Button { get; set; }
+		public LSInputInfo InputInfo { get; set; }
 
 	}
 
@@ -107,7 +116,7 @@ namespace ET
 
 		[MongoDB.Bson.Serialization.Attributes.BsonDictionaryOptions(MongoDB.Bson.Serialization.Options.DictionaryRepresentation.ArrayOfArrays)]
 		[ProtoMember(2)]
-		public Dictionary<long, FrameMessage> Messages { get; set; }
+		public Dictionary<long, LSInputInfo> InputInfos { get; set; }
 	}
 
 	public static class LockStepOuter
@@ -117,8 +126,9 @@ namespace ET
 		 public const ushort Match2G_NotifyMatchSuccess = 11004;
 		 public const ushort C2Room_ChangeSceneFinish = 11005;
 		 public const ushort LockStepUnitInfo = 11006;
-		 public const ushort Room2C_EnterMap = 11007;
-		 public const ushort FrameMessage = 11008;
-		 public const ushort OneFrameMessages = 11009;
+		 public const ushort Room2C_BattleStart = 11007;
+		 public const ushort LSInputInfo = 11008;
+		 public const ushort FrameMessage = 11009;
+		 public const ushort OneFrameMessages = 11010;
 	}
 }

+ 0 - 11
Unity/Assets/Scripts/Codes/Model/Generate/Client/Message/LockStepOuter_C_11001.cs.meta

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

+ 0 - 11
Unity/Assets/Scripts/Codes/Model/Generate/Client/Message/OuterMessage_C_10001.cs.meta

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

+ 0 - 11
Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/InnerMessage_S_20001.cs.meta

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

+ 0 - 11
Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/LockStepInner_S_21001.cs.meta

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

+ 22 - 12
Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/LockStepOuter_C_11001.cs

@@ -68,9 +68,9 @@ namespace ET
 	}
 
 // 房间通知客户端进入战斗
-	[Message(LockStepOuter.Room2C_EnterMap)]
+	[Message(LockStepOuter.Room2C_BattleStart)]
 	[ProtoContract]
-	public partial class Room2C_EnterMap: ProtoObject, IActorMessage
+	public partial class Room2C_BattleStart: ProtoObject, IActorMessage
 	{
 		[ProtoMember(1)]
 		public long StartTime { get; set; }
@@ -80,21 +80,30 @@ namespace ET
 
 	}
 
+	[Message(LockStepOuter.LSInputInfo)]
+	[ProtoContract]
+	public partial class LSInputInfo: ProtoObject
+	{
+		[ProtoMember(1)]
+		public TrueSync.TSVector2 V { get; set; }
+
+		[ProtoMember(2)]
+		public int Button { get; set; }
+
+	}
+
 	[Message(LockStepOuter.FrameMessage)]
 	[ProtoContract]
 	public partial class FrameMessage: ProtoObject, IActorMessage
 	{
 		[ProtoMember(1)]
-		public long PlayerId { get; set; }
+		public int Frame { get; set; }
 
 		[ProtoMember(2)]
-		public int Frame { get; set; }
+		public long PlayerId { get; set; }
 
 		[ProtoMember(3)]
-		public TrueSync.TSVector2 V { get; set; }
-
-		[ProtoMember(4)]
-		public int Button { get; set; }
+		public LSInputInfo InputInfo { get; set; }
 
 	}
 
@@ -107,7 +116,7 @@ namespace ET
 
 		[MongoDB.Bson.Serialization.Attributes.BsonDictionaryOptions(MongoDB.Bson.Serialization.Options.DictionaryRepresentation.ArrayOfArrays)]
 		[ProtoMember(2)]
-		public Dictionary<long, FrameMessage> Messages { get; set; }
+		public Dictionary<long, LSInputInfo> InputInfos { get; set; }
 	}
 
 	public static class LockStepOuter
@@ -117,8 +126,9 @@ namespace ET
 		 public const ushort Match2G_NotifyMatchSuccess = 11004;
 		 public const ushort C2Room_ChangeSceneFinish = 11005;
 		 public const ushort LockStepUnitInfo = 11006;
-		 public const ushort Room2C_EnterMap = 11007;
-		 public const ushort FrameMessage = 11008;
-		 public const ushort OneFrameMessages = 11009;
+		 public const ushort Room2C_BattleStart = 11007;
+		 public const ushort LSInputInfo = 11008;
+		 public const ushort FrameMessage = 11009;
+		 public const ushort OneFrameMessages = 11010;
 	}
 }

+ 0 - 11
Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/LockStepOuter_C_11001.cs.meta

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

+ 0 - 11
Unity/Assets/Scripts/Codes/Model/Generate/ClientServer/Message/OuterMessage_C_10001.cs.meta

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

+ 0 - 11
Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/InnerMessage_S_20001.cs.meta

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

+ 0 - 11
Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/LockStepInner_S_21001.cs.meta

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

+ 22 - 12
Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/LockStepOuter_C_11001.cs

@@ -68,9 +68,9 @@ namespace ET
 	}
 
 // 房间通知客户端进入战斗
-	[Message(LockStepOuter.Room2C_EnterMap)]
+	[Message(LockStepOuter.Room2C_BattleStart)]
 	[ProtoContract]
-	public partial class Room2C_EnterMap: ProtoObject, IActorMessage
+	public partial class Room2C_BattleStart: ProtoObject, IActorMessage
 	{
 		[ProtoMember(1)]
 		public long StartTime { get; set; }
@@ -80,21 +80,30 @@ namespace ET
 
 	}
 
+	[Message(LockStepOuter.LSInputInfo)]
+	[ProtoContract]
+	public partial class LSInputInfo: ProtoObject
+	{
+		[ProtoMember(1)]
+		public TrueSync.TSVector2 V { get; set; }
+
+		[ProtoMember(2)]
+		public int Button { get; set; }
+
+	}
+
 	[Message(LockStepOuter.FrameMessage)]
 	[ProtoContract]
 	public partial class FrameMessage: ProtoObject, IActorMessage
 	{
 		[ProtoMember(1)]
-		public long PlayerId { get; set; }
+		public int Frame { get; set; }
 
 		[ProtoMember(2)]
-		public int Frame { get; set; }
+		public long PlayerId { get; set; }
 
 		[ProtoMember(3)]
-		public TrueSync.TSVector2 V { get; set; }
-
-		[ProtoMember(4)]
-		public int Button { get; set; }
+		public LSInputInfo InputInfo { get; set; }
 
 	}
 
@@ -107,7 +116,7 @@ namespace ET
 
 		[MongoDB.Bson.Serialization.Attributes.BsonDictionaryOptions(MongoDB.Bson.Serialization.Options.DictionaryRepresentation.ArrayOfArrays)]
 		[ProtoMember(2)]
-		public Dictionary<long, FrameMessage> Messages { get; set; }
+		public Dictionary<long, LSInputInfo> InputInfos { get; set; }
 	}
 
 	public static class LockStepOuter
@@ -117,8 +126,9 @@ namespace ET
 		 public const ushort Match2G_NotifyMatchSuccess = 11004;
 		 public const ushort C2Room_ChangeSceneFinish = 11005;
 		 public const ushort LockStepUnitInfo = 11006;
-		 public const ushort Room2C_EnterMap = 11007;
-		 public const ushort FrameMessage = 11008;
-		 public const ushort OneFrameMessages = 11009;
+		 public const ushort Room2C_BattleStart = 11007;
+		 public const ushort LSInputInfo = 11008;
+		 public const ushort FrameMessage = 11009;
+		 public const ushort OneFrameMessages = 11010;
 	}
 }

+ 0 - 11
Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/LockStepOuter_C_11001.cs.meta

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

+ 0 - 11
Unity/Assets/Scripts/Codes/Model/Generate/Server/Message/OuterMessage_C_10001.cs.meta

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

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Server/LockStep/Map/RoomPlayer.cs

@@ -5,5 +5,6 @@ namespace ET.Server
     public class RoomPlayer: Entity, IAwake
     {
         public bool IsJoinRoom { get; set; }
+        public int Slot { get; set; }
     }
 }

+ 0 - 8
Unity/Assets/Scripts/Codes/Model/Server/LockStep/Room/BattleSceneServerUpdater.cs

@@ -1,8 +0,0 @@
-namespace ET.Server
-{
-    [ComponentOf(typeof(BattleScene))]
-    public class BattleSceneServerUpdater: Entity, IAwake, IUpdate
-    {
-        
-    }
-}

+ 0 - 3
Unity/Assets/Scripts/Codes/Model/Server/LockStep/Room/BattleSceneServerUpdater.cs.meta

@@ -1,3 +0,0 @@
-fileFormatVersion: 2
-guid: 4c03fc3bffeb4f8ebf23568e96d286d9
-timeCreated: 1681820407

+ 29 - 2
Unity/Assets/Scripts/Codes/Model/Share/LockStep/BattleScene.cs

@@ -1,10 +1,37 @@
 using System.Collections.Generic;
+using TrueSync;
 
 namespace ET
 {
     [ComponentOf(typeof(Scene))]
     public class BattleScene: Entity, IScene, IAwake, IUpdate
     {
+        public readonly struct SlotIdPair
+        {
+            private readonly long[] SlotIds = new long[LSConstValue.MatchCount];
+            private readonly Dictionary<long, int> IdSlots = new(LSConstValue.MatchCount);
+
+            public SlotIdPair()
+            {
+            }
+
+            public long GetIdBySlot(int slot)
+            {
+                return this.SlotIds[slot];
+            }
+            
+            public int GetSlotById(long id)
+            {
+                return this.IdSlots[id];
+            }
+
+            public void Add(int slot, long id)
+            {
+                this.SlotIds[slot] = id;
+                this.IdSlots[id] = slot;
+            }
+        }
+        
         public SceneType SceneType { get; set; } = SceneType.Battle;
         public string Name { get; set; }
         
@@ -23,10 +50,10 @@ namespace ET
             }
         }
 
-        public int Frame;
-
         public long StartTime { get; set; }
 
         public FrameBuffer FrameBuffer { get; } = new();
+
+        public SlotIdPair SlotIds { get; } = new();
     }
 }

+ 28 - 14
Unity/Assets/Scripts/Codes/Model/Share/LockStep/FrameBuffer.cs

@@ -5,36 +5,47 @@ namespace ET
 {
     public class FrameBuffer
     {
-        private const int TotalFrameCount = 256;
-        private int nowFrameCount;
+        public int NowFrame { get; set; }
+        
+        public int RealFrame { get; set; }
+        
+        public int PredictionCount { get; set; }
+        
+        private const int TotalFrameCount = 128;
+        
         private readonly List<OneFrameMessages> messageBuffer = new(TotalFrameCount);
         private readonly List<byte[]> dataBuffer = new(TotalFrameCount);
         
-        private void CheckFrame(int frame)
+        private bool CheckFrame(int frame)
         {
-            if (frame > this.nowFrameCount)
+            if (frame > this.RealFrame)
             {
-                throw new Exception($"frame > max frame: {frame} {this.nowFrameCount}");
+                return false;
             }
-            if (frame < this.nowFrameCount + 1 - TotalFrameCount || frame < 0)
+            if (frame < this.RealFrame + 1 - TotalFrameCount || frame < 0)
             {
-                throw new Exception($"frame < min frame: {frame} {this.nowFrameCount + 1 - TotalFrameCount}");
+                return false;
             }
+
+            return true;
         }
 
-        public void AddFrameMessage(OneFrameMessages message)
+        public void AddRealFrame(OneFrameMessages message)
         {
-            if (message.Frame != this.nowFrameCount + 1)
+            if (message.Frame != this.RealFrame + 1)
             {
-                return;
+                throw new Exception($"add real frame error: {message.Frame} {this.RealFrame}");
             }
-            this.nowFrameCount = message.Frame;
+            this.RealFrame = message.Frame;
             this.messageBuffer[message.Frame % TotalFrameCount] = message;
         }
         
-        public OneFrameMessages GetFrameMessage(int frame)
+        public OneFrameMessages GetFrame(int frame)
         {
-            CheckFrame(frame);
+            if (!CheckFrame(frame))
+            {
+                return null;
+            }
             return this.messageBuffer[frame % TotalFrameCount];
         }
 
@@ -45,7 +56,10 @@ namespace ET
 
         public byte[] GetDate(int frame)
         {
-            CheckFrame(frame);
+            if (!CheckFrame(frame))
+            {
+                return null;
+            }
             return this.dataBuffer[frame % TotalFrameCount];
         }
     }

+ 0 - 0
Unity/Assets/Scripts/Codes/Hotfix/Share/LockStep/LSConstValue.cs → Unity/Assets/Scripts/Codes/Model/Share/LockStep/LSConstValue.cs


+ 0 - 0
Unity/Assets/Scripts/Codes/Hotfix/Share/LockStep/LSConstValue.cs.meta → Unity/Assets/Scripts/Codes/Model/Share/LockStep/LSConstValue.cs.meta


+ 27 - 0
Unity/Assets/Scripts/Codes/Model/Share/LockStep/LSInputInfo.cs

@@ -0,0 +1,27 @@
+using TrueSync;
+
+namespace ET
+{
+    public partial class LSInputInfo
+    {
+        public static bool operator==(LSInputInfo a, LSInputInfo b)
+        {
+            if (a.V != b.V)
+            {
+                return false;
+            }
+
+            if (a.Button != b.Button)
+            {
+                return false;
+            }
+
+            return true;
+        }
+
+        public static bool operator !=(LSInputInfo a, LSInputInfo b)
+        {
+            return !(a == b);
+        }
+    }
+}

+ 3 - 0
Unity/Assets/Scripts/Codes/Model/Share/LockStep/LSInputInfo.cs.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 0add573f7e4f487cb06c7c034786504c
+timeCreated: 1682006926

+ 17 - 104
Unity/Assets/Scripts/Codes/Model/Share/LockStep/OneFrameMessage.cs

@@ -1,101 +1,13 @@
 using System;
+using System.Collections.Generic;
 
 namespace ET
 {
-    public partial class FrameMessage
-    {
-        public bool Equals(FrameMessage other)
-        {
-            return this.PlayerId == other.PlayerId && this.Frame == other.Frame && this.V.Equals(other.V) && this.Button == other.Button;
-        }
-
-        public override bool Equals(object obj)
-        {
-            if (ReferenceEquals(null, obj))
-            {
-                return false;
-            }
-
-            if (ReferenceEquals(this, obj))
-            {
-                return true;
-            }
-
-            if (obj.GetType() != this.GetType())
-            {
-                return false;
-            }
-
-            return Equals((FrameMessage) obj);
-        }
-
-        public override int GetHashCode()
-        {
-            return HashCode.Combine(this.PlayerId, this.Frame, this.V, this.Button);
-        }
-
-        public static bool operator ==(FrameMessage a, FrameMessage b)
-        {
-            if (a.PlayerId != b.PlayerId)
-            {
-                return false;
-            }
-            
-            if (a.Frame != b.Frame)
-            {
-                return false;
-            }
-
-            if (a.V != b.V)
-            {
-                return false;
-            }
-
-            if (a.Button != b.Button)
-            {
-                return false;
-            }
-
-            return true;
-        }
-
-        public static bool operator !=(FrameMessage a, FrameMessage b)
-        {
-            return !(a == b);
-        }
-    }
-
-
     public partial class OneFrameMessages
     {
-        public bool Equals(OneFrameMessages other)
+        public OneFrameMessages()
         {
-            return this.Frame == other.Frame && Equals(this.Messages, other.Messages);
-        }
-
-        public override bool Equals(object obj)
-        {
-            if (ReferenceEquals(null, obj))
-            {
-                return false;
-            }
-
-            if (ReferenceEquals(this, obj))
-            {
-                return true;
-            }
-
-            if (obj.GetType() != this.GetType())
-            {
-                return false;
-            }
-
-            return Equals((OneFrameMessages) obj);
-        }
-
-        public override int GetHashCode()
-        {
-            return HashCode.Combine(this.Frame, this.Messages);
+            this.InputInfos = new Dictionary<long, LSInputInfo>(LSConstValue.MatchCount);
         }
 
         public static bool operator==(OneFrameMessages a, OneFrameMessages b)
@@ -105,24 +17,13 @@ namespace ET
                 return false;
             }
 
-            if (a.Messages.Count != b.Messages.Count)
-            {
-                return false;
-            }
-
-            foreach (var kv in a.Messages)
+            for (int i = 0; i < LSConstValue.MatchCount; ++i)
             {
-                if (!b.Messages.TryGetValue(kv.Key, out FrameMessage frameMessage))
-                {
-                    return false;
-                }
-
-                if (kv.Value != frameMessage)
+                if (a.InputInfos[i] != b.InputInfos[i])
                 {
                     return false;
                 }
             }
-
             return true;
         }
 
@@ -131,4 +32,16 @@ namespace ET
             return !(a == b);
         }
     }
+    
+    public partial class Room2C_BattleStart
+    {
+        public Room2C_BattleStart()
+        {
+            this.UnitInfo = new List<LockStepUnitInfo>(LSConstValue.MatchCount);
+            for (int i = 0; i < LSConstValue.MatchCount; ++i)
+            {
+                this.UnitInfo.Add(null);
+            }
+        }
+    }
 }