dinput: Move few helper functions and standardize them.

This commit is contained in:
Vitaliy Margolen 2006-12-10 14:15:29 -07:00 committed by Alexandre Julliard
parent 267cbf8289
commit 68176eeda1
4 changed files with 55 additions and 92 deletions

View File

@ -453,6 +453,42 @@ DataFormat *create_DataFormat(LPCDIDATAFORMAT wine_format, LPDIDATAFORMAT asked_
return ret;
}
/* find an object by it's offset in a data format */
int offset_to_object(LPCDIDATAFORMAT df, int offset)
{
int i;
for (i = 0; i < df->dwNumObjs; i++)
if (df->rgodf[i].dwOfs == offset)
return i;
return -1;
}
static int id_to_object(LPCDIDATAFORMAT df, int id)
{
int i;
for (i = 0; i < df->dwNumObjs; i++)
if ((df->rgodf[i].dwType & 0x00ffffff) == (id & 0x00ffffff))
return i;
return -1;
}
int find_property(LPCDIDATAFORMAT df, LPCDIPROPHEADER ph)
{
switch (ph->dwHow)
{
case DIPH_BYID: return id_to_object(df, ph->dwObj);
case DIPH_BYOFFSET: return offset_to_object(df, ph->dwObj);
}
FIXME("Unhandled ph->dwHow=='%04X'\n", (unsigned int)ph->dwHow);
return -1;
}
BOOL DIEnumDevicesCallbackAtoW(LPCDIDEVICEOBJECTINSTANCEA lpddi, LPVOID lpvRef) {
DIDEVICEOBJECTINSTANCEW ddtmp;
device_enumobjects_AtoWcb_data* data;

View File

@ -63,6 +63,9 @@ extern void fill_DataFormat(void *out, const void *in, DataFormat *df) ;
extern DataFormat *create_DataFormat(LPCDIDATAFORMAT wine_format, LPDIDATAFORMAT asked_format, int *offset);
extern void release_DataFormat(DataFormat *df) ;
extern void queue_event(LPDIRECTINPUTDEVICE8A iface, int ofs, DWORD data, DWORD time, DWORD seq);
/* Helper functions to work with data format */
extern int offset_to_object(LPCDIDATAFORMAT df, int offset);
extern int find_property(LPCDIDATAFORMAT df, LPCDIPROPHEADER ph);
/**
* Callback Data used by specific callback

View File

@ -791,19 +791,6 @@ static LONG map_axis(JoystickImpl * This, short val, short index)
return fret;
}
/* convert wine format offset to user format object index */
static int offset_to_object(JoystickImpl *This, int offset)
{
int i;
for (i = 0; i < This->user_df->dwNumObjs; i++) {
if (This->user_df->rgodf[i].dwOfs == offset)
return i;
}
return -1;
}
static LONG calculate_pov(JoystickImpl *This, int index)
{
if (This->povs[index].lX < -16384) {
@ -862,7 +849,7 @@ static void joy_polldev(JoystickImpl *This) {
int number = This->axis_map[jse.number]; /* wine format object index */
if (number < 12) {
int offset = This->offsets[number];
int index = offset_to_object(This, offset);
int index = offset_to_object(This->user_df, offset);
LONG value = map_axis(This, jse.value, index);
/* FIXME do deadzone and saturation here */
@ -958,22 +945,6 @@ static HRESULT WINAPI JoystickAImpl_GetDeviceState(
return DI_OK;
}
static int find_property(JoystickImpl * This, LPCDIPROPHEADER ph)
{
int i;
if (ph->dwHow == DIPH_BYOFFSET) {
return offset_to_object(This, ph->dwObj);
} else if (ph->dwHow == DIPH_BYID) {
for (i = 0; i < This->user_df->dwNumObjs; i++) {
if ((This->user_df->rgodf[i].dwType & 0x00ffffff) == (ph->dwObj & 0x00ffffff)) {
return i;
}
}
}
return -1;
}
/******************************************************************************
* SetProperty : change input device properties
*/
@ -1006,7 +977,7 @@ static HRESULT WINAPI JoystickAImpl_SetProperty(
This->props[i].lMax = pr->lMax;
}
} else {
int obj = find_property(This, ph);
int obj = find_property(This->user_df, ph);
TRACE("proprange(%d,%d) obj=%d\n", pr->lMin, pr->lMax, obj);
if (obj >= 0) {
This->props[obj].lMin = pr->lMin;
@ -1023,7 +994,7 @@ static HRESULT WINAPI JoystickAImpl_SetProperty(
for (i = 0; i < This->user_df->dwNumObjs; i++)
This->props[i].lDeadZone = pd->dwData;
} else {
int obj = find_property(This, ph);
int obj = find_property(This->user_df, ph);
TRACE("deadzone(%d) obj=%d\n", pd->dwData, obj);
if (obj >= 0) {
This->props[obj].lDeadZone = pd->dwData;
@ -1039,7 +1010,7 @@ static HRESULT WINAPI JoystickAImpl_SetProperty(
for (i = 0; i < This->user_df->dwNumObjs; i++)
This->props[i].lSaturation = pd->dwData;
} else {
int obj = find_property(This, ph);
int obj = find_property(This->user_df, ph);
TRACE("saturation(%d) obj=%d\n", pd->dwData, obj);
if (obj >= 0) {
This->props[obj].lSaturation = pd->dwData;
@ -1184,7 +1155,7 @@ static HRESULT WINAPI JoystickAImpl_EnumObjects(
}
if (wine_obj < 8) {
user_offset = This->offsets[wine_obj]; /* get user offset from wine index */
user_object = offset_to_object(This, user_offset);
user_object = offset_to_object(This->user_df, user_offset);
ddoi.dwType = This->user_df->rgodf[user_object].dwType & 0x00ffffff;
ddoi.dwOfs = This->user_df->rgodf[user_object].dwOfs;
@ -1193,7 +1164,7 @@ static HRESULT WINAPI JoystickAImpl_EnumObjects(
} else {
if (pov[wine_obj - 8] < 2) {
user_offset = This->offsets[wine_obj]; /* get user offset from wine index */
user_object = offset_to_object(This, user_offset);
user_object = offset_to_object(This->user_df, user_offset);
ddoi.dwType = This->user_df->rgodf[user_object].dwType & 0x00ffffff;
ddoi.dwOfs = This->user_df->rgodf[user_object].dwOfs;
@ -1218,7 +1189,7 @@ static HRESULT WINAPI JoystickAImpl_EnumObjects(
for (i = 0; i < This->buttons; i++) {
user_offset = This->offsets[i + 12]; /* get user offset from wine index */
user_object = offset_to_object(This, user_offset);
user_object = offset_to_object(This->user_df, user_offset);
ddoi.guidType = GUID_Button;
ddoi.dwType = This->user_df->rgodf[user_object].dwType & 0x00ffffff;
ddoi.dwOfs = This->user_df->rgodf[user_object].dwOfs;
@ -1269,7 +1240,7 @@ static HRESULT WINAPI JoystickAImpl_GetProperty(
switch (LOWORD(rguid)) {
case (DWORD) DIPROP_RANGE: {
LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
int obj = find_property(This, pdiph);
int obj = find_property(This->user_df, pdiph);
/* The app is querying the current range of the axis
* return the lMin and lMax values */
if (obj >= 0) {
@ -1282,7 +1253,7 @@ static HRESULT WINAPI JoystickAImpl_GetProperty(
}
case (DWORD) DIPROP_DEADZONE: {
LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
int obj = find_property(This, pdiph);
int obj = find_property(This->user_df, pdiph);
if (obj >= 0) {
pd->dwData = This->props[obj].lDeadZone;
TRACE("deadzone(%d) obj=%d\n", pd->dwData, obj);
@ -1292,7 +1263,7 @@ static HRESULT WINAPI JoystickAImpl_GetProperty(
}
case (DWORD) DIPROP_SATURATION: {
LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
int obj = find_property(This, pdiph);
int obj = find_property(This->user_df, pdiph);
if (obj >= 0) {
pd->dwData = This->props[obj].lSaturation;
TRACE("saturation(%d) obj=%d\n", pd->dwData, obj);

View File

@ -147,11 +147,9 @@ struct JoystickImpl
};
static void fake_current_js_state(JoystickImpl *ji);
static int find_property_offset(JoystickImpl *This, LPCDIPROPHEADER ph);
static DWORD map_pov(int event_value, int is_x);
static void find_joydevs(void);
static int lxinput_to_user_offset(JoystickImpl *This, int ie_type, int ie_code);
static int offset_to_object(JoystickImpl *This, int offset);
/* This GUID is slightly different from the linux joystick one. Take note. */
static const GUID DInput_Wine_Joystick_Base_GUID = { /* 9e573eda-7734-11d2-8d4a-23903fb6bdf7 */
@ -709,39 +707,6 @@ static DWORD map_pov(int event_value, int is_x)
return ret;
}
static int find_property_offset(JoystickImpl *This, LPCDIPROPHEADER ph)
{
int i, ofs = -1;
switch (ph->dwHow) {
case DIPH_BYOFFSET:
for (i=0; i<This->df->dwNumObjs; i++) {
if (This->offsets[i]==ph->dwObj) {
return i;
}
}
break;
case DIPH_BYID:
for (i=0; i<This->df->dwNumObjs; i++) {
if ((This->df->rgodf[i].dwType & 0x00ffffff) == (ph->dwObj & 0x00ffffff)) {
ofs = This->df->rgodf[i].dwOfs;
break;
}
}
if (ofs!=-1) {
for (i=0; i<This->df->dwNumObjs; i++) {
if (This->offsets[i]==ofs) {
return i;
}
}
}
break;
default:
FIXME("Unhandled ph->dwHow=='%04X'\n", (unsigned int)ph->dwHow);
}
return -1;
}
/* defines how the linux input system offset mappings into c_dfDIJoystick2 */
static int
lxinput_to_user_offset(JoystickImpl *This, int ie_type, int ie_code )
@ -783,18 +748,6 @@ lxinput_to_user_offset(JoystickImpl *This, int ie_type, int ie_code )
}
/* convert wine format offset to user format object index */
static int offset_to_object(JoystickImpl *This, int offset)
{
int i;
for (i = 0; i < This->df->dwNumObjs; i++) {
if (This->df->rgodf[i].dwOfs == offset)
return i;
}
return -1;
}
static void joy_polldev(JoystickImpl *This) {
struct pollfd plfd;
struct input_event ie;
@ -975,7 +928,7 @@ static HRESULT WINAPI JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
This->wantmax[i] = pr->lMax;
}
} else {
int obj = find_property_offset(This, ph);
int obj = find_property(This->df, ph);
TRACE("proprange(%d,%d) obj=%d\n", pr->lMin, pr->lMax, obj);
if (obj >= 0) {
This->wantmin[obj] = pr->lMin;
@ -994,7 +947,7 @@ static HRESULT WINAPI JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
This->deadz[i] = pd->dwData;
}
} else {
int obj = find_property_offset(This, ph);
int obj = find_property(This->df, ph);
TRACE("deadzone(%d) obj=%d\n", pd->dwData, obj);
if (obj >= 0) {
This->deadz[obj] = pd->dwData;
@ -1153,7 +1106,7 @@ static HRESULT WINAPI JoystickAImpl_EnumObjects(
if ((user_offset = lxinput_to_user_offset(This, EV_ABS, i)) == -1) {
continue;
}
user_object = offset_to_object(This, user_offset);
user_object = offset_to_object(This->df, user_offset);
ddoi.dwType = This->df->rgodf[user_object].dwType & 0x00ffffff;
ddoi.dwOfs = This->df->rgodf[user_object].dwOfs;
/* Linux event force feedback supports only (and always) x and y axes */
@ -1178,7 +1131,7 @@ static HRESULT WINAPI JoystickAImpl_EnumObjects(
if ((user_offset = lxinput_to_user_offset(This, EV_ABS, ABS_HAT0X+i))== -1) {
continue;
}
user_object = offset_to_object(This, user_offset);
user_object = offset_to_object(This->df, user_offset);
ddoi.dwType = This->df->rgodf[user_object].dwType & 0x00ffffff;
ddoi.dwOfs = This->df->rgodf[user_object].dwOfs;
sprintf(ddoi.tszName, "%d-POV", i);
@ -1203,7 +1156,7 @@ static HRESULT WINAPI JoystickAImpl_EnumObjects(
if ((user_offset = lxinput_to_user_offset(This, EV_KEY, btncount)) == -1) {
continue;
}
user_object = offset_to_object(This, user_offset);
user_object = offset_to_object(This->df, user_offset);
ddoi.dwType = This->df->rgodf[user_object].dwType & 0x00ffffff;
ddoi.dwOfs = This->df->rgodf[user_object].dwOfs;
sprintf(ddoi.tszName, "%d-Button", btncount);
@ -1252,7 +1205,7 @@ static HRESULT WINAPI JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
switch (LOWORD(rguid)) {
case (DWORD) DIPROP_RANGE: {
LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
int obj = find_property_offset(This, pdiph);
int obj = find_property(This->df, pdiph);
if (obj >= 0) {
pr->lMin = This->joydev->havemin[obj];
pr->lMax = This->joydev->havemax[obj];