Skip to content

Commit

Permalink
fix: Remove hardcoded values Gamepad buttons, axes and hats
Browse files Browse the repository at this point in the history
It caused showing wrong numbers of elements of gamepad and rendering too many unused buttons.
  • Loading branch information
pktiuk committed Oct 10, 2022
1 parent 96a82f1 commit 35c0089
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 38 deletions.
11 changes: 0 additions & 11 deletions src/gamecontroller/gamecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions src/gamecontroller/gamecontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/inputdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/inputdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
18 changes: 0 additions & 18 deletions src/joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
3 changes: 0 additions & 3 deletions src/joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 35c0089

Please sign in to comment.