more accurate gamepad deadzone detection

This commit is contained in:
SerpentSpirale
2021-05-24 18:49:02 +02:00
committed by SerpentSpirale
parent e77499778f
commit ee00a737d4
2 changed files with 3 additions and 20 deletions

View File

@@ -592,7 +592,7 @@ public class BaseMainActivity extends LoggableActivity {
if(Gamepad.isGamepadEvent(ev)){
if(gamepad == null){
gamepad = new Gamepad(this, Tools.grabFirstGamepad());
gamepad = new Gamepad(this, ev.getDevice());
}
gamepad.update(ev);
@@ -644,7 +644,7 @@ public class BaseMainActivity extends LoggableActivity {
if(Gamepad.isGamepadEvent(event)){
if(gamepad == null){
gamepad = new Gamepad(this, Tools.grabFirstGamepad());
gamepad = new Gamepad(this, event.getDevice());
}
gamepad.update(event);

View File

@@ -872,22 +872,5 @@ public final class Tools {
Tools.updateWindowSize(ctx);
}
}
public static InputDevice grabFirstGamepad() {
int[] deviceIds = InputDevice.getDeviceIds();
for (int deviceId : deviceIds) {
InputDevice dev = InputDevice.getDevice(deviceId);
int sources = dev.getSources();
// Verify that the device has gamepad buttons, control sticks, or both.
if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|| ((sources & InputDevice.SOURCE_JOYSTICK)
== InputDevice.SOURCE_JOYSTICK)) {
// This device is a game controller. Store its device ID.
return dev;
}
}
return null;
}
}