Don't assume device IDs won't collide.

This commit is contained in:
Themaister 2013-01-02 19:14:08 +01:00
parent 4b18244c84
commit ef5b656f23
1 changed files with 10 additions and 10 deletions

View File

@ -33,8 +33,8 @@
#define MAX_DEVICE_IDS 50 #define MAX_DEVICE_IDS 50
static unsigned pads_connected; static unsigned pads_connected;
static int state_device_ids[MAX_DEVICE_IDS];
static uint64_t state[MAX_PADS]; static uint64_t state[MAX_PADS];
static int8_t state_device_ids[MAX_DEVICE_IDS];
struct input_pointer struct input_pointer
{ {
@ -75,11 +75,7 @@ static void *android_input_init(void)
g_settings.input.binds[player][RETRO_DEVICE_ID_JOYPAD_R3].joykey = (1ULL << RETRO_DEVICE_ID_JOYPAD_R3); g_settings.input.binds[player][RETRO_DEVICE_ID_JOYPAD_R3].joykey = (1ULL << RETRO_DEVICE_ID_JOYPAD_R3);
} }
for(int i = 0; i < MAX_DEVICE_IDS; i++)
state_device_ids[i] = -1;
input_autodetect_init(); input_autodetect_init();
return (void*)-1; return (void*)-1;
} }
@ -107,13 +103,17 @@ static void android_input_poll(void *data)
int source = AInputEvent_getSource(event); int source = AInputEvent_getSource(event);
int id = AInputEvent_getDeviceId(event); int id = AInputEvent_getDeviceId(event);
int type_event = AInputEvent_getType(event); int type_event = AInputEvent_getType(event);
int state_id = state_device_ids[id]; int state_id = -1;
if(state_id == -1) for (unsigned i = 0; i < pads_connected; i++)
if (state_device_ids[i] == id)
state_id = i;
if (state_id < 0)
{ {
state_id = state_device_ids[id] = pads_connected++; state_id = pads_connected;
state_device_ids[pads_connected++] = id;
input_autodetect_setup(state_id, id, source); input_autodetect_setup(state_id, id, source);
} }