Qt: Rough deadzone estimation

This commit is contained in:
Jeffrey Pfau 2015-04-17 23:55:38 -07:00
parent 02ecfa6843
commit 6750e7775e
4 changed files with 25 additions and 6 deletions

View File

@ -8,6 +8,7 @@ Features:
- Rewind now shows the frame after rewinding
- Import/Export of GameShark/Action Replay snapshots
- Add "Step backwards" item for single increment rewind
- Deadzone estimation for game controllers
Bugfixes:
- GBA: Fix timers not updating timing when writing to only the reload register
- All: Fix sanitize-deb script not cleaning up after itself

View File

@ -47,9 +47,10 @@ GBAKeyEditor::GBAKeyEditor(InputController* controller, int type, const QString&
refresh();
#ifdef BUILD_SDL
lookupAxes(map);
if (type == SDL_BINDING_BUTTON) {
controller->recalibrateAxes();
lookupAxes(map);
m_profileSelect = new QComboBox(this);
m_profileSelect->addItems(controller->connectedGamepads(type));
int activeGamepad = controller->gamepad(type);
@ -61,6 +62,7 @@ GBAKeyEditor::GBAKeyEditor(InputController* controller, int type, const QString&
m_controller->setGamepad(m_type, i);
m_profile = m_profileSelect->currentText();
m_controller->loadProfile(m_type, m_profile);
m_controller->recalibrateAxes();
refresh();
});
}

View File

@ -226,14 +226,27 @@ QSet<int> InputController::activeGamepadButtons() {
return activeButtons;
}
void InputController::recalibrateAxes() {
SDL_Joystick* joystick = m_sdlPlayer.joystick;
SDL_JoystickUpdate();
int numAxes = SDL_JoystickNumAxes(joystick);
m_deadzones.resize(numAxes);
int i;
for (i = 0; i < numAxes; ++i) {
m_deadzones[i] = SDL_JoystickGetAxis(joystick, i);
}
}
QSet<QPair<int, GamepadAxisEvent::Direction>> InputController::activeGamepadAxes() {
SDL_Joystick* joystick = m_sdlPlayer.joystick;
SDL_JoystickUpdate();
int numButtons = SDL_JoystickNumAxes(joystick);
int numAxes = SDL_JoystickNumAxes(joystick);
m_deadzones.resize(numAxes);
QSet<QPair<int, GamepadAxisEvent::Direction>> activeAxes;
int i;
for (i = 0; i < numButtons; ++i) {
for (i = 0; i < numAxes; ++i) {
int32_t axis = SDL_JoystickGetAxis(joystick, i);
axis -= m_deadzones[i];
if (axis >= AXIS_THRESHOLD || axis <= -AXIS_THRESHOLD) {
activeAxes.insert(qMakePair(i, axis > 0 ? GamepadAxisEvent::POSITIVE : GamepadAxisEvent::NEGATIVE));
}
@ -250,11 +263,11 @@ void InputController::bindAxis(uint32_t type, int axis, GamepadAxisEvent::Direct
switch (direction) {
case GamepadAxisEvent::NEGATIVE:
description.lowDirection = key;
description.deadLow = -AXIS_THRESHOLD;
description.deadLow = m_deadzones[axis] - AXIS_THRESHOLD;
break;
case GamepadAxisEvent::POSITIVE:
description.highDirection = key;
description.deadHigh = AXIS_THRESHOLD;
description.deadHigh = m_deadzones[axis] + AXIS_THRESHOLD;
break;
default:
return;

View File

@ -10,6 +10,7 @@
#include <QObject>
#include <QSet>
#include <QVector>
class QTimer;
@ -56,6 +57,7 @@ public:
int testSDLEvents();
QSet<int> activeGamepadButtons();
QSet<QPair<int, GamepadAxisEvent::Direction>> activeGamepadAxes();
void recalibrateAxes();
void bindAxis(uint32_t type, int axis, GamepadAxisEvent::Direction, GBAKey);
@ -84,6 +86,7 @@ private:
static GBASDLEvents s_sdlEvents;
GBASDLPlayer m_sdlPlayer;
bool m_playerAttached;
QVector<int> m_deadzones;
#endif
QSet<int> m_activeButtons;