From 722e7cafc1302d39be55e40bcf6989be8d1add8c Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Thu, 11 Jul 2019 06:12:29 +1000 Subject: [PATCH] xinput improvements *make LB/RB aliases for LS/RS *support LSB/RSB (thumbstick buttons) *move some duplicated code into a function *add button name comments to keyconfig --- data/plugins/keyconfig.ini | 22 +- source/plugins/TLAC/Constants.h | 2 + .../plugins/TLAC/Input/KeyConfig/Config.cpp | 4 + source/plugins/TLAC/Input/Xinput/Xinput.cpp | 539 +++--------------- source/plugins/TLAC/Input/Xinput/Xinput.h | 2 + 5 files changed, 93 insertions(+), 476 deletions(-) diff --git a/data/plugins/keyconfig.ini b/data/plugins/keyconfig.ini index f001c72..d14d206 100644 --- a/data/plugins/keyconfig.ini +++ b/data/plugins/keyconfig.ini @@ -75,4 +75,24 @@ RIGHT_SIDE_SLIDE_RIGHT = O, Ds4_R_Stick_Right, XINPUT_RRIGHT # "Ds4_L_Stick_Up", "Ds4_L_Stick_Right", "Ds4_L_Stick_Down", "Ds4_L_Stick_Left", "Ds4_L3" # - Right Joystick -# "Ds4_R_Stick_Up", "Ds4_R_Stick_Right", "Ds4_R_Stick_Down", "Ds4_R_Stick_Left", "Ds4_R3" \ No newline at end of file +# "Ds4_R_Stick_Up", "Ds4_R_Stick_Right", "Ds4_R_Stick_Down", "Ds4_R_Stick_Left", "Ds4_R3" + +# --- XINPUT BUTTON NAMES: --- + +# - Face Buttons +# "XINPUT_A", "XINPUT_B", "XINPUT_X", "XINPUT_Y" + +# - Standard Buttons +# "XINPUT_START", "XINPUT_BACK", "XINPUT_LS"/"XINPUT_LB", "XINPUT_RS"/"XINPUT_RB" + +# - D-Pad Directions +# "XINPUT_UP", "XINPUT_DOWN", "XINPUT_LEFT", "XINPUT_RIGHT" + +# - Trigger Buttons +# "XINPUT_LT", "XINPUT_RT" + +# - Left Joystick +# "XINPUT_LLEFT", "XINPUT_LRIGHT", "XINPUT_LSB" + +# - Right Joystick +# "XINPUT_RLEFT", "XINPUT_RRIGHT", "XINPUT_RSB" \ No newline at end of file diff --git a/source/plugins/TLAC/Constants.h b/source/plugins/TLAC/Constants.h index 7796b7f..2641721 100644 --- a/source/plugins/TLAC/Constants.h +++ b/source/plugins/TLAC/Constants.h @@ -90,6 +90,8 @@ constexpr uint64_t UI_ASPECT_RATIO = 0x000000014CC621D0; #define XINPUT_RS 0x21 #define XINPUT_LT 0x22 #define XINPUT_RT 0x23 +#define XINPUT_LSB 0x24 +#define XINPUT_RSB 0x25 #define XINPUT_START 0x30 #define XINPUT_BACK 0x31 #define XINPUT_LUP 0x40 diff --git a/source/plugins/TLAC/Input/KeyConfig/Config.cpp b/source/plugins/TLAC/Input/KeyConfig/Config.cpp index ac80fe0..ad8e3c0 100644 --- a/source/plugins/TLAC/Input/KeyConfig/Config.cpp +++ b/source/plugins/TLAC/Input/KeyConfig/Config.cpp @@ -112,8 +112,12 @@ namespace TLAC::Input::KeyConfig { "XINPUT_BACK", XINPUT_BACK}, { "XINPUT_LS", XINPUT_LS}, { "XINPUT_RS", XINPUT_RS}, + { "XINPUT_LB", XINPUT_LS}, + { "XINPUT_RB", XINPUT_RS}, { "XINPUT_LT", XINPUT_LT}, { "XINPUT_RT", XINPUT_RT}, + { "XINPUT_LSB", XINPUT_LSB}, + { "XINPUT_RSB", XINPUT_RSB}, { "XINPUT_LLEFT", XINPUT_LLEFT}, { "XINPUT_LRIGHT", XINPUT_LRIGHT}, { "XINPUT_RLEFT", XINPUT_RLEFT}, diff --git a/source/plugins/TLAC/Input/Xinput/Xinput.cpp b/source/plugins/TLAC/Input/Xinput/Xinput.cpp index c2bb9b4..5818978 100644 --- a/source/plugins/TLAC/Input/Xinput/Xinput.cpp +++ b/source/plugins/TLAC/Input/Xinput/Xinput.cpp @@ -20,6 +20,35 @@ namespace TLAC::Input return instance; } + void Xinput::SetTapStates(BYTE keycode, float elapsed) + { + KeyDoubleTapStates[keycode] = IsTapped(keycode) ? KeyDoubleTapWatches[keycode].Restart() <= DOUBLE_TAP_THRESHOLD : false; + + bool isDown = currentState.KeyStates[keycode]; + bool isTapped = IsTapped(keycode); + + keyIntervalTapStates[keycode] = isTapped; + + if (isTapped) + { + keyIntervalTapTimes[keycode] = 0; + keyIntervalInitials[keycode] = true; + } + else if (isDown) + { + float threshold = keyIntervalInitials[keycode] ? INTERVAL_TAP_DELAY_THRESHOLD : INTERVAL_TAP_THRESHOLD; + + bool intervalTapped = (keyIntervalTapTimes[keycode] += elapsed) > threshold; + keyIntervalTapStates[keycode] = intervalTapped; + + if (intervalTapped) + { + keyIntervalTapTimes[keycode] = 0; + keyIntervalInitials[keycode] = false; + } + } + } + bool Xinput::PollInput() { lastState = currentState; @@ -33,32 +62,7 @@ namespace TLAC::Input currentState.KeyStates[i] = false; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_A) currentState.KeyStates[i] = true; - KeyDoubleTapStates[i] = IsTapped(i) ? KeyDoubleTapWatches[i].Restart() <= DOUBLE_TAP_THRESHOLD : false; - { - bool isDown = currentState.KeyStates[i]; - bool isTapped = IsTapped(i); - - keyIntervalTapStates[i] = isTapped; - - if (isTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = true; - } - else if (isDown) - { - float threshold = keyIntervalInitials[i] ? INTERVAL_TAP_DELAY_THRESHOLD : INTERVAL_TAP_THRESHOLD; - - bool intervalTapped = (keyIntervalTapTimes[i] += elapsed) > threshold; - keyIntervalTapStates[i] = intervalTapped; - - if (intervalTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = false; - } - } - } + SetTapStates(i, elapsed); } i = XINPUT_DOWN; @@ -66,32 +70,7 @@ namespace TLAC::Input currentState.KeyStates[i] = false; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_DOWN) currentState.KeyStates[i] = true; - KeyDoubleTapStates[i] = IsTapped(i) ? KeyDoubleTapWatches[i].Restart() <= DOUBLE_TAP_THRESHOLD : false; - { - bool isDown = currentState.KeyStates[i]; - bool isTapped = IsTapped(i); - - keyIntervalTapStates[i] = isTapped; - - if (isTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = true; - } - else if (isDown) - { - float threshold = keyIntervalInitials[i] ? INTERVAL_TAP_DELAY_THRESHOLD : INTERVAL_TAP_THRESHOLD; - - bool intervalTapped = (keyIntervalTapTimes[i] += elapsed) > threshold; - keyIntervalTapStates[i] = intervalTapped; - - if (intervalTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = false; - } - } - } + SetTapStates(i, elapsed); } i = XINPUT_B; @@ -99,32 +78,7 @@ namespace TLAC::Input currentState.KeyStates[i] = false; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_B) currentState.KeyStates[i] = true; - KeyDoubleTapStates[i] = IsTapped(i) ? KeyDoubleTapWatches[i].Restart() <= DOUBLE_TAP_THRESHOLD : false; - { - bool isDown = currentState.KeyStates[i]; - bool isTapped = IsTapped(i); - - keyIntervalTapStates[i] = isTapped; - - if (isTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = true; - } - else if (isDown) - { - float threshold = keyIntervalInitials[i] ? INTERVAL_TAP_DELAY_THRESHOLD : INTERVAL_TAP_THRESHOLD; - - bool intervalTapped = (keyIntervalTapTimes[i] += elapsed) > threshold; - keyIntervalTapStates[i] = intervalTapped; - - if (intervalTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = false; - } - } - } + SetTapStates(i, elapsed); } i = XINPUT_RIGHT; @@ -132,32 +86,7 @@ namespace TLAC::Input currentState.KeyStates[i] = false; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) currentState.KeyStates[i] = true; - KeyDoubleTapStates[i] = IsTapped(i) ? KeyDoubleTapWatches[i].Restart() <= DOUBLE_TAP_THRESHOLD : false; - { - bool isDown = currentState.KeyStates[i]; - bool isTapped = IsTapped(i); - - keyIntervalTapStates[i] = isTapped; - - if (isTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = true; - } - else if (isDown) - { - float threshold = keyIntervalInitials[i] ? INTERVAL_TAP_DELAY_THRESHOLD : INTERVAL_TAP_THRESHOLD; - - bool intervalTapped = (keyIntervalTapTimes[i] += elapsed) > threshold; - keyIntervalTapStates[i] = intervalTapped; - - if (intervalTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = false; - } - } - } + SetTapStates(i, elapsed); } i = XINPUT_X; @@ -165,32 +94,7 @@ namespace TLAC::Input currentState.KeyStates[i] = false; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_X) currentState.KeyStates[i] = true; - KeyDoubleTapStates[i] = IsTapped(i) ? KeyDoubleTapWatches[i].Restart() <= DOUBLE_TAP_THRESHOLD : false; - { - bool isDown = currentState.KeyStates[i]; - bool isTapped = IsTapped(i); - - keyIntervalTapStates[i] = isTapped; - - if (isTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = true; - } - else if (isDown) - { - float threshold = keyIntervalInitials[i] ? INTERVAL_TAP_DELAY_THRESHOLD : INTERVAL_TAP_THRESHOLD; - - bool intervalTapped = (keyIntervalTapTimes[i] += elapsed) > threshold; - keyIntervalTapStates[i] = intervalTapped; - - if (intervalTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = false; - } - } - } + SetTapStates(i, elapsed); } i = XINPUT_LEFT; @@ -198,32 +102,7 @@ namespace TLAC::Input currentState.KeyStates[i] = false; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_LEFT) currentState.KeyStates[i] = true; - KeyDoubleTapStates[i] = IsTapped(i) ? KeyDoubleTapWatches[i].Restart() <= DOUBLE_TAP_THRESHOLD : false; - { - bool isDown = currentState.KeyStates[i]; - bool isTapped = IsTapped(i); - - keyIntervalTapStates[i] = isTapped; - - if (isTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = true; - } - else if (isDown) - { - float threshold = keyIntervalInitials[i] ? INTERVAL_TAP_DELAY_THRESHOLD : INTERVAL_TAP_THRESHOLD; - - bool intervalTapped = (keyIntervalTapTimes[i] += elapsed) > threshold; - keyIntervalTapStates[i] = intervalTapped; - - if (intervalTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = false; - } - } - } + SetTapStates(i, elapsed); } i = XINPUT_Y; @@ -231,32 +110,7 @@ namespace TLAC::Input currentState.KeyStates[i] = false; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_Y) currentState.KeyStates[i] = true; - KeyDoubleTapStates[i] = IsTapped(i) ? KeyDoubleTapWatches[i].Restart() <= DOUBLE_TAP_THRESHOLD : false; - { - bool isDown = currentState.KeyStates[i]; - bool isTapped = IsTapped(i); - - keyIntervalTapStates[i] = isTapped; - - if (isTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = true; - } - else if (isDown) - { - float threshold = keyIntervalInitials[i] ? INTERVAL_TAP_DELAY_THRESHOLD : INTERVAL_TAP_THRESHOLD; - - bool intervalTapped = (keyIntervalTapTimes[i] += elapsed) > threshold; - keyIntervalTapStates[i] = intervalTapped; - - if (intervalTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = false; - } - } - } + SetTapStates(i, elapsed); } i = XINPUT_UP; @@ -264,32 +118,7 @@ namespace TLAC::Input currentState.KeyStates[i] = false; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_DPAD_UP) currentState.KeyStates[i] = true; - KeyDoubleTapStates[i] = IsTapped(i) ? KeyDoubleTapWatches[i].Restart() <= DOUBLE_TAP_THRESHOLD : false; - { - bool isDown = currentState.KeyStates[i]; - bool isTapped = IsTapped(i); - - keyIntervalTapStates[i] = isTapped; - - if (isTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = true; - } - else if (isDown) - { - float threshold = keyIntervalInitials[i] ? INTERVAL_TAP_DELAY_THRESHOLD : INTERVAL_TAP_THRESHOLD; - - bool intervalTapped = (keyIntervalTapTimes[i] += elapsed) > threshold; - keyIntervalTapStates[i] = intervalTapped; - - if (intervalTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = false; - } - } - } + SetTapStates(i, elapsed); } i = XINPUT_LS; @@ -297,32 +126,7 @@ namespace TLAC::Input currentState.KeyStates[i] = false; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_SHOULDER) currentState.KeyStates[i] = true; - KeyDoubleTapStates[i] = IsTapped(i) ? KeyDoubleTapWatches[i].Restart() <= DOUBLE_TAP_THRESHOLD : false; - { - bool isDown = currentState.KeyStates[i]; - bool isTapped = IsTapped(i); - - keyIntervalTapStates[i] = isTapped; - - if (isTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = true; - } - else if (isDown) - { - float threshold = keyIntervalInitials[i] ? INTERVAL_TAP_DELAY_THRESHOLD : INTERVAL_TAP_THRESHOLD; - - bool intervalTapped = (keyIntervalTapTimes[i] += elapsed) > threshold; - keyIntervalTapStates[i] = intervalTapped; - - if (intervalTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = false; - } - } - } + SetTapStates(i, elapsed); } i = XINPUT_RS; @@ -330,32 +134,23 @@ namespace TLAC::Input currentState.KeyStates[i] = false; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_SHOULDER) currentState.KeyStates[i] = true; - KeyDoubleTapStates[i] = IsTapped(i) ? KeyDoubleTapWatches[i].Restart() <= DOUBLE_TAP_THRESHOLD : false; - { - bool isDown = currentState.KeyStates[i]; - bool isTapped = IsTapped(i); + SetTapStates(i, elapsed); + } + + i = XINPUT_LSB; + { + currentState.KeyStates[i] = false; + if (state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) + currentState.KeyStates[i] = true; + SetTapStates(i, elapsed); + } - keyIntervalTapStates[i] = isTapped; - - if (isTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = true; - } - else if (isDown) - { - float threshold = keyIntervalInitials[i] ? INTERVAL_TAP_DELAY_THRESHOLD : INTERVAL_TAP_THRESHOLD; - - bool intervalTapped = (keyIntervalTapTimes[i] += elapsed) > threshold; - keyIntervalTapStates[i] = intervalTapped; - - if (intervalTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = false; - } - } - } + i = XINPUT_RSB; + { + currentState.KeyStates[i] = false; + if (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) + currentState.KeyStates[i] = true; + SetTapStates(i, elapsed); } i = XINPUT_START; @@ -363,32 +158,7 @@ namespace TLAC::Input currentState.KeyStates[i] = false; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_START) currentState.KeyStates[i] = true; - KeyDoubleTapStates[i] = IsTapped(i) ? KeyDoubleTapWatches[i].Restart() <= DOUBLE_TAP_THRESHOLD : false; - { - bool isDown = currentState.KeyStates[i]; - bool isTapped = IsTapped(i); - - keyIntervalTapStates[i] = isTapped; - - if (isTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = true; - } - else if (isDown) - { - float threshold = keyIntervalInitials[i] ? INTERVAL_TAP_DELAY_THRESHOLD : INTERVAL_TAP_THRESHOLD; - - bool intervalTapped = (keyIntervalTapTimes[i] += elapsed) > threshold; - keyIntervalTapStates[i] = intervalTapped; - - if (intervalTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = false; - } - } - } + SetTapStates(i, elapsed); } i = XINPUT_BACK; @@ -396,33 +166,7 @@ namespace TLAC::Input currentState.KeyStates[i] = false; if (state.Gamepad.wButtons & XINPUT_GAMEPAD_BACK) currentState.KeyStates[i] = true; - KeyDoubleTapStates[i] = IsTapped(i) ? KeyDoubleTapWatches[i].Restart() <= DOUBLE_TAP_THRESHOLD : false; - - { - bool isDown = currentState.KeyStates[i]; - bool isTapped = IsTapped(i); - - keyIntervalTapStates[i] = isTapped; - - if (isTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = true; - } - else if (isDown) - { - float threshold = keyIntervalInitials[i] ? INTERVAL_TAP_DELAY_THRESHOLD : INTERVAL_TAP_THRESHOLD; - - bool intervalTapped = (keyIntervalTapTimes[i] += elapsed) > threshold; - keyIntervalTapStates[i] = intervalTapped; - - if (intervalTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = false; - } - } - } + SetTapStates(i, elapsed); } i = XINPUT_LT; @@ -430,33 +174,7 @@ namespace TLAC::Input currentState.KeyStates[i] = false; if (state.Gamepad.bLeftTrigger > 230) currentState.KeyStates[i] = true; - KeyDoubleTapStates[i] = IsTapped(i) ? KeyDoubleTapWatches[i].Restart() <= DOUBLE_TAP_THRESHOLD : false; - - { - bool isDown = currentState.KeyStates[i]; - bool isTapped = IsTapped(i); - - keyIntervalTapStates[i] = isTapped; - - if (isTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = true; - } - else if (isDown) - { - float threshold = keyIntervalInitials[i] ? INTERVAL_TAP_DELAY_THRESHOLD : INTERVAL_TAP_THRESHOLD; - - bool intervalTapped = (keyIntervalTapTimes[i] += elapsed) > threshold; - keyIntervalTapStates[i] = intervalTapped; - - if (intervalTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = false; - } - } - } + SetTapStates(i, elapsed); } i = XINPUT_RT; @@ -464,33 +182,7 @@ namespace TLAC::Input currentState.KeyStates[i] = false; if (state.Gamepad.bRightTrigger > 230) currentState.KeyStates[i] = true; - KeyDoubleTapStates[i] = IsTapped(i) ? KeyDoubleTapWatches[i].Restart() <= DOUBLE_TAP_THRESHOLD : false; - - { - bool isDown = currentState.KeyStates[i]; - bool isTapped = IsTapped(i); - - keyIntervalTapStates[i] = isTapped; - - if (isTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = true; - } - else if (isDown) - { - float threshold = keyIntervalInitials[i] ? INTERVAL_TAP_DELAY_THRESHOLD : INTERVAL_TAP_THRESHOLD; - - bool intervalTapped = (keyIntervalTapTimes[i] += elapsed) > threshold; - keyIntervalTapStates[i] = intervalTapped; - - if (intervalTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = false; - } - } - } + SetTapStates(i, elapsed); } @@ -500,66 +192,13 @@ namespace TLAC::Input currentState.KeyStates[i] = false; if (state.Gamepad.sThumbLX > 10000) currentState.KeyStates[i] = true; - - - KeyDoubleTapStates[i] = IsTapped(i) ? KeyDoubleTapWatches[i].Restart() <= DOUBLE_TAP_THRESHOLD : false; - - { - bool isDown = currentState.KeyStates[i]; - bool isTapped = IsTapped(i); - - keyIntervalTapStates[i] = isTapped; - - if (isTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = true; - } - else if (isDown) - { - float threshold = keyIntervalInitials[i] ? INTERVAL_TAP_DELAY_THRESHOLD : INTERVAL_TAP_THRESHOLD; - - bool intervalTapped = (keyIntervalTapTimes[i] += elapsed) > threshold; - keyIntervalTapStates[i] = intervalTapped; - - if (intervalTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = false; - } - } - } + SetTapStates(i, elapsed); + i = XINPUT_LLEFT; currentState.KeyStates[i] = false; if (state.Gamepad.sThumbLX < -10000) currentState.KeyStates[i] = true; - KeyDoubleTapStates[i] = IsTapped(i) ? KeyDoubleTapWatches[i].Restart() <= DOUBLE_TAP_THRESHOLD : false; - - { - bool isDown = currentState.KeyStates[i]; - bool isTapped = IsTapped(i); - - keyIntervalTapStates[i] = isTapped; - - if (isTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = true; - } - else if (isDown) - { - float threshold = keyIntervalInitials[i] ? INTERVAL_TAP_DELAY_THRESHOLD : INTERVAL_TAP_THRESHOLD; - - bool intervalTapped = (keyIntervalTapTimes[i] += elapsed) > threshold; - keyIntervalTapStates[i] = intervalTapped; - - if (intervalTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = false; - } - } - } + SetTapStates(i, elapsed); } { @@ -568,63 +207,13 @@ namespace TLAC::Input currentState.KeyStates[i] = false; if (state.Gamepad.sThumbRX > 10000) currentState.KeyStates[i] = true; - KeyDoubleTapStates[i] = IsTapped(i) ? KeyDoubleTapWatches[i].Restart() <= DOUBLE_TAP_THRESHOLD : false; - - { - bool isDown = currentState.KeyStates[i]; - bool isTapped = IsTapped(i); - - keyIntervalTapStates[i] = isTapped; - - if (isTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = true; - } - else if (isDown) - { - float threshold = keyIntervalInitials[i] ? INTERVAL_TAP_DELAY_THRESHOLD : INTERVAL_TAP_THRESHOLD; - - bool intervalTapped = (keyIntervalTapTimes[i] += elapsed) > threshold; - keyIntervalTapStates[i] = intervalTapped; - - if (intervalTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = false; - } - } - } + SetTapStates(i, elapsed); + i = XINPUT_RLEFT; currentState.KeyStates[i] = false; if (state.Gamepad.sThumbRX < -10000) currentState.KeyStates[i] = true; - KeyDoubleTapStates[i] = IsTapped(i) ? KeyDoubleTapWatches[i].Restart() <= DOUBLE_TAP_THRESHOLD : false; - { - bool isDown = currentState.KeyStates[i]; - bool isTapped = IsTapped(i); - - keyIntervalTapStates[i] = isTapped; - - if (isTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = true; - } - else if (isDown) - { - float threshold = keyIntervalInitials[i] ? INTERVAL_TAP_DELAY_THRESHOLD : INTERVAL_TAP_THRESHOLD; - - bool intervalTapped = (keyIntervalTapTimes[i] += elapsed) > threshold; - keyIntervalTapStates[i] = intervalTapped; - - if (intervalTapped) - { - keyIntervalTapTimes[i] = 0; - keyIntervalInitials[i] = false; - } - } - } + SetTapStates(i, elapsed); } } else { diff --git a/source/plugins/TLAC/Input/Xinput/Xinput.h b/source/plugins/TLAC/Input/Xinput/Xinput.h index 255fe95..5b66888 100644 --- a/source/plugins/TLAC/Input/Xinput/Xinput.h +++ b/source/plugins/TLAC/Input/Xinput/Xinput.h @@ -45,5 +45,7 @@ namespace TLAC::Input FLOAT keyIntervalTapTimes[0xFF]; static Xinput* instance; + + void SetTapStates(BYTE keycode, float elapsed); }; }