mirror of https://github.com/mgba-emu/mgba.git
Qt: Rough deadzone estimation
This commit is contained in:
parent
02ecfa6843
commit
6750e7775e
1
CHANGES
1
CHANGES
|
@ -8,6 +8,7 @@ Features:
|
||||||
- Rewind now shows the frame after rewinding
|
- Rewind now shows the frame after rewinding
|
||||||
- Import/Export of GameShark/Action Replay snapshots
|
- Import/Export of GameShark/Action Replay snapshots
|
||||||
- Add "Step backwards" item for single increment rewind
|
- Add "Step backwards" item for single increment rewind
|
||||||
|
- Deadzone estimation for game controllers
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
- GBA: Fix timers not updating timing when writing to only the reload register
|
- GBA: Fix timers not updating timing when writing to only the reload register
|
||||||
- All: Fix sanitize-deb script not cleaning up after itself
|
- All: Fix sanitize-deb script not cleaning up after itself
|
||||||
|
|
|
@ -47,9 +47,10 @@ GBAKeyEditor::GBAKeyEditor(InputController* controller, int type, const QString&
|
||||||
refresh();
|
refresh();
|
||||||
|
|
||||||
#ifdef BUILD_SDL
|
#ifdef BUILD_SDL
|
||||||
|
if (type == SDL_BINDING_BUTTON) {
|
||||||
|
controller->recalibrateAxes();
|
||||||
lookupAxes(map);
|
lookupAxes(map);
|
||||||
|
|
||||||
if (type == SDL_BINDING_BUTTON) {
|
|
||||||
m_profileSelect = new QComboBox(this);
|
m_profileSelect = new QComboBox(this);
|
||||||
m_profileSelect->addItems(controller->connectedGamepads(type));
|
m_profileSelect->addItems(controller->connectedGamepads(type));
|
||||||
int activeGamepad = controller->gamepad(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_controller->setGamepad(m_type, i);
|
||||||
m_profile = m_profileSelect->currentText();
|
m_profile = m_profileSelect->currentText();
|
||||||
m_controller->loadProfile(m_type, m_profile);
|
m_controller->loadProfile(m_type, m_profile);
|
||||||
|
m_controller->recalibrateAxes();
|
||||||
refresh();
|
refresh();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,14 +226,27 @@ QSet<int> InputController::activeGamepadButtons() {
|
||||||
return activeButtons;
|
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() {
|
QSet<QPair<int, GamepadAxisEvent::Direction>> InputController::activeGamepadAxes() {
|
||||||
SDL_Joystick* joystick = m_sdlPlayer.joystick;
|
SDL_Joystick* joystick = m_sdlPlayer.joystick;
|
||||||
SDL_JoystickUpdate();
|
SDL_JoystickUpdate();
|
||||||
int numButtons = SDL_JoystickNumAxes(joystick);
|
int numAxes = SDL_JoystickNumAxes(joystick);
|
||||||
|
m_deadzones.resize(numAxes);
|
||||||
QSet<QPair<int, GamepadAxisEvent::Direction>> activeAxes;
|
QSet<QPair<int, GamepadAxisEvent::Direction>> activeAxes;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < numButtons; ++i) {
|
for (i = 0; i < numAxes; ++i) {
|
||||||
int32_t axis = SDL_JoystickGetAxis(joystick, i);
|
int32_t axis = SDL_JoystickGetAxis(joystick, i);
|
||||||
|
axis -= m_deadzones[i];
|
||||||
if (axis >= AXIS_THRESHOLD || axis <= -AXIS_THRESHOLD) {
|
if (axis >= AXIS_THRESHOLD || axis <= -AXIS_THRESHOLD) {
|
||||||
activeAxes.insert(qMakePair(i, axis > 0 ? GamepadAxisEvent::POSITIVE : GamepadAxisEvent::NEGATIVE));
|
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) {
|
switch (direction) {
|
||||||
case GamepadAxisEvent::NEGATIVE:
|
case GamepadAxisEvent::NEGATIVE:
|
||||||
description.lowDirection = key;
|
description.lowDirection = key;
|
||||||
description.deadLow = -AXIS_THRESHOLD;
|
description.deadLow = m_deadzones[axis] - AXIS_THRESHOLD;
|
||||||
break;
|
break;
|
||||||
case GamepadAxisEvent::POSITIVE:
|
case GamepadAxisEvent::POSITIVE:
|
||||||
description.highDirection = key;
|
description.highDirection = key;
|
||||||
description.deadHigh = AXIS_THRESHOLD;
|
description.deadHigh = m_deadzones[axis] + AXIS_THRESHOLD;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
class QTimer;
|
class QTimer;
|
||||||
|
|
||||||
|
@ -56,6 +57,7 @@ public:
|
||||||
int testSDLEvents();
|
int testSDLEvents();
|
||||||
QSet<int> activeGamepadButtons();
|
QSet<int> activeGamepadButtons();
|
||||||
QSet<QPair<int, GamepadAxisEvent::Direction>> activeGamepadAxes();
|
QSet<QPair<int, GamepadAxisEvent::Direction>> activeGamepadAxes();
|
||||||
|
void recalibrateAxes();
|
||||||
|
|
||||||
void bindAxis(uint32_t type, int axis, GamepadAxisEvent::Direction, GBAKey);
|
void bindAxis(uint32_t type, int axis, GamepadAxisEvent::Direction, GBAKey);
|
||||||
|
|
||||||
|
@ -84,6 +86,7 @@ private:
|
||||||
static GBASDLEvents s_sdlEvents;
|
static GBASDLEvents s_sdlEvents;
|
||||||
GBASDLPlayer m_sdlPlayer;
|
GBASDLPlayer m_sdlPlayer;
|
||||||
bool m_playerAttached;
|
bool m_playerAttached;
|
||||||
|
QVector<int> m_deadzones;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QSet<int> m_activeButtons;
|
QSet<int> m_activeButtons;
|
||||||
|
|
Loading…
Reference in New Issue