Example #1
0
    public void TestNextLockstepFrameIsZeroIndexed()
    {
        //		var gameLogic = NSubstitute.Substitute.For<DeterministicGameLogic> ();

//		var gameLogic = new TestGameStep.GameStepEngineMock ();

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

        LockstepFixedUpdate lockstepGameLogic = new LockstepFixedUpdate(lockstepLogic);

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

        // 0, 1, 2, 3
        // 4, 5, 6, 7
        // 8, 9, 10, 11

//		lockstepGameLogic.SetGameLogic (gameLogic);

//		lockstepLogic.IsReady (0).Returns (true);

        Assert.That(lockstepGameLogic.GetFirstLockstepFrame(), Is.EqualTo(3));

        Assert.That(lockstepGameLogic.GetNextLockstepFrame(0), Is.EqualTo(7));
        Assert.That(lockstepGameLogic.GetNextLockstepFrame(1), Is.EqualTo(7));
        Assert.That(lockstepGameLogic.GetNextLockstepFrame(2), Is.EqualTo(7));

        Assert.That(lockstepGameLogic.GetNextLockstepFrame(4), Is.EqualTo(11));
        Assert.That(lockstepGameLogic.GetNextLockstepFrame(5), Is.EqualTo(11));
        Assert.That(lockstepGameLogic.GetNextLockstepFrame(6), Is.EqualTo(11));

//		Assert.That (lockstepGameLogic.GetNextLockstepFrame (8), Is.EqualTo (16));
    }
    void ResetGameState()
    {
        gameFixedUpdate.Init();

        if (_replay == null)
        {
            gameFixedUpdate.GameFramesPerLockstep = gameFramesPerLockstep;
            gameFixedUpdate.FixedStepTime         = fixedTimestepMilliseconds / 1000.0f;
            unit.Unit.SetPosition(new Vector2(0, 0));

            // by default enqueues an empty command for first lockstep frame
            commandList.AddCommand(new CommandBase()
            {
                ProcessFrame = gameFixedUpdate.GetFirstLockstepFrame()
            });
        }
        else
        {
            if (_replayController.IsRecording)
            {
                gameFixedUpdate.GameFramesPerLockstep = gameFramesPerLockstep;
                gameFixedUpdate.FixedStepTime         = fixedTimestepMilliseconds / 1000.0f;
                unit.Unit.SetPosition(new Vector2(0, 0));

                _replay.SaveInitialGameState(GetGameState());
            }
            else
            {
                // load game state from replay && dont enqueue default message for first lockstep

                Debug.Log("Loading replay gamestate");

                var gameState = _replay.GetInitialGameState() as MyCustomGameState;

                gameFixedUpdate.FixedStepTime         = gameState.fixedDeltaTime;
                gameFixedUpdate.GameFramesPerLockstep = gameState.gameFramesPerLockstep;

                unit.Unit.SetPosition(gameState.unitData.position);
                unit.Unit.Speed = gameState.unitData.speed;

                // all the other data...
            }
        }
    }
Example #3
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));
    }