mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-09 06:36:59 +02:00
SDL2 platform: Rewrite inputUpdate() so joystick/gamecontroller inputs are NOT processed as both joystick AND gamecontroller inputs, since that causes major input problems. (#276)
This commit is contained in:
committed by
GitHub
parent
8cc844e9ea
commit
af08ce9cdc
@@ -346,31 +346,33 @@ void inputUpdate() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
case SDL_KEYUP: {
|
case SDL_KEYUP: {
|
||||||
int scancode = event.key.keysym.scancode;
|
int scancode = event.key.keysym.scancode;
|
||||||
InputKey key = codeToInputKey(scancode);
|
InputKey key = codeToInputKey(scancode);
|
||||||
if (key != ikNone) {
|
if (key != ikNone) {
|
||||||
Input::setDown(key, 0);
|
Input::setDown(key, 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Joystick reading using the modern GameController interface
|
|
||||||
case SDL_CONTROLLERBUTTONDOWN: {
|
// Joystick reading using the modern SDL GameController interface
|
||||||
joyIndex = joyGetIndex(event.cbutton.which);
|
case SDL_CONTROLLERBUTTONDOWN: {
|
||||||
JoyKey key = controllerCodeToJoyKey(event.cbutton.button);
|
joyIndex = joyGetIndex(event.cbutton.which);
|
||||||
Input::setJoyDown(joyIndex, key, 1);
|
JoyKey key = controllerCodeToJoyKey(event.cbutton.button);
|
||||||
break;
|
Input::setJoyDown(joyIndex, key, 1);
|
||||||
}
|
break;
|
||||||
case SDL_CONTROLLERBUTTONUP: {
|
}
|
||||||
joyIndex = joyGetIndex(event.cbutton.which);
|
case SDL_CONTROLLERBUTTONUP: {
|
||||||
JoyKey key = controllerCodeToJoyKey(event.cbutton.button);
|
joyIndex = joyGetIndex(event.cbutton.which);
|
||||||
Input::setJoyDown(joyIndex, key, 0);
|
JoyKey key = controllerCodeToJoyKey(event.cbutton.button);
|
||||||
break;
|
Input::setJoyDown(joyIndex, key, 0);
|
||||||
}
|
break;
|
||||||
case SDL_CONTROLLERAXISMOTION: {
|
}
|
||||||
|
|
||||||
|
case SDL_CONTROLLERAXISMOTION: {
|
||||||
joyIndex = joyGetIndex(event.caxis.which);
|
joyIndex = joyGetIndex(event.caxis.which);
|
||||||
switch (event.caxis.axis) {
|
switch (event.caxis.axis) {
|
||||||
case SDL_CONTROLLER_AXIS_LEFTX: joyL.x = joyAxisValue(event.caxis.value); break;
|
case SDL_CONTROLLER_AXIS_LEFTX: joyL.x = joyAxisValue(event.caxis.value); break;
|
||||||
@@ -381,49 +383,81 @@ void inputUpdate() {
|
|||||||
Input::setJoyPos(joyIndex, jkL, joyDir(joyL));
|
Input::setJoyPos(joyIndex, jkL, joyDir(joyL));
|
||||||
Input::setJoyPos(joyIndex, jkR, joyDir(joyR));
|
Input::setJoyPos(joyIndex, jkR, joyDir(joyR));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Joystick reading using the classic Joystick interface
|
|
||||||
case SDL_JOYBUTTONDOWN: {
|
// GameController connection or disconnection
|
||||||
joyIndex = joyGetIndex(event.jbutton.which);
|
case SDL_CONTROLLERDEVICEADDED: {
|
||||||
JoyKey key = joyCodeToJoyKey(event.jbutton.button);
|
|
||||||
Input::setJoyDown(joyIndex, key, 1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SDL_JOYBUTTONUP: {
|
|
||||||
joyIndex = joyGetIndex(event.jbutton.which);
|
|
||||||
JoyKey key = joyCodeToJoyKey(event.jbutton.button);
|
|
||||||
Input::setJoyDown(joyIndex, key, 0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SDL_JOYAXISMOTION: {
|
|
||||||
joyIndex = joyGetIndex(event.jaxis.which);
|
|
||||||
switch (event.jaxis.axis) {
|
|
||||||
// In the classic joystick interface we know what axis changed by it's number,
|
|
||||||
// they have no names like on the fancy GameController interface.
|
|
||||||
case 0: joyL.x = joyAxisValue(event.jaxis.value); break;
|
|
||||||
case 1: joyL.y = joyAxisValue(event.jaxis.value); break;
|
|
||||||
case 2: joyR.x = joyAxisValue(event.jaxis.value); break;
|
|
||||||
case 3: joyR.y = joyAxisValue(event.jaxis.value); break;
|
|
||||||
}
|
|
||||||
Input::setJoyPos(joyIndex, jkL, joyDir(joyL));
|
|
||||||
Input::setJoyPos(joyIndex, jkR, joyDir(joyR));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// Joystick connection or disconnection
|
|
||||||
case SDL_JOYDEVICEADDED : {
|
|
||||||
// Upon connection, 'which' is the internal SDL2 joystick index,
|
// Upon connection, 'which' is the internal SDL2 joystick index,
|
||||||
// but on disconnection, 'which' is the instanceID.
|
// but on disconnection, 'which' is the instanceID.
|
||||||
// We store the joysticks in their corresponding position on the joysticks array,
|
// We store the joysticks in their corresponding position on the joysticks array,
|
||||||
// IE: joystick with index 3 will be in sdl_joysticks[3].
|
// IE: joystick with index 3 will be in sdl_joysticks[3].
|
||||||
joyAdd(event.jdevice.which);
|
joyAdd(event.cdevice.which);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SDL_JOYDEVICEREMOVED : {
|
case SDL_CONTROLLERDEVICEREMOVED: {
|
||||||
joyRemove(event.jdevice.which);
|
joyRemove(event.cdevice.which);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
// Joystick reading using the old SDL Joystick interface
|
||||||
}
|
case SDL_JOYBUTTONDOWN:
|
||||||
|
case SDL_JOYBUTTONUP:
|
||||||
|
case SDL_JOYAXISMOTION:
|
||||||
|
case SDL_JOYDEVICEADDED:
|
||||||
|
case SDL_JOYDEVICEREMOVED:
|
||||||
|
// Only handle the event if the joystick is incompatible with the SDL_GameController interface.
|
||||||
|
// (Otherwise it will interfere with the normal action of the SDL_GameController API, because
|
||||||
|
// the event is both a GameController event AND a Joystick event.)
|
||||||
|
if (SDL_IsGameController(joyIndex)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (event.type) {
|
||||||
|
case SDL_JOYBUTTONDOWN: {
|
||||||
|
joyIndex = joyGetIndex(event.jbutton.which);
|
||||||
|
JoyKey key = joyCodeToJoyKey(event.jbutton.button);
|
||||||
|
Input::setJoyDown(joyIndex, key, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SDL_JOYBUTTONUP: {
|
||||||
|
joyIndex = joyGetIndex(event.jbutton.which);
|
||||||
|
JoyKey key = joyCodeToJoyKey(event.jbutton.button);
|
||||||
|
Input::setJoyDown(joyIndex, key, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SDL_JOYAXISMOTION: {
|
||||||
|
joyIndex = joyGetIndex(event.jaxis.which);
|
||||||
|
switch (event.jaxis.axis)
|
||||||
|
{
|
||||||
|
// In the classic joystick interface we know what axis changed by it's number,
|
||||||
|
// they have no names like on the fancy GameController interface.
|
||||||
|
case 0: joyL.x = joyAxisValue(event.jaxis.value); break;
|
||||||
|
case 1: joyL.y = joyAxisValue(event.jaxis.value); break;
|
||||||
|
case 2: joyR.x = joyAxisValue(event.jaxis.value); break;
|
||||||
|
case 3: joyR.y = joyAxisValue(event.jaxis.value); break;
|
||||||
|
}
|
||||||
|
Input::setJoyPos(joyIndex, jkL, joyDir(joyL));
|
||||||
|
Input::setJoyPos(joyIndex, jkR, joyDir(joyR));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Joystick connection or disconnection
|
||||||
|
case SDL_JOYDEVICEADDED: {
|
||||||
|
// Upon connection, 'which' is the internal SDL2 joystick index,
|
||||||
|
// but on disconnection, 'which' is the instanceID.
|
||||||
|
// We store the joysticks in their corresponding position on the joysticks array,
|
||||||
|
// IE: joystick with index 3 will be in sdl_joysticks[3].
|
||||||
|
joyAdd(event.jdevice.which);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SDL_JOYDEVICEREMOVED: {
|
||||||
|
joyRemove(event.jdevice.which);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
Reference in New Issue
Block a user