dinput: Add user data format into base class. Implement SetDataFormat.
This commit is contained in:
parent
cd050bf25c
commit
3446caab56
|
@ -288,6 +288,10 @@ void release_DataFormat(DataFormat * format)
|
||||||
format->dt = NULL;
|
format->dt = NULL;
|
||||||
HeapFree(GetProcessHeap(), 0, format->offsets);
|
HeapFree(GetProcessHeap(), 0, format->offsets);
|
||||||
format->offsets = NULL;
|
format->offsets = NULL;
|
||||||
|
if (format->user_df)
|
||||||
|
HeapFree(GetProcessHeap(), 0, format->user_df->rgodf);
|
||||||
|
HeapFree(GetProcessHeap(), 0, format->user_df);
|
||||||
|
format->user_df = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make all instances sequential */
|
/* Make all instances sequential */
|
||||||
|
@ -332,7 +336,7 @@ static void calculate_ids(LPDIDATAFORMAT df)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT create_DataFormat(LPCDIDATAFORMAT wine_format, LPDIDATAFORMAT asked_format, DataFormat *format)
|
HRESULT create_DataFormat(LPCDIDATAFORMAT wine_format, LPCDIDATAFORMAT asked_format, DataFormat *format)
|
||||||
{
|
{
|
||||||
DataTransform *dt;
|
DataTransform *dt;
|
||||||
unsigned int i, j;
|
unsigned int i, j;
|
||||||
|
@ -348,6 +352,14 @@ HRESULT create_DataFormat(LPCDIDATAFORMAT wine_format, LPDIDATAFORMAT asked_form
|
||||||
if (!(format->offsets = HeapAlloc(GetProcessHeap(), 0, wine_format->dwNumObjs * sizeof(int))))
|
if (!(format->offsets = HeapAlloc(GetProcessHeap(), 0, wine_format->dwNumObjs * sizeof(int))))
|
||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
|
if (!(format->user_df = HeapAlloc(GetProcessHeap(), 0, asked_format->dwSize)))
|
||||||
|
goto failed;
|
||||||
|
memcpy(format->user_df, asked_format, asked_format->dwSize);
|
||||||
|
|
||||||
|
if (!(format->user_df->rgodf = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs*asked_format->dwObjSize)))
|
||||||
|
goto failed;
|
||||||
|
memcpy(format->user_df->rgodf, asked_format->rgodf, asked_format->dwNumObjs*asked_format->dwObjSize);
|
||||||
|
|
||||||
TRACE("Creating DataTransform :\n");
|
TRACE("Creating DataTransform :\n");
|
||||||
|
|
||||||
for (i = 0; i < wine_format->dwNumObjs; i++) {
|
for (i = 0; i < wine_format->dwNumObjs; i++) {
|
||||||
|
@ -450,7 +462,7 @@ HRESULT create_DataFormat(LPCDIDATAFORMAT wine_format, LPDIDATAFORMAT asked_form
|
||||||
HeapFree(GetProcessHeap(), 0, done);
|
HeapFree(GetProcessHeap(), 0, done);
|
||||||
|
|
||||||
/* Last step - reset all instances of the new format */
|
/* Last step - reset all instances of the new format */
|
||||||
calculate_ids(asked_format);
|
calculate_ids(format->user_df);
|
||||||
return DI_OK;
|
return DI_OK;
|
||||||
|
|
||||||
failed:
|
failed:
|
||||||
|
@ -459,6 +471,10 @@ failed:
|
||||||
format->dt = NULL;
|
format->dt = NULL;
|
||||||
HeapFree(GetProcessHeap(), 0, format->offsets);
|
HeapFree(GetProcessHeap(), 0, format->offsets);
|
||||||
format->offsets = NULL;
|
format->offsets = NULL;
|
||||||
|
if (format->user_df)
|
||||||
|
HeapFree(GetProcessHeap(), 0, format->user_df->rgodf);
|
||||||
|
HeapFree(GetProcessHeap(), 0, format->user_df);
|
||||||
|
format->user_df = NULL;
|
||||||
|
|
||||||
return DIERR_OUTOFMEMORY;
|
return DIERR_OUTOFMEMORY;
|
||||||
}
|
}
|
||||||
|
@ -570,6 +586,8 @@ HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
|
||||||
IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
|
IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
|
||||||
HRESULT res;
|
HRESULT res;
|
||||||
|
|
||||||
|
if (!This->data_format.user_df) return DIERR_INVALIDPARAM;
|
||||||
|
|
||||||
EnterCriticalSection(&This->crit);
|
EnterCriticalSection(&This->crit);
|
||||||
res = This->acquired ? S_FALSE : DI_OK;
|
res = This->acquired ? S_FALSE : DI_OK;
|
||||||
This->acquired = 1;
|
This->acquired = 1;
|
||||||
|
@ -602,15 +620,25 @@ HRESULT WINAPI IDirectInputDevice2AImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
HRESULT WINAPI IDirectInputDevice2AImpl_SetDataFormat(
|
HRESULT WINAPI IDirectInputDevice2AImpl_SetDataFormat(
|
||||||
LPDIRECTINPUTDEVICE8A iface,LPCDIDATAFORMAT df
|
LPDIRECTINPUTDEVICE8A iface, LPCDIDATAFORMAT df)
|
||||||
) {
|
{
|
||||||
IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
|
IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
|
||||||
|
HRESULT res = DI_OK;
|
||||||
TRACE("(this=%p,%p)\n",This,df);
|
|
||||||
|
if (!df) return E_POINTER;
|
||||||
|
TRACE("(%p) %p\n", This, df);
|
||||||
_dump_DIDATAFORMAT(df);
|
_dump_DIDATAFORMAT(df);
|
||||||
|
|
||||||
return DI_OK;
|
if (df->dwSize != sizeof(DIDATAFORMAT)) return DIERR_INVALIDPARAM;
|
||||||
|
if (This->acquired) return DIERR_ACQUIRED;
|
||||||
|
|
||||||
|
EnterCriticalSection(&This->crit);
|
||||||
|
|
||||||
|
release_DataFormat(&This->data_format);
|
||||||
|
res = create_DataFormat(This->data_format.wine_df, df, &This->data_format);
|
||||||
|
|
||||||
|
LeaveCriticalSection(&This->crit);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
|
|
|
@ -40,7 +40,9 @@ typedef struct
|
||||||
int internal_format_size;
|
int internal_format_size;
|
||||||
DataTransform *dt;
|
DataTransform *dt;
|
||||||
|
|
||||||
int *offsets; /* object offsets */
|
int *offsets; /* object offsets */
|
||||||
|
LPCDIDATAFORMAT wine_df; /* wine internal data format */
|
||||||
|
LPDIDATAFORMAT user_df; /* user defined data format */
|
||||||
} DataFormat;
|
} DataFormat;
|
||||||
|
|
||||||
/* Device implementation */
|
/* Device implementation */
|
||||||
|
@ -67,7 +69,7 @@ struct IDirectInputDevice2AImpl
|
||||||
|
|
||||||
/* Routines to do DataFormat / WineFormat conversions */
|
/* Routines to do DataFormat / WineFormat conversions */
|
||||||
extern void fill_DataFormat(void *out, const void *in, DataFormat *df) ;
|
extern void fill_DataFormat(void *out, const void *in, DataFormat *df) ;
|
||||||
extern HRESULT create_DataFormat(LPCDIDATAFORMAT wine_format, LPDIDATAFORMAT asked_format, DataFormat *format);
|
extern HRESULT create_DataFormat(LPCDIDATAFORMAT wine_format, LPCDIDATAFORMAT asked_format, DataFormat *format);
|
||||||
extern void release_DataFormat(DataFormat *df) ;
|
extern void release_DataFormat(DataFormat *df) ;
|
||||||
extern void queue_event(LPDIRECTINPUTDEVICE8A iface, int ofs, DWORD data, DWORD time, DWORD seq);
|
extern void queue_event(LPDIRECTINPUTDEVICE8A iface, int ofs, DWORD data, DWORD time, DWORD seq);
|
||||||
/* Helper functions to work with data format */
|
/* Helper functions to work with data format */
|
||||||
|
|
Loading…
Reference in New Issue