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.
This commit is contained in:
Vitaliy Margolen 2008-05-03 14:19:57 -06:00 committed by Alexandre Julliard
parent b07ff6ec86
commit bdbc2783a1
1 changed files with 47 additions and 55 deletions

View File

@ -289,70 +289,65 @@ static HRESULT setup_dinput_options(JoystickImpl * device)
if (!device->axis_map) return DIERR_OUTOFMEMORY; if (!device->axis_map) return DIERR_OUTOFMEMORY;
if (!get_config_key( hkey, appkey, device->name, buffer, MAX_PATH )) { 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 = ","; const char *delim = ",";
char * ptr; char * ptr;
TRACE("\"%s\" = \"%s\"\n", device->name, buffer); TRACE("\"%s\" = \"%s\"\n", device->name, buffer);
if ((ptr = strtok(buffer, delim)) != NULL) { if ((ptr = strtok(buffer, delim)) != NULL) {
do { do {
if (strcmp(ptr, "X") == 0) { int i;
device->axis_map[tokens] = 0;
axis++; for (i = 0; i < sizeof(axis_names) / sizeof(axis_names[0]); i++)
} else if (strcmp(ptr, "Y") == 0) { if (!strcmp(ptr, axis_names[i]))
device->axis_map[tokens] = 1; {
axis++; if (!strncmp(ptr, "POV", 3))
} else if (strcmp(ptr, "Z") == 0) { {
device->axis_map[tokens] = 2; if (pov >= 4)
axis++; {
} else if (strcmp(ptr, "Rx") == 0) { WARN("Only 4 POVs supported - ignoring extra\n");
device->axis_map[tokens] = 3; i = -1;
axis++; }
} else if (strcmp(ptr, "Ry") == 0) { else
device->axis_map[tokens] = 4; {
axis++; /* Pov takes two axes */
} else if (strcmp(ptr, "Rz") == 0) { device->axis_map[tokens++] = i;
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++; pov++;
} else if (strcmp(ptr, "POV2") == 0) { }
device->axis_map[tokens++] = 9; }
device->axis_map[tokens] = 9; else
pov++; {
} else if (strcmp(ptr, "POV3") == 0) { if (axis >= 8)
device->axis_map[tokens++] = 10; {
device->axis_map[tokens] = 10; FIXME("Only 8 Axes supported - ignoring extra\n");
pov++; i = -1;
} else if (strcmp(ptr, "POV4") == 0) { }
device->axis_map[tokens++] = 11; else
device->axis_map[tokens] = 11;
pov++;
} else {
ERR("invalid joystick axis type: %s\n", ptr);
device->axis_map[tokens] = tokens;
axis++; 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++; tokens++;
} while ((ptr = strtok(NULL, delim)) != NULL); } 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); ERR("not all joystick axes mapped: %d axes(%d,%d), %d arguments\n", device->axes, axis, pov,tokens);
while (tokens < device->axes) { while (tokens < device->axes) {
device->axis_map[tokens] = tokens; device->axis_map[tokens] = -1;
tokens++; tokens++;
} }
} }
} }
} }
else else
{ {
@ -360,11 +355,13 @@ static HRESULT setup_dinput_options(JoystickImpl * device)
{ {
if (tokens < 8) if (tokens < 8)
device->axis_map[tokens] = axis++; device->axis_map[tokens] = axis++;
else else if (tokens < 16)
{ {
device->axis_map[tokens++] = 8 + pov; device->axis_map[tokens++] = 8 + pov;
device->axis_map[tokens ] = 8 + pov++; device->axis_map[tokens ] = 8 + pov++;
} }
else
device->axis_map[tokens] = -1;
} }
} }
device->devcaps.dwAxes = axis; device->devcaps.dwAxes = axis;
@ -433,13 +430,6 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di
} }
#endif #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) if (newDevice->devcaps.dwButtons > 128)
{ {
WARN("Can't support %d buttons. Clamping down to 128\n", newDevice->devcaps.dwButtons); 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]; int wine_obj = newDevice->axis_map[i];
if (wine_obj < 0) continue;
memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[wine_obj], df->dwObjSize); memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[wine_obj], df->dwObjSize);
if (wine_obj < 8) if (wine_obj < 8)
df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(wine_obj) | DIDFT_ABSAXIS; df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(wine_obj) | DIDFT_ABSAXIS;