From bdbc2783a1b23b80658c74167986cf8cf9538187 Mon Sep 17 00:00:00 2001 From: Vitaliy Margolen Date: Sat, 3 May 2008 14:19:57 -0600 Subject: [PATCH] dinput: Limit number of axes in a different way - map all extra axes to -1. We can't stop device from sending us extra axes so have to keep axes mapping around for them. --- dlls/dinput/joystick_linux.c | 102 ++++++++++++++++------------------- 1 file changed, 47 insertions(+), 55 deletions(-) diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c index bfb8ba0c5c2..a15139035d4 100644 --- a/dlls/dinput/joystick_linux.c +++ b/dlls/dinput/joystick_linux.c @@ -289,70 +289,65 @@ static HRESULT setup_dinput_options(JoystickImpl * device) if (!device->axis_map) return DIERR_OUTOFMEMORY; if (!get_config_key( hkey, appkey, device->name, buffer, MAX_PATH )) { + static const char *axis_names[] = {"X", "Y", "Z", "Rx", "Ry", "Rz", + "Slider1", "Slider2", + "POV1", "POV2", "POV3", "POV4"}; const char *delim = ","; char * ptr; TRACE("\"%s\" = \"%s\"\n", device->name, buffer); if ((ptr = strtok(buffer, delim)) != NULL) { do { - if (strcmp(ptr, "X") == 0) { - device->axis_map[tokens] = 0; - axis++; - } else if (strcmp(ptr, "Y") == 0) { - device->axis_map[tokens] = 1; - axis++; - } else if (strcmp(ptr, "Z") == 0) { - device->axis_map[tokens] = 2; - axis++; - } else if (strcmp(ptr, "Rx") == 0) { - device->axis_map[tokens] = 3; - axis++; - } else if (strcmp(ptr, "Ry") == 0) { - device->axis_map[tokens] = 4; - axis++; - } else if (strcmp(ptr, "Rz") == 0) { - device->axis_map[tokens] = 5; - axis++; - } else if (strcmp(ptr, "Slider1") == 0) { - device->axis_map[tokens] = 6; - axis++; - } else if (strcmp(ptr, "Slider2") == 0) { - device->axis_map[tokens] = 7; - axis++; - } else if (strcmp(ptr, "POV1") == 0) { - device->axis_map[tokens++] = 8; - device->axis_map[tokens] = 8; - pov++; - } else if (strcmp(ptr, "POV2") == 0) { - device->axis_map[tokens++] = 9; - device->axis_map[tokens] = 9; - pov++; - } else if (strcmp(ptr, "POV3") == 0) { - device->axis_map[tokens++] = 10; - device->axis_map[tokens] = 10; - pov++; - } else if (strcmp(ptr, "POV4") == 0) { - device->axis_map[tokens++] = 11; - device->axis_map[tokens] = 11; - pov++; - } else { - ERR("invalid joystick axis type: %s\n", ptr); - device->axis_map[tokens] = tokens; - axis++; + int i; + + for (i = 0; i < sizeof(axis_names) / sizeof(axis_names[0]); i++) + if (!strcmp(ptr, axis_names[i])) + { + if (!strncmp(ptr, "POV", 3)) + { + if (pov >= 4) + { + WARN("Only 4 POVs supported - ignoring extra\n"); + i = -1; + } + else + { + /* Pov takes two axes */ + device->axis_map[tokens++] = i; + pov++; + } + } + else + { + if (axis >= 8) + { + FIXME("Only 8 Axes supported - ignoring extra\n"); + i = -1; + } + else + axis++; + } + break; + } + + if (i == sizeof(axis_names) / sizeof(axis_names[0])) + { + ERR("invalid joystick axis type: \"%s\"\n", ptr); + i = -1; } + device->axis_map[tokens] = i; tokens++; } while ((ptr = strtok(NULL, delim)) != NULL); - if (tokens != device->devcaps.dwAxes) { + if (tokens != device->axes) { ERR("not all joystick axes mapped: %d axes(%d,%d), %d arguments\n", device->axes, axis, pov,tokens); while (tokens < device->axes) { - device->axis_map[tokens] = tokens; + device->axis_map[tokens] = -1; tokens++; } } } - } else { @@ -360,11 +355,13 @@ static HRESULT setup_dinput_options(JoystickImpl * device) { if (tokens < 8) device->axis_map[tokens] = axis++; - else + else if (tokens < 16) { device->axis_map[tokens++] = 8 + pov; device->axis_map[tokens ] = 8 + pov++; } + else + device->axis_map[tokens] = -1; } } device->devcaps.dwAxes = axis; @@ -433,13 +430,6 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di } #endif - if (newDevice->axes > 16) - { - /* There are 24 more axes for velocity that we can use */ - FIXME("Can't support %d axes. Clamping down to 16\n", newDevice->axes); - newDevice->axes = 16; - } - if (newDevice->devcaps.dwButtons > 128) { WARN("Can't support %d buttons. Clamping down to 128\n", newDevice->devcaps.dwButtons); @@ -472,6 +462,8 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di { int wine_obj = newDevice->axis_map[i]; + if (wine_obj < 0) continue; + memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[wine_obj], df->dwObjSize); if (wine_obj < 8) df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(wine_obj) | DIDFT_ABSAXIS;