Example #1
0
    public void LockstepLogicShouldNotProcessAgainIfNoFixedGameStep()
    {
        var gameLogic = new TestGameStep.GameStepEngineMock();

        var lockstepLogic = NSubstitute.Substitute.For <LockstepLogic> ();

        LockstepFixedUpdate lockstepGameLogic = new LockstepFixedUpdate(lockstepLogic);

        lockstepGameLogic.FixedStepTime         = 0.1f;
        lockstepGameLogic.GameFramesPerLockstep = 2;
        lockstepGameLogic.SetGameLogic(gameLogic);

        lockstepLogic.IsReady(0).ReturnsForAnyArgs(false);

        lockstepGameLogic.Update(0.1f);
        lockstepGameLogic.Update(0.1f);

        // didnt process lockstep turn yet
//		lockstepLogic.DidNotReceive ().IsReady (Arg.Any<int> ());
        lockstepLogic.DidNotReceive().Process(Arg.Any <int> ());

        Assert.That(lockstepGameLogic.IsLockstepTurn(), Is.True);

        lockstepLogic.ClearReceivedCalls();

        // if update too low, then even if it is lockstep turn, it didnt process it
        lockstepGameLogic.Update(0.002f);

        lockstepLogic.DidNotReceive().IsReady(Arg.Any <int> ());
        lockstepLogic.DidNotReceive().Process(Arg.Any <int> ());
    }
Example #2
0
    public void LockstepTurnShouldNotAdvanceIfWaitingForActions()
    {
//		var gameLogic = NSubstitute.Substitute.For<DeterministicGameLogic> ();

        var gameLogic = new TestGameStep.GameStepEngineMock();

        var lockstepLogic = NSubstitute.Substitute.For <LockstepLogic> ();

        LockstepFixedUpdate lockstepGameLogic = new LockstepFixedUpdate(lockstepLogic);

        lockstepGameLogic.FixedStepTime         = 0.1f;
        lockstepGameLogic.GameFramesPerLockstep = 1;
        lockstepGameLogic.SetGameLogic(gameLogic);

        lockstepLogic.IsReady(0).ReturnsForAnyArgs(false);

//		LockstepGameLogic lockstepGameLogic = new LockstepGameLogic (gameLogic, pendingCommands);

        lockstepGameLogic.GameFramesPerLockstep = 1;

        lockstepGameLogic.Update(0.1f);
        lockstepGameLogic.Update(0.1f);
        lockstepGameLogic.Update(0.1f);

        Assert.That(gameLogic.lastFrame, Is.EqualTo(0));

        lockstepLogic.IsReady(0).ReturnsForAnyArgs(true);

        lockstepGameLogic.Update(0.1f);

        Assert.That(gameLogic.lastFrame, Is.EqualTo(1));
    }
        public void TestNoFixedUpdateIfNotEnoughTime()
        {
            var gameLogic = new TestGameStep.GameStepEngineMock();

            GameFixedUpdate gameUpdate = new GameFixedUpdate();

            gameUpdate.FixedStepTime = 0.1f;
            gameUpdate.SetGameLogic(gameLogic);

            gameUpdate.Update(0.09f);

            Assert.That(gameLogic.UpdateTimes, Is.EqualTo(0));
        }
        public void TestDoubleTimeIncreasesTwoFixedUpdates()
        {
            var gameLogic = new TestGameStep.GameStepEngineMock();

            GameFixedUpdate gameUpdate = new GameFixedUpdate();

            gameUpdate.FixedStepTime = 0.1f;
            gameUpdate.SetGameLogic(gameLogic);

            gameUpdate.Update(0.1f * 2);

            Assert.That(gameLogic.lastFrame, Is.EqualTo(1));
            Assert.That(gameLogic.lastDt, Is.EqualTo(0.1f).Within(0.001f));
        }
        public void TestFramesStartsZeroIndexed()
        {
            var gameLogic = new TestGameStep.GameStepEngineMock();

            GameFixedUpdate gameUpdate = new GameFixedUpdate();

            gameUpdate.FixedStepTime = 0.1f;
            gameUpdate.SetGameLogic(gameLogic);

            gameUpdate.Update(0.1f);

            Assert.That(gameLogic.lastFrame, Is.EqualTo(0));

            gameUpdate.Update(0.1f);

            Assert.That(gameLogic.lastFrame, Is.EqualTo(1));
        }
Example #6
0
    public void TestLastUpdatedFrameShouldBePreviousToLockstep()
    {
        var gameLogic = new TestGameStep.GameStepEngineMock();

        var lockstepLogic = NSubstitute.Substitute.For <LockstepLogic> ();

        LockstepFixedUpdate lockstepGameLogic = new LockstepFixedUpdate(lockstepLogic);

        lockstepGameLogic.SetGameLogic(gameLogic);

        lockstepGameLogic.FixedStepTime         = 0.1f;
        lockstepGameLogic.MaxAllowedFrameTime   = 1.0f;
        lockstepGameLogic.GameFramesPerLockstep = 4;

        lockstepLogic.IsReady(Arg.Any <int> ()).ReturnsForAnyArgs(false);

        lockstepGameLogic.Update(0.8f);

        Assert.That(gameLogic.lastFrame, Is.EqualTo(lockstepGameLogic.GetFirstLockstepFrame() - 1));
    }