Skip to content

Commit

Permalink
Don't count the Android accelerometer as an input device.
Browse files Browse the repository at this point in the history
SDL uses the joystick interface to expose the functionality of the
accelerometer on Android devices. Since the accelerometer is not
actually a joystick/controller, blacklist it from being counted as an
input device.
  • Loading branch information
Plombo committed Jul 19, 2021
1 parent e198aef commit f7d2b99
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions engine/sdl/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,27 @@ void control_init()
numJoysticks = MAX_DEVICES - 1;
}

int joystickCount = 0;
for (int i = 0; i < numJoysticks; i++)
{
setup_joystick(i, i);
// blacklist the Android accelerometer that SDL counts as a "joystick"
if (0 == stricmp("Android Accelerometer", SDL_JoystickNameForIndex(i)))
{
continue;
}

setup_joystick(joystickCount, i);
joystickCount++;
}

keyboardDeviceID = numJoysticks;
devices[numJoysticks].deviceType = DEVICE_TYPE_KEYBOARD;
keyboardDeviceID = joystickCount;
devices[joystickCount].deviceType = DEVICE_TYPE_KEYBOARD;
#ifdef ANDROID
snprintf(devices[numJoysticks].name, sizeof(devices[numJoysticks].name), "%s", "On-Screen Controller");
snprintf(devices[joystickCount].name, sizeof(devices[joystickCount].name), "%s", "On-Screen Controller");
#else
snprintf(devices[numJoysticks].name, sizeof(devices[numJoysticks].name), "%s", "Keyboard");
snprintf(devices[joystickCount].name, sizeof(devices[joystickCount].name), "%s", "Keyboard");
#endif
load_from_saved_mapping(numJoysticks);
load_from_saved_mapping(joystickCount);

#ifdef ANDROID
for (int i = 0; i < MAX_POINTERS; i++)
Expand Down

0 comments on commit f7d2b99

Please sign in to comment.