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,9 +346,9 @@ void inputUpdate() {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_KEYUP: {
|
||||
int scancode = event.key.keysym.scancode;
|
||||
InputKey key = codeToInputKey(scancode);
|
||||
@@ -357,7 +357,8 @@ void inputUpdate() {
|
||||
}
|
||||
break;
|
||||
}
|
||||
// Joystick reading using the modern GameController interface
|
||||
|
||||
// Joystick reading using the modern SDL GameController interface
|
||||
case SDL_CONTROLLERBUTTONDOWN: {
|
||||
joyIndex = joyGetIndex(event.cbutton.which);
|
||||
JoyKey key = controllerCodeToJoyKey(event.cbutton.button);
|
||||
@@ -370,6 +371,7 @@ void inputUpdate() {
|
||||
Input::setJoyDown(joyIndex, key, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_CONTROLLERAXISMOTION: {
|
||||
joyIndex = joyGetIndex(event.caxis.which);
|
||||
switch (event.caxis.axis) {
|
||||
@@ -382,7 +384,34 @@ void inputUpdate() {
|
||||
Input::setJoyPos(joyIndex, jkR, joyDir(joyR));
|
||||
break;
|
||||
}
|
||||
// Joystick reading using the classic Joystick interface
|
||||
|
||||
// GameController connection or disconnection
|
||||
case SDL_CONTROLLERDEVICEADDED: {
|
||||
// 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.cdevice.which);
|
||||
break;
|
||||
}
|
||||
case SDL_CONTROLLERDEVICEREMOVED: {
|
||||
joyRemove(event.cdevice.which);
|
||||
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);
|
||||
@@ -397,7 +426,8 @@ void inputUpdate() {
|
||||
}
|
||||
case SDL_JOYAXISMOTION: {
|
||||
joyIndex = joyGetIndex(event.jaxis.which);
|
||||
switch (event.jaxis.axis) {
|
||||
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;
|
||||
@@ -409,8 +439,9 @@ void inputUpdate() {
|
||||
Input::setJoyPos(joyIndex, jkR, joyDir(joyR));
|
||||
break;
|
||||
}
|
||||
|
||||
// Joystick connection or disconnection
|
||||
case SDL_JOYDEVICEADDED : {
|
||||
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,
|
||||
@@ -418,10 +449,13 @@ void inputUpdate() {
|
||||
joyAdd(event.jdevice.which);
|
||||
break;
|
||||
}
|
||||
case SDL_JOYDEVICEREMOVED : {
|
||||
case SDL_JOYDEVICEREMOVED: {
|
||||
joyRemove(event.jdevice.which);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user