|
@@ -64,8 +64,6 @@ void InputSDLWorker::run()
|
|
|
{
|
|
|
QElapsedTimer polltimer;
|
|
|
|
|
|
- QHash<int,int> repeats;
|
|
|
-
|
|
|
while (true)
|
|
|
{
|
|
|
SDL_Event event;
|
|
@@ -85,29 +83,18 @@ void InputSDLWorker::run()
|
|
|
{
|
|
|
QLOG_DEBUG() << "SDL Got button down for button #" << event.jbutton.button
|
|
|
<< " on Joystick #" << event.jbutton.which;
|
|
|
-
|
|
|
- emit receivedInput(nameForId(event.jbutton.which), QString("KEY_BUTTON_%1").arg(event.jbutton.button));
|
|
|
+
|
|
|
+ emit receivedInput(nameForId(event.jbutton.which), QString("KEY_BUTTON_%1").arg(event.jbutton.button, true));
|
|
|
|
|
|
-
|
|
|
- auto repeatTimer = new QElapsedTimer();
|
|
|
- m_buttonTimestamps[event.jbutton.button] = repeatTimer;
|
|
|
- repeatTimer->start();
|
|
|
-
|
|
|
- repeats[event.jbutton.button] = 0;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SDL_JOYBUTTONUP:
|
|
|
{
|
|
|
- if (m_buttonTimestamps[event.jbutton.button])
|
|
|
- {
|
|
|
-
|
|
|
- delete m_buttonTimestamps[event.jbutton.button];
|
|
|
- m_buttonTimestamps.remove(event.jbutton.button);
|
|
|
- }
|
|
|
+ QLOG_DEBUG() << "SDL Got button up for button #" << event.jbutton.button
|
|
|
+ << " on Joystick #" << event.jbutton.which;
|
|
|
|
|
|
-
|
|
|
- repeats[event.jbutton.button] = 0;
|
|
|
+ emit receivedInput(nameForId(event.jbutton.which), QString("KEY_BUTTON_%1").arg(event.jbutton.button), false);
|
|
|
|
|
|
break;
|
|
|
}
|
|
@@ -128,28 +115,6 @@ void InputSDLWorker::run()
|
|
|
|
|
|
case SDL_JOYAXISMOTION:
|
|
|
{
|
|
|
- int deadband = 32768 * 0.15;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (std::abs(event.jaxis.value) > deadband)
|
|
|
- {
|
|
|
-
|
|
|
- float normalizedvalue;
|
|
|
- QString keyname;
|
|
|
- if (event.jaxis.value > 0)
|
|
|
- {
|
|
|
- normalizedvalue = (float)(event.jaxis.value - deadband) / (float)(32767 - deadband);
|
|
|
- keyname = QString("KEY_AXIS_%1_VAL_UP").arg(event.jaxis.axis);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- normalizedvalue = (float)(std::abs(event.jaxis.value) - deadband) / (float)(32768 - deadband);
|
|
|
- keyname = QString("KEY_AXIS_%1_VAL_DOWN").arg(event.jaxis.axis);
|
|
|
- }
|
|
|
-
|
|
|
- emit receivedInput(nameForId(event.jaxis.which), keyname, normalizedvalue);
|
|
|
- }
|
|
|
|
|
|
|
|
|
if (std::abs(event.jaxis.value) > 32768 / 2)
|
|
@@ -159,48 +124,25 @@ void InputSDLWorker::run()
|
|
|
m_axisState[event.jaxis.axis] = 1;
|
|
|
|
|
|
if (event.jaxis.value > 0)
|
|
|
- emit receivedInput(nameForId(event.jaxis.which), QString("KEY_AXIS_%1_UP").arg(event.jaxis.axis));
|
|
|
+ emit receivedInput(nameForId(event.jaxis.which), QString("KEY_AXIS_%1_UP").arg(event.jaxis.axis), true);
|
|
|
else
|
|
|
- emit receivedInput(nameForId(event.jaxis.which), QString("KEY_AXIS_%1_DOWN").arg(event.jaxis.axis));
|
|
|
-
|
|
|
- break;
|
|
|
+ emit receivedInput(nameForId(event.jaxis.which), QString("KEY_AXIS_%1_DOWN").arg(event.jaxis.axis), true);
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (m_axisState[event.jaxis.axis])
|
|
|
+ {
|
|
|
+ emit receivedInput(nameForId(event.jaxis.which), QString("KEY_AXIS_%1_UP").arg(event.jaxis.axis), false);
|
|
|
+ emit receivedInput(nameForId(event.jaxis.which), QString("KEY_AXIS_%1_DOWN").arg(event.jaxis.axis), false);
|
|
|
+ }
|
|
|
|
|
|
- m_axisState[event.jaxis.axis] = 0;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- SDLTimeStampMapIterator it = m_buttonTimestamps.constBegin();
|
|
|
- while (it != m_buttonTimestamps.constEnd())
|
|
|
- {
|
|
|
- if (it.value())
|
|
|
- {
|
|
|
-
|
|
|
- if (repeats[it.key()] > 0 && m_buttonTimestamps[it.key()]->elapsed() > SDL_BUTTON_REPEAT_RATE)
|
|
|
- {
|
|
|
- QLOG_DEBUG() << QString("SDL Got button repeat(%1) for button #").arg(repeats[it.key()]) << event.jbutton.button
|
|
|
- << " on Joystick #" << event.jbutton.which;
|
|
|
- emit receivedInput(nameForId(event.jbutton.which), QString("KEY_BUTTON_%1").arg(it.key()));
|
|
|
-
|
|
|
- m_buttonTimestamps[it.key()]->restart();
|
|
|
- it = m_buttonTimestamps.constBegin();
|
|
|
+ m_axisState[event.jaxis.axis] = 0;
|
|
|
+ }
|
|
|
|
|
|
- repeats[it.key()]++;
|
|
|
- continue;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
-
|
|
|
- if (m_buttonTimestamps[it.key()]->elapsed() > SDL_BUTTON_REPEAT_DELAY)
|
|
|
- repeats[it.key()]++;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- it++;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -222,7 +164,6 @@ void InputSDLWorker::refreshJoystickList()
|
|
|
}
|
|
|
|
|
|
m_joysticks.clear();
|
|
|
- m_buttonTimestamps.clear();
|
|
|
|
|
|
|
|
|
int numJoysticks = SDL_NumJoysticks();
|