Vitaliy Margolen : dinput: Move internal function calculate_ids to where it 's really used.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Dec 11 10:34:48 CST 2006


Module: wine
Branch: master
Commit: 267cbf82896017adc18f22cde55125137d59c9bf
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=267cbf82896017adc18f22cde55125137d59c9bf

Author: Vitaliy Margolen <wine-patches at kievinfo.com>
Date:   Sun Dec 10 14:15:20 2006 -0700

dinput: Move internal function calculate_ids to where it's really used.

---

 dlls/dinput/device.c              |   49 +++++++++++++++++++++++++++++++-
 dlls/dinput/device_private.h      |    2 +-
 dlls/dinput/joystick_linux.c      |   55 -------------------------------------
 dlls/dinput/joystick_linuxinput.c |   54 ------------------------------------
 dlls/dinput/mouse.c               |    2 +-
 5 files changed, 49 insertions(+), 113 deletions(-)

diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c
index 8b97875..bee9ff7 100644
--- a/dlls/dinput/device.c
+++ b/dlls/dinput/device.c
@@ -287,7 +287,50 @@ void release_DataFormat(DataFormat * for
     HeapFree(GetProcessHeap(), 0, format->dt);
 }
 
-DataFormat *create_DataFormat(const DIDATAFORMAT *wine_format, LPCDIDATAFORMAT asked_format, int *offset) {
+/* Make all instances sequential */
+static void calculate_ids(LPDIDATAFORMAT df)
+{
+    int i, axis = 0, pov = 0, button = 0;
+    int axis_base, pov_base, button_base;
+    DWORD type;
+
+    /* Make two passes over the format. The first counts the number
+     * for each type and the second sets the id */
+    for (i = 0; i < df->dwNumObjs; i++)
+    {
+        type = DIDFT_GETTYPE(df->rgodf[i].dwType);
+        if      (type & DIDFT_AXIS)   axis++;
+        else if (type & DIDFT_POV)    pov++;
+        else if (type & DIDFT_BUTTON) button++;
+    }
+
+    axis_base   = 0;
+    pov_base    = axis_base + axis;
+    button_base = pov_base + pov;
+    axis = pov = button = 0;
+
+    for (i = 0; i < df->dwNumObjs; i++)
+    {
+        type = DIDFT_GETTYPE(df->rgodf[i].dwType);
+        if (type & DIDFT_AXIS)
+        {
+            type |= DIDFT_MAKEINSTANCE(axis_base + axis++);
+            TRACE("axis type = 0x%08x\n", type);
+        } else if (type & DIDFT_POV)
+        {
+            type |= DIDFT_MAKEINSTANCE(pov_base + pov++);
+            TRACE("POV type = 0x%08x\n", type);
+        } else if (type & DIDFT_BUTTON)
+        {
+            type |= DIDFT_MAKEINSTANCE(button_base + button++);
+            TRACE("button type = 0x%08x\n", type);
+        }
+        df->rgodf[i].dwType = type;
+    }
+}
+
+DataFormat *create_DataFormat(LPCDIDATAFORMAT wine_format, LPDIDATAFORMAT asked_format, int *offset)
+{
     DataFormat *ret;
     DataTransform *dt;
     unsigned int i, j;
@@ -404,7 +447,9 @@ DataFormat *create_DataFormat(const DIDA
     }
     
     HeapFree(GetProcessHeap(), 0, done);
-    
+
+    /* Last step - reset all instances of the new format */
+    calculate_ids(asked_format);
     return ret;
 }
 
diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h
index 4e63af4..84b6d02 100644
--- a/dlls/dinput/device_private.h
+++ b/dlls/dinput/device_private.h
@@ -60,7 +60,7 @@ typedef struct {
   DataTransform *dt;
 } DataFormat;
 extern void fill_DataFormat(void *out, const void *in, DataFormat *df) ;
-extern DataFormat *create_DataFormat(const DIDATAFORMAT *wine_format, LPCDIDATAFORMAT asked_format, int *offset) ;
+extern DataFormat *create_DataFormat(LPCDIDATAFORMAT wine_format, LPDIDATAFORMAT asked_format, int *offset);
 extern void release_DataFormat(DataFormat *df) ;
 extern void queue_event(LPDIRECTINPUTDEVICE8A iface, int ofs, DWORD data, DWORD time, DWORD seq);
 
diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c
index 474678c..0fb7e22 100644
--- a/dlls/dinput/joystick_linux.c
+++ b/dlls/dinput/joystick_linux.c
@@ -393,57 +393,6 @@ static HRESULT setup_dinput_options(Joys
     return DI_OK;
 }
 
-static void calculate_ids(JoystickImpl* device)
-{
-    int i;
-    int axis = 0;
-    int button = 0;
-    int pov = 0;
-    int axis_base;
-    int pov_base;
-    int button_base;
-
-    /* Make two passes over the format. The first counts the number
-     * for each type and the second sets the id */
-    for (i = 0; i < device->user_df->dwNumObjs; i++) {
-        if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_AXIS)
-            axis++;
-        else if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_POV)
-            pov++;
-        else if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_BUTTON)
-            button++;
-    }
-
-    axis_base = 0;
-    pov_base = axis;
-    button_base = axis + pov;
-
-    axis = 0;
-    button = 0;
-    pov = 0;
-
-    for (i = 0; i < device->user_df->dwNumObjs; i++) {
-        DWORD type = 0;
-        if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_AXIS) {
-            axis++;
-            type = DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) |
-                DIDFT_MAKEINSTANCE(axis + axis_base);
-            TRACE("axis type = 0x%08x\n", type);
-        } else if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_POV) {
-            pov++;
-            type = DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) |
-                DIDFT_MAKEINSTANCE(pov + pov_base);
-            TRACE("POV type = 0x%08x\n", type);
-        } else if (DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) & DIDFT_BUTTON) {
-            button++;
-            type = DIDFT_GETTYPE(device->user_df->rgodf[i].dwType) |
-                DIDFT_MAKEINSTANCE(button + button_base);
-            TRACE("button type = 0x%08x\n", type);
-        }
-        device->user_df->rgodf[i].dwType = type;
-    }
-}
-
 static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl *dinput, LPDIRECTINPUTDEVICEA* pdev)
 {
     DWORD i;
@@ -554,8 +503,6 @@ static HRESULT alloc_device(REFGUID rgui
     /* create the default transform filter */
     newDevice->transform = create_DataFormat(&c_dfDIJoystick2, newDevice->user_df, newDevice->offsets);
 
-    calculate_ids(newDevice);
-
     IDirectInputDevice_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput);
 
     newDevice->devcaps.dwSize = sizeof(newDevice->devcaps);
@@ -765,8 +712,6 @@ static HRESULT WINAPI JoystickAImpl_SetD
     }
     This->transform = create_DataFormat(&c_dfDIJoystick2, This->user_df, This->offsets);
 
-    calculate_ids(This);
-
     return DI_OK;
 
 FAILED:
diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c
index 369c26d..2fe0b7c 100644
--- a/dlls/dinput/joystick_linuxinput.c
+++ b/dlls/dinput/joystick_linuxinput.c
@@ -152,7 +152,6 @@ static DWORD map_pov(int event_value, in
 static void find_joydevs(void);
 static int lxinput_to_user_offset(JoystickImpl *This, int ie_type, int ie_code);
 static int offset_to_object(JoystickImpl *This, int offset);
-static void calculate_ids(LPDIDATAFORMAT df);
 
 /* This GUID is slightly different from the linux joystick one. Take note. */
 static const GUID DInput_Wine_Joystick_Base_GUID = { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
@@ -414,7 +413,6 @@ static JoystickImpl *alloc_device(REFGUI
 
   /* create the default transform filter */
   newDevice->transform = create_DataFormat(&c_dfDIJoystick2, newDevice->df, newDevice->offsets);
-  calculate_ids(newDevice->df);
 
   return newDevice;
 
@@ -577,7 +575,6 @@ static HRESULT WINAPI JoystickAImpl_SetD
   memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
 
   This->transform = create_DataFormat(&c_dfDIJoystick2, This->df, This->offsets);
-  calculate_ids(This->df);
 
   return DI_OK;
 }
@@ -798,57 +795,6 @@ static int offset_to_object(JoystickImpl
     return -1;
 }
 
-static void calculate_ids(LPDIDATAFORMAT df)
-{
-    int i;
-    int axis = 0;
-    int button = 0;
-    int pov = 0;
-    int axis_base;
-    int pov_base;
-    int button_base;
-
-    /* Make two passes over the format. The first counts the number
-     * for each type and the second sets the id */
-    for (i = 0; i < df->dwNumObjs; i++) {
-        if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_AXIS)
-            axis++;
-        else if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_POV)
-            pov++;
-        else if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_BUTTON)
-            button++;
-    }
-
-    axis_base = 0;
-    pov_base = axis;
-    button_base = axis + pov;
-
-    axis = 0;
-    button = 0;
-    pov = 0;
-
-    for (i = 0; i < df->dwNumObjs; i++) {
-        DWORD type = 0;
-        if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_AXIS) {
-            axis++;
-            type = DIDFT_GETTYPE(df->rgodf[i].dwType) |
-                DIDFT_MAKEINSTANCE(axis + axis_base);
-            TRACE("axis type = 0x%08x\n", type);
-        } else if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_POV) {
-            pov++;
-            type = DIDFT_GETTYPE(df->rgodf[i].dwType) |
-                DIDFT_MAKEINSTANCE(pov + pov_base);
-            TRACE("POV type = 0x%08x\n", type);
-        } else if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_BUTTON) {
-            button++;
-            type = DIDFT_GETTYPE(df->rgodf[i].dwType) |
-                DIDFT_MAKEINSTANCE(button + button_base);
-            TRACE("button type = 0x%08x\n", type);
-        }
-        df->rgodf[i].dwType = type;
-    }
-}
-
 static void joy_polldev(JoystickImpl *This) {
     struct pollfd plfd;
     struct	input_event ie;
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c
index 0ede9ce..bcb16fa 100644
--- a/dlls/dinput/mouse.c
+++ b/dlls/dinput/mouse.c
@@ -366,7 +366,7 @@ static HRESULT WINAPI SysMouseAImpl_SetD
     memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
     
     /* Prepare all the data-conversion filters */
-    This->wine_df = create_DataFormat(&(Wine_InternalMouseFormat), df, This->offset_array);
+    This->wine_df = create_DataFormat(&Wine_InternalMouseFormat, This->df, This->offset_array);
     
     return DI_OK;
 }




More information about the wine-cvs mailing list