Commit 5347ab42 authored by Vitaliy Margolen's avatar Vitaliy Margolen Committed by Alexandre Julliard

dinput: Move axes mapping array and default dead-zone into generic joystick class.

parent 2c85da06
...@@ -87,8 +87,6 @@ struct JoystickImpl ...@@ -87,8 +87,6 @@ struct JoystickImpl
/* joystick private */ /* joystick private */
int joyfd; int joyfd;
LONG deadzone;
int *axis_map;
int axes; int axes;
POINTL povs[4]; POINTL povs[4];
}; };
...@@ -257,12 +255,12 @@ static HRESULT setup_dinput_options(JoystickImpl * device) ...@@ -257,12 +255,12 @@ static HRESULT setup_dinput_options(JoystickImpl * device)
/* get options */ /* get options */
if (!get_config_key( hkey, appkey, "DefaultDeadZone", buffer, MAX_PATH )) { if (!get_config_key( hkey, appkey, "DefaultDeadZone", buffer, MAX_PATH )) {
device->deadzone = atoi(buffer); device->generic.deadzone = atoi(buffer);
TRACE("setting default deadzone to: \"%s\" %d\n", buffer, device->deadzone); TRACE("setting default deadzone to: \"%s\" %d\n", buffer, device->generic.deadzone);
} }
device->axis_map = HeapAlloc(GetProcessHeap(), 0, device->axes * sizeof(int)); device->generic.axis_map = HeapAlloc(GetProcessHeap(), 0, device->axes * sizeof(int));
if (!device->axis_map) return DIERR_OUTOFMEMORY; if (!device->generic.axis_map) return DIERR_OUTOFMEMORY;
if (!get_config_key( hkey, appkey, device->generic.name, buffer, MAX_PATH )) { if (!get_config_key( hkey, appkey, device->generic.name, buffer, MAX_PATH )) {
static const char *axis_names[] = {"X", "Y", "Z", "Rx", "Ry", "Rz", static const char *axis_names[] = {"X", "Y", "Z", "Rx", "Ry", "Rz",
...@@ -289,7 +287,7 @@ static HRESULT setup_dinput_options(JoystickImpl * device) ...@@ -289,7 +287,7 @@ static HRESULT setup_dinput_options(JoystickImpl * device)
else else
{ {
/* Pov takes two axes */ /* Pov takes two axes */
device->axis_map[tokens++] = i; device->generic.axis_map[tokens++] = i;
pov++; pov++;
} }
} }
...@@ -312,14 +310,14 @@ static HRESULT setup_dinput_options(JoystickImpl * device) ...@@ -312,14 +310,14 @@ static HRESULT setup_dinput_options(JoystickImpl * device)
i = -1; i = -1;
} }
device->axis_map[tokens] = i; device->generic.axis_map[tokens] = i;
tokens++; tokens++;
} while ((ptr = strtok(NULL, delim)) != NULL); } while ((ptr = strtok(NULL, delim)) != NULL);
if (tokens != device->axes) { 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] = -1; device->generic.axis_map[tokens] = -1;
tokens++; tokens++;
} }
} }
...@@ -330,14 +328,14 @@ static HRESULT setup_dinput_options(JoystickImpl * device) ...@@ -330,14 +328,14 @@ static HRESULT setup_dinput_options(JoystickImpl * device)
for (tokens = 0; tokens < device->axes; tokens++) for (tokens = 0; tokens < device->axes; tokens++)
{ {
if (tokens < 8) if (tokens < 8)
device->axis_map[tokens] = axis++; device->generic.axis_map[tokens] = axis++;
else if (tokens < 16) else if (tokens < 16)
{ {
device->axis_map[tokens++] = 8 + pov; device->generic.axis_map[tokens++] = 8 + pov;
device->axis_map[tokens ] = 8 + pov++; device->generic.axis_map[tokens ] = 8 + pov++;
} }
else else
device->axis_map[tokens] = -1; device->generic.axis_map[tokens] = -1;
} }
} }
device->generic.devcaps.dwAxes = axis; device->generic.devcaps.dwAxes = axis;
...@@ -425,7 +423,7 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di ...@@ -425,7 +423,7 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di
newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->generic.base.crit"); newDevice->generic.base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": JoystickImpl*->generic.base.crit");
/* setup_dinput_options may change these */ /* setup_dinput_options may change these */
newDevice->deadzone = 0; newDevice->generic.deadzone = 0;
/* do any user specified configuration */ /* do any user specified configuration */
hr = setup_dinput_options(newDevice); hr = setup_dinput_options(newDevice);
...@@ -441,7 +439,7 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di ...@@ -441,7 +439,7 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di
for (i = 0; i < newDevice->axes; i++) for (i = 0; i < newDevice->axes; i++)
{ {
int wine_obj = newDevice->axis_map[i]; int wine_obj = newDevice->generic.axis_map[i];
if (wine_obj < 0) continue; if (wine_obj < 0) continue;
...@@ -468,7 +466,7 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di ...@@ -468,7 +466,7 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di
newDevice->generic.props[i].lDevMax = +32767; newDevice->generic.props[i].lDevMax = +32767;
newDevice->generic.props[i].lMin = 0; newDevice->generic.props[i].lMin = 0;
newDevice->generic.props[i].lMax = 0xffff; newDevice->generic.props[i].lMax = 0xffff;
newDevice->generic.props[i].lDeadZone = newDevice->deadzone; /* % * 1000 */ newDevice->generic.props[i].lDeadZone = newDevice->generic.deadzone; /* % * 1000 */
newDevice->generic.props[i].lSaturation = 0; newDevice->generic.props[i].lSaturation = 0;
} }
...@@ -489,7 +487,7 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di ...@@ -489,7 +487,7 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *di
if (TRACE_ON(dinput)) { if (TRACE_ON(dinput)) {
_dump_DIDATAFORMAT(newDevice->generic.base.data_format.wine_df); _dump_DIDATAFORMAT(newDevice->generic.base.data_format.wine_df);
for (i = 0; i < (newDevice->axes); i++) for (i = 0; i < (newDevice->axes); i++)
TRACE("axis_map[%d] = %d\n", i, newDevice->axis_map[i]); TRACE("axis_map[%d] = %d\n", i, newDevice->generic.axis_map[i]);
_dump_DIDEVCAPS(&newDevice->generic.devcaps); _dump_DIDEVCAPS(&newDevice->generic.devcaps);
} }
...@@ -503,7 +501,7 @@ FAILED1: ...@@ -503,7 +501,7 @@ FAILED1:
if (df) HeapFree(GetProcessHeap(), 0, df->rgodf); if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
HeapFree(GetProcessHeap(), 0, df); HeapFree(GetProcessHeap(), 0, df);
release_DataFormat(&newDevice->generic.base.data_format); release_DataFormat(&newDevice->generic.base.data_format);
HeapFree(GetProcessHeap(),0,newDevice->axis_map); HeapFree(GetProcessHeap(),0,newDevice->generic.axis_map);
HeapFree(GetProcessHeap(),0,newDevice->generic.name); HeapFree(GetProcessHeap(),0,newDevice->generic.name);
HeapFree(GetProcessHeap(),0,newDevice); HeapFree(GetProcessHeap(),0,newDevice);
*pdev = 0; *pdev = 0;
...@@ -684,7 +682,7 @@ static void joy_polldev(JoystickGenericImpl *This_in) { ...@@ -684,7 +682,7 @@ static void joy_polldev(JoystickGenericImpl *This_in) {
} }
else if (jse.type & JS_EVENT_AXIS) else if (jse.type & JS_EVENT_AXIS)
{ {
int number = This->axis_map[jse.number]; /* wine format object index */ int number = This->generic.axis_map[jse.number]; /* wine format object index */
if (number < 0) return; if (number < 0) return;
inst_id = DIDFT_MAKEINSTANCE(number) | (number < 8 ? DIDFT_ABSAXIS : DIDFT_POV); inst_id = DIDFT_MAKEINSTANCE(number) | (number < 8 ? DIDFT_ABSAXIS : DIDFT_POV);
......
...@@ -46,6 +46,9 @@ typedef struct JoystickGenericImpl ...@@ -46,6 +46,9 @@ typedef struct JoystickGenericImpl
GUID guidInstance; GUID guidInstance;
char *name; char *name;
int *axis_map; /* User axes remapping */
LONG deadzone; /* Default dead-zone */
joy_polldev_handler *joy_polldev; joy_polldev_handler *joy_polldev;
} JoystickGenericImpl; } JoystickGenericImpl;
......
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