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> ()); }
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)); }
void Awake() { commandList = new CommandsList(); // ChecksumRecorder checksumRecorder = new ChecksumRecorder (new GameStateChecksumProvider (_gameStateBuilder, this)); // TODO: set replay.... gameFixedUpdate = new LockstepFixedUpdate(new CommandsListLockstepLogic(commandList, this)); gameFixedUpdate.GameFramesPerLockstep = gameFramesPerLockstep; gameFixedUpdate.FixedStepTime = fixedTimestepMilliseconds / 1000.0f; gameFixedUpdate.SetGameLogic(this); GameFixedUpdateDebug updateDebug = gameObject.AddComponent <GameFixedUpdateDebug> (); updateDebug.SetGameFixedUpdate(gameFixedUpdate); _checksumProvider = new GameStateChecksumProvider(this); ChecksumRecorderDebug checksumRecorderDebug = gameObject.AddComponent <ChecksumRecorderDebug> (); checksumRecorderDebug.checksumRecorder = new ChecksumRecorder(_checksumProvider); _commandSender = new CommandQueueBase(gameFixedUpdate, this); ResetGameState(); _replay = new MyCustomReplay(_checksumProvider, this); _replay.SaveInitialGameState(GetGameState()); _replayController = new ReplayController(gameFixedUpdate, _checksumProvider, recorderView, commandList, _replay); _replayController.GameFramesPerChecksumCheck = gameFramesPerChecksumCheck; StartRecording(); // debug... Application.targetFrameRate = 60; // commandList.AddCommand (new Command () { // CreationFrame = 0, // ProcessFrame = gameFixedUpdate.GetFirstLockstepFrame() // }); }
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)); }