From 35c0089173605da4662e897266cc562ccc5cdb1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kotiuk?= Date: Mon, 10 Oct 2022 19:17:10 +0200 Subject: [PATCH] fix: Remove hardcoded values Gamepad buttons, axes and hats It caused showing wrong numbers of elements of gamepad and rendering too many unused buttons. --- src/gamecontroller/gamecontroller.cpp | 11 ----------- src/gamecontroller/gamecontroller.h | 3 --- src/inputdevice.cpp | 6 ++++++ src/inputdevice.h | 6 +++--- src/joystick.cpp | 18 ------------------ src/joystick.h | 3 --- 6 files changed, 9 insertions(+), 38 deletions(-) diff --git a/src/gamecontroller/gamecontroller.cpp b/src/gamecontroller/gamecontroller.cpp index 8edb830d0..83c49a89f 100644 --- a/src/gamecontroller/gamecontroller.cpp +++ b/src/gamecontroller/gamecontroller.cpp @@ -181,15 +181,6 @@ void GameController::closeSDLDevice() } } -int GameController::getNumberRawButtons() { return SDL_CONTROLLER_BUTTON_MAX; } - -int GameController::getNumberRawAxes() -{ - qDebug() << "Controller has " << SDL_CONTROLLER_AXIS_MAX << " raw axes"; - - return SDL_CONTROLLER_AXIS_MAX; -} - /** * @brief Queries the data rate of the given sensor from SDL. * @returns Data rate in events per second or zero if data rate is unavailable. @@ -223,8 +214,6 @@ bool GameController::hasRawSensor(JoySensorType type) return false; } -int GameController::getNumberRawHats() { return 0; } - void GameController::setCounterUniques(int counter) { counterUniques = counter; } QString GameController::getBindStringForAxis(int index, bool) diff --git a/src/gamecontroller/gamecontroller.h b/src/gamecontroller/gamecontroller.h index 0e7c0ebf8..e6b277897 100644 --- a/src/gamecontroller/gamecontroller.h +++ b/src/gamecontroller/gamecontroller.h @@ -57,9 +57,6 @@ class GameController : public InputDevice virtual void closeSDLDevice() override; virtual SDL_JoystickID getSDLJoystickID() override; - virtual int getNumberRawButtons() override; - virtual int getNumberRawAxes() override; - virtual int getNumberRawHats() override; virtual double getRawSensorRate(JoySensorType type) override; virtual bool hasRawSensor(JoySensorType type) override; void setCounterUniques(int counter) override; diff --git a/src/inputdevice.cpp b/src/inputdevice.cpp index eea5dbbe1..161abd3c1 100644 --- a/src/inputdevice.cpp +++ b/src/inputdevice.cpp @@ -1353,6 +1353,12 @@ QString InputDevice::getDescription() return full_desc; } +int InputDevice::getNumberRawAxes() { return SDL_JoystickNumAxes(m_joyhandle); } + +int InputDevice::getNumberRawButtons() { return SDL_JoystickNumButtons(m_joyhandle); } + +int InputDevice::getNumberRawHats() { return SDL_JoystickNumHats(m_joyhandle); } + QString InputDevice::getSDLPlatform() { QString temp = SDL_GetPlatform(); diff --git a/src/inputdevice.h b/src/inputdevice.h index 471bdd95e..dbae8298d 100644 --- a/src/inputdevice.h +++ b/src/inputdevice.h @@ -105,9 +105,9 @@ class InputDevice : public QObject void setDPadName(int dpadIndex, QString tempName); // InputDeviceHat class void setVDPadName(int vdpadIndex, QString tempName); // InputDeviceVDPad class - virtual int getNumberRawButtons() = 0; - virtual int getNumberRawAxes() = 0; - virtual int getNumberRawHats() = 0; + virtual int getNumberRawButtons(); + virtual int getNumberRawAxes(); + virtual int getNumberRawHats(); virtual double getRawSensorRate(JoySensorType type) = 0; virtual bool hasRawSensor(JoySensorType type) = 0; diff --git a/src/joystick.cpp b/src/joystick.cpp index abe67fe12..f8efa7da9 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -151,24 +151,6 @@ void Joystick::closeSDLDevice() } } -int Joystick::getNumberRawButtons() -{ - int numbuttons = SDL_JoystickNumButtons(m_joyhandle); - return numbuttons; -} - -int Joystick::getNumberRawAxes() -{ - int numaxes = SDL_JoystickNumAxes(m_joyhandle); - return numaxes; -} - -int Joystick::getNumberRawHats() -{ - int numhats = SDL_JoystickNumHats(m_joyhandle); - return numhats; -} - double Joystick::getRawSensorRate(JoySensorType _) { return 0; } bool Joystick::hasRawSensor(JoySensorType _) { return false; } diff --git a/src/joystick.h b/src/joystick.h index 564b901ca..266cdedd4 100644 --- a/src/joystick.h +++ b/src/joystick.h @@ -44,9 +44,6 @@ class Joystick : public InputDevice virtual void closeSDLDevice() override; virtual SDL_JoystickID getSDLJoystickID() override; - virtual int getNumberRawButtons() override; - virtual int getNumberRawAxes() override; - virtual int getNumberRawHats() override; virtual double getRawSensorRate(JoySensorType type) override; virtual bool hasRawSensor(JoySensorType type) override;