diff options
-rw-r--r-- | src/defaults.cpp | 5 | ||||
-rw-r--r-- | src/input/joystick.cpp | 49 | ||||
-rw-r--r-- | src/input/joystick.h | 5 |
3 files changed, 19 insertions, 40 deletions
diff --git a/src/defaults.cpp b/src/defaults.cpp index 4869de8ef..30c5f3caf 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -194,10 +194,7 @@ void setConfigDefaults(Configuration &cfg) #else AddDEF("joystickEnabled", false); #endif - AddDEF("upTolerance", 100); - AddDEF("downTolerance", 100); - AddDEF("leftTolerance", 100); - AddDEF("rightTolerance", 100); + AddDEF("joystickTolerance", 10000); AddDEF("logNpcInGui", true); AddDEF("download-music", true); AddDEF("guialpha", 0.8F); 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 diff --git a/src/input/joystick.h b/src/input/joystick.h index a3c129950..3587d1ba0 100644 --- a/src/input/joystick.h +++ b/src/input/joystick.h @@ -148,10 +148,7 @@ class Joystick final SDL_Joystick *mJoystick; - int mUpTolerance; - int mDownTolerance; - int mLeftTolerance; - int mRightTolerance; + int mTolerance; bool mCalibrating; int mNumber; bool mCalibrated; |