[dinput-4/6] add offsets and transform
Christoph Frick
frick at sc-networks.de
Mon Jul 3 04:31:10 CDT 2006
License: LGPL
ChangeLog:
2006-07-02 Christoph Frick <rid at zefix.tv>
adds offset and transform and their basic handling to the joy impl
---
dlls/dinput/joystick_linuxinput.c | 61 ++++++++++++++++++++++++++++++++++++-
1 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c
index c0ef0e0..4e5d141 100644
--- a/dlls/dinput/joystick_linuxinput.c
+++ b/dlls/dinput/joystick_linuxinput.c
@@ -125,6 +125,8 @@ struct JoystickImpl
int joyfd;
LPDIDATAFORMAT df;
+ DataFormat *transform; /* wine to user format converter */
+ int *offsets; /* object offsets */
HANDLE hEvent;
LPDIDEVICEOBJECTDATA data_queue;
int queue_head, queue_tail, queue_len;
@@ -339,6 +341,10 @@ static JoystickImpl *alloc_device(REFGUI
int i;
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
+ if (newDevice==NULL) {
+ return NULL;
+ }
+
newDevice->lpVtbl = jvt;
newDevice->ref = 1;
newDevice->joyfd = -1;
@@ -359,7 +365,37 @@ #endif
newDevice->deadz[i] = 0;
}
fake_current_js_state(newDevice);
+
+ /* wine uses DIJOYSTATE2 as it's internal format so copy
+ * the already defined format c_dfDIJoystick2 */
+ newDevice->df = HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2.dwSize);
+ if (newDevice->df == 0)
+ goto FAILED;
+
+ CopyMemory(newDevice->df, &c_dfDIJoystick2, c_dfDIJoystick2.dwSize);
+
+ /* copy default objects */
+ newDevice->df->rgodf = HeapAlloc(GetProcessHeap(),0,c_dfDIJoystick2.dwNumObjs*c_dfDIJoystick2.dwObjSize);
+ if (newDevice->df->rgodf == 0)
+ goto FAILED;
+
+ CopyMemory(newDevice->df->rgodf,c_dfDIJoystick2.rgodf,c_dfDIJoystick2.dwNumObjs*c_dfDIJoystick2.dwObjSize);
+
+ /* create an offsets array */
+ newDevice->offsets = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,c_dfDIJoystick2.dwNumObjs*sizeof(int));
+ if (newDevice->offsets == 0)
+ goto FAILED;
+
+ /* create the default transform filter */
+ newDevice->transform = create_DataFormat(&c_dfDIJoystick2, newDevice->df, newDevice->offsets);
+
return newDevice;
+
+FAILED:
+ HeapFree(GetProcessHeap(),0,newDevice->df->rgodf);
+ HeapFree(GetProcessHeap(),0,newDevice->df);
+ HeapFree(GetProcessHeap(),0,newDevice);
+ return NULL;
}
static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
@@ -383,6 +419,10 @@ static HRESULT joydev_create_deviceA(IDi
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;
@@ -415,6 +455,10 @@ static HRESULT joydev_create_deviceW(IDi
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;
@@ -452,10 +496,17 @@ static ULONG WINAPI JoystickAImpl_Releas
HeapFree(GetProcessHeap(),0,This->data_queue);
/* Free the DataFormat */
+ HeapFree(GetProcessHeap(), 0, This->df->rgodf);
HeapFree(GetProcessHeap(), 0, This->df);
- HeapFree(GetProcessHeap(),0,This);
- return 0;
+ /* Free the offsets array */
+ HeapFree(GetProcessHeap(),0,This->offsets);
+
+ /* release the data transform filter */
+ release_DataFormat(This->transform);
+
+ HeapFree(GetProcessHeap(),0,This);
+ return 0;
}
/******************************************************************************
@@ -487,6 +538,10 @@ static HRESULT WINAPI JoystickAImpl_SetD
return DIERR_ACQUIRED;
}
+ HeapFree(GetProcessHeap(),0,This->df->rgodf);
+ HeapFree(GetProcessHeap(),0,This->df);
+ release_DataFormat(This->transform);
+
/* Store the new data format */
This->df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
if (This->df==NULL) {
@@ -500,6 +555,8 @@ 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);
+
return DI_OK;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 163 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-patches/attachments/20060703/86c29162/attachment.pgp
More information about the wine-patches
mailing list