public virtual bool ReadInputs( int player, long frame, sbyte?selectedOption, bool remoteCharacterInputPrediction ) { FluxPlayer p = this.GetPlayer(player); if (p != null && p.inputBuffer != null && p.inputController != null && !p.inputBuffer.IsFull()) { FrameInput?oldInput; // As we don't want to override existing values, // we need to check if there was already a predicted input for the specified frame... if (!p.inputBuffer.TryGetInput(frame, out oldInput) || oldInput == null) { FrameInput currentInput; // Check if the specified player is using a Dummy Controller... if (p.inputController is DummyInputController && p.inputBuffer.TryGetInput(frame - 1L, out oldInput)) { // In that case, repeat the input from last frame (if any) currentInput = oldInput != null ? oldInput.Value : new FrameInput(FrameInput.NullSelectedOption); } else { // Retrieve the "predicted input" for the specified frame... try{ currentInput = p.inputController.inputs.ToFrameInput(selectedOption); }catch (Exception e) { Debug.LogError("Read Input: " + player + " | " + frame + " | " + selectedOption); throw e; } } // Find out if it's a local character or if the prediction of remote character input is enabled bool localCharacter = p.isLocalPlayer; if (remoteCharacterInputPrediction || localCharacter) { p.inputBuffer.TrySetPredictedInput(frame, currentInput); } // If it's a local character, then mark the "predicted input" as "confirmed"... if (localCharacter) { p.inputBuffer.TrySetConfirmedInput(frame, currentInput); } return(true); } } return(false); }
public long GetNextExpectedFrame(int player) { FluxPlayer p = this.GetPlayer(player); if (p != null) { // // Return the first frame without a confirmed input // for (long i = p.inputBuffer.FirstFrame; i <= p.inputBuffer.LastFrame; ++i){ // int index = p.inputBuffer.GetIndex(i); // // if (index >= 0 && p.inputBuffer[index].ConfirmedInput == null){ // return i; // } // } // // return p.inputBuffer.LastFrame + 1L; return(p.inputBuffer.GetLastFrameWithConfirmedInput() + 1L); } return(0L); }