all repos — mgba @ 6750e7775e1c5d6cf191f05219bfb57f5fff19fe

mGBA Game Boy Advance Emulator

Qt: Rough deadzone estimation
Jeffrey Pfau jeffrey@endrift.com
Fri, 17 Apr 2015 23:55:38 -0700
commit

6750e7775e1c5d6cf191f05219bfb57f5fff19fe

parent

02ecfa684360a458de8477665162fcd394ef2c09

M CHANGESCHANGES

@@ -8,6 +8,7 @@ - More shortcuts are editable (e.g. quick save/load, solar sensor)

- 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
M src/platform/qt/GBAKeyEditor.cppsrc/platform/qt/GBAKeyEditor.cpp

@@ -47,9 +47,10 @@

refresh(); #ifdef BUILD_SDL - lookupAxes(map); + if (type == SDL_BINDING_BUTTON) { + controller->recalibrateAxes(); + lookupAxes(map); - if (type == SDL_BINDING_BUTTON) { m_profileSelect = new QComboBox(this); m_profileSelect->addItems(controller->connectedGamepads(type)); int activeGamepad = controller->gamepad(type);

@@ -61,6 +62,7 @@ connect(m_profileSelect, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [this] (int i) {

m_controller->setGamepad(m_type, i); m_profile = m_profileSelect->currentText(); m_controller->loadProfile(m_type, m_profile); + m_controller->recalibrateAxes(); refresh(); }); }
M src/platform/qt/InputController.cppsrc/platform/qt/InputController.cpp

@@ -226,14 +226,27 @@ }

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 @@ }

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;
M src/platform/qt/InputController.hsrc/platform/qt/InputController.h

@@ -10,6 +10,7 @@ #include "GamepadAxisEvent.h"

#include <QObject> #include <QSet> +#include <QVector> class QTimer;

@@ -56,6 +57,7 @@

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 @@ static int s_sdlInited;

static GBASDLEvents s_sdlEvents; GBASDLPlayer m_sdlPlayer; bool m_playerAttached; + QVector<int> m_deadzones; #endif QSet<int> m_activeButtons;