Commit f0f3b0a3 authored by Christoph Frick's avatar Christoph Frick Committed by Alexandre Julliard

dinput: Adds offset and transform and their basic handling to the joystick implementation.

parent 03260f73
...@@ -124,6 +124,8 @@ struct JoystickImpl ...@@ -124,6 +124,8 @@ struct JoystickImpl
int joyfd; int joyfd;
LPDIDATAFORMAT df; LPDIDATAFORMAT df;
DataFormat *transform; /* wine to user format converter */
int *offsets; /* object offsets */
HANDLE hEvent; HANDLE hEvent;
LPDIDEVICEOBJECTDATA data_queue; LPDIDEVICEOBJECTDATA data_queue;
int queue_head, queue_tail, queue_len; int queue_head, queue_tail, queue_len;
...@@ -338,6 +340,10 @@ static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputIm ...@@ -338,6 +340,10 @@ static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputIm
int i; int i;
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl)); newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
if (newDevice==NULL) {
return NULL;
}
newDevice->lpVtbl = jvt; newDevice->lpVtbl = jvt;
newDevice->ref = 1; newDevice->ref = 1;
newDevice->joyfd = -1; newDevice->joyfd = -1;
...@@ -358,7 +364,37 @@ static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputIm ...@@ -358,7 +364,37 @@ static JoystickImpl *alloc_device(REFGUID rguid, const void *jvt, IDirectInputIm
newDevice->deadz[i] = 0; newDevice->deadz[i] = 0;
} }
fake_current_js_state(newDevice); 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; 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) static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
...@@ -378,6 +414,10 @@ static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, RE ...@@ -378,6 +414,10 @@ static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, RE
IsEqualGUID(&IID_IDirectInputDevice8A,riid)) { IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
*pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput, &joydevs[i]); *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput, &joydevs[i]);
TRACE("Creating a Joystick device (%p)\n", *pdev); TRACE("Creating a Joystick device (%p)\n", *pdev);
if (*pdev==0) {
ERR("out of memory\n");
return DIERR_OUTOFMEMORY;
}
return DI_OK; return DI_OK;
} else { } else {
return DIERR_NOINTERFACE; return DIERR_NOINTERFACE;
...@@ -406,6 +446,10 @@ static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, RE ...@@ -406,6 +446,10 @@ static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, RE
IsEqualGUID(&IID_IDirectInputDevice8W,riid)) { IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
*pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput, &joydevs[i]); *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput, &joydevs[i]);
TRACE("Creating a Joystick device (%p)\n", *pdev); TRACE("Creating a Joystick device (%p)\n", *pdev);
if (*pdev==0) {
ERR("out of memory\n");
return DIERR_OUTOFMEMORY;
}
return DI_OK; return DI_OK;
} else { } else {
return DIERR_NOINTERFACE; return DIERR_NOINTERFACE;
...@@ -443,10 +487,17 @@ static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface) ...@@ -443,10 +487,17 @@ static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
HeapFree(GetProcessHeap(),0,This->data_queue); HeapFree(GetProcessHeap(),0,This->data_queue);
/* Free the DataFormat */ /* Free the DataFormat */
HeapFree(GetProcessHeap(), 0, This->df->rgodf);
HeapFree(GetProcessHeap(), 0, This->df); HeapFree(GetProcessHeap(), 0, This->df);
HeapFree(GetProcessHeap(),0,This); /* Free the offsets array */
return 0; HeapFree(GetProcessHeap(),0,This->offsets);
/* release the data transform filter */
release_DataFormat(This->transform);
HeapFree(GetProcessHeap(),0,This);
return 0;
} }
/****************************************************************************** /******************************************************************************
...@@ -478,6 +529,10 @@ static HRESULT WINAPI JoystickAImpl_SetDataFormat( ...@@ -478,6 +529,10 @@ static HRESULT WINAPI JoystickAImpl_SetDataFormat(
return DIERR_ACQUIRED; return DIERR_ACQUIRED;
} }
HeapFree(GetProcessHeap(),0,This->df->rgodf);
HeapFree(GetProcessHeap(),0,This->df);
release_DataFormat(This->transform);
/* Store the new data format */ /* Store the new data format */
This->df = HeapAlloc(GetProcessHeap(),0,df->dwSize); This->df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
if (This->df==NULL) { if (This->df==NULL) {
...@@ -491,6 +546,8 @@ static HRESULT WINAPI JoystickAImpl_SetDataFormat( ...@@ -491,6 +546,8 @@ static HRESULT WINAPI JoystickAImpl_SetDataFormat(
} }
memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize); memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
This->transform = create_DataFormat(&c_dfDIJoystick2, This->df, This->offsets);
return DI_OK; return DI_OK;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment