Module: wine Branch: master Commit: 8ff74b157acc7ec3d4c69c84091421db5584666e URL: https://gitlab.winehq.org/wine/wine/-/commit/8ff74b157acc7ec3d4c69c84091421d...
Author: Rémi Bernon rbernon@codeweavers.com Date: Wed Mar 22 09:01:08 2023 +0100
dinput: Initialize object formats from device objects in SetActionMap.
---
dlls/dinput/device.c | 50 +++++++++---------------------------------- dlls/dinput/tests/joystick8.c | 11 ++++------ 2 files changed, 14 insertions(+), 47 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index fb7be1e2e6d..28494c3bec6 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -1975,7 +1975,6 @@ static HRESULT WINAPI dinput_device_SetActionMap( IDirectInputDevice8W *iface, D const WCHAR *username, DWORD flags ) { struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface ); - DIOBJECTDATAFORMAT *obj_df = NULL; DIDATAFORMAT data_format = { .dwSize = sizeof(DIDATAFORMAT), @@ -2011,9 +2010,8 @@ static HRESULT WINAPI dinput_device_SetActionMap( IDirectInputDevice8W *iface, D }; WCHAR username_buf[MAX_PATH]; DWORD username_len = MAX_PATH; - int i, action = 0, num_actions = 0; + int i, index, action = 0, num_actions = 0; unsigned int offset = 0; - const DIDATAFORMAT *df; ActionMap *action_map;
FIXME( "iface %p, format %p, username %s, flags %#lx stub!\n", iface, format, @@ -2021,21 +2019,6 @@ static HRESULT WINAPI dinput_device_SetActionMap( IDirectInputDevice8W *iface, D
if (!format) return DIERR_INVALIDPARAM;
- switch (GET_DIDEVICE_TYPE( impl->instance.dwDevType )) - { - case DIDEVTYPE_KEYBOARD: - case DI8DEVTYPE_KEYBOARD: - df = &c_dfDIKeyboard; - break; - case DIDEVTYPE_MOUSE: - case DI8DEVTYPE_MOUSE: - df = &c_dfDIMouse2; - break; - default: - df = &impl->device_format; - break; - } - if (impl->status == STATUS_ACQUIRED) return DIERR_ACQUIRED;
/* Count the actions */ @@ -2045,34 +2028,21 @@ static HRESULT WINAPI dinput_device_SetActionMap( IDirectInputDevice8W *iface, D
if (num_actions == 0) return DI_NOEFFECT;
- /* Construct the dataformat and actionmap */ - obj_df = malloc( sizeof(DIOBJECTDATAFORMAT) * num_actions ); - data_format.rgodf = (LPDIOBJECTDATAFORMAT)obj_df; + data_format.rgodf = malloc( sizeof(DIOBJECTDATAFORMAT) * num_actions ); data_format.dwDataSize = format->dwDataSize;
action_map = malloc( sizeof(ActionMap) * num_actions );
for (i = 0; i < format->dwNumActions; i++, offset += sizeof(ULONG)) { - if (IsEqualGUID( &impl->guid, &format->rgoAction[i].guidInstance )) - { - DWORD inst = DIDFT_GETINSTANCE( format->rgoAction[i].dwObjID ); - DWORD type = DIDFT_GETTYPE( format->rgoAction[i].dwObjID ); - LPDIOBJECTDATAFORMAT obj; - - if (type == DIDFT_PSHBUTTON) type = DIDFT_BUTTON; - if (type == DIDFT_RELAXIS) type = DIDFT_AXIS; + if (!IsEqualGUID( &impl->guid, &format->rgoAction[i].guidInstance )) continue; + if ((index = dinput_device_object_index_from_id( iface, format->rgoAction[i].dwObjID )) < 0) continue;
- if (!(obj = dataformat_to_odf_by_type( df, inst, type ))) continue; - - memcpy( &obj_df[action], obj, df->dwObjSize ); - - action_map[action].uAppData = format->rgoAction[i].uAppData; - action_map[action].offset = offset; - obj_df[action].dwOfs = offset; - data_format.dwNumObjs++; - action++; - } + action_map[action].uAppData = format->rgoAction[i].uAppData; + action_map[action].offset = offset; + data_format.rgodf[data_format.dwNumObjs] = impl->device_format.rgodf[index]; + data_format.rgodf[data_format.dwNumObjs].dwOfs = offset; + data_format.dwNumObjs++; }
IDirectInputDevice8_SetDataFormat( iface, &data_format ); @@ -2080,7 +2050,7 @@ static HRESULT WINAPI dinput_device_SetActionMap( IDirectInputDevice8W *iface, D impl->action_map = action_map; impl->num_actions = num_actions;
- free( obj_df ); + free( data_format.rgodf );
if (format->lAxisMin != format->lAxisMax) { diff --git a/dlls/dinput/tests/joystick8.c b/dlls/dinput/tests/joystick8.c index 1ca2975a15e..40fd3d23e29 100644 --- a/dlls/dinput/tests/joystick8.c +++ b/dlls/dinput/tests/joystick8.c @@ -1046,13 +1046,11 @@ static void test_action_map( IDirectInputDevice8W *device, HANDLE file, HANDLE e
hr = IDirectInputDevice8_GetDeviceState( device, sizeof(state), state ); ok( hr == DI_OK, "GetDeviceState returned: %#lx\n", hr ); - todo_wine_if( i > 5 ) ok( state[0] == expect_state[i][0], "got state[0] %+ld\n", state[0] ); - todo_wine_if( i == 2 || i > 4 ) + todo_wine_if( i == 2 || i == 5 ) ok( state[1] == expect_state[i][1], "got state[1] %+ld\n", state[1] ); todo_wine_if( expect_state[i][2] ) ok( state[2] == expect_state[i][2], "got state[2] %+ld\n", state[2] ); - todo_wine_if( i > 5 ) ok( state[3] == expect_state[i][3], "got state[3] %+ld\n", state[3] ); todo_wine_if( expect_state[i][4] ) ok( state[4] == expect_state[i][4], "got state[4] %+ld\n", state[4] ); @@ -1060,7 +1058,6 @@ static void test_action_map( IDirectInputDevice8W *device, HANDLE file, HANDLE e ok( state[5] == expect_state[i][5], "got state[5] %+ld\n", state[5] ); todo_wine_if( expect_state[i][6] ) ok( state[6] == expect_state[i][6], "got state[6] %+ld\n", state[6] ); - todo_wine_if( expect_state[i][7] ) ok( state[7] == expect_state[i][7] || broken(state[7] == -45 && expect_state[i][7] == -43) /* 32-bit rounding */, "got state[7] %+ld\n", state[7] ); @@ -1082,13 +1079,13 @@ static void test_action_map( IDirectInputDevice8W *device, HANDLE file, HANDLE e while (res--) { winetest_push_context( "%lu", res ); - todo_wine_if( res != 1 && res != 4 ) + todo_wine check_member( objdata[res], expect_objdata[res], "%#lx", dwOfs ); - todo_wine_if( res == 0 || res == 3 || res == 6 ) + todo_wine ok( objdata[res].dwData == expect_objdata[res].dwData || broken(objdata[res].dwData == -45 && expect_objdata[res].dwData == -43) /* 32-bit rounding */, "got dwData %+ld\n", objdata[res].dwData ); - todo_wine_if( res != 1 && res != 4 ) + todo_wine check_member( objdata[res], expect_objdata[res], "%#Ix", uAppData ); winetest_pop_context(); }