public VibrationMotorState(double maximumAmount, TimeSpan duration, EasingType easingType) { this = new GamepadState.VibrationMotorState(); this.Active = true; this.LastAmount = this.CurrentAmount = 0.0f; this.ElapsedTime = TimeSpan.Zero; this.MaximumAmount = (float)FezMath.Saturate(maximumAmount); this.Duration = duration; this.EasingType = easingType; }
public void Vibrate(VibrationMotor motor, double amount, TimeSpan duration, EasingType easingType) { GamepadState.VibrationMotorState vibrationMotorState = new GamepadState.VibrationMotorState(amount, duration, easingType); switch (motor) { case VibrationMotor.LeftLow: this.leftMotor = vibrationMotorState; break; case VibrationMotor.RightHigh: this.rightMotor = vibrationMotorState; break; } }
private static GamepadState.VibrationMotorState UpdateMotor(GamepadState.VibrationMotorState motorState, TimeSpan elapsedTime) { if (motorState.ElapsedTime <= motorState.Duration) { float num = Easing.EaseIn(1.0 - motorState.ElapsedTime.TotalSeconds / motorState.Duration.TotalSeconds, motorState.EasingType); motorState.CurrentAmount = num * motorState.MaximumAmount; } else { motorState.CurrentAmount = 0.0f; motorState.Active = false; } motorState.ElapsedTime += elapsedTime; return(motorState); }
private void XInputUpdate(TimeSpan elapsed) { this.sinceCheckedConnected += elapsed; if (this.sinceCheckedConnected >= GamepadState.ConnectedCheckFrequency) { bool xinputConnected = this.XInputConnected; this.XInputConnected = GamePad.GetState(this.PlayerIndex, GamePadDeadZone.IndependentAxes).IsConnected; if (xinputConnected && !this.XInputConnected) { this.NewlyDisconnected = true; } } if (!this.XInputConnected) { return; } GamePadState state; try { state = GamePad.GetState(this.PlayerIndex, GamePadDeadZone.IndependentAxes); } catch { return; } this.XInputConnected = state.IsConnected; if (!this.XInputConnected) { return; } if (SettingsManager.Settings.Vibration) { if (this.leftMotor.Active) { this.leftMotor = GamepadState.UpdateMotor(this.leftMotor, elapsed); } if (this.rightMotor.Active) { this.rightMotor = GamepadState.UpdateMotor(this.rightMotor, elapsed); } if ((double)this.leftMotor.LastAmount != (double)this.leftMotor.CurrentAmount || (double)this.rightMotor.LastAmount != (double)this.rightMotor.CurrentAmount) { GamePad.SetVibration(this.PlayerIndex, this.leftMotor.CurrentAmount, this.rightMotor.CurrentAmount); } } this.UpdateFromState(state, elapsed); }
private void XInputUpdate(TimeSpan elapsed) { this.sinceCheckedConnected += elapsed; if (this.sinceCheckedConnected >= GamepadState.ConnectedCheckFrequency) { bool xinputConnected = this.XInputConnected; this.XInputConnected = GamePad.GetState(this.PlayerIndex, GamePadDeadZone.IndependentAxes).IsConnected; if (xinputConnected && !this.XInputConnected) this.NewlyDisconnected = true; } if (!this.XInputConnected) return; GamePadState state; try { state = GamePad.GetState(this.PlayerIndex, GamePadDeadZone.IndependentAxes); } catch { return; } this.XInputConnected = state.IsConnected; if (!this.XInputConnected) return; if (SettingsManager.Settings.Vibration) { if (this.leftMotor.Active) this.leftMotor = GamepadState.UpdateMotor(this.leftMotor, elapsed); if (this.rightMotor.Active) this.rightMotor = GamepadState.UpdateMotor(this.rightMotor, elapsed); if ((double) this.leftMotor.LastAmount != (double) this.leftMotor.CurrentAmount || (double) this.rightMotor.LastAmount != (double) this.rightMotor.CurrentAmount) GamePad.SetVibration(this.PlayerIndex, this.leftMotor.CurrentAmount, this.rightMotor.CurrentAmount); } this.UpdateFromState(state, elapsed); }
public VibrationMotorState(double maximumAmount, TimeSpan duration, EasingType easingType) { this = new GamepadState.VibrationMotorState(); this.Active = true; this.LastAmount = this.CurrentAmount = 0.0f; this.ElapsedTime = TimeSpan.Zero; this.MaximumAmount = (float) FezMath.Saturate(maximumAmount); this.Duration = duration; this.EasingType = easingType; }