Exemplo n.º 1
0
 /// <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);
     }
 }
Exemplo n.º 2
0
 /// <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();
 }
Exemplo n.º 3
0
 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();
 }
Exemplo n.º 4
0
 /// <summary>
 /// Deletes everything lockstep related.
 /// </summary>
 public void Quit()
 {
     buffer          = null;
     currentData     = null;
     pendingCommands = null;
 }