Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 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;
 }