Re: [dinput 4/5] Add a config for the axes

2007-01-16 Thread Christoph Frick
On Mon, Jan 15, 2007 at 08:03:25PM +0100, Christoph Frick wrote:

This is the replacement for [dinput 4/5] - the other patches still
apply.

-- 

Add a config for the axes like we do for the buttons

This adds a mapping from the linux input id of the axis to the instance id
we assigned the axis.

 dlls/dinput/joystick_linuxinput.c |  122 ++---
 1 files changed, 45 insertions(+), 77 deletions(-)

diff --git a/dlls/dinput/joystick_linuxinput.c 
b/dlls/dinput/joystick_linuxinput.c
index 0908424..db51236 100644
--- a/dlls/dinput/joystick_linuxinput.c
+++ b/dlls/dinput/joystick_linuxinput.c
@@ -69,9 +69,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(dinput);
 #define EVDEVPREFIX"/dev/input/event"
 
 /* Wine joystick driver object instances */
-#define WINE_JOYSTICK_AXIS_BASE   0
-#define WINE_JOYSTICK_POV_BASE6
-#define WINE_JOYSTICK_BUTTON_BASE 8
+#define WINE_JOYSTICK_MAX_AXES8
+#define WINE_JOYSTICK_MAX_POVS4
+#define WINE_JOYSTICK_MAX_BUTTONS 128
 
 typedef struct EffectListItem EffectListItem;
 struct EffectListItem
@@ -140,6 +140,8 @@ struct JoystickImpl
 
struct ObjProps props[ABS_MAX];
 
+   int axes[ABS_MAX];
+
/* LUT for KEY_ to offset in rgbButtons */
BYTEbuttons[KEY_MAX];
 
@@ -352,7 +354,7 @@ static JoystickImpl *alloc_device(REFGUID rguid, const void 
*jvt, IDirectInputIm
 JoystickImpl* newDevice;
 LPDIDATAFORMAT df = NULL;
 int i, idx = 0;
-int axis = 0, pov = 0, btn = 0;
+int axis = 0, btn = 0;
 
 newDevice = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 
sizeof(JoystickImpl));
 if (!newDevice) return NULL;
@@ -367,19 +369,6 @@ static JoystickImpl *alloc_device(REFGUID rguid, const 
void *jvt, IDirectInputIm
 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
   newDevice->ff_state = FF_STATUS_STOPPED;
 #endif
-  for (i=0;iprops[i].wantmin = newDevice->props[i].havemin = 
newDevice->joydev->axes[i][AXIS_ABSMIN];
-newDevice->props[i].wantmax = newDevice->props[i].havemax = 
newDevice->joydev->axes[i][AXIS_ABSMAX];
-/* 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->props[i].deadzone = 0;
-  }
-  fake_current_js_state(newDevice);
 
 /* Create copy of default data format */
 if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIJoystick2.dwSize))) goto 
failed;
@@ -387,33 +376,47 @@ static JoystickImpl *alloc_device(REFGUID rguid, const 
void *jvt, IDirectInputIm
 if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * 
df->dwObjSize))) goto failed;
 
 /* Supported Axis & POVs should map 1-to-1 */
-for (i = 0; i < 8; i++)
+for (i = 0; i < WINE_JOYSTICK_MAX_AXES; i++)
 {
-if (!test_bit(newDevice->joydev->absbits, i)) continue;
+if (!test_bit(newDevice->joydev->absbits, i)) {
+newDevice->axes[i] = -1;
+continue;
+}
 
-memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[axis + 
WINE_JOYSTICK_AXIS_BASE], df->dwObjSize);
+memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i], df->dwObjSize);
+newDevice->axes[i] = idx;
+newDevice->props[idx].wantmin = newDevice->props[idx].havemin = 
newDevice->joydev->axes[i][AXIS_ABSMIN];
+newDevice->props[idx].wantmax = newDevice->props[idx].havemax = 
newDevice->joydev->axes[i][AXIS_ABSMAX];
+newDevice->props[idx].deadzone = 0;
 df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(axis++) | DIDFT_ABSAXIS;
 }
-for (i = 0; i < 4; i++)
+
+for (i = 0; i < WINE_JOYSTICK_MAX_POVS; i++)
 {
 if (!test_bit(newDevice->joydev->absbits, ABS_HAT0X + i * 2) ||
-!test_bit(newDevice->joydev->absbits, ABS_HAT0Y + i * 2))
+!test_bit(newDevice->joydev->absbits, ABS_HAT0Y + i * 2)) {
+newDevice->axes[ABS_HAT0X + i * 2] = newDevice->axes[ABS_HAT0Y + i 
* 2] = -1;
 continue;
+}
 
-memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[pov + 
WINE_JOYSTICK_POV_BASE], df->dwObjSize);
-df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(pov++) | DIDFT_POV;
+memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[i + 
WINE_JOYSTICK_MAX_AXES], df->dwObjSize);
+newDevice->axes[ABS_HAT0X + i * 2] = newDevice->axes[ABS_HAT0Y + i * 
2] = i;
+df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_POV;
 }
+
 /* Buttons can be anywhere, so check all */
-for (i = 0; i < KEY_MAX && btn < 128; i++)
+for (i = 0; i < KEY_MAX && btn < WINE_JOYSTICK_MAX_BUTTONS; i++)
 {
 if (!test_bit(newDevice->joydev->keybits, i)) continue;
 
-memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[btn + 
WINE_JOYSTICK_BUTTON_BASE], df->dwObjSize);
+memcpy(&df->rgodf[idx], &c_dfDIJoystick2.rgodf[btn + 
WINE_JOYSTICK_MAX_AXES + WINE_JOYSTICK_MAX_POVS], df->dwObjSize);
 

Re: [dinput 4/5] Add a config for the axes

2007-01-15 Thread Christoph Frick
On Mon, Jan 15, 2007 at 10:42:10AM -0700, Vitaliy Margolen wrote:

> >  df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(axis++) | 
> > DIDFT_ABSAXIS;
> >  }
> > -for (i = 0; i < 4; i++)
> > +
> > +idx = WINE_JOYSTICK_MAX_AXES;
> Why are you creating a gap? This is exactly the point here to skip all
> the objects that we do not have. And they all need to be sequential in
> godf - no gaps. Otherwise you braking EnumObjects.

you are right. funny thing is - everything works with this patches :/ i
will drop the two idx assigns and resubmit the patch.

-- 
cu


pgpaoMUOrdkfV.pgp
Description: PGP signature



Re: [dinput 4/5] Add a config for the axes

2007-01-15 Thread Vitaliy Margolen
Christoph Frick wrote:
> Add a config for the axes like we do for the buttons
> 
> This adds a mapping from the linux input id of the axis to the instance id
> we assigned the axis.
> ---

>  df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(axis++) | DIDFT_ABSAXIS;
>  }
> -for (i = 0; i < 4; i++)
> +
> +idx = WINE_JOYSTICK_MAX_AXES;
Why are you creating a gap? This is exactly the point here to skip all
the objects that we do not have. And they all need to be sequential in
godf - no gaps. Otherwise you braking EnumObjects.

Vitaliy.