diff options
Diffstat (limited to 'src/input/joystick.cpp')
-rw-r--r-- | src/input/joystick.cpp | 49 |
1 files changed, 17 insertions, 32 deletions
diff --git a/src/input/joystick.cpp b/src/input/joystick.cpp index 52d9a7525..5396adadc 100644 --- a/src/input/joystick.cpp +++ b/src/input/joystick.cpp @@ -48,10 +48,7 @@ bool Joystick::mInitialized = false; Joystick::Joystick(const int no) : mDirection(0), mJoystick(nullptr), - mUpTolerance(0), - mDownTolerance(0), - mLeftTolerance(0), - mRightTolerance(0), + mTolerance(0), mCalibrating(false), mNumber(no >= joystickCount ? joystickCount : no), mCalibrated(false), @@ -201,18 +198,12 @@ bool Joystick::open() #ifdef __SWITCH__ config.setValue("joystick" + toString(mNumber) + "calibrated", true); - config.setValue("leftTolerance" + toString(mNumber), -10000); - config.setValue("rightTolerance" + toString(mNumber), 10000); - config.setValue("upTolerance" + toString(mNumber), -10000); - config.setValue("downTolerance" + toString(mNumber), 10000); + config.setValue("joystickTolerance" + toString(mNumber), 10000); #endif mCalibrated = config.getValueBool("joystick" + toString(mNumber) + "calibrated", false); - mUpTolerance = config.getIntValue("upTolerance" + toString(mNumber)); - mDownTolerance = config.getIntValue("downTolerance" + toString(mNumber)); - mLeftTolerance = config.getIntValue("leftTolerance" + toString(mNumber)); - mRightTolerance = config.getIntValue("rightTolerance" + toString(mNumber)); + mTolerance = config.getIntValue("joystickTolerance" + toString(mNumber)); mUseInactive = config.getBoolValue("useInactiveJoystick"); return true; @@ -266,16 +257,16 @@ void Joystick::logic() { // X-Axis int position = SDL_JoystickGetAxis(mJoystick, 0); - if (position >= mRightTolerance) + if (position >= mTolerance) mDirection |= RIGHT; - else if (position <= mLeftTolerance) + else if (position <= -mTolerance) mDirection |= LEFT; // Y-Axis position = SDL_JoystickGetAxis(mJoystick, 1); - if (position <= mUpTolerance) + if (position <= -mTolerance) mDirection |= UP; - else if (position >= mDownTolerance) + else if (position >= mTolerance) mDirection |= DOWN; #ifdef DEBUG_JOYSTICK @@ -324,10 +315,7 @@ void Joystick::logic() void Joystick::startCalibration() { - mUpTolerance = 0; - mDownTolerance = 0; - mLeftTolerance = 0; - mRightTolerance = 0; + mTolerance = 0; mCalibrating = true; } @@ -335,17 +323,17 @@ void Joystick::doCalibration() { // X-Axis int position = SDL_JoystickGetAxis(mJoystick, 0); - if (position > mRightTolerance) - mRightTolerance = position; - else if (position < mLeftTolerance) - mLeftTolerance = position; + if (position > mTolerance) + mTolerance = position; + else if (position < -mTolerance) + mTolerance = -position; // Y-Axis position = SDL_JoystickGetAxis(mJoystick, 1); - if (position > mDownTolerance) - mDownTolerance = position; - else if (position < mUpTolerance) - mUpTolerance = position; + if (position > mTolerance) + mTolerance = position; + else if (position < -mTolerance) + mTolerance = -position; } void Joystick::finishCalibration() @@ -353,10 +341,7 @@ void Joystick::finishCalibration() mCalibrated = true; mCalibrating = false; config.setValue("joystick" + toString(mNumber) + "calibrated", true); - config.setValue("leftTolerance" + toString(mNumber), mLeftTolerance); - config.setValue("rightTolerance" + toString(mNumber), mRightTolerance); - config.setValue("upTolerance" + toString(mNumber), mUpTolerance); - config.setValue("downTolerance" + toString(mNumber), mDownTolerance); + config.setValue("joystickTolerance" + toString(mNumber), mTolerance); } bool Joystick::buttonPressed(const unsigned char no) const |