Skip to content

Commit

Permalink
1.MessageOuterSender在OnRead的时候加了一层分发
Browse files Browse the repository at this point in the history
2.默认时Mailbox类型的分发,这种分发就跟MessageInnerSender是一样的效果,直接把消息加到Mailbox中去
3.NetInner Scene会使用NetInner分发,这种分发就是原来的NetInner实现
4.这样设计的原因是,每个纤程都可以挂上MessageOuterSender 使用Mailbox类型的分发来收发网络消息,这样就不需要通过NetInner中转
大家按需选择
另外
MessageInnerSender改为ProcessInnerSender,MessageOuterSender改为ProcessOuterSender
因为Inner跟Outer是进程的内外,这样命名更清晰
  • Loading branch information
egametang committed Aug 13, 2023
1 parent 97f1781 commit 0f0196c
Show file tree
Hide file tree
Showing 54 changed files with 322 additions and 197 deletions.
8 changes: 4 additions & 4 deletions Unity/Assets/Scripts/Core/Fiber/Fiber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ public CoroutineLockComponent CoroutineLockComponent
}
}

private EntityRef<MessageInnerSender> messageInnerSender;
public MessageInnerSender MessageInnerSender
private EntityRef<ProcessInnerSender> processInnerSender;
public ProcessInnerSender ProcessInnerSender
{
get
{
return this.messageInnerSender;
return this.processInnerSender;
}
set
{
this.messageInnerSender = value;
this.processInnerSender = value;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace ET
{
[ComponentOf(typeof(Scene))]
public class MessageInnerSender: Entity, IAwake, IDestroy, IUpdate
public class ProcessInnerSender: Entity, IAwake, IDestroy, IUpdate
{
public const long TIMEOUT_TIME = 40 * 1000;

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@

namespace ET
{
[EntitySystemOf(typeof(MessageInnerSender))]
[FriendOf(typeof(MessageInnerSender))]
public static partial class MessageInnerSenderSystem
[EntitySystemOf(typeof(ProcessInnerSender))]
[FriendOf(typeof(ProcessInnerSender))]
public static partial class ProcessInnerSenderSystem
{
[EntitySystem]
private static void Destroy(this MessageInnerSender self)
private static void Destroy(this ProcessInnerSender self)
{
Fiber fiber = self.Fiber();
MessageQueue.Instance.RemoveQueue(fiber.Id);
}

[EntitySystem]
private static void Awake(this MessageInnerSender self)
private static void Awake(this ProcessInnerSender self)
{
Fiber fiber = self.Fiber();
MessageQueue.Instance.AddQueue(fiber.Id);
fiber.MessageInnerSender = self;
fiber.ProcessInnerSender = self;
}

[EntitySystem]
private static void Update(this MessageInnerSender self)
private static void Update(this ProcessInnerSender self)
{
self.list.Clear();
Fiber fiber = self.Fiber();
Expand All @@ -36,7 +36,7 @@ private static void Update(this MessageInnerSender self)
}
}

private static void HandleMessage(this MessageInnerSender self, Fiber fiber, in MessageInfo messageInfo)
private static void HandleMessage(this ProcessInnerSender self, Fiber fiber, in MessageInfo messageInfo)
{
if (messageInfo.MessageObject is IResponse response)
{
Expand All @@ -62,7 +62,7 @@ private static void HandleMessage(this MessageInnerSender self, Fiber fiber, in
mailBoxComponent.Add(actorId.Address, message);
}

private static void HandleIActorResponse(this MessageInnerSender self, IResponse response)
private static void HandleIActorResponse(this ProcessInnerSender self, IResponse response)
{
if (!self.requestCallback.Remove(response.RpcId, out MessageSenderStruct actorMessageSender))
{
Expand All @@ -89,17 +89,17 @@ private static void Run(MessageSenderStruct self, IResponse response)
((MessageObject)response).Dispose();
}

public static void Reply(this MessageInnerSender self, Address fromAddress, IResponse message)
public static void Reply(this ProcessInnerSender self, Address fromAddress, IResponse message)
{
self.SendInner(new ActorId(fromAddress, 0), (MessageObject)message);
}

public static void Send(this MessageInnerSender self, ActorId actorId, IMessage message)
public static void Send(this ProcessInnerSender self, ActorId actorId, IMessage message)
{
self.SendInner(actorId, (MessageObject)message);
}

private static void SendInner(this MessageInnerSender self, ActorId actorId, MessageObject message)
private static void SendInner(this ProcessInnerSender self, ActorId actorId, MessageObject message)
{
Fiber fiber = self.Fiber();

Expand All @@ -118,13 +118,13 @@ private static void SendInner(this MessageInnerSender self, ActorId actorId, Mes
MessageQueue.Instance.Send(fiber.Address, actorId, message);
}

public static int GetRpcId(this MessageInnerSender self)
public static int GetRpcId(this ProcessInnerSender self)
{
return ++self.RpcId;
}

public static async ETTask<IResponse> Call(
this MessageInnerSender self,
this ProcessInnerSender self,
ActorId actorId,
IRequest request,
bool needException = true
Expand All @@ -141,7 +141,7 @@ public static async ETTask<IResponse> Call(
}

public static async ETTask<IResponse> Call(
this MessageInnerSender self,
this ProcessInnerSender self,
ActorId actorId,
int rpcId,
IRequest iRequest,
Expand All @@ -167,7 +167,7 @@ public static async ETTask<IResponse> Call(

async ETTask Timeout()
{
await fiber.TimerComponent.WaitAsync(MessageInnerSender.TIMEOUT_TIME);
await fiber.TimerComponent.WaitAsync(ProcessInnerSender.TIMEOUT_TIME);

if (!self.requestCallback.Remove(rpcId, out MessageSenderStruct action))
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static async ETTask<long> LoginAsync(this ClientSenderCompnent self, stri
self.fiberId = await FiberManager.Instance.Create(SchedulerType.ThreadPool, 0, SceneType.NetClient, "");
self.netClientActorId = new ActorId(self.Fiber().Process, self.fiberId);

NetClient2Main_Login response = await self.Fiber().MessageInnerSender.Call(self.netClientActorId, new Main2NetClient_Login()
NetClient2Main_Login response = await self.Fiber().ProcessInnerSender.Call(self.netClientActorId, new Main2NetClient_Login()
{
OwnerFiberId = self.Fiber().Id, Account = account, Password = password
}) as NetClient2Main_Login;
Expand All @@ -46,14 +46,14 @@ public static void Send(this ClientSenderCompnent self, IMessage message)
{
A2NetClient_Message a2NetClientMessage = A2NetClient_Message.Create();
a2NetClientMessage.MessageObject = message;
self.Fiber().MessageInnerSender.Send(self.netClientActorId, a2NetClientMessage);
self.Fiber().ProcessInnerSender.Send(self.netClientActorId, a2NetClientMessage);
}

public static async ETTask<IResponse> Call(this ClientSenderCompnent self, IRequest request, bool needException = true)
{
A2NetClient_Request a2NetClientRequest = A2NetClient_Request.Create();
a2NetClientRequest.MessageObject = request;
A2NetClient_Response a2NetClientResponse = await self.Fiber().MessageInnerSender.Call(self.netClientActorId, a2NetClientRequest) as A2NetClient_Response;
A2NetClient_Response a2NetClientResponse = await self.Fiber().ProcessInnerSender.Call(self.netClientActorId, a2NetClientRequest) as A2NetClient_Response;
IResponse response = a2NetClientResponse.MessageObject;

if (response.Error == ErrorCore.ERR_MessageTimeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public override async ETTask Handle(FiberInit fiberInit)
root.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.UnOrderedMessage);
root.AddComponent<TimerComponent>();
root.AddComponent<CoroutineLockComponent>();
root.AddComponent<MessageInnerSender>();
root.AddComponent<ProcessInnerSender>();
root.AddComponent<FiberParentComponent>();
await ETTask.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected override async ETTask Run(Scene root, Main2NetClient_Login request, Ne
routerAddressComponent =
root.AddComponent<RouterAddressComponent, string, int>(ConstValue.RouterHttpHost, ConstValue.RouterHttpPort);
await routerAddressComponent.Init();
root.AddComponent<NetOuterComponent, AddressFamily>(routerAddressComponent.RouterManagerIPAddress.AddressFamily);
root.AddComponent<NetComponent, AddressFamily>(routerAddressComponent.RouterManagerIPAddress.AddressFamily);
root.GetComponent<FiberParentComponent>().ParentFiberId = request.OwnerFiberId;
}
IPEndPoint realmAddress = routerAddressComponent.GetRealmAddress(account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static async ETTask<Session> CreateRouterSession(Scene root, IPEndPoint a

root.Fiber().Info($"get router: {recvLocalConn} {routerAddress}");

Session routerSession = root.GetComponent<NetOuterComponent>().Create(routerAddress, address, recvLocalConn);
Session routerSession = root.GetComponent<NetComponent>().Create(routerAddress, address, recvLocalConn);
routerSession.AddComponent<PingComponent>();
routerSession.AddComponent<RouterCheckComponent>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private static void Destroy(this ClientSessionErrorComponent self)
}
NetClient2Main_SessionDispose message = NetClient2Main_SessionDispose.Create();
message.Error = self.GetParent<Session>().Error;
fiber.MessageInnerSender.Send(new ActorId(fiber.Process, ConstFiberId.Main), message);
fiber.ProcessInnerSender.Send(new ActorId(fiber.Process, ConstFiberId.Main), message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace ET.Client
{
[Invoke((long)SceneType.NetClient)]
public class NetOuterComponentOnReadInvoker_NetClient: AInvokeHandler<NetOuterComponentOnRead>
public class NetComponentOnReadInvoker_NetClient: AInvokeHandler<NetOuterComponentOnRead>
{
public override void Handle(NetOuterComponentOnRead args)
{
Expand All @@ -27,7 +27,7 @@ public override void Handle(NetOuterComponentOnRead args)
{
// 扔到Main纤程队列中
int parentFiberId = fiber.Root.GetComponent<FiberParentComponent>().ParentFiberId;
fiber.MessageInnerSender.Send(new ActorId(fiber.Process, parentFiberId), iActorMessage);
fiber.ProcessInnerSender.Send(new ActorId(fiber.Process, parentFiberId), iActorMessage);
break;
}
default:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ private static void Awake(this BenchmarkClientComponent self)

private static async ETTask Start(this BenchmarkClientComponent self)
{
NetOuterComponent netOuterClientComponent = self.Root().GetComponent<NetOuterComponent>();
using Session session = netOuterClientComponent.Create(StartSceneConfigCategory.Instance.Benchmark.OuterIPPort);
NetComponent netClientComponent = self.Root().GetComponent<NetComponent>();
using Session session = netClientComponent.Create(StartSceneConfigCategory.Instance.Benchmark.OuterIPPort);
List<ETTask> list = new List<ETTask>(100000);

async ETTask Call(Session s)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override async ETTask Handle(FiberInit fiberInit)
//root.AddComponent<GateSessionKeyComponent>();
//root.AddComponent<LocationProxyComponent>();
//root.AddComponent<ActorLocationSenderComponent>();
root.AddComponent<NetOuterComponent, AddressFamily>(AddressFamily.InterNetwork);
root.AddComponent<NetComponent, AddressFamily>(AddressFamily.InterNetwork);
root.AddComponent<BenchmarkClientComponent>();
await ETTask.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override async ETTask Handle(FiberInit fiberInit)
//root.AddComponent<GateSessionKeyComponent>();
//root.AddComponent<LocationProxyComponent>();
//root.AddComponent<ActorLocationSenderComponent>();
root.AddComponent<NetOuterComponent, IPEndPoint>(StartSceneConfigCategory.Instance.Benchmark.OuterIPPort);
root.AddComponent<NetComponent, IPEndPoint>(StartSceneConfigCategory.Instance.Benchmark.OuterIPPort);
root.AddComponent<BenchmarkServerComponent>();
await ETTask.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace ET.Server
{
[Invoke((long)SceneType.BenchmarkServer)]
public class NetOuterComponentOnReadInvoker_BenchmarkServer: AInvokeHandler<NetOuterComponentOnRead>
public class NetComponentOnReadInvoker_BenchmarkServer: AInvokeHandler<NetOuterComponentOnRead>
{
public override void Handle(NetOuterComponentOnRead args)
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public override async ETTask Handle(FiberInit fiberInit)
root.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.UnOrderedMessage);
root.AddComponent<TimerComponent>();
root.AddComponent<CoroutineLockComponent>();
root.AddComponent<MessageInnerSender>();
root.AddComponent<ProcessInnerSender>();
root.AddComponent<MessageSender>();
root.AddComponent<PlayerComponent>();
root.AddComponent<GateSessionKeyComponent>();
root.AddComponent<LocationProxyComponent>();
root.AddComponent<MessageLocationSenderComponent>();

StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.Get((int)root.Id);
root.AddComponent<NetOuterComponent, IPEndPoint>(startSceneConfig.InnerIPPort);
root.AddComponent<NetComponent, IPEndPoint>(startSceneConfig.InnerIPPort);
await ETTask.CompletedTask;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace ET.Server
{
[Invoke((long)SceneType.Gate)]
//[Invoke((long)SceneType.Realm)]
public class NetOuterComponentOnReadInvoker_Gate: AInvokeHandler<NetOuterComponentOnRead>
public class NetComponentOnReadInvoker_Gate: AInvokeHandler<NetOuterComponentOnRead>
{
public override void Handle(NetOuterComponentOnRead args)
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public override async ETTask Handle(FiberInit fiberInit)
root.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.UnOrderedMessage);
root.AddComponent<TimerComponent>();
root.AddComponent<CoroutineLockComponent>();
root.AddComponent<MessageInnerSender>();
root.AddComponent<ProcessInnerSender>();
root.AddComponent<MessageSender>();
StartSceneConfig startSceneConfig = StartSceneConfigCategory.Instance.Get(root.Fiber.Id);
root.AddComponent<NetOuterComponent, IPEndPoint>(startSceneConfig.InnerIPPort);
root.AddComponent<NetComponent, IPEndPoint>(startSceneConfig.InnerIPPort);

await ETTask.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace ET.Server
{
[Invoke((long)SceneType.Realm)]
public class NetOuterComponentOnReadInvoker_Realm: AInvokeHandler<NetOuterComponentOnRead>
public class NetComponentOnReadInvoker_Realm: AInvokeHandler<NetOuterComponentOnRead>
{
public override void Handle(NetOuterComponentOnRead args)
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public override async ETTask Handle(FiberInit fiberInit)
root.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.UnOrderedMessage);
root.AddComponent<TimerComponent>();
root.AddComponent<CoroutineLockComponent>();
root.AddComponent<MessageInnerSender>();
root.AddComponent<ProcessInnerSender>();
root.AddComponent<PlayerComponent>();
root.AddComponent<CurrentScenesComponent>();
root.AddComponent<ObjectWait>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public override async ETTask Handle(FiberInit fiberInit)
root.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.UnOrderedMessage);
root.AddComponent<TimerComponent>();
root.AddComponent<CoroutineLockComponent>();
root.AddComponent<MessageInnerSender>();
root.AddComponent<ProcessInnerSender>();
root.AddComponent<MessageSender>();
root.AddComponent<UnitComponent>();
root.AddComponent<AOIManagerComponent>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public override async ETTask Handle(FiberInit fiberInit)
root.AddComponent<MailBoxComponent, MailBoxType>(MailBoxType.UnOrderedMessage);
root.AddComponent<TimerComponent>();
root.AddComponent<CoroutineLockComponent>();
root.AddComponent<MessageInnerSender>();
root.AddComponent<ProcessInnerSender>();
root.AddComponent<MessageSender>();
root.AddComponent<MatchComponent>();
root.AddComponent<LocationProxyComponent>();
Expand Down
Loading

0 comments on commit 0f0196c

Please sign in to comment.