Ver Fonte

调通了进程间通信

tanghai há 2 anos atrás
pai
commit
325f249979
32 ficheiros alterados com 183 adições e 145 exclusões
  1. 2 2
      Unity/Assets/Scripts/Core/World/Module/EventSystem/IInvoke.cs
  2. 1 0
      Unity/Assets/Scripts/Hotfix/Server/Demo/EntryEvent2_InitServer.cs
  3. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Gate/C2G_LoginGateHandler.cs
  4. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Gate/FiberInit_Gate.cs
  5. 2 2
      Unity/Assets/Scripts/Hotfix/Server/Demo/Gate/NetServerComponentOnReadEvent.cs
  6. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Map/Transfer/TransferHelper.cs
  7. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/MessageHelper.cs
  8. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Realm/C2R_LoginHandler.cs
  9. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Realm/FiberInit_Realm.cs
  10. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Gate/C2G_MatchHandler.cs
  11. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Map/FiberInit_Map.cs
  12. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Map/Match2Map_GetRoomHandler.cs
  13. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Match/FiberInit_Match.cs
  14. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Match/MatchComponentSystem.cs
  15. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Room/FiberInit_RoomRoot.cs
  16. 6 6
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorLocationSenderComponentSystem.cs
  17. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/FiberInit_Location.cs
  18. 5 5
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationProxyComponentSystem.cs
  19. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Module/Message/A2NetInner_RequestHandler.cs
  20. 16 20
      Unity/Assets/Scripts/Hotfix/Server/Module/Message/ActorOuterComponentSystem.cs
  21. 81 0
      Unity/Assets/Scripts/Hotfix/Server/Module/Message/ActorSenderComponentSystem.cs
  22. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Module/Message/ActorSenderComponentSystem.cs.meta
  23. 18 5
      Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetInnerComponentOnReadEvent.cs
  24. 0 48
      Unity/Assets/Scripts/Hotfix/Server/Module/Message/ServerSenderComponentSystem.cs
  25. 1 0
      Unity/Assets/Scripts/Hotfix/Server/Module/NetInner/FiberInit_NetInner.cs
  26. 14 15
      Unity/Assets/Scripts/Hotfix/Share/Module/Actor/ActorInnerComponentSystem.cs
  27. 14 0
      Unity/Assets/Scripts/Model/Server/Module/Message/ActorSenderComponent.cs
  28. 1 1
      Unity/Assets/Scripts/Model/Server/Module/Message/ActorSenderComponent.cs.meta
  29. 0 20
      Unity/Assets/Scripts/Model/Server/Module/Message/ServerSenderComponent.cs
  30. 4 3
      Unity/Assets/Scripts/Model/Server/Module/NetInner/A2NetInner_Message.cs
  31. 1 1
      Unity/Assets/Scripts/Model/Share/Module/Actor/ActorHelper.cs
  32. 2 2
      Unity/Assets/Scripts/Model/Share/Module/Actor/ActorInnerComponent.cs

+ 2 - 2
Unity/Assets/Scripts/Core/World/Module/EventSystem/IInvoke.cs

@@ -17,7 +17,7 @@ namespace ET
             }
         }
 
-        public abstract void Handle(A a);
+        public abstract void Handle(A args);
     }
     
     public abstract class AInvokeHandler<A, T>: IInvoke where A: struct
@@ -30,6 +30,6 @@ namespace ET
             }
         }
 
-        public abstract T Handle(A a);
+        public abstract T Handle(A args);
     }
 }

+ 1 - 0
Unity/Assets/Scripts/Hotfix/Server/Demo/EntryEvent2_InitServer.cs

@@ -25,6 +25,7 @@ namespace ET.Server
                 }
                 case AppType.Watcher:
                 {
+                    root.AddComponent<WatcherComponent>();
                     break;
                 }
                 case AppType.GameTool:

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

@@ -59,7 +59,7 @@ namespace ET.Server
             Fiber fiber = player.Fiber();
             await fiber.WaitFrameFinish();
             
-            using Room2G_Reconnect room2GateReconnect = await fiber.Root.GetComponent<ActorInnerComponent>().Call(
+            using Room2G_Reconnect room2GateReconnect = await fiber.Root.GetComponent<ActorSenderComponent>().Call(
                 player.GetComponent<PlayerRoomComponent>().RoomActorId,
                 new G2Room_Reconnect() { PlayerId = player.Id }) as Room2G_Reconnect;
             G2C_Reconnect g2CReconnect = new() { StartTime = room2GateReconnect.StartTime, Frame = room2GateReconnect.Frame };

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Gate/FiberInit_Gate.cs

@@ -10,7 +10,7 @@ namespace ET.Server
             Scene root = fiberInit.Fiber.Root;
             root.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.UnOrderedMessage);
             root.AddComponent<ActorInnerComponent>();
-            root.AddComponent<ServerSenderComponent>();
+            root.AddComponent<ActorSenderComponent>();
             root.AddComponent<ActorRecverComponent>();
             root.AddComponent<PlayerComponent>();
             root.AddComponent<GateSessionKeyComponent>();

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Server/Demo/Gate/NetServerComponentOnReadEvent.cs

@@ -23,7 +23,7 @@
                     Player player = session.GetComponent<SessionPlayerComponent>().Player;
                     ActorId roomActorId = player.GetComponent<PlayerRoomComponent>().RoomActorId;
                     frameMessage.PlayerId = player.Id;
-                    root.GetComponent<ActorInnerComponent>().Send(roomActorId, frameMessage);
+                    root.GetComponent<ActorSenderComponent>().Send(roomActorId, frameMessage);
                     break;
                 }
                 case IActorRoom actorRoom:
@@ -31,7 +31,7 @@
                     Player player = session.GetComponent<SessionPlayerComponent>().Player;
                     ActorId roomActorId = player.GetComponent<PlayerRoomComponent>().RoomActorId;
                     actorRoom.PlayerId = player.Id;
-                    root.GetComponent<ActorInnerComponent>().Send(roomActorId, actorRoom);
+                    root.GetComponent<ActorSenderComponent>().Send(roomActorId, actorRoom);
                     break;
                 }
                 case IActorLocationMessage actorLocationMessage:

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

@@ -33,7 +33,7 @@ namespace ET.Server
             unit.Dispose();
             
             await root.GetComponent<LocationProxyComponent>().Lock(LocationType.Unit, unitId, request.OldActorId);
-            await root.GetComponent<ActorInnerComponent>().Call(sceneInstanceId, request);
+            await root.GetComponent<ActorSenderComponent>().Call(sceneInstanceId, request);
         }
     }
 }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/MessageHelper.cs

@@ -43,7 +43,7 @@ namespace ET.Server
         /// </summary>
         public static void SendActor(Scene root, ActorId actorId, IActorMessage message)
         {
-            root.GetComponent<ActorInnerComponent>().Send(actorId, message);
+            root.GetComponent<ActorSenderComponent>().Send(actorId, message);
         }
     }
 }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Realm/C2R_LoginHandler.cs

@@ -14,7 +14,7 @@ namespace ET.Server
 			Log.Debug($"gate address: {config}");
 			
 			// 向gate请求一个key,客户端可以拿着这个key连接gate
-			G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey) await session.Fiber().Root.GetComponent<ActorInnerComponent>().Call(
+			G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey) await session.Fiber().Root.GetComponent<ActorSenderComponent>().Call(
 				config.ActorId, new R2G_GetLoginKey() {Account = request.Account});
 
 			response.Address = config.InnerIPPort.ToString();

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Realm/FiberInit_Realm.cs

@@ -10,7 +10,7 @@ namespace ET.Server
             Scene root = fiberInit.Fiber.Root;
             root.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.UnOrderedMessage);
             root.AddComponent<ActorInnerComponent>();
-            root.AddComponent<ServerSenderComponent>();
+            root.AddComponent<ActorSenderComponent>();
             root.AddComponent<ActorRecverComponent>();
             StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.Get(root.Fiber.Id);
             root.AddComponent<NetServerComponent, IPEndPoint>(startSceneConfig.InnerIPPort);

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/LockStep/Gate/C2G_MatchHandler.cs

@@ -9,7 +9,7 @@
 
 			StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.Match;
 
-			await session.Root().GetComponent<ActorInnerComponent>().Call(startSceneConfig.ActorId,
+			await session.Root().GetComponent<ActorSenderComponent>().Call(startSceneConfig.ActorId,
 				new G2Match_Match() { Id = player.Id });
 		}
 	}

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

@@ -10,7 +10,7 @@ namespace ET.Server
             Scene root = fiberInit.Fiber.Root;
             root.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.UnOrderedMessage);
             root.AddComponent<ActorInnerComponent>();
-            root.AddComponent<ServerSenderComponent>();
+            root.AddComponent<ActorSenderComponent>();
             root.AddComponent<ActorRecverComponent>();
             root.AddComponent<UnitComponent>();
             root.AddComponent<AOIManagerComponent>();

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

@@ -17,7 +17,7 @@ namespace ET.Server
 			// 发送消息给房间纤程,初始化
 			RoomManager2Room_Init roomManager2RoomInit = RoomManager2Room_Init.Create();
 			roomManager2RoomInit.PlayerIds.AddRange(request.PlayerIds);
-			await root.GetComponent<ActorInnerComponent>().Call(roomRootActorId, roomManager2RoomInit);
+			await root.GetComponent<ActorSenderComponent>().Call(roomRootActorId, roomManager2RoomInit);
 			
 			response.ActorId = roomRootActorId;
 			await ETTask.CompletedTask;

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/LockStep/Match/FiberInit_Match.cs

@@ -10,7 +10,7 @@ namespace ET.Server
             Scene root = fiberInit.Fiber.Root;
             root.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.UnOrderedMessage);
             root.AddComponent<ActorInnerComponent>();
-            root.AddComponent<ServerSenderComponent>();
+            root.AddComponent<ActorSenderComponent>();
             root.AddComponent<ActorRecverComponent>();
             root.AddComponent<MatchComponent>();
             root.AddComponent<LocationProxyComponent>();

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/LockStep/Match/MatchComponentSystem.cs

@@ -32,7 +32,7 @@ namespace ET.Server
             self.waitMatchPlayers.Clear();
 
             Scene root = self.Root();
-            Map2Match_GetRoom map2MatchGetRoom = await root.GetComponent<ActorInnerComponent>().Call(
+            Map2Match_GetRoom map2MatchGetRoom = await root.GetComponent<ActorSenderComponent>().Call(
                 startSceneConfig.ActorId, match2MapGetRoom) as Map2Match_GetRoom;
 
             Match2G_NotifyMatchSuccess match2GNotifyMatchSuccess = new() { ActorId = map2MatchGetRoom.ActorId };

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

@@ -10,7 +10,7 @@ namespace ET.Server
             Scene root = fiberInit.Fiber.Root;
             root.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.UnOrderedMessage);
             root.AddComponent<ActorInnerComponent>();
-            root.AddComponent<ServerSenderComponent>();
+            root.AddComponent<ActorSenderComponent>();
             root.AddComponent<ActorRecverComponent>();
             Room room = root.AddChild<Room>();
             root.AddComponent<LocationProxyComponent>();

+ 6 - 6
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorLocationSenderComponentSystem.cs

@@ -105,7 +105,7 @@ namespace ET.Server
             if (actorLocationSender.ActorId != default)
             {
                 actorLocationSender.LastSendOrRecvTime = self.Fiber().TimeInfo.ServerNow();
-                root.GetComponent<ActorInnerComponent>().Send(actorLocationSender.ActorId, message);
+                root.GetComponent<ActorSenderComponent>().Send(actorLocationSender.ActorId, message);
                 return;
             }
             
@@ -129,7 +129,7 @@ namespace ET.Server
                 }
                 
                 actorLocationSender.LastSendOrRecvTime = self.Fiber().TimeInfo.ServerNow();
-                root.GetComponent<ActorInnerComponent>().Send(actorLocationSender.ActorId, message);
+                root.GetComponent<ActorSenderComponent>().Send(actorLocationSender.ActorId, message);
             }
         }
 
@@ -144,7 +144,7 @@ namespace ET.Server
             if (actorLocationSender.ActorId != default)
             {
                 actorLocationSender.LastSendOrRecvTime = self.Fiber().TimeInfo.ServerNow();
-                return await root.GetComponent<ActorInnerComponent>().Call(actorLocationSender.ActorId, request);
+                return await root.GetComponent<ActorSenderComponent>().Call(actorLocationSender.ActorId, request);
             }
             
             long instanceId = actorLocationSender.InstanceId;
@@ -168,7 +168,7 @@ namespace ET.Server
             }
 
             actorLocationSender.LastSendOrRecvTime = self.Fiber().TimeInfo.ServerNow();
-            return await root.GetComponent<ActorInnerComponent>().Call(actorLocationSender.ActorId, request);
+            return await root.GetComponent<ActorSenderComponent>().Call(actorLocationSender.ActorId, request);
         }
 
         public static void Send(this ActorLocationSenderOneType self, long entityId, IActorLocationMessage message)
@@ -183,7 +183,7 @@ namespace ET.Server
             Scene root = self.Root();
             
             // 先序列化好
-            int rpcId = root.GetComponent<ActorInnerComponent>().GetRpcId();
+            int rpcId = root.GetComponent<ActorSenderComponent>().GetRpcId();
             iActorRequest.RpcId = rpcId;
             
             long actorLocationSenderInstanceId = actorLocationSender.InstanceId;
@@ -242,7 +242,7 @@ namespace ET.Server
                     actorLocationSender.Error = ErrorCore.ERR_NotFoundActor;
                     return ActorHelper.CreateResponse(iActorRequest, ErrorCore.ERR_NotFoundActor);
                 }
-                IActorResponse response = await root.GetComponent<ActorInnerComponent>().Call(actorLocationSender.ActorId, rpcId, iActorRequest, needException: false);
+                IActorResponse response = await root.GetComponent<ActorSenderComponent>().Call(actorLocationSender.ActorId, rpcId, iActorRequest, needException: false);
                 if (actorLocationSender.InstanceId != instanceId)
                 {
                     throw new RpcException(ErrorCore.ERR_ActorLocationSenderTimeout3, $"{iActorRequest}");

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/FiberInit_Location.cs

@@ -10,7 +10,7 @@ namespace ET.Server
             Scene root = fiberInit.Fiber.Root;
             root.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.UnOrderedMessage);
             root.AddComponent<ActorInnerComponent>();
-            root.AddComponent<ServerSenderComponent>();
+            root.AddComponent<ActorSenderComponent>();
             root.AddComponent<ActorRecverComponent>();
             root.AddComponent<LocationManagerComoponent>();
 

+ 5 - 5
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationProxyComponentSystem.cs

@@ -12,28 +12,28 @@ namespace ET.Server
         public static async ETTask Add(this LocationProxyComponent self, int type, long key, ActorId actorId)
         {
             Log.Info($"location proxy add {key}, {actorId} {self.Fiber().TimeInfo.ServerNow()}");
-            await self.Root().GetComponent<ActorInnerComponent>().Call(GetLocationSceneId(key),
+            await self.Root().GetComponent<ActorSenderComponent>().Call(GetLocationSceneId(key),
                 new ObjectAddRequest() { Type = type, Key = key, ActorId = actorId });
         }
 
         public static async ETTask Lock(this LocationProxyComponent self, int type, long key, ActorId actorId, int time = 60000)
         {
             Log.Info($"location proxy lock {key}, {actorId} {self.Fiber().TimeInfo.ServerNow()}");
-            await self.Root().GetComponent<ActorInnerComponent>().Call(GetLocationSceneId(key),
+            await self.Root().GetComponent<ActorSenderComponent>().Call(GetLocationSceneId(key),
                 new ObjectLockRequest() { Type = type, Key = key, ActorId = actorId, Time = time });
         }
 
         public static async ETTask UnLock(this LocationProxyComponent self, int type, long key, ActorId oldActorId, ActorId newActorId)
         {
             Log.Info($"location proxy unlock {key}, {newActorId} {self.Fiber().TimeInfo.ServerNow()}");
-            await self.Root().GetComponent<ActorInnerComponent>().Call(GetLocationSceneId(key),
+            await self.Root().GetComponent<ActorSenderComponent>().Call(GetLocationSceneId(key),
                 new ObjectUnLockRequest() { Type = type, Key = key, OldActorId = oldActorId, NewActorId = newActorId });
         }
 
         public static async ETTask Remove(this LocationProxyComponent self, int type, long key)
         {
             Log.Info($"location proxy add {key}, {self.Fiber().TimeInfo.ServerNow()}");
-            await self.Root().GetComponent<ActorInnerComponent>().Call(GetLocationSceneId(key),
+            await self.Root().GetComponent<ActorSenderComponent>().Call(GetLocationSceneId(key),
                 new ObjectRemoveRequest() { Type = type, Key = key });
         }
 
@@ -46,7 +46,7 @@ namespace ET.Server
 
             // location server配置到共享区,一个大战区可以配置N多个location server,这里暂时为1
             ObjectGetResponse response =
-                    (ObjectGetResponse) await self.Root().GetComponent<ActorInnerComponent>().Call(GetLocationSceneId(key),
+                    (ObjectGetResponse) await self.Root().GetComponent<ActorSenderComponent>().Call(GetLocationSceneId(key),
                         new ObjectGetRequest() { Type = type, Key = key });
             return response.ActorId;
         }

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Module/Message/A2NetInner_RequestHandler.cs

@@ -7,7 +7,7 @@ namespace ET.Server
     {
         protected override async ETTask Run(Scene root, A2NetInner_Request request, A2NetInner_Response response)
         {
-            response.MessageObject = await root.GetComponent<ActorOuterComponent>().Call(request.ActorId, request.MessageObject);
+            response.MessageObject = await root.GetComponent<ActorOuterComponent>().Call(request.ActorId, request.MessageObject, request.NeedException);
         }
     }
 }

+ 16 - 20
Unity/Assets/Scripts/Hotfix/Server/Module/Message/ActorOuterComponentSystem.cs

@@ -2,14 +2,15 @@
 
 namespace ET.Server
 {
-    public static class ActorOuterComponentSystem
+    [FriendOf(typeof(ActorOuterComponent))]
+    public static partial class ActorOuterComponentSystem
     {
         [EntitySystem]
         private static void Awake(this ActorOuterComponent self)
         {
             self.NetInnerComponent = self.Root().GetComponent<NetInnerComponent>();
         }
-        
+
         public static void HandleIActorResponse(this ActorOuterComponent self, IActorResponse response)
         {
             ActorMessageSender actorMessageSender;
@@ -19,10 +20,10 @@ namespace ET.Server
             }
 
             self.requestCallback.Remove(response.RpcId);
-            
+
             Run(actorMessageSender, response);
         }
-        
+
         private static void Run(ActorMessageSender self, IActorResponse response)
         {
             if (response.Error == ErrorCore.ERR_ActorTimeout)
@@ -39,11 +40,6 @@ namespace ET.Server
 
             self.Tcs.SetResult(response);
         }
-        
-        public static void Reply(this ActorOuterComponent self, Address fromAddress, IActorResponse message)
-        {
-            self.SendInner(new ActorId(fromAddress, 0), message as MessageObject);
-        }
 
         public static void Send(this ActorOuterComponent self, ActorId actorId, IActorMessage message)
         {
@@ -63,9 +59,9 @@ namespace ET.Server
             {
                 throw new Exception($"actor is the same process: {fiber.Process} {actorId.Process}");
             }
-            
+
             StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.NetInners[actorId.Process];
-            Session session = self.NetInnerComponent.GetComponent<NetInnerComponent>().Get(startSceneConfig.Process);
+            Session session = self.NetInnerComponent.Get(startSceneConfig.Id);
             actorId.Process = fiber.Process;
             session.Send(actorId, message);
         }
@@ -81,16 +77,16 @@ namespace ET.Server
             {
                 throw new Exception($"actor id is 0: {iActorRequest}");
             }
-
-            int rpcId = self.GetRpcId();
+            Fiber fiber = self.Fiber();
             
+            int rpcId = self.GetRpcId();
+
             var tcs = ETTask<IActorResponse>.Create(true);
 
-            Fiber fiber = self.Fiber();
             self.requestCallback.Add(self.RpcId, new ActorMessageSender(actorId, iActorRequest, tcs, needException));
-            
+
             self.SendInner(actorId, iActorRequest as MessageObject);
-            
+
             async ETTask Timeout()
             {
                 await fiber.TimerComponent.WaitAsync(ActorOuterComponent.TIMEOUT_TIME);
@@ -102,13 +98,13 @@ namespace ET.Server
                 self.requestCallback.Remove(rpcId);
                 action.Tcs.SetException(new Exception($"actor sender timeout: {iActorRequest}"));
             }
-            
+
             Timeout().Coroutine();
-            
+
             long beginTime = fiber.TimeInfo.ServerFrameTime();
 
             IActorResponse response = await tcs;
-            
+
             long endTime = fiber.TimeInfo.ServerFrameTime();
 
             long costTime = endTime - beginTime;
@@ -116,7 +112,7 @@ namespace ET.Server
             {
                 Log.Warning($"actor rpc time > 200: {costTime} {iActorRequest}");
             }
-            
+
             return response;
         }
     }

+ 81 - 0
Unity/Assets/Scripts/Hotfix/Server/Module/Message/ActorSenderComponentSystem.cs

@@ -0,0 +1,81 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace ET
+{
+    [FriendOf(typeof(ActorSenderComponent))]
+    public static partial class ActorSenderComponentSystem
+    {
+        public static void Send(this ActorSenderComponent self, ActorId actorId, IActorMessage message)
+        {
+            Fiber fiber = self.Fiber();
+            // 如果发向同一个进程,则扔到消息队列中
+            if (actorId.Process == fiber.Process)
+            {
+                ActorMessageQueue.Instance.Send(fiber.Address, actorId, (MessageObject)message);
+                return;
+            }
+            
+            // 发给NetInner纤程
+            A2NetInner_Message a2NetInnerMessage = A2NetInner_Message.Create();
+            a2NetInnerMessage.FromAddress = fiber.Address;
+            a2NetInnerMessage.ActorId = actorId;
+            a2NetInnerMessage.MessageObject = message;
+
+            StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.NetInners[fiber.Process];
+            ActorMessageQueue.Instance.Send(startSceneConfig.ActorId, a2NetInnerMessage);
+        }
+
+        public static int GetRpcId(this ActorSenderComponent self)
+        {
+            return ++self.RpcId;
+        }
+
+        public static async ETTask<IActorResponse> Call(
+                this ActorSenderComponent self,
+                ActorId actorId,
+                IActorRequest request,
+                bool needException = true
+        )
+        {
+            request.RpcId = self.GetRpcId();
+            
+            if (actorId == default)
+            {
+                throw new Exception($"actor id is 0: {request}");
+            }
+
+            return await self.Call(actorId, request.RpcId, request, needException);
+        }
+        
+        public static async ETTask<IActorResponse> Call(
+                this ActorSenderComponent self,
+                ActorId actorId,
+                int rpcId,
+                IActorRequest iActorRequest,
+                bool needException = true
+        )
+        {
+            if (actorId == default)
+            {
+                throw new Exception($"actor id is 0: {iActorRequest}");
+            }
+            Fiber fiber = self.Fiber();
+            if (fiber.Process == actorId.Process)
+            {
+                return await fiber.Root.GetComponent<ActorInnerComponent>().Call(actorId, rpcId, iActorRequest, needException);
+            }
+            
+            // 发给NetInner纤程
+            A2NetInner_Request a2NetInner_Request = A2NetInner_Request.Create();
+            a2NetInner_Request.ActorId = actorId;
+            a2NetInner_Request.MessageObject = iActorRequest;
+
+            StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.NetInners[fiber.Process];
+            A2NetInner_Response response = await fiber.Root.GetComponent<ActorSenderComponent>().Call(
+                startSceneConfig.ActorId, a2NetInner_Request, needException: a2NetInner_Request.NeedException) as A2NetInner_Response;
+            return response.MessageObject;
+        }
+    }
+}

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Module/Message/ServerSenderComponentSystem.cs.meta → Unity/Assets/Scripts/Hotfix/Server/Module/Message/ActorSenderComponentSystem.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: b5758614a7d40cf42a6b3b91b791bbb3
+guid: 1dbffb76761f34144a9e283ec16a499a
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 18 - 5
Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetInnerComponentOnReadEvent.cs

@@ -6,15 +6,28 @@
         protected override async ETTask Run(Scene root, NetInnerComponentOnRead args)
         {
             ActorId actorId = args.ActorId;
+            int fromProcess = actorId.Process;
+            actorId.Process = root.Fiber.Process;
             object message = args.Message;
 
-            if (message is IActorResponse iActorResponse)
+            switch (message)
             {
-                root.GetComponent<ActorOuterComponent>().HandleIActorResponse(iActorResponse);
-                return;
+                case IActorResponse iActorResponse:
+                    root.GetComponent<ActorOuterComponent>().HandleIActorResponse(iActorResponse);
+                    return;
+                case IActorRequest iActorRequest:
+                {
+                    IActorResponse response = await root.GetComponent<ActorInnerComponent>().Call(actorId, iActorRequest);
+                    actorId.Process = fromProcess;
+                    root.GetComponent<ActorOuterComponent>().Send(actorId, response);
+                    break;
+                }
+                default:
+                {
+                    ActorMessageQueue.Instance.Send(actorId, (MessageObject)message);
+                    break;
+                }
             }
-            
-            ActorMessageQueue.Instance.Send(actorId, (MessageObject)message);
 
             await ETTask.CompletedTask;
         }

+ 0 - 48
Unity/Assets/Scripts/Hotfix/Server/Module/Message/ServerSenderComponentSystem.cs

@@ -1,48 +0,0 @@
-using System;
-
-namespace ET.Server
-{
-
-    public static class ServerSenderComponentSystem
-    {
-        public static void Send(this ServerSenderComponent self, ActorId actorId, IActorMessage message)
-        {
-            Fiber fiber = self.Fiber();
-            if (actorId.Process == fiber.Process)
-            {
-                self.ActorInnerComponent.Send(actorId, message);
-                return;
-            }
-
-            // 发给NetInner纤程
-            A2NetInner_Message a2NetInnerMessage = A2NetInner_Message.Create();
-            a2NetInnerMessage.FromAddress = fiber.Address;
-            a2NetInnerMessage.ActorId = actorId;
-            a2NetInnerMessage.MessageObject = message;
-
-            StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.NetInners[fiber.Process];
-            self.ActorInnerComponent.Send(startSceneConfig.ActorId, a2NetInnerMessage);
-        }
-
-
-        public static async ETTask<IActorResponse> Call(this ServerSenderComponent self, ActorId actorId, IActorRequest request, bool needException = true)
-        {
-            Fiber fiber = self.Fiber();
-            if (actorId.Process == fiber.Process)
-            {
-                return await self.ActorInnerComponent.Call(actorId, request, needException);
-            }
-
-            // 发给NetInner纤程
-            A2NetInner_Request a2NetInner_Request = A2NetInner_Request.Create();
-            a2NetInner_Request.ActorId = actorId;
-            a2NetInner_Request.MessageObject = request;
-            a2NetInner_Request.FromAddress = fiber.Address;
-
-            StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.NetInners[fiber.Process];
-            A2NetInner_Response response = await self.ActorInnerComponent.Call(startSceneConfig.ActorId, a2NetInner_Request, needException: needException) as A2NetInner_Response;
-            return response.MessageObject;
-        }
-    }
-}
-

+ 1 - 0
Unity/Assets/Scripts/Hotfix/Server/Module/NetInner/FiberInit_NetInner.cs

@@ -14,6 +14,7 @@ namespace ET.Server
             root.AddComponent<NetInnerComponent, IPEndPoint>(startSceneConfig.InnerIPPort);
             root.AddComponent<ActorOuterComponent>();
             root.AddComponent<ActorInnerComponent>();
+            //root.AddComponent<ActorSenderComponent>();
             root.AddComponent<ActorRecverComponent>();
 
             await ETTask.CompletedTask;

+ 14 - 15
Unity/Assets/Scripts/Hotfix/Share/Module/Actor/ActorInnerComponentSystem.cs

@@ -39,28 +39,23 @@ namespace ET
         
         public static void Reply(this ActorInnerComponent self, Address fromAddress, IActorResponse message)
         {
-            self.SendInner(new ActorId(fromAddress, 0), message as MessageObject);
+            self.Send(new ActorId(fromAddress, 0), message);
         }
 
         public static void Send(this ActorInnerComponent self, ActorId actorId, IActorMessage message)
         {
-            self.SendInner(actorId, message as MessageObject);
-        }
-
-        private static void SendInner(this ActorInnerComponent self, ActorId actorId, MessageObject message)
-        {
-            if (actorId == default)
-            {
-                throw new Exception($"actor id is 0: {message}");
-            }
-
             Fiber fiber = self.Fiber();
             // 如果发向同一个进程,则扔到消息队列中
             if (actorId.Process != fiber.Process)
             {
-                throw new Exception($"actor is not the same process: {fiber.Process} {actorId.Process}");
+                throw new Exception($"actor inner process diff: {actorId.Process} {fiber.Process}");
             }
-            
+            ActorMessageQueue.Instance.Send(fiber.Address, actorId, (MessageObject)message);
+        }
+
+        private static void SendInner(this ActorInnerComponent self, ActorId actorId, MessageObject message)
+        {
+            Fiber fiber = self.Fiber();
             ActorMessageQueue.Instance.Send(fiber.Address, actorId, message);
         }
 
@@ -98,10 +93,14 @@ namespace ET
             {
                 throw new Exception($"actor id is 0: {iActorRequest}");
             }
-
+            Fiber fiber = self.Fiber();
+            if (fiber.Process != actorId.Process)
+            {
+                throw new Exception($"actor inner process diff: {actorId.Process} {fiber.Process}");
+            }
+            
             var tcs = ETTask<IActorResponse>.Create(true);
 
-            Fiber fiber = self.Fiber();
             self.requestCallback.Add(rpcId, new ActorMessageSender(actorId, iActorRequest, tcs, needException));
             
             self.SendInner(actorId, iActorRequest as MessageObject);

+ 14 - 0
Unity/Assets/Scripts/Model/Server/Module/Message/ActorSenderComponent.cs

@@ -0,0 +1,14 @@
+using System.Collections.Generic;
+
+namespace ET
+{
+    [ComponentOf(typeof(Scene))]
+    public class ActorSenderComponent: Entity, IAwake, IDestroy
+    {
+        public const long TIMEOUT_TIME = 40 * 1000;
+
+        public int RpcId;
+
+        public readonly Dictionary<int, ActorMessageSender> requestCallback = new();
+    }
+}

+ 1 - 1
Unity/Assets/Scripts/Model/Server/Module/Message/ServerSenderComponent.cs.meta → Unity/Assets/Scripts/Model/Server/Module/Message/ActorSenderComponent.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: b6425cccf0e3f6f4ebafdeb632948d50
+guid: ecc41a2013820624bbe9d11dc8940dc8
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 0 - 20
Unity/Assets/Scripts/Model/Server/Module/Message/ServerSenderComponent.cs

@@ -1,20 +0,0 @@
-namespace ET.Server
-{
-    [ComponentOf(typeof(Scene))]
-    public class ServerSenderComponent: Entity, IAwake
-    {
-        private EntityRef<ActorInnerComponent> actorInnerComponent;
-
-        public ActorInnerComponent ActorInnerComponent
-        {
-            get
-            {
-                return this.actorInnerComponent;
-            }
-            set
-            {
-                this.actorInnerComponent = value;
-            }
-        }
-    }
-}

+ 4 - 3
Unity/Assets/Scripts/Model/Server/Module/NetInner/A2NetInner_Message.cs

@@ -24,6 +24,7 @@ namespace ET
     }
     
     [Message(2)]
+    [ResponseType(nameof(A2NetInner_Response))]
     public class A2NetInner_Request: MessageObject, IActorRequest
     {
         public static A2NetInner_Request Create()
@@ -34,20 +35,20 @@ namespace ET
         public override void Dispose()
         {
             this.RpcId = default;
-            this.FromAddress = default;
             this.ActorId = default;
             this.MessageObject = default;
+            this.NeedException = default;
             
             ObjectPool.Instance.Recycle(this);
         }
         
         public int RpcId { get; set; }
-        public Address FromAddress;
         public ActorId ActorId;
+        public bool NeedException;
         public IActorRequest MessageObject;
     }
     
-    [Message(1)]
+    [Message(3)]
     public class A2NetInner_Response: MessageObject, IActorResponse
     {
         public static A2NetInner_Response Create()

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Module/Actor/ActorHelper.cs

@@ -7,7 +7,7 @@ namespace ET
         public static IActorResponse CreateResponse(IActorRequest iActorRequest, int error)
         {
             Type responseType = OpcodeType.Instance.GetResponseType(iActorRequest.GetType());
-            IActorResponse response = (IActorResponse)Activator.CreateInstance(responseType);
+            IActorResponse response = (IActorResponse)ObjectPool.Instance.Fetch(responseType);
             response.Error = error;
             response.RpcId = iActorRequest.RpcId;
             return response;

+ 2 - 2
Unity/Assets/Scripts/Model/Share/Module/Actor/ActorInnerComponent.cs

@@ -3,10 +3,10 @@
 namespace ET
 {
     [ComponentOf(typeof(Scene))]
-    public class ActorInnerComponent: Entity, IAwake, IDestroy
+    public class ActorInnerComponent: Entity, IAwake
     {
         public const long TIMEOUT_TIME = 40 * 1000;
-
+        
         public int RpcId;
 
         public readonly Dictionary<int, ActorMessageSender> requestCallback = new();