Esempio n. 1
0
        //DoTick 处理tick,将对演示状态进行一定修正,所有的碰撞都在此处发生响应
        public void DoNetTick(WarPb.Tick tick)
        {
            //Debug.Log("tickIndex : " + tick.Index.ToString() + "...netTickIndex : " + netTickIndex);

            if (tick.Index <= netTickIndex)             //NOTE: 收到的重复帧,直接丢弃
            {
                return;
            }

            if (leftSimularTimes > 0 || (tick.Index > (netTickIndex + 1)))        //NOTE: 错帧,加到错帧列表中
            {
                InsertToList(laterTicks, tick);
                return;
            }

            netTickIndex++;
            //NOTE: 此处要处理 NetTick 与 LocalTick 相同的情况,此情况下 shotUpdated 为false
            //DoTick(tick);

            //while (laterTicks.Count > 0)
            //{
            //    if (laterTicks[0].Index > (netTickIndex + 1))
            //        break;

            //    netTickIndex++;
            //    DoTick(laterTicks[0]);
            //    laterTicks.RemoveAt(0);
            //}
            DoTick(tick);
        }
Esempio n. 2
0
        private void DoTick(WarPb.Tick tick)
        {
            //Debug.Log("do tick index : " + tick.Index);
            if (tick.Actions.Count > 0)
            {
                foreach (var any in tick.Actions)
                {
                    if (any.Is(WarPb.Move.Descriptor))
                    {
                        var move = any.Unpack <WarPb.Move>();
                        var tm   = GetTM(move.Uid);

                        var speed = move.Speed;
                        tm.MoveForward = (new Vector3(float.Parse(speed.X), 0f, float.Parse(speed.Z))).normalized;
                        continue;
                    }
                    if (any.Is(WarPb.Shoot.Descriptor))
                    {
                        Debug.Log("do shoot");
                        var shoot = any.Unpack <WarPb.Shoot>();
                        var tm    = GetTM(shoot.Uid);
                        tm.FireInfo = shoot;
                        continue;
                    }
                }
            }
            //foreach (var tm in m_Tanks)
            //{
            //    tm.Do(0.06f);
            //}
            //Physics.defaultPhysicsScene.Simulate(0.06f);
            leftSimularTimes = 3;
            curTick          = tick;
        }
Esempio n. 3
0
 //DoLocalTick 响应本地tick,融合修正
 public void DoLocalTick(WarPb.Tick tick)
 {
     ////Debug.Log("DoLocalTick");
     //if (shotUpdated)        //NOTE: 如果状态更新了,重新计算
     //{
     //    shotUpdated = false;
     //    List<ItemInfo> curShot = new List<ItemInfo>();
     //    Snapshot(curShot);          //NOTE: 将当前状态保存各快照
     //    //NOTE: 此处从shot 开始快速演示到上一tick,并且根据传入tick的方向做修正
     //    QuickPlay();
     //}
     ////else
     //DoTick(tick);
     //InsertToList(localTicks, tick);
 }
Esempio n. 4
0
        ////NOTE: 处理射击,会生成一个信息子弹Item
        //private void DoShoot(WarPb.Shoot shoot)
        //{
        //    Item rootItem = GetItem(shoot.Uid);
        //    var bullet = rootItem.NewBullet(shoot.Super);
        //    bullet.transform.parent = plane.transform;
        //}

        private void InsertToList(List <WarPb.Tick> list, WarPb.Tick tick)
        {
            if (list.FindIndex((c) => { return(c.Index == tick.Index); }) != -1)     //NOTE: 冗余帧
            {
                return;
            }

            int idx = list.FindIndex((c) => { return(c.Index > tick.Index); });

            if (idx != -1)
            {
                list.Insert(idx, tick);
            }
            else
            {
                list.Add(tick);
            }
        }
Esempio n. 5
0
 // Start is called before the first frame update
 private void Start()
 {
     localTick       = new WarPb.Tick();
     localTick.Index = 0;
 }