コード例 #1
0
        public static async void HandleAsync(this ActorComponent self)
        {
            ActorMessageDispatherComponent actorMessageDispatherComponent = Game.Scene.GetComponent <ActorMessageDispatherComponent>();

            while (true)
            {
                if (self.IsDisposed)
                {
                    return;
                }
                try
                {
                    ActorMessageInfo info = await self.GetAsync();

                    // 返回null表示actor已经删除,协程要终止
                    if (info.Message == null)
                    {
                        return;
                    }

                    // 根据这个actor的类型分发给相应的ActorHandler处理
                    await actorMessageDispatherComponent.ActorTypeHandle(self.ActorType, (Entity)self.Parent, info);
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
            }
        }
コード例 #2
0
        private static async void HandleAsync(this ActorComponent self)
        {
            while (true)
            {
                if (self.IsDisposed)
                {
                    return;
                }
                try
                {
                    ActorMessageInfo info = await self.GetAsync();

                    // 返回null表示actor已经删除,协程要终止
                    if (info == null)
                    {
                        return;
                    }
                    await self.entityActorHandler.Handle(info.Session, (Entity)self.Parent, info.RpcId, info.Message);
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// 在初始化后会 Start里面会自动调用
        /// </summary>
        /// <param name="self"></param>
        public static async void HandleAsync(this MailBoxComponent self)
        {
            ActorMessageDispatherComponent actorMessageDispatherComponent = Game.Scene.GetComponent <ActorMessageDispatherComponent>();

            long instanceId = self.InstanceId;

            while (true)
            {
                if (self.InstanceId != instanceId)
                {
                    return;
                }
                try
                {
                    ActorMessageInfo info = await self.GetAsync();

                    // 返回null表示actor已经删除,协程要终止
                    if (info.Message == null)
                    {
                        return;
                    }

                    // 根据这个actor的类型分发给相应的ActorHandler处理
                    await actorMessageDispatherComponent.Handle(self, info);
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
            }
        }
        /// <summary>
        /// 分发actor消息
        /// </summary>
        public static async ETTask Handle(
            this ActorMessageDispatcherComponent self, Entity entity, ActorMessageInfo actorMessageInfo)
        {
            if (!self.ActorMessageHandlers.TryGetValue(actorMessageInfo.Message.GetType(), out IMActorHandler handler))
            {
                throw new Exception($"not found message handler: {MongoHelper.ToJson(actorMessageInfo.Message)}");
            }

            await handler.Handle(actorMessageInfo.Session, entity, actorMessageInfo.Message);
        }
コード例 #5
0
        /// <summary>
        /// 根据mailbox类型做不同的处理
        /// </summary>
        public static async ETTask Handle(
            this MailboxDispatcherComponent self, MailBoxComponent mailBoxComponent, ActorMessageInfo actorMessageInfo)
        {
            IMailboxHandler iMailboxHandler;

            if (self.MailboxHandlers.TryGetValue(mailBoxComponent.MailboxType, out iMailboxHandler))
            {
                await iMailboxHandler.Handle(actorMessageInfo.Session, mailBoxComponent.Entity, actorMessageInfo.Message);
            }
        }
コード例 #6
0
ファイル: ActorSystem.cs プロジェクト: wang10998588/Egametang
		public static void Add(this ActorComponent self, ActorMessageInfo info)
		{
			self.queue.Enqueue(info);

			if (self.tcs == null)
			{
				return;
			}

			var t = self.tcs;
			self.tcs = null;
			t.SetResult(self.queue.Dequeue());
		}
コード例 #7
0
ファイル: ActorSystem.cs プロジェクト: wang10998588/Egametang
		private static async void HandleAsync(this ActorComponent self)
		{
			while (true)
			{
				try
				{
					ActorMessageInfo info = await self.GetAsync();
					await self.entityActorHandler.Handle(info.Session, self.Entity, info.Message);
				}
				catch (Exception e)
				{
					Log.Error(e.ToString());
				}
			}
		}
コード例 #8
0
        public static async Task Handle(
            this ActorMessageDispatherComponent self, MailBoxComponent mailBoxComponent, ActorMessageInfo actorMessageInfo)
        {
            // 有拦截器使用拦截器处理
            IActorInterceptTypeHandler iActorInterceptTypeHandler;

            if (self.ActorTypeHandlers.TryGetValue(mailBoxComponent.ActorInterceptType, out iActorInterceptTypeHandler))
            {
                await iActorInterceptTypeHandler.Handle(actorMessageInfo.Session, mailBoxComponent.Entity, actorMessageInfo.Message);

                return;
            }

            // 没有拦截器就用IMActorHandler处理
            if (!self.ActorMessageHandlers.TryGetValue(actorMessageInfo.Message.GetType(), out IMActorHandler handler))
            {
                throw new Exception($"not found message handler: {MongoHelper.ToJson(actorMessageInfo.Message)}");
            }

            await handler.Handle(actorMessageInfo.Session, mailBoxComponent.Entity, actorMessageInfo.Message);
        }
コード例 #9
0
        /// <summary>
        /// 一个actor收到的所有消息先由其指定的ActorTypeHandle处理
        /// </summary>
        public static async Task ActorTypeHandle(
            this ActorMessageDispatherComponent self, string actorType, Entity entity, ActorMessageInfo actorMessageInfo)
        {
            IActorTypeHandler iActorTypeHandler;

            if (!self.ActorTypeHandlers.TryGetValue(actorType, out iActorTypeHandler))
            {
                throw new Exception($"not found actortype handler: {actorType}");
            }

            await iActorTypeHandler.Handle(actorMessageInfo.Session, entity, actorMessageInfo.Message);
        }
 /// <summary>
 /// 分发actor消息
 /// </summary>
 public static async ETTask Handle(this ActorMessageDispatcherComponent self, Entity entity, ActorMessageInfo actorMessageInfo)
 {
     //根据消息类型 获取已缓存的 用于处理Actor消息的实例 如果没有则抛出异常
     if (!self.ActorMessageHandlers.TryGetValue(actorMessageInfo.Message.GetType(), out IMActorHandler handler))
     {
         throw new Exception($"not found message handler: {MongoHelper.ToJson(actorMessageInfo.Message)}");
     }
     //调用获取到的处理方法 进行处理...
     await handler.Handle(actorMessageInfo.Session, entity, actorMessageInfo.Message);
 }