fix scrambeled axis/buttons indices

This commit is contained in:
Mathias Panzenböck
2016-04-03 00:20:59 +02:00
parent 5af554723d
commit 017f2229ce
6 changed files with 19 additions and 15 deletions

View File

@ -57,13 +57,14 @@ class Axis : public QObject {
//recalculates the gradient curve. This should be run every time
//maxSpeed, xZone, or dZone are changed.
void adjustGradient();
int axisIndex() const { return index; }
protected:
int tick;
//This axis is logically depressed (positive or negative)
//if the axis is gradient, this is true even if it is not
//currently generating a keypress at the instant.
bool isOn;
//which joystick this actually is
//the index of this axis on the joystick
int index;
//actually sends key events. Press is true iff the key
//is to be depressed as opposed to released.

View File

@ -36,6 +36,7 @@ class Button : public QObject {
void setKey(bool mouse, int value);
//happens every MSEC (constant.h) milliseconds
void timerTick( int tick );
int buttonIndex() const { return index; }
protected:
//true iff this button is physically depressed.
bool isButtonPressed;

View File

@ -23,6 +23,6 @@ inline void debug_mesg(const char *fmt, ...) {
}
#else
inline void debug_mesg(...) {}
#define debug_mesg(...)
#define debug_mesg(...) {}
#endif
#endif

View File

@ -86,11 +86,11 @@ void JoyPad::open(int dev) {
//have a real joystick axis mapped to it, and this function suddenly brings
//that axis into use, the key assignment will not be lost because the axis
//will already exist and no new axis will be created.
for (int i = 0; i < axisCount; i++) {
if (axes[i] == 0) axes.insert(i, new Axis( i, this ));
for (int i = axes.size(); i < axisCount; i++) {
axes.append(new Axis( i, this ));
}
for (int i = 0; i < buttonCount; i++) {
if (buttons[i] == 0) buttons.insert(i, new Button( i, this ));
for (int i = buttons.size(); i < buttonCount; i++) {
buttons.append(new Button( i, this ));
}
debug_mesg("Setting up joyDeviceListeners\n");
readNotifier = new QSocketNotifier(joydev, QSocketNotifier::Read, this);
@ -235,14 +235,14 @@ void JoyPad::jsevent(const js_event &msg) {
if (type == JS_EVENT_AXIS) {
debug_mesg("DEBUG: passing on an axis event\n");
debug_mesg("DEBUG: %d %d\n", msg.number, msg.value);
Axis *axis = axes[msg.number];
if (axis) axis->jsevent(msg.value);
if (msg.number < axes.size()) axes[msg.number]->jsevent(msg.value);
else debug_mesg("DEBUG: axis index out of range: %d\n", msg.value);
}
else if (type == JS_EVENT_BUTTON) {
debug_mesg("DEBUG: passing on a button event\n");
debug_mesg("DEBUG: %d %d\n", msg.number, msg.value);
Button *button = buttons[msg.number];
if (button) button->jsevent(msg.value);
if (msg.number < buttons.size()) buttons[msg.number]->jsevent(msg.value);
else debug_mesg("DEBUG: button index out of range: %d\n", msg.value);
}
}

View File

@ -12,7 +12,7 @@
#include "error.h"
#include <QTextStream>
#include <QHash>
#include <QList>
#include <QSocketNotifier>
class JoyPadWidget;
@ -63,8 +63,8 @@ class JoyPad : public QObject {
//layouts with different numbers of axes/buttons than the current
//devices. Note that with the current layout settings, the defined
//buttons that don't actually exist on the device may not be contiguous.
QHash<int, Axis*> axes;
QHash<int, Button*> buttons;
QList<Axis*> axes;
QList<Button*> buttons;
//the index of this device (devicenum)
int index;

View File

@ -91,10 +91,12 @@ void JoyPadWidget::jsevent( const js_event& msg ) {
//other than a flash :)
unsigned int type = msg.type & ~JS_EVENT_INIT;
if (type == JS_EVENT_AXIS) {
if (msg.number < axes.count()) axes[msg.number]->jsevent(msg.value);
if (msg.number < axes.size()) axes[msg.number]->jsevent(msg.value);
else debug_mesg("DEBUG: axis index out of range: %d\n", msg.value);
}
else if (type == JS_EVENT_BUTTON) {
if (msg.number < buttons.count()) buttons[msg.number]->jsevent(msg.value);
if (msg.number < buttons.size()) buttons[msg.number]->jsevent(msg.value);
else debug_mesg("DEBUG: button index out of range: %d\n", msg.value);
}
//if we're doing quickset, it needs to know when we do something.
if (quickset != NULL) {