[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wine-devel
Subject:    Re: dinput - Allow the use of the standard Joystick
From:       Peter Dons Tychsen <donpedro () tdcadsl ! dk>
Date:       2007-07-30 19:29:02
Message-ID: 1185823742.3167.9.camel () dhcppc2
[Download RAW message or body]

On Mon, 2007-07-30 at 21:20 +0200, Peter Dons Tychsen wrote:
> On Sun, 2007-07-29 at 17:43 -0600, Vitaliy Margolen wrote:
> > Peter Dons Tychsen wrote:
> > > OK. Please review this diff:
> > > 
> > > I will re-submit it if you like it.
> > > 
> > > /Pedro
> > 
> > Alright looks good now (you might want to remove the extra white space your 
> > patch adds - git complains about those). Just left to make the same change 
> > to the other joystick interface :)
> > 
> > BTW don't forget to cc: the wine-devel list when you replying.
> > 
> > Vitaliy.
> 
> OK. I still feel that trying to sync joystick_linuxinput.c and
> joystick_linux.c is out of scope for this patch. But as my steadiness
> has limits i have done some of it anyway... :). I have kept the changes
> modest.
> 
> Please take a look at the new patch.
> 
> On another note i will agree with you that it would be practical if the
> two files had similar (or maybe even shared) code. Redundant code is
> never very practical as it always ends up as this very example. The two
> implementations which were supposed to identical always drift apart. If
> things are supposed to do the same, keep them together to begin with.
> 
> Thanks,
> 
> /pedro
> 
> 
> 

Maybe i would be more successful if i actually attached the
patch.... :-)

Here it is....

["0001-Allow-the-use-of-the-standard-Joystick-GUID-when-cal.patch" (0001-Allow-the-use-of-the-standard-Joystick-GUID-when-cal.patch)]

> From 7354965eb322fdde57f8521b71839a863a0b92cd Mon Sep 17 00:00:00 2001
From: Peter Dons Tychsen <donpedro@dhcppc2.(none)>
Date: Sun, 29 Jul 2007 21:21:17 +0200
Subject: [PATCH] Allow the use of the standard Joystick GUID when calling \
CreateDevice This fixes a startup crash bug for the small game "Air Agression".
Patch is backwards compatible with previous behavior.
---
 dlls/dinput/joystick_linux.c      |   35 +++++++++-----
 dlls/dinput/joystick_linuxinput.c |   98 ++++++++++++++++++++-----------------
 2 files changed, 76 insertions(+), 57 deletions(-)

diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c
index 57f1d7a..f7a5a79 100644
--- a/dlls/dinput/joystick_linux.c
+++ b/dlls/dinput/joystick_linux.c
@@ -171,7 +171,6 @@ static INT find_joystick_devices(void)
 
     return joystick_devices_count;
 }
-#undef MAX_JOYSTICKS
 
 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA \
lpddi, DWORD version, int id)  {
@@ -412,7 +411,8 @@ static HRESULT setup_dinput_options(JoystickImpl * device)
     return DI_OK;
 }
 
-static HRESULT alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl \
*dinput, LPDIRECTINPUTDEVICEA* pdev) +static HRESULT alloc_device(REFGUID rguid, \
const void *jvt, IDirectInputImpl *dinput,  +    LPDIRECTINPUTDEVICEA* pdev, unsigned \
short index)  {
     DWORD i;
     JoystickImpl* newDevice;
@@ -428,7 +428,7 @@ static HRESULT alloc_device(REFGUID rguid, const void *jvt, \
IDirectInputImpl *di  return DIERR_OUTOFMEMORY;
     }
 
-    if (!lstrcpynA(newDevice->dev, joystick_devices[rguid->Data3], \
sizeof(newDevice->dev)) || +    if (!lstrcpynA(newDevice->dev, \
joystick_devices[index], sizeof(newDevice->dev)) ||  (newDevice->joyfd = \
open(newDevice->dev, O_RDONLY)) < 0)  {
         WARN("open(%s, O_RDONLY) failed: %s\n", newDevice->dev, strerror(errno));
@@ -568,27 +568,37 @@ FAILED1:
     return hr;
 }
 
-static BOOL IsJoystickGUID(REFGUID guid)
+/******************************************************************************
+  *     get_joystick_index : Get the joystick index from a given GUID
+  */
+static unsigned short get_joystick_index(REFGUID guid)
 {
     GUID wine_joystick = DInput_Wine_Joystick_GUID;
     GUID dev_guid = *guid;
-
+ 
     wine_joystick.Data3 = 0;
     dev_guid.Data3 = 0;
 
-    return IsEqualGUID(&wine_joystick, &dev_guid);
+    /* for the standard joystick GUID use index 0 */
+    if(IsEqualGUID(&GUID_Joystick,guid)) return 0;
+
+    /* for the wine joystick GUIDs use the index stored in Data3 */
+    if(IsEqualGUID(&wine_joystick, &dev_guid)) return guid->Data3;
+
+    return MAX_JOYSTICKS;
 }
 
 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID \
riid, LPDIRECTINPUTDEVICEA* pdev)  {
-  if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
-      (IsJoystickGUID(rguid))) {
+  unsigned short index;
+
+  if ((index = get_joystick_index(rguid)) < MAX_JOYSTICKS) {
     if ((riid == NULL) ||
 	IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
 	IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
 	IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
 	IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
-      return alloc_device(rguid, &JoystickAvt, dinput, pdev);
+      return alloc_device(rguid, &JoystickAvt, dinput, pdev, index);
     } else {
       WARN("no interface\n");
       *pdev = 0;
@@ -603,14 +613,15 @@ static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, \
REFGUID rguid, RE  
 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID \
riid, LPDIRECTINPUTDEVICEW* pdev)  {
-  if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
-      (IsJoystickGUID(rguid))) {
+  unsigned short index;
+
+  if ((index = get_joystick_index(rguid)) < MAX_JOYSTICKS) {
     if ((riid == NULL) ||
 	IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
 	IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
 	IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
 	IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
-      return alloc_device(rguid, &JoystickWvt, dinput, (LPDIRECTINPUTDEVICEA \
*)pdev); +      return alloc_device(rguid, &JoystickWvt, dinput, \
(LPDIRECTINPUTDEVICEA *)pdev, index);  } else {
       WARN("no interface\n");
       *pdev = 0;
diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c
index 6a8dd44..882b360 100644
--- a/dlls/dinput/joystick_linuxinput.c
+++ b/dlls/dinput/joystick_linuxinput.c
@@ -349,7 +349,7 @@ static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, \
LPDIDEVICEINSTAN  return FALSE;
 }
 
-static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputImpl \
*dinput, struct JoyDev *joydev) +static JoystickImpl *alloc_device(REFGUID rguid, \
const void *jvt, IDirectInputImpl *dinput, unsigned short index)  {
     JoystickImpl* newDevice;
     LPDIDATAFORMAT df = NULL;
@@ -365,7 +365,7 @@ static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, \
IDirectInputIm  newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": \
JoystickImpl*->base.crit");  newDevice->joyfd = -1;
   newDevice->base.dinput = dinput;
-  newDevice->joydev = joydev;
+  newDevice->joydev = &joydevs[index];
 #ifdef HAVE_STRUCT_FF_EFFECT_DIRECTION
   newDevice->ff_state = FF_STATUS_STOPPED;
 #endif
@@ -430,31 +430,45 @@ failed:
     return NULL;
 }
 
-static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID \
riid, LPDIRECTINPUTDEVICEA* pdev) \
+/****************************************************************************** +  * \
get_joystick_index : Get the joystick index from a given GUID +  */
+static unsigned short get_joystick_index(REFGUID guid)
 {
-  int i;
+    GUID wine_joystick = DInput_Wine_Joystick_Base_GUID;
+    GUID dev_guid = *guid;
+ 
+    wine_joystick.Data3 = 0;
+    dev_guid.Data3 = 0;
 
-  find_joydevs();
+    /* for the standard joystick GUID use index 0 */
+    if(IsEqualGUID(&GUID_Joystick,guid)) return 0;
 
-  for (i=0; i<have_joydevs; i++) {
-    if (IsEqualGUID(&GUID_Joystick,rguid) ||
-        IsEqualGUID(&joydevs[i].guid,rguid)
-        ) {
-      if ((riid == NULL) ||
-          IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
-          IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
-          IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
-          IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
-        *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput, \
                &joydevs[i]);
-        TRACE("Creating a Joystick device (%p)\n", *pdev);
-        if (*pdev==0) {
-          ERR("out of memory\n");
-          return DIERR_OUTOFMEMORY;
-        }
-        return DI_OK;
-      } else {
-        return DIERR_NOINTERFACE;
+    /* for the wine joystick GUIDs use the index stored in Data3 */
+    if(IsEqualGUID(&wine_joystick, &dev_guid)) return guid->Data3;
+
+    return MAX_JOYDEV;
+}
+
+static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID \
riid, LPDIRECTINPUTDEVICEA* pdev) +{
+  unsigned short index;
+
+  if ((index = get_joystick_index(rguid)) < MAX_JOYDEV) {
+    if ((riid == NULL) ||
+    IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
+    IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
+    IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
+    IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
+      *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput, \
index); +      TRACE("Creating a Joystick device (%p)\n", *pdev);
+      if (*pdev==0) {
+        ERR("out of memory\n");
+        return DIERR_OUTOFMEMORY;
       }
+      return DI_OK;
+    } else {
+      return DIERR_NOINTERFACE;
     }
   }
 
@@ -464,29 +478,23 @@ static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, \
REFGUID rguid, RE  
 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID \
riid, LPDIRECTINPUTDEVICEW* pdev)  {
-  int i;
-
-  find_joydevs();
-
-  for (i=0; i<have_joydevs; i++) {
-    if (IsEqualGUID(&GUID_Joystick,rguid) ||
-        IsEqualGUID(&joydevs[i].guid,rguid)
-        ) {
-      if ((riid == NULL) ||
-          IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
-          IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
-          IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
-          IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
-        *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput, \
                &joydevs[i]);
-        TRACE("Creating a Joystick device (%p)\n", *pdev);
-        if (*pdev==0) {
-          ERR("out of memory\n");
-          return DIERR_OUTOFMEMORY;
-        }
-        return DI_OK;
-      } else {
-        return DIERR_NOINTERFACE;
+  unsigned short index;
+
+  if ((index = get_joystick_index(rguid)) < MAX_JOYDEV) {
+    if ((riid == NULL) ||
+    IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
+    IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
+    IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
+    IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
+      *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput, \
index); +      TRACE("Creating a Joystick device (%p)\n", *pdev);
+      if (*pdev==0) {
+        ERR("out of memory\n");
+        return DIERR_OUTOFMEMORY;
       }
+      return DI_OK;
+    } else {
+      return DIERR_NOINTERFACE;
     }
   }
 
-- 
1.5.2.2





[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic