Exemplo n.º 1
0
 public override void Update()
 {
     lock (Entitas.EntityWorld.SyncRoot)
     {
         logicBehaviour  = Sim.GetBehaviour <LogicFrameBehaviour>();
         backupBehaviour = Sim.GetBehaviour <ComponentsBackupBehaviour>();
         while (Service.Get <LoginService>().QueueKeyFrameCollection.Count > 0)
         {
             PtKeyFrameCollection pt = null;
             if (Service.Get <LoginService>().QueueKeyFrameCollection.TryPeek(out pt) && pt.FrameIdx < logicBehaviour.CurrentFrameIdx)
             {
                 PtKeyFrameCollection keyframeCollection = null;
                 if (Service.Get <LoginService>().QueueKeyFrameCollection.TryDequeue(out keyframeCollection))
                 {
                     RollImpl(keyframeCollection);
                 }
                 else
                 {
                     break;
                 }
                 //DebugFrameIdx = string.Format("{0} CollectionFrameIdx:{1}", logicBehaviour.CurrentFrameIdx, keyframeCollection.FrameIdx);
             }
             else
             {
                 break;
             }
         }
     }
 }
Exemplo n.º 2
0
        public override void Update()
        {
            lock (Entitas.EntityWorld.SyncRoot)
            {
                logicBehaviour  = Sim.GetBehaviour <LogicFrameBehaviour>();
                backupBehaviour = Sim.GetBehaviour <ComponentsBackupBehaviour>();

                int count = 0;
                while (MgobeHelper.QueueKeyFrameCollection.Count > 0)
                {
                    count++;
                    if (count > MaxCount)
                    {
                        break;
                    }

                    PtKeyFrameCollection pt = null;
                    if (MgobeHelper.QueueKeyFrameCollection.TryPeek(out pt))
                    {
                        PtKeyFrameCollection keyframeCollection = null;
                        if (pt.FrameIdx < logicBehaviour.CurrentFrameIdx)
                        {
                            if (MgobeHelper.QueueKeyFrameCollection.TryDequeue(out keyframeCollection))
                            {
                                RollImpl(keyframeCollection);
                            }
                            else
                            {
                                break;
                            }
                        }
                        else if (pt.FrameIdx > logicBehaviour.CurrentFrameIdx)
                        {
                            if (MgobeHelper.QueueKeyFrameCollection.TryDequeue(out keyframeCollection))
                            {
                                QuickImpl(keyframeCollection);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void Update()
        {
            LogicFrameBehaviour logic = Sim.GetBehaviour <LogicFrameBehaviour>();

            Entitas.Entity entity = Sim.GetEntityWorld().GetEntity(GameClientData.SelfControlEntityId);
            if (entity != null)
            {
                MoveComponent comp = entity.GetComponent <MoveComponent>();
                if (comp != null)
                {
                    Vector2 dir = comp.GetDirVector2();
                    if (InputManager.Instance.IsKeyCodeActive(KeyCode.A))
                    {
                        dir.x = -1;
                    }
                    if (InputManager.Instance.IsKeyCodeActive(KeyCode.S))
                    {
                        dir.y = -1;
                    }
                    if (InputManager.Instance.IsKeyCodeActive(KeyCode.W))
                    {
                        dir.y = 1;
                    }
                    if (InputManager.Instance.IsKeyCodeActive(KeyCode.D))
                    {
                        dir.x = 1;
                    }
                    if (!InputManager.Instance.IsAnyKeyCodeActive())
                    {
                        dir.x = 0;
                        dir.y = 0;
                    }
                    if (dir != comp.GetDirVector2())
                    {
                        Debug.Log(string.Format("keyframeIdx:{0} roleid:{1}", logic.CurrentFrameIdx, comp.EntityId));

                        //KeyFrameSender.AddFrameCommand(new FrameIdxInfo(logic.CurrentFrameIdx,FrameCommand.SYNC_MOVE,comp.EntityId,new string[] { dir.x + "", dir.y + "", "0" }));

                        KeyFrameSender.AddCurrentFrameCommand(FrameCommand.SYNC_MOVE, comp.EntityId, new string[] { dir.x + "", dir.y + "", "0" });
                    }

                    //bullet
                    if (InputManager.Instance.IsKeyCodeActive(KeyCode.Space))
                    {
                        KeyFrameSender.AddCurrentFrameCommand(FrameCommand.SYNC_CREATE_ENTITY, Common.Utils.GuidToString(), new string[] { ((int)EntityWorld.EntityOperationEvent.CreateBullet) + "", comp.EntityId });
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void Update()
        {
            LogicFrameBehaviour logic = Sim.GetBehaviour <LogicFrameBehaviour>();

            if (logic.CurrentFrameIdx % randomStepFrame == 0)
            {
                //randomStepFrame = new System.Random().Next(10, 30);
                Entitas.Entity entity = Sim.GetEntityWorld().GetEntity(GameClientData.SelfControlEntityId);
                if (entity != null)
                {
                    MoveComponent comp = entity.GetComponent <MoveComponent>();
                    if (comp != null)
                    {
                        Vector2 dir   = comp.GetDirVector2();
                        int     value = new System.Random().Next(0, 5);
                        if (value == 0)
                        {
                            dir.x = -1;
                        }
                        else if (value == 1)
                        {
                            dir.y = -1;
                        }
                        else if (value == 2)
                        {
                            dir.y = 1;
                        }
                        else if (value == 3)
                        {
                            dir.x = 1;
                        }
                        else if (value == 4)
                        {
                            dir.x = 0;
                            dir.y = 0;
                        }
                        if (dir != comp.GetDirVector2())
                        {
                            //Debug.Log(string.Format("keyframeIdx:{0} roleid:{1}", logic.CurrentFrameIdx, comp.EntityId));

                            KeyFrameSender.AddFrameCommand(new FrameIdxInfo(logic.CurrentFrameIdx, FrameCommand.SYNC_MOVE, comp.EntityId.ToString(), new string[] { dir.x + "", dir.y + "", "0" }));
                        }
                    }
                }
            }
        }