Skip to content

Commit

Permalink
Remove support for XInput 9.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn committed Dec 6, 2024
1 parent b233333 commit fa0f1e5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 84 deletions.
4 changes: 0 additions & 4 deletions Inc/GamePad.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@

#elif defined(USING_XINPUT)
#ifdef _MSC_VER
#if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/ )
#pragma comment(lib,"xinput.lib")
#else
#pragma comment(lib,"xinput9_1_0.lib")
#endif
#endif
#endif

Expand Down
82 changes: 2 additions & 80 deletions Src/GamePad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1286,11 +1286,6 @@ class GamePad::Impl
mOwner(owner),
mConnected{},
mLastReadTime{}
#if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
, mLeftMotor{}
, mRightMotor{}
, mSuspended(false)
#endif
{
for (int j = 0; j < XUSER_MAX_COUNT; ++j)
{
Expand Down Expand Up @@ -1319,15 +1314,6 @@ class GamePad::Impl

if (!ThrottleRetry(player, time))
{
#if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
if (mSuspended)
{
memset(&state, 0, sizeof(State));
state.connected = mConnected[player];
return;
}
#endif

XINPUT_STATE xstate;
const DWORD result = XInputGetState(DWORD(player), &xstate);
if (result == ERROR_DEVICE_NOT_CONNECTED)
Expand Down Expand Up @@ -1414,7 +1400,6 @@ class GamePad::Impl
if (xcaps.Type == XINPUT_DEVTYPE_GAMEPAD)
{
static_assert(Capabilities::GAMEPAD == XINPUT_DEVSUBTYPE_GAMEPAD, "xinput.h mismatch");
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
static_assert(XINPUT_DEVSUBTYPE_WHEEL == Capabilities::WHEEL, "xinput.h mismatch");
static_assert(XINPUT_DEVSUBTYPE_ARCADE_STICK == Capabilities::ARCADE_STICK, "xinput.h mismatch");
#ifndef __MINGW32__
Expand All @@ -1426,19 +1411,13 @@ class GamePad::Impl
static_assert(XINPUT_DEVSUBTYPE_DRUM_KIT == Capabilities::DRUM_KIT, "xinput.h mismatch");
static_assert(XINPUT_DEVSUBTYPE_GUITAR_BASS == Capabilities::GUITAR_BASS, "xinput.h mismatch");
static_assert(XINPUT_DEVSUBTYPE_ARCADE_PAD == Capabilities::ARCADE_PAD, "xinput.h mismatch");
#endif

caps.gamepadType = Capabilities::Type(xcaps.SubType);
}

// Hard-coded VID/PID
caps.vid = 0x045E;
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
caps.pid = (xcaps.Flags & XINPUT_CAPS_WIRELESS) ? 0x0719 : 0;
#else
caps.pid = 0;
#endif

return;
}
}
Expand All @@ -1463,14 +1442,6 @@ class GamePad::Impl
UNREFERENCED_PARAMETER(leftTrigger);
UNREFERENCED_PARAMETER(rightTrigger);

#if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
mLeftMotor[player] = leftMotor;
mRightMotor[player] = rightMotor;

if (mSuspended)
return mConnected[player];
#endif

XINPUT_VIBRATION xvibration;
xvibration.wLeftMotorSpeed = WORD(leftMotor * 0xFFFF);
xvibration.wRightMotorSpeed = WORD(rightMotor * 0xFFFF);
Expand All @@ -1494,56 +1465,17 @@ class GamePad::Impl
{
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
// XInput focus is handled automatically on Windows 10
#elif (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
XInputEnable(FALSE);
#else
// For XInput 9.1.0, we have to emulate the behavior of XInputEnable( FALSE )
if (!mSuspended)
{
for (size_t j = 0; j < XUSER_MAX_COUNT; ++j)
{
if (mConnected[j])
{
XINPUT_VIBRATION xvibration;
xvibration.wLeftMotorSpeed = xvibration.wRightMotorSpeed = 0;
std::ignore = XInputSetState(DWORD(j), &xvibration);
}
}

mSuspended = true;
}
XInputEnable(FALSE);
#endif
}

void Resume() noexcept
{
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
// XInput focus is handled automatically on Windows 10
#elif (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
XInputEnable(TRUE);
#else
// For XInput 9.1.0, we have to emulate the behavior of XInputEnable( TRUE )
if (mSuspended)
{
const ULONGLONG time = GetTickCount64();

for (int j = 0; j < XUSER_MAX_COUNT; ++j)
{
if (mConnected[j])
{
XINPUT_VIBRATION xvibration;
xvibration.wLeftMotorSpeed = WORD(mLeftMotor[j] * 0xFFFF);
xvibration.wRightMotorSpeed = WORD(mRightMotor[j] * 0xFFFF);
const DWORD result = XInputSetState(DWORD(j), &xvibration);
if (result == ERROR_DEVICE_NOT_CONNECTED)
{
ClearSlot(j, time);
}
}
}

mSuspended = false;
}
XInputEnable(TRUE);
#endif
}

Expand All @@ -1555,13 +1487,6 @@ class GamePad::Impl
bool mConnected[XUSER_MAX_COUNT];
ULONGLONG mLastReadTime[XUSER_MAX_COUNT];

#if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
// Variables for emulating XInputEnable on XInput 9.1.0
float mLeftMotor[XUSER_MAX_COUNT];
float mRightMotor[XUSER_MAX_COUNT];
bool mSuspended;
#endif

bool ThrottleRetry(int player, ULONGLONG time)
{
// This function minimizes a potential performance issue with XInput on Windows when
Expand Down Expand Up @@ -1596,9 +1521,6 @@ class GamePad::Impl
{
mConnected[player] = false;
mLastReadTime[player] = time;
#if (_WIN32_WINNT < _WIN32_WINNT_WIN8)
mLeftMotor[player] = mRightMotor[player] = 0.f;
#endif
}

int GetMostRecent()
Expand Down

0 comments on commit fa0f1e5

Please sign in to comment.