diff options
author | ewewukek <ewewukek@gmail.com> | 2024-01-10 22:29:22 +0300 |
---|---|---|
committer | Fedja Beader <fedja@protonmail.ch> | 2024-05-14 01:14:04 +0000 |
commit | 9e3a03079cfa530fd3885e36d3f7214ec2348818 (patch) | |
tree | 8666b32e3f7c95b45a26d0722c4ee219a122bbbb /src | |
parent | 4337008fdeef5bb01be2fc6fed1683d5941f23ae (diff) | |
download | plus-9e3a03079cfa530fd3885e36d3f7214ec2348818.tar.gz plus-9e3a03079cfa530fd3885e36d3f7214ec2348818.tar.bz2 plus-9e3a03079cfa530fd3885e36d3f7214ec2348818.tar.xz plus-9e3a03079cfa530fd3885e36d3f7214ec2348818.zip |
Use single tolerance value for all 4 joystick movement directions
Diffstat (limited to 'src')
-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; |