Commit feb0ef34 authored by Christoph Frick's avatar Christoph Frick Committed by Alexandre Julliard

- Added missing break statement.

- Changed the mapping of the axis to a simpler formula, that ignores the middle of an axis. - Min/max values where initalized switched. - Added the missing button and axis events that are registered earlier in the code but never made it to the application. - Added a little more descriptive comment about the deadzone.
parent d1e0782c
...@@ -239,7 +239,12 @@ static JoystickImpl *alloc_device(REFGUID rguid, LPVOID jvt, IDirectInputImpl *d ...@@ -239,7 +239,12 @@ static JoystickImpl *alloc_device(REFGUID rguid, LPVOID jvt, IDirectInputImpl *d
for (i=0;i<ABS_MAX;i++) { for (i=0;i<ABS_MAX;i++) {
newDevice->wantmin[i] = -32768; newDevice->wantmin[i] = -32768;
newDevice->wantmax[i] = 32767; newDevice->wantmax[i] = 32767;
newDevice->deadz[i] = 1024; /* guessing */ /* TODO:
* direct input defines a default for the deadzone somewhere; but as long
* as in map_axis the code for the dead zone is commented out its no
* problem
*/
newDevice->deadz[i] = 0;
} }
return newDevice; return newDevice;
} }
...@@ -412,8 +417,8 @@ static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface) ...@@ -412,8 +417,8 @@ static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
This->axes[i][AXE_ABSFUZZ], This->axes[i][AXE_ABSFUZZ],
This->axes[i][AXE_ABSFLAT] This->axes[i][AXE_ABSFLAT]
); );
This->havemax[i] = This->axes[i][AXE_ABSMIN]; This->havemin[i] = This->axes[i][AXE_ABSMIN];
This->havemin[i] = This->axes[i][AXE_ABSMAX]; This->havemax[i] = This->axes[i][AXE_ABSMAX];
} }
} }
MESSAGE("\n"); MESSAGE("\n");
...@@ -460,12 +465,8 @@ map_axis(JoystickImpl* This, int axis, int val) { ...@@ -460,12 +465,8 @@ map_axis(JoystickImpl* This, int axis, int val) {
if (xmin == xmax) return val; if (xmin == xmax) return val;
if ((hmin == hmax) || (hmax==xmid) || (hmin==xmid)) return val; if ((hmin == hmax) || (hmax==xmid) || (hmin==xmid)) return val;
/* don't assume total linearity, but linearity starting from a zeropoint */ /* map the value from the hmin-hmax range into the wmin-wmax range */
if (val > xmid) { ret = (val * (wmax-wmin)) / (hmax-hmin) + wmin;
ret = (val-xmid)*((wmax-wmin)/2)/(hmax-xmid)+0;
} else {
ret = (xmid-val)*((wmax-wmin)/2)/(hmin-xmid)+0;
}
#if 0 #if 0
/* deadzone doesn't work comfortably enough right now. needs more testing*/ /* deadzone doesn't work comfortably enough right now. needs more testing*/
...@@ -519,8 +520,54 @@ static void joy_polldev(JoystickImpl *This) { ...@@ -519,8 +520,54 @@ static void joy_polldev(JoystickImpl *This) {
GEN_EVENT(DIJOFS_BUTTON(2),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++); GEN_EVENT(DIJOFS_BUTTON(2),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
This->js.rgbButtons[2] = ie.value?0x80:0x00; This->js.rgbButtons[2] = ie.value?0x80:0x00;
break; break;
case BTN_TOP:
case BTN_X:
case BTN_4:
GEN_EVENT(DIJOFS_BUTTON(3),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
This->js.rgbButtons[3] = ie.value?0x80:0x00;
break;
case BTN_TOP2:
case BTN_Y:
case BTN_5:
GEN_EVENT(DIJOFS_BUTTON(4),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
This->js.rgbButtons[4] = ie.value?0x80:0x00;
break;
case BTN_PINKIE:
case BTN_Z:
case BTN_6:
GEN_EVENT(DIJOFS_BUTTON(5),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
This->js.rgbButtons[5] = ie.value?0x80:0x00;
break;
case BTN_BASE:
case BTN_TL:
case BTN_7:
GEN_EVENT(DIJOFS_BUTTON(6),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
This->js.rgbButtons[6] = ie.value?0x80:0x00;
break;
case BTN_BASE2:
case BTN_TR:
case BTN_8:
GEN_EVENT(DIJOFS_BUTTON(7),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
This->js.rgbButtons[7] = ie.value?0x80:0x00;
break;
case BTN_BASE3:
case BTN_TL2:
case BTN_9:
GEN_EVENT(DIJOFS_BUTTON(8),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
This->js.rgbButtons[8] = ie.value?0x80:0x00;
break;
case BTN_BASE4:
case BTN_TR2:
GEN_EVENT(DIJOFS_BUTTON(9),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
This->js.rgbButtons[9] = ie.value?0x80:0x00;
break;
case BTN_BASE5:
case BTN_SELECT:
GEN_EVENT(DIJOFS_BUTTON(10),ie.value?0x80:0x0,ie.time.tv_usec,(This->dinput->evsequence)++);
This->js.rgbButtons[10] = ie.value?0x80:0x00;
break;
default: default:
FIXME("unhandled joystick axe %x, value %d\n",ie.code,ie.value); FIXME("unhandled joystick button %x, value %d\n",ie.code,ie.value);
break; break;
} }
break; break;
...@@ -533,10 +580,23 @@ static void joy_polldev(JoystickImpl *This) { ...@@ -533,10 +580,23 @@ static void joy_polldev(JoystickImpl *This) {
case ABS_Y: case ABS_Y:
GEN_EVENT(DIJOFS_Y,ie.value,ie.time.tv_usec,(This->dinput->evsequence)++); GEN_EVENT(DIJOFS_Y,ie.value,ie.time.tv_usec,(This->dinput->evsequence)++);
This->js.lY = map_axis(This,1,ie.value); This->js.lY = map_axis(This,1,ie.value);
break;
case ABS_Z: case ABS_Z:
GEN_EVENT(DIJOFS_Z,ie.value,ie.time.tv_usec,(This->dinput->evsequence)++); GEN_EVENT(DIJOFS_Z,ie.value,ie.time.tv_usec,(This->dinput->evsequence)++);
This->js.lZ = map_axis(This,2,ie.value); This->js.lZ = map_axis(This,2,ie.value);
break; break;
case ABS_RX:
GEN_EVENT(DIJOFS_RX,ie.value,ie.time.tv_usec,(This->dinput->evsequence)++);
This->js.lRx = map_axis(This,3,ie.value);
break;
case ABS_RY:
GEN_EVENT(DIJOFS_RY,ie.value,ie.time.tv_usec,(This->dinput->evsequence)++);
This->js.lRy = map_axis(This,4,ie.value);
break;
case ABS_RZ:
GEN_EVENT(DIJOFS_RZ,ie.value,ie.time.tv_usec,(This->dinput->evsequence)++);
This->js.lRz = map_axis(This,5,ie.value);
break;
default: default:
FIXME("unhandled joystick axe event (code %d, value %d)\n",ie.code,ie.value); FIXME("unhandled joystick axe event (code %d, value %d)\n",ie.code,ie.value);
break; break;
......
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