summaryrefslogtreecommitdiff
path: root/src/input
diff options
context:
space:
mode:
authorewewukek <ewewukek@gmail.com>2024-01-10 23:26:42 +0300
committerFedja Beader <fedja@protonmail.ch>2024-05-14 01:14:04 +0000
commit84a11a02aad86d9388175c7fd0971accdb586473 (patch)
tree2074498193d24700a002319a0c4b412752809f43 /src/input
parente0f535979ad9315efbe4a16ab1ad345d9e9a4347 (diff)
downloadmv-84a11a02aad86d9388175c7fd0971accdb586473.tar.gz
mv-84a11a02aad86d9388175c7fd0971accdb586473.tar.bz2
mv-84a11a02aad86d9388175c7fd0971accdb586473.tar.xz
mv-84a11a02aad86d9388175c7fd0971accdb586473.zip
Switch joystick axis tolerance type to float
Diffstat (limited to 'src/input')
-rw-r--r--src/input/joystick.cpp12
-rw-r--r--src/input/joystick.h13
2 files changed, 17 insertions, 8 deletions
diff --git a/src/input/joystick.cpp b/src/input/joystick.cpp
index 4bcb070d3..0ab6102c5 100644
--- a/src/input/joystick.cpp
+++ b/src/input/joystick.cpp
@@ -195,9 +195,9 @@ bool Joystick::open()
mButtonsNumber = MAX_BUTTONS;
#ifdef __SWITCH__
- config.setValue("joystickTolerance", 10000);
+ config.setValue("joystickTolerance", 0.1F);
#endif
- mTolerance = config.getIntValue("joystickTolerance");
+ mTolerance = config.getFloatValue("joystickTolerance");
mUseInactive = config.getBoolValue("useInactiveJoystick");
return true;
@@ -243,16 +243,16 @@ void Joystick::logic()
{
// X-Axis
int position = SDL_JoystickGetAxis(mJoystick, 0);
- if (position >= mTolerance)
+ if (position >= mTolerance * SDL_JOYSTICK_AXIS_MAX)
mDirection |= RIGHT;
- else if (position <= -mTolerance)
+ else if (position <= mTolerance * SDL_JOYSTICK_AXIS_MIN)
mDirection |= LEFT;
// Y-Axis
position = SDL_JoystickGetAxis(mJoystick, 1);
- if (position <= -mTolerance)
+ if (position <= mTolerance * SDL_JOYSTICK_AXIS_MIN)
mDirection |= UP;
- else if (position >= mTolerance)
+ else if (position >= mTolerance * SDL_JOYSTICK_AXIS_MAX)
mDirection |= DOWN;
#ifdef DEBUG_JOYSTICK
diff --git a/src/input/joystick.h b/src/input/joystick.h
index d90420395..32fdddf2e 100644
--- a/src/input/joystick.h
+++ b/src/input/joystick.h
@@ -31,6 +31,15 @@ PRAGMA48(GCC diagnostic ignored "-Wshadow")
#include <SDL_events.h>
PRAGMA48(GCC diagnostic pop)
+// defined first in SDL 2.0.6
+// not available on older distros
+#ifndef SDL_JOYSTICK_AXIS_MIN
+#define SDL_JOYSTICK_AXIS_MIN -32768
+#endif
+#ifndef SDL_JOYSTICK_AXIS_MAX
+#define SDL_JOYSTICK_AXIS_MAX 32767
+#endif
+
class Joystick final
{
public:
@@ -115,7 +124,7 @@ class Joystick final
int getNumber() const noexcept2 A_WARN_UNUSED
{ return mNumber; }
- void setTolerance(const int tolerance)
+ void setTolerance(const float tolerance)
{ mTolerance = tolerance; }
void setUseInactive(const bool b)
@@ -144,7 +153,7 @@ class Joystick final
SDL_Joystick *mJoystick;
- int mTolerance;
+ float mTolerance;
int mNumber;
int mButtonsNumber;
bool mUseInactive;