From f9e11d8093deead9ff74f0b2673c4dceeca8c9f8 Mon Sep 17 00:00:00 2001 From: _ <@> Date: Thu, 8 Aug 2019 04:07:22 +0200 Subject: [PATCH] Xinput improvements with more than 1 controller --- source-code/data/plugins/keyconfig.ini | 3 ++ .../plugins/TLAC/Input/Xinput/Xinput.cpp | 32 ++++++++++++++----- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/source-code/data/plugins/keyconfig.ini b/source-code/data/plugins/keyconfig.ini index d14d206..1cee184 100644 --- a/source-code/data/plugins/keyconfig.ini +++ b/source-code/data/plugins/keyconfig.ini @@ -10,6 +10,9 @@ mouse_scroll_pv_selection = true # in most cases this does not need editing. touch_slider_emulation_speed = 750.0 +# preferred Xinput controller (0-3) +xinput_preferred = 0 + # JVS Buttons: JVS_TEST = F1 JVS_SERVICE = F2 diff --git a/source-code/source/plugins/TLAC/Input/Xinput/Xinput.cpp b/source-code/source/plugins/TLAC/Input/Xinput/Xinput.cpp index 5818978..7ecf435 100644 --- a/source-code/source/plugins/TLAC/Input/Xinput/Xinput.cpp +++ b/source-code/source/plugins/TLAC/Input/Xinput/Xinput.cpp @@ -1,6 +1,8 @@ #include #include "Xinput.h" #include "../../Constants.h" +#include "../../FileSystem/ConfigFile.h" +#include "../../framework.h" namespace TLAC::Input { @@ -55,8 +57,16 @@ namespace TLAC::Input ZeroMemory(&state, sizeof(XINPUT_STATE)); float elapsed = keyIntervalWatch.Restart(); - if (XInputGetState(0, &state) == ERROR_SUCCESS) + TLAC::FileSystem::ConfigFile configFile(TLAC::framework::GetModuleDirectory(), "keyconfig.ini"); + configFile.OpenRead(); + + int xc_pref = configFile.GetIntegerValue("xinput_preferred"); + if (xc_pref < 0 || xc_pref > 3) xc_pref = 0; + for (int n = 0; n < 4; n++) { + ZeroMemory(&state, sizeof(XINPUT_STATE)); + if (XInputGetState(xc_pref, &state) == ERROR_SUCCESS) + { BYTE i = XINPUT_A; { currentState.KeyStates[i] = false; @@ -136,7 +146,7 @@ namespace TLAC::Input currentState.KeyStates[i] = true; SetTapStates(i, elapsed); } - + i = XINPUT_LSB; { currentState.KeyStates[i] = false; @@ -193,7 +203,7 @@ namespace TLAC::Input if (state.Gamepad.sThumbLX > 10000) currentState.KeyStates[i] = true; SetTapStates(i, elapsed); - + i = XINPUT_LLEFT; currentState.KeyStates[i] = false; if (state.Gamepad.sThumbLX < -10000) @@ -208,17 +218,23 @@ namespace TLAC::Input if (state.Gamepad.sThumbRX > 10000) currentState.KeyStates[i] = true; SetTapStates(i, elapsed); - + i = XINPUT_RLEFT; currentState.KeyStates[i] = false; if (state.Gamepad.sThumbRX < -10000) currentState.KeyStates[i] = true; SetTapStates(i, elapsed); } - } - else { - ZeroMemory(&state, sizeof(XINPUT_STATE)); - ZeroMemory(¤tState, sizeof(currentState)); + + break; + } + else if (n == 3) { + ZeroMemory(&state, sizeof(XINPUT_STATE)); + ZeroMemory(¤tState, sizeof(currentState)); + } + + if (xc_pref == 3) xc_pref = 0; + else xc_pref++; } return TRUE; }