Skip to content

Commit

Permalink
osd/modules/input/input_dinput.cpp: Adjusted heuristics to work bette…
Browse files Browse the repository at this point in the history
…r with newer DualShock/DualSense controllers.
  • Loading branch information
cuavas committed Mar 29, 2023
1 parent 1302585 commit 664f210
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
32 changes: 16 additions & 16 deletions src/osd/modules/input/input_dinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ might expect from the HID mapping.
Gamepads:
Axis Logitech Xinput Switch
X Left X Left X Left X
Y Left Y Left Y Left Y
Z Right X Triggers
Rx Right X Right X
Ry Right Y Right Y
Rz Right Y
Axis Logitech DS4 Xinput Switch
X Left X Left X Left X Left X
Y Left Y Left Y Left Y Left Y
Z Right X Right X Triggers
Rx Left trigger Right X Right X
Ry Right trigger Right Y Right Y
Rz Right Y Right Y
Thrustmaster controllers:
Expand Down Expand Up @@ -1041,12 +1041,11 @@ void dinput_joystick_device::configure(input_device &device)
{ axisitems[0], axisitems[1] },
{ ITEM_ID_INVALID, ITEM_ID_INVALID } };
input_item_id pedalaxis = ITEM_ID_INVALID;
if ((ITEM_ID_INVALID != axisitems[3]) && (ITEM_ID_INVALID != axisitems[4]))
if ((ITEM_ID_INVALID != axisitems[2]) && (ITEM_ID_INVALID != axisitems[5]))
{
// assume Rx/Ry are right stick and Z is triggers if present
stickaxes[1][0] = axisitems[3];
stickaxes[1][1] = axisitems[4];
pedalaxis = axisitems[2];
// assume Z/Rz are right stick
stickaxes[1][0] = axisitems[2];
stickaxes[1][1] = axisitems[5];
add_twin_stick_assignments(
assignments,
stickaxes[0][0],
Expand All @@ -1062,11 +1061,12 @@ void dinput_joystick_device::configure(input_device &device)
ITEM_ID_INVALID,
ITEM_ID_INVALID);
}
else if ((ITEM_ID_INVALID != axisitems[2]) && (ITEM_ID_INVALID != axisitems[5]))
else if ((ITEM_ID_INVALID != axisitems[3]) && (ITEM_ID_INVALID != axisitems[4]))
{
// assume Z/Rz are right stick
stickaxes[1][0] = axisitems[2];
stickaxes[1][1] = axisitems[5];
// assume Rx/Ry are right stick and Z is triggers if present
stickaxes[1][0] = axisitems[3];
stickaxes[1][1] = axisitems[4];
pedalaxis = axisitems[2];
add_twin_stick_assignments(
assignments,
stickaxes[0][0],
Expand Down
18 changes: 9 additions & 9 deletions src/osd/modules/input/input_dinput.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <mutex>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>

#include <windows.h>
Expand Down Expand Up @@ -87,17 +88,10 @@ class dinput_api_helper
template <typename T>
HRESULT enum_attached_devices(int devclass, T &&callback) const
{
struct helper
{
static BOOL CALLBACK callback(LPCDIDEVICEINSTANCE instance, LPVOID ref)
{
return (*reinterpret_cast<T *>(ref))(instance);
}
};
return m_dinput->EnumDevices(
devclass,
&helper::callback,
reinterpret_cast<LPVOID>(&callback),
&di_emun_devices_cb<std::remove_reference_t<T> >,
LPVOID(&callback),
DIEDFL_ATTACHEDONLY);
}

Expand Down Expand Up @@ -128,6 +122,12 @@ class dinput_api_helper

static std::string make_id(LPCDIDEVICEINSTANCE instance);

template <typename T>
static BOOL CALLBACK di_emun_devices_cb(LPCDIDEVICEINSTANCE instance, LPVOID ref)

This comment has been minimized.

Copy link
@pmackinlay

pmackinlay Mar 29, 2023

Contributor

enum typo?

This comment has been minimized.

Copy link
@cuavas

cuavas Mar 29, 2023

Author Member

It is in fact a typo propagated by autocomplete.

The main purpose of the change to the header is to allow it to work if the supplied callback isn't an rvalue. (I'd preciously made the bare minimum change to fix 32-bit Windows builds. It worked for all the uses in MAME, but it would break attempting to create a pointer to a reference if the callback is an lvalue.)

{
return (*reinterpret_cast<T *>(ref))(instance);
}

Microsoft::WRL::ComPtr<IDirectInput8> m_dinput;
dynamic_module::ptr m_dinput_dll;
};
Expand Down

0 comments on commit 664f210

Please sign in to comment.