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

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

On Tue, 2007-07-31 at 06:34 -0600, Vitaliy Margolen wrote:
> Peter Dons Tychsen wrote:
> > 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,
> > > 
> > Maybe i would be more successful if i actually attached the
> > patch.... :-)
> > 
> > Here it is....
> 
> Just few small things left:
> 
> > -#undef MAX_JOYSTICKS
> As I mentioned earlier you should move this instead of removing it completely.
> 
> 
> > static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, \
> > REFIID riid, LPDIRECTINPUTDEVICEW* pdev) {
> > -  int i;
> > -
> > -  find_joydevs();
> You removed a really important function call here.
> 
> 
> > +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) ||
> If you reformat the whole function, please make it 4-space indented.
> 
> Vitaliy.

OK. Here is the new patch:

/pedro


["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 e7b20f0771858695d55b69b214166eea73da362b 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      |   37 +++++++++++++------
 dlls/dinput/joystick_linuxinput.c |   68 +++++++++++++++++++++---------------
 2 files changed, 65 insertions(+), 40 deletions(-)

diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c
index 57f1d7a..29febfc 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;
@@ -623,6 +634,8 @@ static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, \
REFGUID rguid, RE  return DIERR_DEVICENOTREG;
 }
 
+#undef MAX_JOYSTICKS
+
 const struct dinput_device joystick_linux_device = {
   "Wine Linux joystick driver",
   joydev_enum_deviceA,
diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c
index 6a8dd44..94e6725 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,22 +430,39 @@ failed:
     return NULL;
 }
 
+/******************************************************************************
+  *     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_Base_GUID;
+    GUID dev_guid = *guid;
+ 
+    wine_joystick.Data3 = 0;
+    dev_guid.Data3 = 0;
+
+    /* 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_JOYDEV;
+}
+
 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID \
riid, LPDIRECTINPUTDEVICEA* pdev)  {
-  int i;
+    unsigned short index;
 
-  find_joydevs();
+    find_joydevs();
 
-  for (i=0; i<have_joydevs; i++) {
-    if (IsEqualGUID(&GUID_Joystick,rguid) ||
-        IsEqualGUID(&joydevs[i].guid,rguid)
-        ) {
+    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, \
&joydevs[i]); +      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");
@@ -456,28 +473,24 @@ static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, \
REFGUID rguid, RE  return DIERR_NOINTERFACE;
       }
     }
-  }
 
-  return DIERR_DEVICENOTREG;
+    return DIERR_DEVICENOTREG;
 }
 
 
 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID \
riid, LPDIRECTINPUTDEVICEW* pdev)  {
-  int i;
+    unsigned short index;
 
-  find_joydevs();
+    find_joydevs();
 
-  for (i=0; i<have_joydevs; i++) {
-    if (IsEqualGUID(&GUID_Joystick,rguid) ||
-        IsEqualGUID(&joydevs[i].guid,rguid)
-        ) {
+    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, \
&joydevs[i]); +      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");
@@ -488,9 +501,8 @@ static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, \
REFGUID rguid, RE  return DIERR_NOINTERFACE;
       }
     }
-  }
 
-  return DIERR_DEVICENOTREG;
+    return DIERR_DEVICENOTREG;
 }
 
 const struct dinput_device joystick_linuxinput_device = {
-- 
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