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

1.抽象出来LSEntity LSScene,有很多好处
2.普通的组件无法挂载在LockStep的Entity上,避免误用
3.LockStep场景中所有组件跟孩子的Id都是统一分配的,这样不会出现不一致

tanghai пре 2 година
родитељ
комит
f35752c561
42 измењених фајлова са 416 додато и 120 уклоњено
  1. 0 5
      DotNet/Hotfix/DotNet.Hotfix.csproj
  2. 1 1
      Share/Analyzer/Analyzer/EntityClassDeclarationAnalyzer.cs
  3. 0 2
      Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Helper/SceneFactory.cs
  4. 5 0
      Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Session/NetInnerComponentOnReadEvent.cs
  5. 8 0
      Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Session/NetServerComponentOnReadEvent.cs
  6. 4 4
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/C2Room_ChangeSceneFinishHandler.cs
  7. 1 1
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/C2Room_ChangeSceneFinishHandler.cs.meta
  8. 10 0
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/FrameMessageHelper.cs
  9. 1 1
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/FrameMessageHelper.cs.meta
  10. 3 3
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Match2Map_GetRoomHandler.cs
  11. 1 1
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Match2Map_GetRoomHandler.cs.meta
  12. 4 0
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomComponentSystem.cs
  13. 1 1
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomComponentSystem.cs.meta
  14. 4 2
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomManagerComponentSystem.cs
  15. 1 1
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomManagerComponentSystem.cs.meta
  16. 0 0
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomMessageHelper.cs
  17. 1 1
      Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomMessageHelper.cs.meta
  18. 0 50
      Unity/Assets/Scripts/Codes/Hotfix/Share/Module/FixedUpdate/FixedUpdateComponentSystem.cs
  19. 0 0
      Unity/Assets/Scripts/Codes/Model/Client/LockStep/EventType.cs
  20. 1 1
      Unity/Assets/Scripts/Codes/Model/Client/LockStep/EventType.cs.meta
  21. 14 0
      Unity/Assets/Scripts/Codes/Model/Server/LockStep/Map/RoomComponent.cs
  22. 8 0
      Unity/Assets/Scripts/Codes/Model/Share/LockStep/Message.meta
  23. 0 0
      Unity/Assets/Scripts/Codes/Model/Share/LockStep/Message/IActorRoom.cs
  24. 1 1
      Unity/Assets/Scripts/Codes/Model/Share/LockStep/Message/IActorRoom.cs.meta
  25. 8 0
      Unity/Assets/Scripts/Codes/Model/Share/LockStep/Message/IFrameMessage.cs
  26. 1 1
      Unity/Assets/Scripts/Codes/Model/Share/LockStep/Message/IFrameMessage.cs.meta
  27. 0 0
      Unity/Assets/Scripts/Codes/Model/Share/LockStep/UnitF/UnitF.cs
  28. 1 1
      Unity/Assets/Scripts/Codes/Model/Share/LockStep/UnitF/UnitF.cs.meta
  29. 0 30
      Unity/Assets/Scripts/Codes/Model/Share/Module/FixedUpdate/FixedUpdateComponent.cs
  30. 8 0
      Unity/Assets/Scripts/Core/LockStep.meta
  31. 8 0
      Unity/Assets/Scripts/Core/LockStep/FixedUpdate.meta
  32. 0 0
      Unity/Assets/Scripts/Core/LockStep/FixedUpdate/AFixUpdateHandler.cs
  33. 0 0
      Unity/Assets/Scripts/Core/LockStep/FixedUpdate/AFixUpdateHandler.cs.meta
  34. 81 0
      Unity/Assets/Scripts/Core/LockStep/FixedUpdate/FixedUpdater.cs
  35. 11 0
      Unity/Assets/Scripts/Core/LockStep/FixedUpdate/FixedUpdater.cs.meta
  36. 92 0
      Unity/Assets/Scripts/Core/LockStep/LSEntity.cs
  37. 11 0
      Unity/Assets/Scripts/Core/LockStep/LSEntity.cs.meta
  38. 112 0
      Unity/Assets/Scripts/Core/LockStep/LSScene.cs
  39. 11 0
      Unity/Assets/Scripts/Core/LockStep/LSScene.cs.meta
  40. 1 12
      Unity/Assets/Scripts/Core/Module/Entity/Entity.cs
  41. 1 1
      Unity/Assets/Scripts/Core/Module/Entity/Scene.cs
  42. 1 0
      Unity/Assets/Scripts/Core/Module/Entity/SceneType.cs

+ 0 - 5
DotNet/Hotfix/DotNet.Hotfix.csproj

@@ -40,10 +40,5 @@
         <ProjectReference Include="..\Loader\DotNet.Loader.csproj" />
         <ProjectReference Include="..\Model\DotNet.Model.csproj" />
     </ItemGroup>
-    <ItemGroup>
-      <Folder Include="..\..\Unity\Assets\Scripts\Codes\Hotfix\Server\LockStep\Map">
-        <Link>Server\LockStep\Map</Link>
-      </Folder>
-    </ItemGroup>
 
 </Project>

+ 1 - 1
Share/Analyzer/Analyzer/EntityClassDeclarationAnalyzer.cs

@@ -18,7 +18,7 @@ namespace ET.Analyzer
 
             context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
             context.EnableConcurrentExecution();
-            context.RegisterSymbolAction(this.Analyzer, SymbolKind.NamedType);
+            //context.RegisterSymbolAction(this.Analyzer, SymbolKind.NamedType);
         }
 
         private void Analyzer(SymbolAnalysisContext context)

+ 0 - 2
Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Helper/SceneFactory.cs

@@ -52,8 +52,6 @@ namespace ET.Server
                 case SceneType.Match:
                     scene.AddComponent<MatchComponent>();
                     break;
-                case SceneType.Room:
-                    break;
             }
 
             return scene;

+ 5 - 0
Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Session/NetInnerComponentOnReadEvent.cs

@@ -15,6 +15,11 @@ namespace ET.Server
                 // 收到actor消息,放入actor队列
                 switch (message)
                 {
+                    case IFrameMessage iFrameMessage:
+                    {
+                        FrameMessageHelper.HandleIFrameMessage(iFrameMessage);
+                        break;
+                    }
                     case IActorResponse iActorResponse:
                     {
                         ActorHandleHelper.HandleIActorResponse(iActorResponse);

+ 8 - 0
Unity/Assets/Scripts/Codes/Hotfix/Server/Demo/Session/NetServerComponentOnReadEvent.cs

@@ -17,6 +17,14 @@
             // 根据消息接口判断是不是Actor消息,不同的接口做不同的处理,比如需要转发给Chat Scene,可以做一个IChatMessage接口
             switch (message)
             {
+                case IFrameMessage frameMessage:
+                {
+                    Player player = session.GetComponent<SessionPlayerComponent>().Player;
+                    long roomInstanceId = player.GetComponent<PlayerRoomComponent>().RoomInstanceId;
+                    frameMessage.PlayerId = player.Id;
+                    ActorMessageSenderComponent.Instance.Send(roomInstanceId, frameMessage);
+                    break;
+                }
                 case IActorRoom actorRoom:
                 {
                     Player player = session.GetComponent<SessionPlayerComponent>().Player;

+ 4 - 4
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Room/C2Room_ChangeSceneFinishHandler.cs → Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/C2Room_ChangeSceneFinishHandler.cs

@@ -7,10 +7,10 @@ namespace ET.Server
     [FriendOf(typeof (RoomComponent))]
     public class C2Room_ChangeSceneFinishHandler: AMActorHandler<Scene, C2Room_ChangeSceneFinish>
     {
-        protected override async ETTask Run(Scene scene, C2Room_ChangeSceneFinish message)
+        protected override async ETTask Run(Scene room, C2Room_ChangeSceneFinish message)
         {
-            RoomComponent roomComponent = scene.GetComponent<RoomComponent>();
-            RoomPlayer roomPlayer = scene.GetComponent<RoomComponent>().GetChild<RoomPlayer>(message.PlayerId);
+            RoomComponent roomComponent = room.GetComponent<RoomComponent>();
+            RoomPlayer roomPlayer = room.GetComponent<RoomComponent>().GetChild<RoomPlayer>(message.PlayerId);
             roomPlayer.IsJoinRoom = true;
             roomComponent.AlreadyJoinRoomCount++;
 
@@ -34,7 +34,7 @@ namespace ET.Server
                     });
                 }
 
-                RoomMessageHelper.BroadCast(scene, room2CEnterMap);
+                RoomMessageHelper.BroadCast(room, room2CEnterMap);
             }
 
             await ETTask.CompletedTask;

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Room/C2Room_ChangeSceneFinishHandler.cs.meta → Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/C2Room_ChangeSceneFinishHandler.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: c1b648aa5095a40f78c71d2dcb1a2e36
+guid: 228e4d43b85774ae08bf5da1f3425627
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 10 - 0
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/FrameMessageHelper.cs

@@ -0,0 +1,10 @@
+namespace ET.Server
+{
+    public static class FrameMessageHelper
+    {
+        public static void HandleIFrameMessage(IFrameMessage iFrameMessage)
+        {
+             
+        }
+    }
+}

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Share/Module/FixedUpdate/FixedUpdateComponentSystem.cs.meta → Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/FrameMessageHelper.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: ca08e5008ca25443bacdfb6e699c0dfa
+guid: 40bebd1c111464ddb96d36e4d0966070
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 3 - 3
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Room/Match2Map_GetRoomHandler.cs → Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Match2Map_GetRoomHandler.cs

@@ -9,9 +9,9 @@ namespace ET.Server
 		protected override async ETTask Run(Scene scene, Match2Map_GetRoom request, Map2Match_GetRoom response)
 		{
 			RoomManagerComponent roomManagerComponent = scene.GetComponent<RoomManagerComponent>();
-			Scene room = await roomManagerComponent.CreateRoom(request);
-			room.AddComponent<RoomComponent, Match2Map_GetRoom>(request);
-			response.InstanceId = room.InstanceId;
+			Scene roomScene = await roomManagerComponent.CreateRoom(request);
+			roomScene.AddComponent<RoomComponent, Match2Map_GetRoom>(request);
+			response.InstanceId = scene.InstanceId;
 			await ETTask.CompletedTask;
 		}
 	}

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Room/Match2Map_GetRoomHandler.cs.meta → Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Match2Map_GetRoomHandler.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: edd10bc4ce7b44cb7903d4b836609b58
+guid: 7f404c61e317c4fc0ad28508eea3f5f2
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 4 - 0
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Room/RoomComponentSystem.cs → Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomComponentSystem.cs

@@ -14,6 +14,10 @@ namespace ET.Server
                 {
                     RoomPlayer roomPlayer = self.AddChildWithId<RoomPlayer>(id);
                 }
+                
+                // 创建LockStep场景
+                LSScene lsScene = new LSScene(IdGenerater.Instance.GenerateInstanceId(), self.DomainZone(), SceneType.LockStep, "LockStep", self);
+                self.LsScene = lsScene;
             }
         }
     }

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Room/RoomComponentSystem.cs.meta → Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomComponentSystem.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 75973af3dec134f3fb9919202375a667
+guid: 6ea8b984794ae4cb592d5d55b5cb653b
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 4 - 2
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Room/RoomManagerComponentSystem.cs → Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomManagerComponentSystem.cs

@@ -8,11 +8,13 @@ namespace ET.Server
         public static async ETTask<Scene> CreateRoom(this RoomManagerComponent self, Match2Map_GetRoom match2MapGetRoom)
         {
             long instanceId = IdGenerater.Instance.GenerateInstanceId();
-            Scene room = await SceneFactory.CreateServerScene(
+            Scene scene = await SceneFactory.CreateServerScene(
                 self, instanceId, instanceId, 
                 self.DomainZone(), "Room", SceneType.Room);
+
+            scene.AddComponent<RoomComponent, Match2Map_GetRoom>(match2MapGetRoom);
             
-            return room;
+            return scene;
         }
     }
 }

+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Room/RoomManagerComponentSystem.cs.meta → Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomManagerComponentSystem.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: dfeb90496cae44d9795ff742d4d5659a
+guid: 242c6c229fa3944b9ab71bb01d077b74
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 0 - 0
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Room/RoomMessageHelper.cs → Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomMessageHelper.cs


+ 1 - 1
Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/Room/RoomMessageHelper.cs.meta → Unity/Assets/Scripts/Codes/Hotfix/Server/LockStep/Map/RoomMessageHelper.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: fca16cf530fcc49f2b9350e6c8f65348
+guid: 015483a7767f844349026490961481a1
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 0 - 50
Unity/Assets/Scripts/Codes/Hotfix/Share/Module/FixedUpdate/FixedUpdateComponentSystem.cs

@@ -1,50 +0,0 @@
-using System;
-
-namespace ET
-{
-    [FriendOf(typeof(FixedUpdateComponent))]
-    public static class FixedUpdateComponentSystem
-    {
-        public static void Update(this FixedUpdateComponent self)
-        {
-            ++self.NowFrame;
-
-            // 让id保持从小到大update,后加进来的在一帧后面Update
-            while (self.addUpdateIds.Count > 0)
-            {
-                self.updateIds.Add(self.addUpdateIds.Dequeue());
-            }
-
-            foreach (long updateId in self.updateIds)
-            {
-                if (!self.updateEntities.TryGetValue(updateId, out FixedUpdateComponent.UpdateInfo updateInfo))
-                {
-                    self.removeUpdateIds.Enqueue(updateId);
-                    continue;
-                }
-                EventSystem.Instance.Invoke(updateInfo.Type, new FixUpdateInvokerArgs() {Entity = updateInfo.Entity});
-            }
-
-            while (self.removeUpdateIds.Count > 0)
-            {
-                self.updateIds.Remove(self.removeUpdateIds.Dequeue());
-            }
-        }
-        
-        public static long Add(this FixedUpdateComponent self, int type, Entity entity)
-        {
-            long updateId = ++self.idGenerator;
-            FixedUpdateComponent.UpdateInfo updateInfo = new() { UpdateId = updateId, Entity = entity, Type = type };
-            
-            self.updateEntities.Add(updateId, updateInfo);
-            
-            self.addUpdateIds.Enqueue(updateId);
-            return updateId;
-        }
-        
-        public static void Remove(this FixedUpdateComponent self, long updateId)
-        {
-            self.updateEntities.Remove(updateId);
-        }
-    }
-}

+ 0 - 0
Unity/Assets/Scripts/Codes/Model/Share/LockStep/EventType.cs → Unity/Assets/Scripts/Codes/Model/Client/LockStep/EventType.cs


+ 1 - 1
Unity/Assets/Scripts/Codes/Model/Share/LockStep/EventType.cs.meta → Unity/Assets/Scripts/Codes/Model/Client/LockStep/EventType.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: fef33b433a0a84111b2b8a9f8fafae3d
+guid: 02de10d07ce524cb9bc79e666f460484
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 14 - 0
Unity/Assets/Scripts/Codes/Model/Server/LockStep/Map/RoomComponent.cs

@@ -6,5 +6,19 @@ namespace ET.Server
     public class RoomComponent: Entity, IAwake<Match2Map_GetRoom>
     {
         public int AlreadyJoinRoomCount;
+
+        private long sceneInstanceId;
+        
+        public LSScene LsScene
+        {
+            get
+            {
+                return Root.Instance.Get(this.sceneInstanceId) as LSScene;
+            }
+            set
+            {
+                this.sceneInstanceId = value.InstanceId;
+            }
+        }
     }
 }

+ 8 - 0
Unity/Assets/Scripts/Codes/Model/Share/LockStep/Message.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: ec7ec19a01fc746faad23d8859935dfe
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 0 - 0
Unity/Assets/Scripts/Codes/Model/Share/LockStep/IActorRoom.cs → Unity/Assets/Scripts/Codes/Model/Share/LockStep/Message/IActorRoom.cs


+ 1 - 1
Unity/Assets/Scripts/Codes/Model/Share/LockStep/IActorRoom.cs.meta → Unity/Assets/Scripts/Codes/Model/Share/LockStep/Message/IActorRoom.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: e8c7f89e3e51a4232a3c2071037cfda8
+guid: 88154111be2b445c295e7208376f428b
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 8 - 0
Unity/Assets/Scripts/Codes/Model/Share/LockStep/Message/IFrameMessage.cs

@@ -0,0 +1,8 @@
+namespace ET
+{
+    public interface IFrameMessage: IActorMessage
+    {
+        long PlayerId { get; set; }
+        int Frame { get; set; }
+    }
+}

+ 1 - 1
Unity/Assets/Scripts/Codes/Model/Share/Module/FixedUpdate/FixedUpdateComponent.cs.meta → Unity/Assets/Scripts/Codes/Model/Share/LockStep/Message/IFrameMessage.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: d49b0ee70c9b04ca89a04591c581b5b3
+guid: c2c7dca6cfebf401db8aca46b007123b
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

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


+ 1 - 1
Unity/Assets/Scripts/Codes/Model/Share/LockStep/UnitF.cs.meta → Unity/Assets/Scripts/Codes/Model/Share/LockStep/UnitF/UnitF.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 48ea68c8730ba4ad18d3819586034fcf
+guid: e4863a354356c4627a25ce6f4be81837
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 0 - 30
Unity/Assets/Scripts/Codes/Model/Share/Module/FixedUpdate/FixedUpdateComponent.cs

@@ -1,30 +0,0 @@
-using System.Collections.Generic;
-using MongoDB.Bson.Serialization.Attributes;
-
-namespace ET
-{
-    [ComponentOf(typeof(Scene))]
-    public class FixedUpdateComponent: Entity
-    {
-        public long idGenerator;
-        
-        public int ToFrame;
-        public int NowFrame;
-        
-        public struct UpdateInfo
-        {
-            public long UpdateId;
-            public int Type;
-            public Entity Entity;
-        }
-
-        [BsonIgnore]
-        public SortedSet<long> updateIds = new SortedSet<long>();
-        [BsonIgnore]
-        public Queue<long> addUpdateIds = new Queue<long>();
-        [BsonIgnore]
-        public Queue<long> removeUpdateIds = new Queue<long>();
-        [BsonIgnore]
-        public Dictionary<long, UpdateInfo> updateEntities = new Dictionary<long, UpdateInfo>();
-    }
-}

+ 8 - 0
Unity/Assets/Scripts/Core/LockStep.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 70189de8f3c1f441694ef7eb16ba4e78
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 0
Unity/Assets/Scripts/Core/LockStep/FixedUpdate.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 3aa68d39697b847a990387cad99782b6
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 0 - 0
Unity/Assets/Scripts/Codes/Model/Share/Module/FixedUpdate/AFixUpdateHandler.cs → Unity/Assets/Scripts/Core/LockStep/FixedUpdate/AFixUpdateHandler.cs


+ 0 - 0
Unity/Assets/Scripts/Codes/Model/Share/Module/FixedUpdate/AFixUpdateHandler.cs.meta → Unity/Assets/Scripts/Core/LockStep/FixedUpdate/AFixUpdateHandler.cs.meta


+ 81 - 0
Unity/Assets/Scripts/Core/LockStep/FixedUpdate/FixedUpdater.cs

@@ -0,0 +1,81 @@
+using System.Collections.Generic;
+using MongoDB.Bson.Serialization.Attributes;
+
+namespace ET
+{
+    [FriendOf(typeof(FixedUpdater))]
+    public static class FixedUpdaterSystem
+    {
+        [ObjectSystem]
+        public class AwakeSystem: AwakeSystem<FixedUpdater>
+        {
+            protected override void Awake(FixedUpdater self)
+            {
+                self.GetParent<LSScene>().FixedUpdater = self;
+            }
+        }
+        
+        public static void Update(this FixedUpdater self)
+        {
+            ++self.Frame;
+
+            // 让id保持从小到大update,后加进来的在一帧后面Update
+            while (self.addUpdateIds.Count > 0)
+            {
+                self.updateIds.Add(self.addUpdateIds.Dequeue());
+            }
+
+            foreach (long updateId in self.updateIds)
+            {
+                if (!self.updateEntities.TryGetValue(updateId, out FixedUpdater.UpdateInfo updateInfo))
+                {
+                    self.removeUpdateIds.Enqueue(updateId);
+                    continue;
+                }
+                EventSystem.Instance.Invoke(updateInfo.Type, new FixUpdateInvokerArgs() {Entity = updateInfo.Entity});
+            }
+
+            while (self.removeUpdateIds.Count > 0)
+            {
+                self.updateIds.Remove(self.removeUpdateIds.Dequeue());
+            }
+        }
+        
+        public static long Add(this FixedUpdater self, int type, Entity entity)
+        {
+            long updateId = self.DomainScene().GetId();
+            FixedUpdater.UpdateInfo updateInfo = new() { Entity = entity, Type = type };
+            
+            self.updateEntities.Add(updateId, updateInfo);
+            
+            self.addUpdateIds.Enqueue(updateId);
+            return updateId;
+        }
+        
+        public static void Remove(this FixedUpdater self, long updateId)
+        {
+            self.updateEntities.Remove(updateId);
+        }
+    }
+    
+    [ComponentOf(typeof(LSScene))]
+    public class FixedUpdater: LSEntity, IAwake
+    {
+        public int Frame;
+        
+        public struct UpdateInfo
+        {
+            public int Type;
+            public Entity Entity;
+        }
+
+        [BsonIgnore]
+        public SortedSet<long> updateIds = new SortedSet<long>();
+        [BsonIgnore]
+        public Queue<long> addUpdateIds = new Queue<long>();
+        [BsonIgnore]
+        public Queue<long> removeUpdateIds = new Queue<long>();
+        [BsonIgnore]
+        public Dictionary<long, UpdateInfo> updateEntities = new Dictionary<long, UpdateInfo>();
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Core/LockStep/FixedUpdate/FixedUpdater.cs.meta

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

+ 92 - 0
Unity/Assets/Scripts/Core/LockStep/LSEntity.cs

@@ -0,0 +1,92 @@
+using System;
+
+namespace ET
+{
+    public class LSEntity: Entity
+    {
+        public new K AddComponent<K>(bool isFromPool = false) where K : LSEntity, IAwake, new()
+        {
+            return base.AddComponentWithId<K>(this.DomainScene().GetId(), isFromPool);
+        }
+
+        public new K AddComponent<K, P1>(P1 p1, bool isFromPool = false) where K : LSEntity, IAwake<P1>, new()
+        {
+            return base.AddComponentWithId<K, P1>(this.DomainScene().GetId(), p1, isFromPool);
+        }
+
+        public new K AddComponent<K, P1, P2>(P1 p1, P2 p2, bool isFromPool = false) where K : LSEntity, IAwake<P1, P2>, new()
+        {
+            return base.AddComponentWithId<K, P1, P2>(this.DomainScene().GetId(), p1, p2, isFromPool);
+        }
+
+        public new K AddComponent<K, P1, P2, P3>(P1 p1, P2 p2, P3 p3, bool isFromPool = false) where K : LSEntity, IAwake<P1, P2, P3>, new()
+        {
+            return base.AddComponentWithId<K, P1, P2, P3>(this.DomainScene().GetId(), p1, p2, p3, isFromPool);
+        }
+
+        public new K AddComponentWithId<K>(long id, bool isFromPool = false) where K : Entity, IAwake, new()
+        {
+            throw new Exception("dont use this");
+        }
+        
+        public new K AddComponentWithId<K, P1>(long id, P1 p1, bool isFromPool = false) where K : Entity, IAwake<P1>, new()
+        {
+            throw new Exception("dont use this");
+        }
+
+        public new K AddComponentWithId<K, P1, P2>(long id, P1 p1, P2 p2, bool isFromPool = false) where K : Entity, IAwake<P1, P2>, new()
+        {
+            throw new Exception("dont use this");
+        }
+
+        public new K AddComponentWithId<K, P1, P2, P3>(long id, P1 p1, P2 p2, P3 p3, bool isFromPool = false) where K : Entity, IAwake<P1, P2, P3>, new()
+        {
+            throw new Exception("dont use this");
+        }
+        
+        public Entity AddChild(LSEntity entity)
+        {
+            return entity.AddChild(entity);
+        }
+
+        public new T AddChild<T>(bool isFromPool = false) where T : LSEntity, IAwake
+        {
+            return base.AddChildWithId<T>(this.DomainScene().GetId(), isFromPool);
+        }
+
+        public new T AddChild<T, A>(A a, bool isFromPool = false) where T : LSEntity, IAwake<A>
+        {
+            return base.AddChildWithId<T, A>(this.DomainScene().GetId(), a, isFromPool);
+        }
+
+        public new T AddChild<T, A, B>(A a, B b, bool isFromPool = false) where T : LSEntity, IAwake<A, B>
+        {
+            return base.AddChildWithId<T, A, B>(this.DomainScene().GetId(), a, b, isFromPool);
+        }
+
+        public new T AddChild<T, A, B, C>(A a, B b, C c, bool isFromPool = false) where T : LSEntity, IAwake<A, B, C>
+        {
+            return base.AddChildWithId<T, A, B, C>(this.DomainScene().GetId(), a, b, c, isFromPool);
+        }
+
+        public new T AddChildWithId<T>(long id, bool isFromPool = false) where T : LSEntity, IAwake, new()
+        {
+            throw new Exception("dont use this");
+        }
+
+        public new T AddChildWithId<T, A>(long id, A a, bool isFromPool = false) where T : LSEntity, IAwake<A>
+        {
+            throw new Exception("dont use this");
+        }
+
+        public new T AddChildWithId<T, A, B>(long id, A a, B b, bool isFromPool = false) where T : LSEntity, IAwake<A, B>
+        {
+            throw new Exception("dont use this");
+        }
+
+        public new T AddChildWithId<T, A, B, C>(long id, A a, B b, C c, bool isFromPool = false) where T : LSEntity, IAwake<A, B, C>
+        {
+            throw new Exception("dont use this");
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Core/LockStep/LSEntity.cs.meta

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

+ 112 - 0
Unity/Assets/Scripts/Core/LockStep/LSScene.cs

@@ -0,0 +1,112 @@
+using System.Diagnostics;
+using MongoDB.Bson.Serialization.Attributes;
+
+namespace ET
+{
+    [EnableMethod]
+    [ChildOf]
+    public class LSScene: LSEntity
+    {
+        public int Zone
+        {
+            get;
+        }
+
+        public SceneType SceneType
+        {
+            get;
+        }
+
+        public string Name
+        {
+            get;
+        }
+
+        public LSScene(long instanceId, int zone, SceneType sceneType, string name, Entity parent)
+        {
+            this.Id = instanceId;
+            this.InstanceId = instanceId;
+            this.Zone = zone;
+            this.SceneType = sceneType;
+            this.Name = name;
+            this.IsCreated = true;
+            this.IsNew = true;
+            this.Parent = parent;
+            this.Domain = this;
+            this.IsRegister = true;
+            Log.Info($"scene create: {this.SceneType} {this.Name} {this.Id} {this.InstanceId} {this.Zone}");
+        }
+
+        public LSScene(long id, long instanceId, int zone, SceneType sceneType, string name, Entity parent)
+        {
+            this.Id = id;
+            this.InstanceId = instanceId;
+            this.Zone = zone;
+            this.SceneType = sceneType;
+            this.Name = name;
+            this.IsCreated = true;
+            this.IsNew = true;
+            this.Parent = parent;
+            this.Domain = this;
+            this.IsRegister = true;
+            Log.Info($"scene create: {this.SceneType} {this.Name} {this.Id} {this.InstanceId} {this.Zone}");
+        }
+
+        public override void Dispose()
+        {
+            base.Dispose();
+            
+            Log.Info($"scene dispose: {this.SceneType} {this.Name} {this.Id} {this.InstanceId} {this.Zone}");
+        }
+
+        [BsonIgnore]
+        public new Entity Domain
+        {
+            get => this.domain;
+            private set => this.domain = value;
+        }
+
+        [BsonIgnore]
+        public new Entity Parent
+        {
+            get
+            {
+                return this.parent;
+            }
+            private set
+            {
+                if (value == null)
+                {
+                    //this.parent = this;
+                    return;
+                }
+
+                this.parent = value;
+                this.parent.Children.Add(this.Id, this);
+            }
+        }
+
+        [BsonElement]
+        private long idGenerator;
+
+        public long GetId()
+        {
+            return ++this.idGenerator;
+        }
+
+        public FixedUpdater FixedUpdater { get; set; }
+    }
+
+    public static class LSSceneHelper
+    {
+        public static LSScene DomainScene(this LSEntity entity)
+        {
+            return entity.Domain as LSScene;
+        }
+        
+        public static long GetId(this LSEntity entity)
+        {
+            return entity.DomainScene().GetId();
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Core/LockStep/LSScene.cs.meta

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

+ 1 - 12
Unity/Assets/Scripts/Core/Module/Entity/Entity.cs

@@ -857,18 +857,7 @@ namespace ET
             return component;
         }
 
-        public T AddChild<T, A, B, C, D>(A a, B b, C c, D d, bool isFromPool = false) where T : Entity, IAwake<A, B, C, D>
-        {
-            Type type = typeof (T);
-            T component = (T) Entity.Create(type, isFromPool);
-            component.Id = IdGenerater.Instance.GenerateId();
-            component.Parent = this;
-
-            EventSystem.Instance.Awake(component, a, b, c, d);
-            return component;
-        }
-
-        public T AddChildWithId<T>(long id, bool isFromPool = false) where T : Entity, IAwake, new()
+        public T AddChildWithId<T>(long id, bool isFromPool = false) where T : Entity, IAwake
         {
             Type type = typeof (T);
             T component = Entity.Create(type, isFromPool) as T;

+ 1 - 1
Unity/Assets/Scripts/Core/Module/Entity/Scene.cs

@@ -5,7 +5,7 @@ namespace ET
     [EnableMethod]
     [DebuggerDisplay("ViewName,nq")]
     [ChildOf]
-    public sealed class Scene: Entity
+    public class Scene: Entity
     {
         public int Zone
         {

+ 1 - 0
Unity/Assets/Scripts/Core/Module/Entity/SceneType.cs

@@ -21,6 +21,7 @@ namespace ET
 		Benchmark = 1 << 13,
 		Match = 1 << 14,
 		Room = 1 << 15,
+		LockStep = 1 << 16,
 
 		// 客户端Model层
 		Client = 1 << 30,