Ejemplo n.º 1
0
 /// <summary>
 /// 同步之前收到的最后一帧的处理结果
 /// </summary>
 /// <param name="optionEvent"></param>
 /// <exception cref="NotImplementedException"></exception>
 private void OnAsyncLastLogicFrame(FrameOptionEvent optionEvent)
 {
     //把所有英雄的输入进行数据同步,同步的时间间隔就是帧的时间间隔
     foreach (var opt in optionEvent.opts)
     {
         var hero = GetHero(opt.seatid);
         if (!hero)
         {
             Debug.LogError("找不到这个seatid: " + opt.seatid);
             continue;
         }
         hero.OnAsyncLastLogicFrame(opt);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 跳帧
        /// 不用播放动画
        /// </summary>
        /// <param name="frameOpts"></param>
        /// <exception cref="NotImplementedException"></exception>
        private void OnJumpToNextFrame(FrameOptionEvent optionEvent)
        {
            foreach (var opt in optionEvent.opts)
            {
                var hero = GetHero(opt.seatid);
                if (!hero)
                {
                    Debug.LogError("找不到这个seatid: " + opt.seatid);
                    continue;
                }
                hero.OnJumpToNextFrame(opt);
            }

            OnBulletLogicFrameUpdate();

            OnTowerLogicFrameUpdate();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 处理最新帧逻辑
        /// </summary>
        /// <param name="frameOptionEvent"></param>
        private void OnHandlerCurrentLogicFrame(FrameOptionEvent optionEvent)
        {
            //把所有英雄输入代入进去,更新数据,进而控制表现
            foreach (var opt in optionEvent.opts)
            {
                var hero = GetHero(opt.seatid);
                if (!hero)
                {
                    Debug.LogError("找不到这个seatid: " + opt.seatid);
                    continue;
                }
                hero.OnHandlerCurrentLogicFrame(opt);
            }

            //子弹先走
            OnBulletLogicFrameUpdate();

            //塔AI,根据我们处理,进一步处理
            OnTowerLogicFrameUpdate();
        }
Ejemplo n.º 4
0
        private void OnLogicFrame(LogicFrame obj)
        {
            if (obj.frameid < this.sync_frameid)
            {
                return;
            }

            /*print("未同步的帧:" + obj.unsync_frames.Count);
             * var temp = "";
             * foreach (var frameOptionEvent in obj.unsync_frames)
             * {
             *  foreach (var opt in frameOptionEvent.opts)
             *  {
             *      temp+=($"optType: {opt.optype}, stick: [{opt.x},{opt.y}]\n");
             *  }
             * }
             *
             * print(temp);*/

            // 同步之前收到的最后一帧的处理结果,据此保证所有客户端的处理结果都是一样的
            // 同步客户端上一帧逻辑操作,调整位置,调整后,客户端同步到的就是sync_frame
            if (null != lastOptionEvent)
            {
                this.OnAsyncLastLogicFrame(lastOptionEvent);
            }

            // 同步丢掉的帧
            // 从sync_frame 同步到 obj.frameid-1
            foreach (var frame in obj.unsync_frames)
            {
                if (this.sync_frameid >= frame.frameid)
                {// 已经同步
                    continue;
                }
                if (frame.frameid >= obj.frameid)
                {// 无需同步
                    break;
                }

                //跳帧
                this.OnJumpToNextFrame(frame);
            }


            //记录下当前帧操作
            this.sync_frameid = obj.frameid;
            if (obj.unsync_frames.Count > 0)
            {
                //保留最新帧信息
                this.lastOptionEvent = obj.unsync_frames.Last();
                //获取最新帧信息,处理逻辑
                this.OnHandlerCurrentLogicFrame(this.lastOptionEvent);
            }
            else
            {
                this.lastOptionEvent = null;
            }

            //采集下一帧事件发布给服务器
            CollectNextFrameOpts();
        }