Просмотр исходного кода

1.创建Fiber根据SceneType分发
2.MailBox根据MailBoxType分发

tanghai 2 лет назад
Родитель
Сommit
f0fbeaebfd
36 измененных файлов с 273 добавлено и 87 удалено
  1. BIN
      Unity/Assets/Config/Excel/StartConfig/Release/StartSceneConfig@s.xlsx
  2. 1 0
      Unity/Assets/Scripts/Core/Fiber/Fiber.cs
  3. 0 1
      Unity/Assets/Scripts/Core/Fiber/IdGenerater.cs
  4. 20 8
      Unity/Assets/Scripts/Core/Fiber/MailBoxComponent.cs
  5. 9 0
      Unity/Assets/Scripts/Core/Fiber/MailBoxType.cs
  6. 0 9
      Unity/Assets/Scripts/Core/Fiber/MailboxType.cs
  7. 2 2
      Unity/Assets/Scripts/Core/World/Module/Actor/ActorMessageDispatcherComponent.cs
  8. 1 1
      Unity/Assets/Scripts/Core/World/Module/Actor/IMActorHandler.cs
  9. 8 0
      Unity/Assets/Scripts/Core/World/Module/Fiber/FiberInit.cs
  10. 11 0
      Unity/Assets/Scripts/Core/World/Module/Fiber/FiberInit.cs.meta
  11. 19 28
      Unity/Assets/Scripts/Core/World/Module/Fiber/FiberManager.cs
  12. 6 6
      Unity/Assets/Scripts/Hotfix/Server/Demo/Helper/SceneFactory.cs
  13. 5 5
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/C2G_LoginGateHandler.cs
  14. 19 0
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/FiberInit_Gate.cs
  15. 11 0
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/FiberInit_Gate.cs.meta
  16. 16 0
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/MailBoxType_GateSessionHandler.cs
  17. 11 0
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/MailBoxType_GateSessionHandler.cs.meta
  18. 4 4
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/R2G_GetLoginKeyHandler.cs
  19. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Map/Transfer/M2M_UnitTransferRequestHandler.cs
  20. 16 0
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Realm/FiberInit_Realm.cs
  21. 11 0
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Realm/FiberInit_Realm.cs.meta
  22. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Robot/Scene/RobotSceneFactory.cs
  23. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Map/RoomManagerComponentSystem.cs
  24. 4 4
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorMessageLocationHandler.cs
  25. 3 3
      Unity/Assets/Scripts/Hotfix/Share/Module/Actor/ActorMessageHandler.cs
  26. 7 4
      Unity/Assets/Scripts/Hotfix/Share/Module/Actor/ActorMessageRecvComponentSystem.cs
  27. 2 2
      Unity/Assets/Scripts/Hotfix/Share/Module/Actor/ActorMessageSenderComponentSystem.cs
  28. 37 0
      Unity/Assets/Scripts/Hotfix/Share/Module/Actor/MailBoxType_OrderedMessageHandler.cs
  29. 11 0
      Unity/Assets/Scripts/Hotfix/Share/Module/Actor/MailBoxType_OrderedMessageHandler.cs.meta
  30. 19 0
      Unity/Assets/Scripts/Hotfix/Share/Module/Actor/MailBoxType_UnOrderedMessageHandler.cs
  31. 11 0
      Unity/Assets/Scripts/Hotfix/Share/Module/Actor/MailBoxType_UnOrderedMessageHandler.cs.meta
  32. 1 0
      Unity/Assets/Scripts/Model/Generate/Server/ConfigPartial/StartSceneConfig.cs
  33. 2 2
      Unity/Assets/Scripts/Model/Server/Demo/Gate/GateSessionKeyComponent.cs
  34. 1 1
      Unity/Assets/Scripts/Model/Server/Demo/Gate/PlayerComponent.cs
  35. 1 1
      Unity/Assets/Scripts/Model/Server/Module/Message/NetServerComponent.cs
  36. 1 3
      Unity/Assets/Scripts/Model/Share/Entry.cs

BIN
Unity/Assets/Config/Excel/StartConfig/Release/StartSceneConfig@s.xlsx


+ 1 - 0
Unity/Assets/Scripts/Core/Fiber/Fiber.cs

@@ -50,6 +50,7 @@ namespace ET
         {
             this.SceneType = sceneType;
             this.Id = id;
+            this.InstanceId = 1;
             this.Process = process;
             this.Root = this;
             this.EntitySystem = new EntitySystem();

+ 0 - 1
Unity/Assets/Scripts/Core/Fiber/IdGenerater.cs

@@ -1,6 +1,5 @@
 using System;
 using System.Runtime.InteropServices;
-using MemoryPack;
 
 namespace ET
 {

+ 20 - 8
Unity/Assets/Scripts/Core/Fiber/MailBoxComponent.cs

@@ -4,11 +4,13 @@
     public static partial class MailBoxComponentSystem
     {
         [EntitySystem]       
-        private static void Awake(this MailBoxComponent self, MailboxType mailboxType)
+        private static void Awake(this MailBoxComponent self, MailBoxType mailBoxType)
         {
-            self.MailboxType = mailboxType;
+            Fiber fiber = self.Fiber();
+            self.MailBoxType = mailBoxType;
             self.ParentInstanceId = self.Parent.InstanceId;
-            self.Fiber().Mailboxes.Add(self);
+            fiber.Mailboxes.Add(self);
+            self.CoroutineLockComponent = fiber.GetComponent<CoroutineLockComponent>();
         }
         
         [EntitySystem]
@@ -18,20 +20,30 @@
         }
 
         // 加到mailbox
-        public static void Add(this MailBoxComponent self, MessageObject messageObject)
+        public static void Add(this MailBoxComponent self, Address fromAddress, MessageObject messageObject)
         {
-            
+            // 根据mailboxType进行分发处理
+            EventSystem.Instance.Invoke((int)self.MailBoxType, new MailBoxInvoker() {MailBoxComponent = self, MessageObject = messageObject, FromAddress = fromAddress});
         }
     }
+
+    public struct MailBoxInvoker
+    {
+        public Address FromAddress;
+        public MessageObject MessageObject;
+        public MailBoxComponent MailBoxComponent;
+    }
     
     /// <summary>
     /// 挂上这个组件表示该Entity是一个Actor,接收的消息将会队列处理
     /// </summary>
     [ComponentOf]
-    public class MailBoxComponent: Entity, IAwake<MailboxType>, IDestroy
+    public class MailBoxComponent: Entity, IAwake<MailBoxType>, IDestroy
     {
-        public long ParentInstanceId;
+        public long ParentInstanceId { get; set; }
         // Mailbox的类型
-        public MailboxType MailboxType { get; set; }
+        public MailBoxType MailBoxType { get; set; }
+
+        public EntityRef<CoroutineLockComponent> CoroutineLockComponent { get; set; }
     }
 }

+ 9 - 0
Unity/Assets/Scripts/Core/Fiber/MailBoxType.cs

@@ -0,0 +1,9 @@
+namespace ET
+{
+    public enum MailBoxType
+    {
+        OrderedMessage = 1,
+        UnOrderMessage,
+        GateSession,
+    }
+}

+ 0 - 9
Unity/Assets/Scripts/Core/Fiber/MailboxType.cs

@@ -1,9 +0,0 @@
-namespace ET
-{
-    public enum MailboxType
-    {
-        OrderedMessage,
-        UnOrderMessageDispatcher,
-        GateSession,
-    }
-}

+ 2 - 2
Unity/Assets/Scripts/Core/World/Module/Actor/ActorMessageDispatcherComponent.cs

@@ -90,7 +90,7 @@ namespace ET
             this.ActorMessageHandlers[type].Add(handler);
         }
 
-        public async ETTask Handle(Entity entity, ActorId actorId, object message)
+        public async ETTask Handle(Entity entity, Address fromAddress, object message)
         {
             List<ActorMessageDispatcherInfo> list;
             if (!this.ActorMessageHandlers.TryGetValue(message.GetType(), out list))
@@ -105,7 +105,7 @@ namespace ET
                 {
                     continue;
                 }
-                await actorMessageDispatcherInfo.IMActorHandler.Handle(entity, actorId, message);   
+                await actorMessageDispatcherInfo.IMActorHandler.Handle(entity, fromAddress, message);   
             }
         }
     }

+ 1 - 1
Unity/Assets/Scripts/Core/World/Module/Actor/IMActorHandler.cs

@@ -4,7 +4,7 @@ namespace ET
 {
     public interface IMActorHandler
     {
-        ETTask Handle(Entity entity, ActorId actorId, object actorMessage);
+        ETTask Handle(Entity entity, Address fromAddress, object actorMessage);
         Type GetRequestType();
         Type GetResponseType();
     }

+ 8 - 0
Unity/Assets/Scripts/Core/World/Module/Fiber/FiberInit.cs

@@ -0,0 +1,8 @@
+namespace ET
+{
+
+    public struct FiberInit
+    {
+        public Fiber Fiber { get; set; }
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Core/World/Module/Fiber/FiberInit.cs.meta

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

+ 19 - 28
Unity/Assets/Scripts/Core/World/Module/Fiber/FiberManager.cs

@@ -1,17 +1,13 @@
 using System.Collections.Concurrent;
 using System.Collections.Generic;
+using System.Threading;
 
 namespace ET
 {
-    public struct FiberInit
-    {
-        public SceneType SceneType;
-    }
-
     public partial class FiberManager: Singleton<FiberManager>, ISingletonAwake
     {
-        private int idGenerator = int.MaxValue;
-        private readonly Dictionary<int, Fiber> fibers = new();
+        private int idGenerator = 1000; // 1000以下为保留的fiber id
+        private readonly ConcurrentDictionary<int, Fiber> fibers = new();
         
         public void Awake()
         {
@@ -19,39 +15,34 @@ namespace ET
         
         public int Create(int fiberId, SceneType sceneType)
         {
-            lock (this)
-            {
-                if (fiberId == 0)
-                {
-                    fiberId = --this.idGenerator;
-                }
-                Fiber fiber = new(fiberId, Options.Instance.Process, sceneType);
-                this.fibers.Add((int)fiber.Id, fiber);
-                EventSystem.Instance.Invoke((int)sceneType, new FiberInit());
-                return fiberId;
-            }
+            fiberId = Interlocked.Increment(ref this.idGenerator);
+            Fiber fiber = new(fiberId, Options.Instance.Process, sceneType);
+            
+            fiber.AddComponent<TimerComponent>();
+            fiber.AddComponent<CoroutineLockComponent>();
+            fiber.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.UnOrderMessage);
+                
+            // 根据Fiber的SceneType分发Init
+            EventSystem.Instance.Invoke((int)sceneType, new FiberInit() {Fiber = fiber});
+                
+            this.fibers[(int)fiber.Id] = fiber;
+            return fiberId;
         }
         
         // 不允许外部调用,只能由Schecher执行完成一帧调用,否则容易出现多线程问题
         private void Remove(int id)
         {
-            lock (this)
+            if (this.fibers.Remove(id, out Fiber fiber))
             {
-                if (this.fibers.Remove(id, out Fiber process))
-                {
-                    process.Dispose();
-                }
+                fiber.Dispose();
             }
         }
 
         // 不允许外部调用,容易出现多线程问题
         private Fiber Get(int id)
         {
-            lock (this)
-            {
-                this.fibers.TryGetValue(id, out Fiber process);
-                return process;
-            }
+            this.fibers.TryGetValue(id, out Fiber fiber);
+            return fiber;
         }
     }
 }

+ 6 - 6
Unity/Assets/Scripts/Hotfix/Server/Demo/Helper/SceneFactory.cs

@@ -10,7 +10,7 @@ namespace ET.Server
             await ETTask.CompletedTask;
             Scene scene = EntitySceneFactory.CreateScene(id, instanceId, zone, sceneType, name, parent);
 
-            scene.AddComponent<MailBoxComponent, MailboxType>(MailboxType.UnOrderMessageDispatcher);
+            scene.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.UnOrderMessage);
 
             switch (scene.SceneType)
             {
@@ -24,12 +24,12 @@ namespace ET.Server
                     scene.AddComponent<HttpComponent, string>($"http://*:{startSceneConfig.OuterPort}/");
                     break;
                 case SceneType.Realm:
-                    scene.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.InnerIPOutPort);
+                    //scene.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.InnerIPOutPort);
                     break;
                 case SceneType.Gate:
-                    scene.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.InnerIPOutPort);
-                    scene.AddComponent<PlayerComponent>();
-                    scene.AddComponent<GateSessionKeyComponent>();
+                    //scene.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.InnerIPOutPort);
+                    //scene.AddComponent<PlayerComponent>();
+                    //scene.AddComponent<GateSessionKeyComponent>();
                     break;
                 case SceneType.Map:
                     scene.AddComponent<UnitComponent>();
@@ -44,7 +44,7 @@ namespace ET.Server
                     break;
                 case SceneType.BenchmarkServer:
                     scene.AddComponent<BenchmarkServerComponent>();
-                    scene.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.OuterIPPort);
+                    //scene.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.OuterIPPort);
                     break;
                 case SceneType.BenchmarkClient:
                     scene.AddComponent<BenchmarkClientComponent>();

+ 5 - 5
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/C2G_LoginGateHandler.cs

@@ -8,8 +8,8 @@ namespace ET.Server
     {
         protected override async ETTask Run(Session session, C2G_LoginGate request, G2C_LoginGate response)
         {
-            Scene scene = session.Scene();
-            string account = scene.GetComponent<GateSessionKeyComponent>().Get(request.Key);
+            Fiber fiber = session.Fiber();
+            string account = fiber.GetComponent<GateSessionKeyComponent>().Get(request.Key);
             if (account == null)
             {
                 response.Error = ErrorCore.ERR_ConnectGateKeyError;
@@ -19,17 +19,17 @@ namespace ET.Server
             
             session.RemoveComponent<SessionAcceptTimeoutComponent>();
 
-            PlayerComponent playerComponent = scene.GetComponent<PlayerComponent>();
+            PlayerComponent playerComponent = fiber.GetComponent<PlayerComponent>();
             Player player = playerComponent.GetByAccount(account);
             if (player == null)
             {
                 player = playerComponent.AddChild<Player, string>(account);
                 playerComponent.Add(player);
                 PlayerSessionComponent playerSessionComponent = player.AddComponent<PlayerSessionComponent>();
-                playerSessionComponent.AddComponent<MailBoxComponent, MailboxType>(MailboxType.GateSession);
+                playerSessionComponent.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.GateSession);
                 await playerSessionComponent.AddLocation(LocationType.GateSession);
 			
-                player.AddComponent<MailBoxComponent, MailboxType>(MailboxType.UnOrderMessageDispatcher);
+                player.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.UnOrderMessage);
                 await player.AddLocation(LocationType.Player);
 			
                 session.AddComponent<SessionPlayerComponent>().Player = player;

+ 19 - 0
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/FiberInit_Gate.cs

@@ -0,0 +1,19 @@
+using System.Net;
+
+namespace ET.Server
+{
+    [Invoke((int)SceneType.Gate)]
+    public class FiberInit_Gate: AInvokeHandler<FiberInit>
+    {
+        public override void Handle(FiberInit fiberInit)
+        {
+            Fiber fiber = fiberInit.Fiber;
+
+            fiber.AddComponent<PlayerComponent>();
+            fiber.AddComponent<GateSessionKeyComponent>();
+
+            StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.Get((int)fiber.Id);
+            fiber.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.InnerIPOutPort);
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/FiberInit_Gate.cs.meta

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

+ 16 - 0
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/MailBoxType_GateSessionHandler.cs

@@ -0,0 +1,16 @@
+namespace ET.Server
+{
+    [Invoke((int)MailBoxType.GateSession)]
+    public class MailBoxType_GateSessionHandler: AInvokeHandler<MailBoxInvoker>
+    {
+        public override void Handle(MailBoxInvoker args)
+        {
+            MailBoxComponent mailBoxComponent = args.MailBoxComponent;
+            MessageObject messageObject = args.MessageObject;
+            if (mailBoxComponent.Parent is PlayerSessionComponent playerSessionComponent)
+            {
+                playerSessionComponent.Session?.Send(messageObject as IMessage);
+            }
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/MailBoxType_GateSessionHandler.cs.meta

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

+ 4 - 4
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/R2G_GetLoginKeyHandler.cs

@@ -4,14 +4,14 @@
 namespace ET.Server
 {
 	[ActorMessageHandler(SceneType.Gate)]
-	public class R2G_GetLoginKeyHandler : ActorMessageHandler<Scene, R2G_GetLoginKey, G2R_GetLoginKey>
+	public class R2G_GetLoginKeyHandler : ActorMessageHandler<Fiber, R2G_GetLoginKey, G2R_GetLoginKey>
 	{
-		protected override async ETTask Run(Scene scene, R2G_GetLoginKey request, G2R_GetLoginKey response)
+		protected override async ETTask Run(Fiber fiber, R2G_GetLoginKey request, G2R_GetLoginKey response)
 		{
 			long key = RandomGenerator.RandInt64();
-			scene.GetComponent<GateSessionKeyComponent>().Add(key, request.Account);
+			fiber.GetComponent<GateSessionKeyComponent>().Add(key, request.Account);
 			response.Key = key;
-			response.GateId = scene.Id;
+			response.GateId = fiber.Id;
 			await ETTask.CompletedTask;
 		}
 	}

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Map/Transfer/M2M_UnitTransferRequestHandler.cs

@@ -24,7 +24,7 @@ namespace ET.Server
             unit.AddComponent<PathfindingComponent, string>(scene.Name);
             unit.Position = new float3(-10, 0, -10);
 
-            unit.AddComponent<MailBoxComponent, MailboxType>(MailboxType.OrderedMessage);
+            unit.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.OrderedMessage);
 
             // 通知客户端开始切场景
             M2C_StartSceneChange m2CStartSceneChange = new() { SceneInstanceId = scene.InstanceId, SceneName = scene.Name };

+ 16 - 0
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Realm/FiberInit_Realm.cs

@@ -0,0 +1,16 @@
+using System.Net;
+
+namespace ET.Server
+{
+    [Invoke((int)SceneType.Realm)]
+    public class FiberInit_Realm: AInvokeHandler<FiberInit>
+    {
+        public override void Handle(FiberInit fiberInit)
+        {
+            Fiber fiber = fiberInit.Fiber;
+            
+            StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.Get((int)fiber.Id);
+            fiber.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.InnerIPOutPort);
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Realm/FiberInit_Realm.cs.meta

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

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Robot/Scene/RobotSceneFactory.cs

@@ -16,7 +16,7 @@ namespace ET.Server
             Log.Info($"create scene: {sceneType} {name} {zone}");
             Scene scene = EntitySceneFactory.CreateScene(id, instanceId, zone, sceneType, name, parent);
 
-            scene.AddComponent<MailBoxComponent, MailboxType>(MailboxType.UnOrderMessageDispatcher);
+            scene.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.UnOrderMessage);
 
             switch (scene.SceneType)
             {

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/LockStep/Map/RoomManagerComponentSystem.cs

@@ -16,7 +16,7 @@ namespace ET.Server
 
             room.LSWorld = new LSWorld(SceneType.LockStepServer);
 
-            room.AddComponent<MailBoxComponent, MailboxType>(MailboxType.UnOrderMessageDispatcher);
+            room.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.UnOrderMessage);
             
             return room;
         }

+ 4 - 4
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorMessageLocationHandler.cs

@@ -7,7 +7,7 @@ namespace ET.Server
     {
         protected abstract ETTask Run(E entity, Message message);
 
-        public async ETTask Handle(Entity entity, ActorId actorId, object actorMessage)
+        public async ETTask Handle(Entity entity, Address fromAddress, object actorMessage)
         {
             if (actorMessage is not Message message)
             {
@@ -22,7 +22,7 @@ namespace ET.Server
             }
             
             ActorResponse response = new() {RpcId = message.RpcId};
-            entity.Fiber().GetComponent<ActorMessageSenderComponent>().Reply(actorId, response);
+            entity.Fiber().GetComponent<ActorMessageSenderComponent>().Reply(fromAddress, response);
 
             await this.Run(e, message);
         }
@@ -45,7 +45,7 @@ namespace ET.Server
     {
         protected abstract ETTask Run(E unit, Request request, Response response);
 
-        public async ETTask Handle(Entity entity, ActorId actorId, object actorMessage)
+        public async ETTask Handle(Entity entity, Address fromAddress, object actorMessage)
         {
             try
             {
@@ -75,7 +75,7 @@ namespace ET.Server
                     response.Message = exception.ToString();
                 }
                 response.RpcId = rpcId;
-                entity.Fiber().GetComponent<ActorMessageSenderComponent>().Reply(actorId, response);
+                entity.Fiber().GetComponent<ActorMessageSenderComponent>().Reply(fromAddress, response);
             }
             catch (Exception e)
             {

+ 3 - 3
Unity/Assets/Scripts/Hotfix/Share/Module/Actor/ActorMessageHandler.cs

@@ -8,7 +8,7 @@ namespace ET
     {
         protected abstract ETTask Run(E entity, Message message);
 
-        public async ETTask Handle(Entity entity, ActorId actorId, object actorMessage)
+        public async ETTask Handle(Entity entity, Address fromAddress, object actorMessage)
         {
             if (actorMessage is not Message msg)
             {
@@ -48,7 +48,7 @@ namespace ET
     {
         protected abstract ETTask Run(E unit, Request request, Response response);
 
-        public async ETTask Handle(Entity entity, ActorId actorId, object actorMessage)
+        public async ETTask Handle(Entity entity, Address fromAddress, object actorMessage)
         {
             try
             {
@@ -79,7 +79,7 @@ namespace ET
                 }
                 
                 response.RpcId = rpcId;
-                entity.Fiber().GetComponent<ActorMessageSenderComponent>().Reply(actorId, response);
+                entity.Fiber().GetComponent<ActorMessageSenderComponent>().Reply(fromAddress, response);
             }
             catch (Exception e)
             {

+ 7 - 4
Unity/Assets/Scripts/Hotfix/Share/Module/Actor/ActorMessageRecvComponentSystem.cs

@@ -35,16 +35,19 @@ namespace ET
 
                 ActorId actorId = actorMessageInfo.ActorId;
                 MessageObject message = actorMessageInfo.MessageObject;
-                actorId.Address = fiber.Address;
+
                 MailBoxComponent mailBoxComponent = self.Fiber().Mailboxes.Get(actorId.InstanceId);
                 if (mailBoxComponent == null)
                 {
                     Log.Warning($"actor not found mailbox: {actorId} {message}");
-                    IActorResponse resp = ActorHelper.CreateResponse((IActorRequest)message, ErrorCore.ERR_NotFoundActor);
-                    actorMessageSenderComponent.Reply(actorId, resp);
+                    if (message is IActorRequest request)
+                    {
+                        IActorResponse resp = ActorHelper.CreateResponse(request, ErrorCore.ERR_NotFoundActor);
+                        actorMessageSenderComponent.Reply(actorId.Address, resp);
+                    }
                     return;
                 }
-                mailBoxComponent.Add(message);
+                mailBoxComponent.Add(actorId.Address, message);
             }
         }
     }

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Share/Module/Actor/ActorMessageSenderComponentSystem.cs

@@ -89,9 +89,9 @@ namespace ET
             self.TimeoutActorMessageSenders.Clear();
         }
         
-        public static void Reply(this ActorMessageSenderComponent self, ActorId actorId, IMessage message)
+        public static void Reply(this ActorMessageSenderComponent self, Address fromAddress, IMessage message)
         {
-            self.Send(actorId, message);
+            self.Send(new ActorId(fromAddress, 0), message);
         }
 
         public static void Send(this ActorMessageSenderComponent self, ActorId actorId, IMessage message)

+ 37 - 0
Unity/Assets/Scripts/Hotfix/Share/Module/Actor/MailBoxType_OrderedMessageHandler.cs

@@ -0,0 +1,37 @@
+namespace ET
+{
+    [Invoke((int)MailBoxType.OrderedMessage)]
+    public class MailBoxType_OrderedMessageHandler: AInvokeHandler<MailBoxInvoker>
+    {
+        public override void Handle(MailBoxInvoker args)
+        {
+            HandleInner(args).Coroutine();
+        }
+
+        private async ETTask HandleInner(MailBoxInvoker args)
+        {
+            MailBoxComponent mailBoxComponent = args.MailBoxComponent;
+            MessageObject messageObject = args.MessageObject;
+            CoroutineLockComponent coroutineLockComponent = mailBoxComponent.CoroutineLockComponent;
+            if (coroutineLockComponent == null)
+            {
+                return;
+            }
+
+            long instanceId = mailBoxComponent.InstanceId;
+            using (await coroutineLockComponent.Wait(CoroutineLockType.Mailbox, mailBoxComponent.ParentInstanceId))
+            {
+                if (mailBoxComponent.InstanceId != instanceId)
+                {
+                    if (messageObject is IActorRequest request)
+                    {
+                        IActorResponse resp = ActorHelper.CreateResponse(request, ErrorCore.ERR_NotFoundActor);
+                        mailBoxComponent.Fiber().GetComponent<ActorMessageSenderComponent>().Reply(args.FromAddress, resp);
+                    }
+                    return;
+                }
+                await ActorMessageDispatcherComponent.Instance.Handle(mailBoxComponent.Parent, args.FromAddress, messageObject);
+            }
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Hotfix/Share/Module/Actor/MailBoxType_OrderedMessageHandler.cs.meta

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

+ 19 - 0
Unity/Assets/Scripts/Hotfix/Share/Module/Actor/MailBoxType_UnOrderedMessageHandler.cs

@@ -0,0 +1,19 @@
+namespace ET
+{
+    [Invoke((int)MailBoxType.UnOrderMessage)]
+    public class MailBoxType_UnOrderedMessageHandler: AInvokeHandler<MailBoxInvoker>
+    {
+        public override void Handle(MailBoxInvoker args)
+        {
+            MailBoxComponent mailBoxComponent = args.MailBoxComponent;
+            MessageObject messageObject = args.MessageObject;
+            CoroutineLockComponent coroutineLockComponent = mailBoxComponent.CoroutineLockComponent;
+            if (coroutineLockComponent == null)
+            {
+                return;
+            }
+
+            ActorMessageDispatcherComponent.Instance.Handle(mailBoxComponent.Parent, args.FromAddress, messageObject).Coroutine();
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Hotfix/Share/Module/Actor/MailBoxType_UnOrderedMessageHandler.cs.meta

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

+ 1 - 0
Unity/Assets/Scripts/Model/Generate/Server/ConfigPartial/StartSceneConfig.cs

@@ -135,6 +135,7 @@ namespace ET
 
         public override void EndInit()
         {
+            this.ActorId = new ActorId(this.Process, this.Id, 1);
             this.Type = EnumHelper.FromString<SceneType>(this.SceneType);
         }
     }

+ 2 - 2
Unity/Assets/Scripts/Model/Server/Demo/Gate/GateSessionKeyComponent.cs

@@ -2,9 +2,9 @@
 
 namespace ET.Server
 {
-    [ComponentOf(typeof(Scene))]
+    [ComponentOf(typeof(Fiber))]
     public class GateSessionKeyComponent : Entity, IAwake
     {
-        public readonly Dictionary<long, string> sessionKey = new Dictionary<long, string>();
+        public readonly Dictionary<long, string> sessionKey = new();
     }
 }

+ 1 - 1
Unity/Assets/Scripts/Model/Server/Demo/Gate/PlayerComponent.cs

@@ -3,7 +3,7 @@ using System.Linq;
 
 namespace ET.Server
 {
-	[ComponentOf(typeof(Scene))]
+	[ComponentOf(typeof(Fiber))]
 	public class PlayerComponent : Entity, IAwake, IDestroy
 	{
 		public Dictionary<string, Player> dictionary = new Dictionary<string, Player>();

+ 1 - 1
Unity/Assets/Scripts/Model/Server/Module/Message/NetServerComponent.cs

@@ -8,7 +8,7 @@ namespace ET.Server
         public object Message;
     }
     
-    [ComponentOf(typeof(Scene))]
+    [ComponentOf(typeof(Fiber))]
     public class NetServerComponent: Entity, IAwake<IPEndPoint>, IDestroy
     {
         public AService AService;

+ 1 - 3
Unity/Assets/Scripts/Model/Share/Entry.cs

@@ -59,9 +59,7 @@ namespace ET
 
             Fiber fiber = Fiber.Instance;
             
-            fiber.AddComponent<MainThreadSynchronizationContext>();
-            fiber.AddComponent<TimerComponent>();
-            fiber.AddComponent<CoroutineLockComponent>();
+
 
             await World.Instance.AddSingleton<ConfigComponent>().LoadAsync();