/// <summary> /// Shifts the command buffer to the left, returning the commands stored in the first list. /// </summary> /// <returns>commands for the current turn</returns> public TurnData Advance() { lock (bufferLock) { TurnData current = turnCommands[position]; turnCommands[position] = new TurnData(NumPlayers); position = (position + 1) % bufferSize; return(current); } }
/// <summary> /// Process commands for the current turn, recovering from a delay if necessary. /// </summary> private void ProcessTurn() { if (status == LockstepStatus.Delay) { ClearPendingCommands(); status = LockstepStatus.Playing; Simulation.Delay(recoverTime); } currentData = buffer.Advance(); currentData.ProcessCommands(); NextTurn(); }
public CommandBuffer(int lookAhead, int numPlayers) { this.bufferSize = lookAhead; this.numPlayers = numPlayers; this.turnCommands = new TurnData[this.bufferSize]; for (uint i = 0; i < bufferSize; i++) { turnCommands[i] = new TurnData(numPlayers); } position = 0; bufferLock = new object(); countLock = new object(); }
/// <summary> /// Deletes everything lockstep related. /// </summary> public void Quit() { buffer = null; currentData = null; pendingCommands = null; }