Commit 736d03c8 authored by Vitaliy Margolen's avatar Vitaliy Margolen Committed by Alexandre Julliard

dinput: Fix default axes mapping generation.

parent 67a7a8a8
...@@ -271,6 +271,9 @@ static HRESULT setup_dinput_options(JoystickImpl * device) ...@@ -271,6 +271,9 @@ static HRESULT setup_dinput_options(JoystickImpl * device)
{ {
char buffer[MAX_PATH+16]; char buffer[MAX_PATH+16];
HKEY hkey, appkey; HKEY hkey, appkey;
int tokens = 0;
int axis = 0;
int pov = 0;
buffer[MAX_PATH]='\0'; buffer[MAX_PATH]='\0';
...@@ -283,18 +286,14 @@ static HRESULT setup_dinput_options(JoystickImpl * device) ...@@ -283,18 +286,14 @@ static HRESULT setup_dinput_options(JoystickImpl * device)
TRACE("setting default deadzone to: \"%s\" %d\n", buffer, device->deadzone); TRACE("setting default deadzone to: \"%s\" %d\n", buffer, device->deadzone);
} }
device->axis_map = HeapAlloc(GetProcessHeap(), 0, device->axes * sizeof(int));
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 )) {
int tokens = 0;
int axis = 0;
int pov = 0;
const char *delim = ","; const char *delim = ",";
char * ptr; char * ptr;
TRACE("\"%s\" = \"%s\"\n", device->name, buffer); TRACE("\"%s\" = \"%s\"\n", device->name, buffer);
device->axis_map = HeapAlloc(GetProcessHeap(), 0, device->axes * sizeof(int));
if (device->axis_map == 0)
return DIERR_OUTOFMEMORY;
if ((ptr = strtok(buffer, delim)) != NULL) { if ((ptr = strtok(buffer, delim)) != NULL) {
do { do {
if (strcmp(ptr, "X") == 0) { if (strcmp(ptr, "X") == 0) {
...@@ -355,9 +354,22 @@ static HRESULT setup_dinput_options(JoystickImpl * device) ...@@ -355,9 +354,22 @@ static HRESULT setup_dinput_options(JoystickImpl * device)
} }
} }
device->devcaps.dwAxes = axis;
device->devcaps.dwPOVs = pov;
} }
else
{
for (tokens = 0; tokens < device->axes; tokens++)
{
if (tokens < 8)
device->axis_map[tokens] = axis++;
else
{
device->axis_map[tokens ] = 8 + pov;
device->axis_map[tokens++] = 8 + pov++;
}
}
}
device->devcaps.dwAxes = axis;
device->devcaps.dwPOVs = pov;
if (appkey) if (appkey)
RegCloseKey( appkey ); RegCloseKey( appkey );
...@@ -445,29 +457,17 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di ...@@ -445,29 +457,17 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di
/* setup_dinput_options may change these */ /* setup_dinput_options may change these */
newDevice->deadzone = 0; newDevice->deadzone = 0;
newDevice->devcaps.dwButtons = newDevice->buttons; newDevice->devcaps.dwButtons = newDevice->buttons;
newDevice->devcaps.dwAxes = newDevice->axes;
newDevice->devcaps.dwPOVs = 0;
/* do any user specified configuration */ /* do any user specified configuration */
hr = setup_dinput_options(newDevice); hr = setup_dinput_options(newDevice);
if (hr != DI_OK) if (hr != DI_OK)
goto FAILED1; goto FAILED1;
if (newDevice->axis_map == 0) {
newDevice->axis_map = HeapAlloc(GetProcessHeap(), 0, newDevice->axes * sizeof(int));
if (newDevice->axis_map == 0)
goto FAILED;
for (i = 0; i < newDevice->axes; i++)
newDevice->axis_map[i] = i;
}
/* Create copy of default data format */ /* Create copy of default data format */
if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto FAILED; if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto FAILED;
memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize); memcpy(df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
/* Axes include POVs */ df->dwNumObjs = newDevice->devcaps.dwAxes + newDevice->devcaps.dwPOVs + newDevice->buttons;
df->dwNumObjs = newDevice->axes + newDevice->buttons;
if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto FAILED; if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto FAILED;
for (i = 0; i < newDevice->axes; i++) for (i = 0; i < newDevice->axes; i++)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment