public void ValueRollbackTest()
        {
            ResourcesConfigManager.Initialize();
            WorldManager.IntervalTime = 100;

            LockStepEntityTestWorld world = (LockStepEntityTestWorld)WorldManager.CreateWorld <LockStepEntityTestWorld>();

            world.IsClient = true;
            world.IsStart  = true;
            world.IsLocal  = true;

            ConnectStatusComponent csc = world.GetSingletonComp <ConnectStatusComponent>();

            csc.confirmFrame = 0; //从目标帧之后开始计算

            SelfComponent sc = new SelfComponent();

            EntityBase c1 = world.CreateEntityImmediately("1", sc);

            LockStepInputSystem.commandCache.moveDir.x = 1000;

            world.CallRecalc();
            world.FixedLoop(WorldManager.IntervalTime);

            LockStepInputSystem.commandCache.moveDir.x = 0000;

            TestMoveComponent mc = c1.GetComp <TestMoveComponent>();

            //Debug.Log("mc.pos.x " + mc.pos.x + " frame " + world.FrameCount);

            Assert.AreEqual(400, mc.pos.x);

            TestCommandComponent cmd = new TestCommandComponent();

            cmd.frame = 1;
            cmd.id    = 1;
            GlobalEvent.DispatchTypeEvent(cmd);

            world.CallRecalc();
            world.FixedLoop(WorldManager.IntervalTime);

            mc = c1.GetComp <TestMoveComponent>();
            //Debug.Log("mc.pos.x " + mc.pos.x + " frame " + world.FrameCount);

            for (int i = 0; i < 10; i++)
            {
                world.CallRecalc();
                world.FixedLoop(WorldManager.IntervalTime);
                mc = c1.GetComp <TestMoveComponent>();
                //Debug.Log("mc.pos.x " + mc.pos.x + " frame " + world.FrameCount);
            }

            Assert.AreEqual(0, mc.pos.x);
        }
    public override void OnPlayerJoin(EntityBase entity)
    {
        if (!entity.GetExistComp <TestMoveComponent>())
        {
            TestMoveComponent c = new TestMoveComponent();
            entity.AddComp(c);
        }

        if (!entity.GetExistComp <TestCommandComponent>())
        {
            TestCommandComponent c = new TestCommandComponent();
            entity.AddComp(c);
        }
    }
Пример #3
0
    public override MomentComponentBase DeepCopy()
    {
        TestMoveComponent mc = new TestMoveComponent();

        mc.ID    = ID;
        mc.Frame = Frame;

        mc.pos = pos.DeepCopy();
        mc.dir = dir.DeepCopy();

        mc.m_velocity  = m_velocity;
        mc.isCollision = isCollision;
        return(mc);
    }
Пример #4
0
    void UpdateMove(EntityBase entity, int deltaTime)
    {
        TestMoveComponent    mc = (TestMoveComponent)entity.GetComp("TestMoveComponent");
        TestCommandComponent cc = (TestCommandComponent)entity.GetComp("TestCommandComponent");

        mc.dir        = cc.moveDir;
        mc.m_velocity = 4000;

        //Debug.Log("LockStepTestMoveSystem " + mc.dir);

        SyncVector3 newPos = mc.pos.DeepCopy();

        newPos.x += (mc.dir.x * deltaTime / 1000) * mc.m_velocity / 1000;
        newPos.y += (mc.dir.y * deltaTime / 1000) * mc.m_velocity / 1000;
        newPos.z += (mc.dir.z * deltaTime / 1000) * mc.m_velocity / 1000;

        //Debug.Log("mc.pos "+ mc.pos  + " newPos " + newPos + " mc.dir.x " + mc.dir.x + " mc.m_velocity " + mc.m_velocity);

        mc.pos = newPos;

        //Debug.DrawRay(newPos.ToVector(), Vector3.up, Color.yellow, 10);
    }
        public void SameMsgTest_1()
        {
            ResourcesConfigManager.Initialize();
            WorldManager.IntervalTime = 100;

            LockStepEntityTestWorld world = (LockStepEntityTestWorld)WorldManager.CreateWorld <LockStepEntityTestWorld>();

            world.IsClient = true;
            world.IsStart  = true;
            world.IsLocal  = true;

            ConnectStatusComponent csc = world.GetSingletonComp <ConnectStatusComponent>();

            csc.confirmFrame = 0; //从目标帧之后开始计算

            SelfComponent sc = new SelfComponent();

            EntityBase c1 = world.CreateEntityImmediately("1", sc);

            LockStepInputSystem.commandCache.moveDir.x = 0;

            world.CallRecalc();
            world.FixedLoop(WorldManager.IntervalTime);

            world.CallRecalc();
            world.FixedLoop(WorldManager.IntervalTime);
            TestMoveComponent mc = c1.GetComp <TestMoveComponent>();

            Assert.AreEqual(0, mc.pos.x);

            LockStepInputSystem.commandCache.moveDir.x = 1000;

            world.CallRecalc();
            world.FixedLoop(WorldManager.IntervalTime);

            mc = c1.GetComp <TestMoveComponent>();

            Assert.AreEqual(1000, mc.pos.x);

            TestCommandComponent cmd = new TestCommandComponent();

            cmd.frame     = 1;
            cmd.id        = 1;
            cmd.moveDir.x = 1000;
            GlobalEvent.DispatchTypeEvent(cmd);

            world.CallRecalc();
            world.FixedLoop(WorldManager.IntervalTime);

            mc = c1.GetComp <TestMoveComponent>();

            Assert.AreEqual(1000, mc.pos.x);

            SameCommand sameMsg = new SameCommand();

            sameMsg.id    = 1;
            sameMsg.frame = 2;

            GlobalEvent.DispatchTypeEvent(sameMsg);

            mc = c1.GetComp <TestMoveComponent>();

            world.CallRecalc();
            world.FixedLoop(WorldManager.IntervalTime);
            mc = c1.GetComp <TestMoveComponent>();


            Assert.AreEqual(0, mc.pos.x);
        }