From 0bd31e1567b46ac08ec04ae80f1030ca7ae27c03 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 2 Apr 2017 14:34:20 -0700 Subject: [PATCH] Windows: Reduce CPU usage with no XInput connected. --- Windows/XinputDevice.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Windows/XinputDevice.cpp b/Windows/XinputDevice.cpp index 1604022de2..45fd321557 100644 --- a/Windows/XinputDevice.cpp +++ b/Windows/XinputDevice.cpp @@ -111,6 +111,10 @@ XinputDevice::XinputDevice() { if (LoadXInputDLL() != 0) { WARN_LOG(SCECTRL, "Failed to load XInput! DLL missing"); } + + for (size_t i = 0; i < ARRAY_SIZE(check_delay); ++i) { + check_delay[i] = i; + } } XinputDevice::~XinputDevice() { @@ -228,10 +232,13 @@ int XinputDevice::UpdateState() { if (dwResult == ERROR_SUCCESS) { UpdatePad(i, state); anySuccess = true; + } else { + check_delay[i] = 30; } } - // If we get XInput, skip the others. This might not actually be a good idea. + // If we get XInput, skip the others. This might not actually be a good idea, + // and was done to avoid conflicts between DirectInput and XInput. return anySuccess ? UPDATESTATE_SKIP_PAD : 0; } @@ -298,8 +305,8 @@ void XinputDevice::UpdatePad(int pad, const XINPUT_STATE &state) { NativeAxis(axis); } - this->prevState[pad] = state; - this->check_delay[pad] = 0; + prevState[pad] = state; + check_delay[pad] = 0; } void XinputDevice::ApplyButtons(int pad, const XINPUT_STATE &state) {