summaryrefslogtreecommitdiff
path: root/src/input/joystick.h
diff options
context:
space:
mode:
authorasuratva <asuratva@proton.me>2024-05-18 10:58:37 +0000
committerasuratva <asuratva@proton.me>2024-05-18 10:58:37 +0000
commit1d7ee3161693ed016264a4940778a6e4b2258e38 (patch)
tree059f68cc39a725a0bc64538e5771ef3525aa6ec6 /src/input/joystick.h
parent9294f5a1ba84c7a4e947ab94a2645625e8a6171d (diff)
parent5570d9d1c2b1b5fba50283ec443088430332bb86 (diff)
downloadplus-1d7ee3161693ed016264a4940778a6e4b2258e38.tar.gz
plus-1d7ee3161693ed016264a4940778a6e4b2258e38.tar.bz2
plus-1d7ee3161693ed016264a4940778a6e4b2258e38.tar.xz
plus-1d7ee3161693ed016264a4940778a6e4b2258e38.zip
Merge branch plus:master into masterHEADmaster
Diffstat (limited to 'src/input/joystick.h')
-rw-r--r--src/input/joystick.h67
1 files changed, 52 insertions, 15 deletions
diff --git a/src/input/joystick.h b/src/input/joystick.h
index a3c129950..49c4e553a 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:
@@ -42,6 +51,27 @@ class Joystick final
MAX_BUTTONS = 64
};
+ enum
+ {
+ RESERVED_AXES = 2, // reserved for movement
+ MAX_AXES = 8 // number of axes we can handle
+ };
+
+ /**
+ * Additional "buttons" for hat 0 (d-pad),
+ * sticks and triggers.
+ */
+ enum
+ {
+ KEY_UP = MAX_BUTTONS,
+ KEY_DOWN,
+ KEY_LEFT,
+ KEY_RIGHT,
+ KEY_NEGATIVE_AXIS_FIRST,
+ KEY_POSITIVE_AXIS_FIRST = KEY_NEGATIVE_AXIS_FIRST + MAX_AXES,
+ KEY_END = KEY_POSITIVE_AXIS_FIRST + MAX_AXES
+ };
+
/**
* Directions, to be used as bitmask values.
*/
@@ -98,14 +128,7 @@ class Joystick final
*/
void logic();
- void startCalibration();
-
- void finishCalibration();
-
- bool isCalibrating() const noexcept2 A_WARN_UNUSED
- { return mCalibrating; }
-
- bool buttonPressed(const unsigned char no) const A_WARN_UNUSED;
+ bool buttonPressed(const int no) const A_WARN_UNUSED;
bool isUp() const noexcept2 A_WARN_UNUSED
{ return mEnabled && ((mDirection & UP) != 0); }
@@ -122,15 +145,25 @@ class Joystick final
int getNumber() const noexcept2 A_WARN_UNUSED
{ return mNumber; }
+ void setTolerance(const float tolerance)
+ { mTolerance = tolerance; }
+
+ void setUseHatForMovement(const bool b)
+ { mUseHatForMovement = b; }
+
void setUseInactive(const bool b)
{ mUseInactive = b; }
void update();
+ bool isActionEvent(const SDL_Event &event) A_WARN_UNUSED;
+
KeysVector *getActionVector(const SDL_Event &event) A_WARN_UNUSED;
KeysVector *getActionVectorByKey(const int i) A_WARN_UNUSED;
+ InputActionT getActionId(const SDL_Event &event) A_WARN_UNUSED;
+
int getButtonFromEvent(const SDL_Event &event) const A_WARN_UNUSED;
bool isActionActive(const InputActionT index) const A_WARN_UNUSED;
@@ -144,18 +177,18 @@ class Joystick final
protected:
unsigned char mDirection;
+ unsigned char mHatPosition;
+ int mAxesPositions[MAX_AXES];
+ bool mIsTrigger[MAX_AXES];
bool mActiveButtons[MAX_BUTTONS];
SDL_Joystick *mJoystick;
- int mUpTolerance;
- int mDownTolerance;
- int mLeftTolerance;
- int mRightTolerance;
- bool mCalibrating;
+ float mTolerance;
int mNumber;
- bool mCalibrated;
+ int mAxesNumber;
int mButtonsNumber;
+ bool mUseHatForMovement;
bool mUseInactive;
bool mHaveHats;
@@ -172,7 +205,11 @@ class Joystick final
static bool mInitialized;
static int joystickCount;
- void doCalibration();
+ int getButton(const int key) const A_WARN_UNUSED;
+
+ int getNegativeAxis(const int key) const A_WARN_UNUSED;
+
+ int getPositiveAxis(const int key) const A_WARN_UNUSED;
};
extern Joystick *joystick;