From c8e6b4e8dba5af2344def348e01306f7f1c2973f Mon Sep 17 00:00:00 2001 From: zsccat Date: Thu, 4 Jun 2020 12:47:46 +0000 Subject: [PATCH 01/20] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=87=B3=20'source-code/data/plugins'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add generic usb game controller support. genericusbinput.ini contains the VID and PID for the game controller --- source-code/data/plugins/genericusbinput.ini | 6 ++++++ source-code/data/plugins/keyconfig.ini | 14 ++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 source-code/data/plugins/genericusbinput.ini diff --git a/source-code/data/plugins/genericusbinput.ini b/source-code/data/plugins/genericusbinput.ini new file mode 100644 index 0000000..2062a67 --- /dev/null +++ b/source-code/data/plugins/genericusbinput.ini @@ -0,0 +1,6 @@ +#Check you Vendor ID and Product ID in Device Manager or dxdiag tool + +[genericusbinput] + +VID = 046D +PID = C216 diff --git a/source-code/data/plugins/keyconfig.ini b/source-code/data/plugins/keyconfig.ini index 018431d..bcbeaea 100644 --- a/source-code/data/plugins/keyconfig.ini +++ b/source-code/data/plugins/keyconfig.ini @@ -114,3 +114,17 @@ RIGHT_SIDE_SLIDE_RIGHT = O, Ds4_R_Stick_Right, XINPUT_RRIGHT # - Right Joystick # "XINPUT_RLEFT", "XINPUT_RRIGHT", "XINPUT_RUP", "XINPUT_RDOWN", "XINPUT_RSB" + +# --- Generic USB BUTTON NAMES: --- + +# - Standard Buttons (Button number in "Game controller settings", max allowed 13 buttons at the moment) +# "GU_BUTTON1", "GU_BUTTON2", "GU_BUTTON3", "GU_BUTTON4", "GU_BUTTON5", "GU_BUTTON6", "GU_BUTTON7", "GU_BUTTON8", "GU_BUTTON9", "GU_BUTTON10", "GU_BUTTON11", "GU_BUTTON12", "GU_BUTTON13" + +# - D-Pad Directions +# "GU_DPAD_UP", "GU_DPAD_RIGHT", "GU_DPAD_DOWN", "GU_DPAD_LEFT" + +# - Left Joystick +# "GU_L_STICK_UP", "GU_L_STICK_RIGHT", "GU_L_STICK_DOWN", "GU_L_STICK_LEFT" + +# - Right Joystick +# "GU_R_STICK_UP", "GU_R_STICK_RIGHT", "GU_R_STICK_DOWN", "GU_R_STICK_LEFT" From 3c35aa7822a7d9490e5e5fa16c050cf1709144f0 Mon Sep 17 00:00:00 2001 From: zsccat Date: Thu, 4 Jun 2020 12:51:44 +0000 Subject: [PATCH 02/20] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=87=B3=20'source-code/source/plugins/TLAC/FileSystem'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New function added "GetStringValue" to get string value from the config file --- source-code/source/plugins/TLAC/FileSystem/ConfigFile.cpp | 8 ++++++++ source-code/source/plugins/TLAC/FileSystem/ConfigFile.h | 1 + 2 files changed, 9 insertions(+) diff --git a/source-code/source/plugins/TLAC/FileSystem/ConfigFile.cpp b/source-code/source/plugins/TLAC/FileSystem/ConfigFile.cpp index 379fda2..76d2e5d 100644 --- a/source-code/source/plugins/TLAC/FileSystem/ConfigFile.cpp +++ b/source-code/source/plugins/TLAC/FileSystem/ConfigFile.cpp @@ -47,6 +47,14 @@ namespace TLAC::FileSystem return found ? (float)atof(pair->second.c_str()) : 0.0f; } + std::string ConfigFile::GetStringValue(const std::string& key) + { + auto pair = ConfigMap.find(key); + bool found = pair != ConfigMap.end(); + + return found ? pair->second : ""; + } + void ConfigFile::Parse(std::ifstream &fileStream) { std::string line; diff --git a/source-code/source/plugins/TLAC/FileSystem/ConfigFile.h b/source-code/source/plugins/TLAC/FileSystem/ConfigFile.h index 8f453ea..bf96e27 100644 --- a/source-code/source/plugins/TLAC/FileSystem/ConfigFile.h +++ b/source-code/source/plugins/TLAC/FileSystem/ConfigFile.h @@ -17,6 +17,7 @@ namespace TLAC::FileSystem int GetIntegerValue(const std::string& key); bool GetBooleanValue(const std::string& key); float GetFloatValue(const std::string& key); + std::string GetStringValue(const std::string& key); protected: virtual void Parse(std::ifstream &fileStream) override; From 35520472ed1783f15042642b33c179923611b42e Mon Sep 17 00:00:00 2001 From: zsccat Date: Thu, 4 Jun 2020 12:53:48 +0000 Subject: [PATCH 03/20] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=87=B3=20'source-code/source/plugins/TLAC/Input/KeyConfig'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow to load key config for generic usb game controller. --- .../plugins/TLAC/Input/KeyConfig/Config.cpp | 49 ++++++++++++++++++- .../plugins/TLAC/Input/KeyConfig/Config.h | 3 ++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/source-code/source/plugins/TLAC/Input/KeyConfig/Config.cpp b/source-code/source/plugins/TLAC/Input/KeyConfig/Config.cpp index a045fe2..0009a6d 100644 --- a/source-code/source/plugins/TLAC/Input/KeyConfig/Config.cpp +++ b/source-code/source/plugins/TLAC/Input/KeyConfig/Config.cpp @@ -2,6 +2,7 @@ #include "windows.h" #include "../Bindings/KeyboardBinding.h" #include "../Bindings/Ds4Binding.h" +#include "../Bindings/GuBinding.h" #include "../../Utilities/Operations.h" #include "../Bindings/XinputBinding.h" #include "../../Constants.h" @@ -218,6 +219,43 @@ namespace TLAC::Input::KeyConfig { "Ds4_R_Stick_Left", DS4_R_STICK_LEFT }, }; + GuButtonMap Config::GuMap = + { + // Face Buttons + { "GU_BUTTON1", GU_BUTTON1 }, + { "GU_BUTTON2", GU_BUTTON2 }, + { "GU_BUTTON3", GU_BUTTON3 }, + { "GU_BUTTON4", GU_BUTTON4 }, + { "GU_BUTTON5", GU_BUTTON5 }, + { "GU_BUTTON6", GU_BUTTON6 }, + { "GU_BUTTON7", GU_BUTTON7 }, + { "GU_BUTTON8", GU_BUTTON8 }, + { "GU_BUTTON9", GU_BUTTON9 }, + { "GU_BUTTON10", GU_BUTTON10 }, + { "GU_BUTTON11", GU_BUTTON11 }, + { "GU_BUTTON12", GU_BUTTON12 }, + { "GU_BUTTON13", GU_BUTTON13 }, + + // D-Pad Directions + { "GU_DPAD_UP", GU_DPAD_UP }, + { "GU_DPAD_RIGHT", GU_DPAD_RIGHT }, + { "GU_DPAD_DOWN", GU_DPAD_DOWN }, + { "GU_DPAD_LEFT", GU_DPAD_LEFT }, + + // Left Joystick + { "GU_L_STICK_UP", GU_L_STICK_UP }, + { "GU_L_STICK_RIGHT", GU_L_STICK_RIGHT }, + { "GU_L_STICK_DOWN", GU_L_STICK_DOWN }, + { "GU_L_STICK_LEFT", GU_L_STICK_LEFT }, + + // Right Joystick + { "GU_R_STICK_UP", GU_R_STICK_UP }, + { "GU_R_STICK_RIGHT", GU_R_STICK_RIGHT }, + { "GU_R_STICK_DOWN", GU_R_STICK_DOWN }, + { "GU_R_STICK_LEFT", GU_R_STICK_LEFT }, + + }; + void Config::BindConfigKeys(std::unordered_map &configMap, const char *configKeyName, Binding &bindObj, std::vector defaultKeys) { std::vector keys; @@ -271,7 +309,16 @@ namespace TLAC::Input::KeyConfig } else { - printf("[TLAC] Config::BindConfigKeys(): Unable to parse key: '%s'\n", key.c_str()); + auto guButton = Config::GuMap.find(key.c_str()); + + if (guButton != Config::GuMap.end()) + { + bindObj.AddBinding(new GuBinding(guButton->second)); + } + else + { + printf("[TLAC] Config::BindConfigKeys(): Unable to parse key: '%s'\n", key.c_str()); + } } } } diff --git a/source-code/source/plugins/TLAC/Input/KeyConfig/Config.h b/source-code/source/plugins/TLAC/Input/KeyConfig/Config.h index 194cd13..2a19842 100644 --- a/source-code/source/plugins/TLAC/Input/KeyConfig/Config.h +++ b/source-code/source/plugins/TLAC/Input/KeyConfig/Config.h @@ -5,11 +5,13 @@ #include "KeyStringHash.h" #include "../Bindings/Binding.h" #include "../DirectInput/Ds4/Ds4Button.h" +#include "../DirectInput/GenericUsb/GuButton.h" namespace TLAC::Input::KeyConfig { typedef std::unordered_map KeycodeMap; typedef std::unordered_map Ds4ButtonMap; + typedef std::unordered_map GuButtonMap; class Config { @@ -17,6 +19,7 @@ namespace TLAC::Input::KeyConfig static KeycodeMap Keymap; static Ds4ButtonMap Ds4Map; static KeycodeMap XinputMap; + static GuButtonMap GuMap; static void BindConfigKeys(std::unordered_map &configMap, const char *configKeyName, Binding &bindObj, std::vector defaultKeys); }; From b8321f79d2f8dd821b565bf40a12f255b448a7c5 Mon Sep 17 00:00:00 2001 From: zsccat Date: Thu, 4 Jun 2020 12:54:59 +0000 Subject: [PATCH 04/20] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=87=B3=20'source-code/source/plugins/TLAC/Input/Bindings'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add binding for generic usb game controller. --- .../plugins/TLAC/Input/Bindings/GuBinding.cpp | 29 +++++++++++++++++++ .../plugins/TLAC/Input/Bindings/GuBinding.h | 19 ++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 source-code/source/plugins/TLAC/Input/Bindings/GuBinding.cpp create mode 100644 source-code/source/plugins/TLAC/Input/Bindings/GuBinding.h diff --git a/source-code/source/plugins/TLAC/Input/Bindings/GuBinding.cpp b/source-code/source/plugins/TLAC/Input/Bindings/GuBinding.cpp new file mode 100644 index 0000000..d88bb29 --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/Bindings/GuBinding.cpp @@ -0,0 +1,29 @@ +#include "GuBinding.h" + +namespace TLAC::Input +{ + #define GuInstanceCheckDefault(checkFunc) (GenericUsbInput::InstanceInitialized() ? GenericUsbInput::GetInstance()->checkFunc : false) + + GuBinding::GuBinding(GuButton button) : Button(button) + { + } + + GuBinding::~GuBinding() + { + } + + bool GuBinding::IsDown() + { + return GuInstanceCheckDefault(IsDown(Button)); + } + + bool GuBinding::IsTapped() + { + return GuInstanceCheckDefault(IsTapped(Button)); + } + + bool GuBinding::IsReleased() + { + return GuInstanceCheckDefault(IsReleased(Button)); + } +} \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Input/Bindings/GuBinding.h b/source-code/source/plugins/TLAC/Input/Bindings/GuBinding.h new file mode 100644 index 0000000..3fe0429 --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/Bindings/GuBinding.h @@ -0,0 +1,19 @@ +#pragma once +#include "IInputBinding.h" +#include "../DirectInput/GenericUsb/GenericUsbInput.h" + +namespace TLAC::Input +{ + class GuBinding : public IInputBinding + { + public: + GuButton Button; + + GuBinding(GuButton button); + ~GuBinding(); + + bool IsDown() override; + bool IsTapped() override; + bool IsReleased() override; + }; +} \ No newline at end of file From 93e1608afd1cfbd87375c772b2057336a66acd60 Mon Sep 17 00:00:00 2001 From: zsccat Date: Thu, 4 Jun 2020 12:56:47 +0000 Subject: [PATCH 05/20] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=87=B3=20'source-code/source/plugins/TLAC/Input/DirectInput'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Support for generic usb game controller --- .../Input/DirectInput/GenericUsbInput.cpp | 181 ++++++++++++++++++ .../TLAC/Input/DirectInput/GenericUsbInput.h | 53 +++++ .../plugins/TLAC/Input/DirectInput/GuButton.h | 52 +++++ .../TLAC/Input/DirectInput/GuState.cpp | 14 ++ .../plugins/TLAC/Input/DirectInput/GuState.h | 39 ++++ 5 files changed, 339 insertions(+) create mode 100644 source-code/source/plugins/TLAC/Input/DirectInput/GenericUsbInput.cpp create mode 100644 source-code/source/plugins/TLAC/Input/DirectInput/GenericUsbInput.h create mode 100644 source-code/source/plugins/TLAC/Input/DirectInput/GuButton.h create mode 100644 source-code/source/plugins/TLAC/Input/DirectInput/GuState.cpp create mode 100644 source-code/source/plugins/TLAC/Input/DirectInput/GuState.h diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsbInput.cpp b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsbInput.cpp new file mode 100644 index 0000000..e2a9b22 --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsbInput.cpp @@ -0,0 +1,181 @@ +#include "GenericUsbInput.h" +#include "../../../Utilities/Math.h" +#include "../../../framework.h" +#include "../../../FileSystem/ConfigFile.h" +#include + +const std::string GU_CONFIG_FILE_NAME = "genericusbinput.ini"; + +namespace TLAC::Input +{ + GenericUsbInput* GenericUsbInput::instance; + + GenericUsbInput::GenericUsbInput() + { + } + + GenericUsbInput::~GenericUsbInput() + { + DI_Dispose(); + } + + bool GenericUsbInput::TryInitializeInstance() + { + if (InstanceInitialized()) + return true; + + if (!DirectInputInitialized()) + return false; + + GenericUsbInput *genericUsbInput = new GenericUsbInput (); + + bool success = genericUsbInput->Initialize(); + instance = success ? genericUsbInput : nullptr; + + if (!success) + delete genericUsbInput; + + return success; + } + + bool GenericUsbInput::Initialize() + { + HRESULT result = NULL; + + FileSystem::ConfigFile configFile(framework::GetModuleDirectory(), GU_CONFIG_FILE_NAME); + configFile.OpenRead(); + + std::string stt = "0x"; + std::string vid = configFile.GetStringValue("VID"); + std::string pid = configFile.GetStringValue("PID"); + + unsigned int gid = std::strtoul((stt + pid + vid).c_str(), 0, 16); + + GUID GUID_GenericUsb = { gid, 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; + + result = DI_CreateDevice(GUID_GenericUsb); + + if (!FAILED(result)) + { + if (FAILED(result = DI_SetDataFormat(&c_dfDIJoystick2))) + return false; + + result = DI_Acquire(); + + return true; + } + else + { + return false; + } + } + + bool GenericUsbInput::PollInput() + { + lastState = currentState; + + HRESULT result = NULL; + result = DI_Poll(); + result = DI_GetDeviceState(sizeof(DIJOYSTATE2), ¤tState.DI_JoyState); + + if (result != DI_OK) + return false; + + UpdateInternalGuState(currentState); + + for (int button = 0; button < GU_BUTTON_MAX; button++) + currentState.Buttons[button] = GetButtonState(currentState, (GuButton)button); + + return true; + } + + void GenericUsbInput::UpdateInternalGuState(GuState &state) + { + if (state.Dpad.IsDown = state.DI_JoyState.rgdwPOV[0] != -1) + { + state.Dpad.Angle = (state.DI_JoyState.rgdwPOV[0] / 100.0f); + + auto direction = Utilities::GetDirection(state.Dpad.Angle); + state.Dpad.Stick = { direction.Y, -direction.X }; + } + else + { + state.Dpad.Angle = 0; + state.Dpad.Stick = GuJoystick(); + } + + state.LeftStick = NormalizeStick(state.DI_JoyState.lX, state.DI_JoyState.lY); + state.RightStick = NormalizeStick(state.DI_JoyState.lZ, state.DI_JoyState.lRz); + + state.LeftTrigger = { NormalizeTrigger(state.DI_JoyState.lRx) }; + state.RightTrigger = { NormalizeTrigger(state.DI_JoyState.lRy) }; + } + + bool GenericUsbInput::IsDown(GuButton button) + { + return currentState.Buttons[button]; + } + + bool GenericUsbInput::IsUp(GuButton button) + { + return !IsDown(button); + } + + bool GenericUsbInput::IsTapped(GuButton button) + { + return IsDown(button) && WasUp(button); + } + + bool GenericUsbInput::IsReleased(GuButton button) + { + return IsUp(button) && WasDown(button); + } + + bool GenericUsbInput::WasDown(GuButton button) + { + return lastState.Buttons[button]; + } + + bool GenericUsbInput::WasUp(GuButton button) + { + return !WasDown(button); + } + + bool GenericUsbInput::MatchesDirection(GuJoystick joystick, GuDirection directionEnum, float threshold) + { + switch (directionEnum) + { + case TLAC::Input::GU_DIR_UP: + return joystick.YAxis <= -threshold; + + case TLAC::Input::GU_DIR_RIGHT: + return joystick.XAxis >= +threshold; + + case TLAC::Input::GU_DIR_DOWN: + return joystick.YAxis >= +threshold; + + case TLAC::Input::GU_DIR_LEFT: + return joystick.XAxis <= -threshold; + + default: + return false; + } + } + + bool GenericUsbInput::GetButtonState(GuState &state, GuButton button) + { + if (button >= GU_BUTTON1 && button <= GU_BUTTON13) + return state.DI_JoyState.rgbButtons[button]; + + if (button >= GU_DPAD_UP && button <= GU_DPAD_LEFT) + return state.Dpad.IsDown ? MatchesDirection(state.Dpad.Stick, (GuDirection)(button - GU_DPAD_UP), dpadThreshold) : false; + + if (button >= GU_L_STICK_UP && button <= GU_L_STICK_LEFT) + return MatchesDirection(state.LeftStick, (GuDirection)(button - GU_L_STICK_UP), joystickThreshold); + + if (button >= GU_R_STICK_UP && button <= GU_R_STICK_LEFT) + return MatchesDirection(state.RightStick, (GuDirection)(button - GU_R_STICK_UP), joystickThreshold); + + return false; + } +} diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsbInput.h b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsbInput.h new file mode 100644 index 0000000..898b7ce --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsbInput.h @@ -0,0 +1,53 @@ +#pragma once +#include "../Controller.h" +#include "../../IInputDevice.h" +#include "GuState.h" + +namespace TLAC::Input +{ + class GenericUsbInput : public Controller, public IInputDevice + { + public: + GenericUsbInput(); + ~GenericUsbInput(); + + static bool TryInitializeInstance(); + + bool Initialize(); + bool PollInput() override; + + bool IsDown(GuButton button); + bool IsUp(GuButton button); + bool IsTapped(GuButton button); + bool IsReleased(GuButton button); + bool WasDown(GuButton button); + bool WasUp(GuButton button); + + inline GuJoystick GetLeftStick() { return currentState.LeftStick; }; + inline GuJoystick GetRightStick() { return currentState.RightStick; }; + inline GuJoystick GetDpad() { return currentState.Dpad.Stick; }; + + static inline bool InstanceInitialized() { return instance != nullptr; }; + static inline GenericUsbInput* GetInstance() { return instance; }; + static inline void DeleteInstance() { delete instance; instance = nullptr; }; + + private: + static GenericUsbInput* instance; + + GuState lastState; + GuState currentState; + + const float triggerThreshold = 0.5f; + const float joystickThreshold = 0.5f; + const float dpadThreshold = 0.5f; + + inline float NormalizeTrigger(long value) { return (float)value / USHRT_MAX; }; + inline float NormalizeStick(long value) { return (float)value / USHRT_MAX * 2.0f - 1.0f; }; + inline GuJoystick NormalizeStick(long x, long y) { return GuJoystick(NormalizeStick(x), NormalizeStick(y)); }; + + void UpdateInternalGuState(GuState &state); + + bool MatchesDirection(GuJoystick joystick, GuDirection directionEnum, float threshold); + bool GetButtonState(GuState &state, GuButton button); + }; +} \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GuButton.h b/source-code/source/plugins/TLAC/Input/DirectInput/GuButton.h new file mode 100644 index 0000000..1df2e2a --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GuButton.h @@ -0,0 +1,52 @@ +#pragma once + +namespace TLAC::Input +{ + enum GuDirection + { + GU_DIR_UP, + GU_DIR_RIGHT, + GU_DIR_DOWN, + GU_DIR_LEFT + }; + + enum GuButton : int + { + GU_BUTTON1 = 0, + GU_BUTTON2 = 1, + GU_BUTTON3 = 2, + GU_BUTTON4 = 3, + + GU_BUTTON5 = 4, + GU_BUTTON6 = 5, + + GU_BUTTON7 = 6, + GU_BUTTON8 = 7, + + GU_BUTTON9 = 8, + GU_BUTTON10 = 9, + + GU_BUTTON11 = 10, + GU_BUTTON12 = 11, + + GU_BUTTON13 = 12, + + + GU_DPAD_UP = 14, + GU_DPAD_RIGHT = 15, + GU_DPAD_DOWN = 16, + GU_DPAD_LEFT = 17, + + GU_L_STICK_UP = 18, + GU_L_STICK_RIGHT = 19, + GU_L_STICK_DOWN = 20, + GU_L_STICK_LEFT = 21, + + GU_R_STICK_UP = 22, + GU_R_STICK_RIGHT = 23, + GU_R_STICK_DOWN = 24, + GU_R_STICK_LEFT = 25, + + GU_BUTTON_MAX = 26, + }; +} \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GuState.cpp b/source-code/source/plugins/TLAC/Input/DirectInput/GuState.cpp new file mode 100644 index 0000000..cc60409 --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GuState.cpp @@ -0,0 +1,14 @@ +#include "GuState.h" + +namespace TLAC::Input +{ + GuJoystick::GuJoystick() : XAxis(0.0f), YAxis(0.0f) + { + return; + }; + + GuJoystick::GuJoystick(float xAxis, float yAxis) : XAxis(xAxis), YAxis(yAxis) + { + return; + }; +} \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GuState.h b/source-code/source/plugins/TLAC/Input/DirectInput/GuState.h new file mode 100644 index 0000000..9060e8d --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GuState.h @@ -0,0 +1,39 @@ +#pragma once +#include "../DirectInput.h" +#include "GuButton.h" + +namespace TLAC::Input +{ + struct GuJoystick + { + FLOAT XAxis, YAxis; + + GuJoystick(); + GuJoystick(float xAxis, float yAxis); + }; + + struct GuDpad + { + BOOL IsDown; + FLOAT Angle; + GuJoystick Stick; + }; + + struct GuTrigger + { + FLOAT Axis; + }; + + struct GuState + { + DIJOYSTATE2 DI_JoyState; + + BYTE Buttons[GU_BUTTON_MAX]; + + GuDpad Dpad; + GuJoystick LeftStick; + GuJoystick RightStick; + GuTrigger LeftTrigger; + GuTrigger RightTrigger; + }; +} \ No newline at end of file From fe59e7ac0227f6d34f8da516bdc380365f746911 Mon Sep 17 00:00:00 2001 From: zsccat Date: Thu, 4 Jun 2020 12:57:41 +0000 Subject: [PATCH 06/20] =?UTF-8?q?=E5=88=A0=E9=99=A4=20'source-code/source/?= =?UTF-8?q?plugins/TLAC/Input/DirectInput/GenericUsbInput.cpp'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Input/DirectInput/GenericUsbInput.cpp | 181 ------------------ 1 file changed, 181 deletions(-) delete mode 100644 source-code/source/plugins/TLAC/Input/DirectInput/GenericUsbInput.cpp diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsbInput.cpp b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsbInput.cpp deleted file mode 100644 index e2a9b22..0000000 --- a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsbInput.cpp +++ /dev/null @@ -1,181 +0,0 @@ -#include "GenericUsbInput.h" -#include "../../../Utilities/Math.h" -#include "../../../framework.h" -#include "../../../FileSystem/ConfigFile.h" -#include - -const std::string GU_CONFIG_FILE_NAME = "genericusbinput.ini"; - -namespace TLAC::Input -{ - GenericUsbInput* GenericUsbInput::instance; - - GenericUsbInput::GenericUsbInput() - { - } - - GenericUsbInput::~GenericUsbInput() - { - DI_Dispose(); - } - - bool GenericUsbInput::TryInitializeInstance() - { - if (InstanceInitialized()) - return true; - - if (!DirectInputInitialized()) - return false; - - GenericUsbInput *genericUsbInput = new GenericUsbInput (); - - bool success = genericUsbInput->Initialize(); - instance = success ? genericUsbInput : nullptr; - - if (!success) - delete genericUsbInput; - - return success; - } - - bool GenericUsbInput::Initialize() - { - HRESULT result = NULL; - - FileSystem::ConfigFile configFile(framework::GetModuleDirectory(), GU_CONFIG_FILE_NAME); - configFile.OpenRead(); - - std::string stt = "0x"; - std::string vid = configFile.GetStringValue("VID"); - std::string pid = configFile.GetStringValue("PID"); - - unsigned int gid = std::strtoul((stt + pid + vid).c_str(), 0, 16); - - GUID GUID_GenericUsb = { gid, 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; - - result = DI_CreateDevice(GUID_GenericUsb); - - if (!FAILED(result)) - { - if (FAILED(result = DI_SetDataFormat(&c_dfDIJoystick2))) - return false; - - result = DI_Acquire(); - - return true; - } - else - { - return false; - } - } - - bool GenericUsbInput::PollInput() - { - lastState = currentState; - - HRESULT result = NULL; - result = DI_Poll(); - result = DI_GetDeviceState(sizeof(DIJOYSTATE2), ¤tState.DI_JoyState); - - if (result != DI_OK) - return false; - - UpdateInternalGuState(currentState); - - for (int button = 0; button < GU_BUTTON_MAX; button++) - currentState.Buttons[button] = GetButtonState(currentState, (GuButton)button); - - return true; - } - - void GenericUsbInput::UpdateInternalGuState(GuState &state) - { - if (state.Dpad.IsDown = state.DI_JoyState.rgdwPOV[0] != -1) - { - state.Dpad.Angle = (state.DI_JoyState.rgdwPOV[0] / 100.0f); - - auto direction = Utilities::GetDirection(state.Dpad.Angle); - state.Dpad.Stick = { direction.Y, -direction.X }; - } - else - { - state.Dpad.Angle = 0; - state.Dpad.Stick = GuJoystick(); - } - - state.LeftStick = NormalizeStick(state.DI_JoyState.lX, state.DI_JoyState.lY); - state.RightStick = NormalizeStick(state.DI_JoyState.lZ, state.DI_JoyState.lRz); - - state.LeftTrigger = { NormalizeTrigger(state.DI_JoyState.lRx) }; - state.RightTrigger = { NormalizeTrigger(state.DI_JoyState.lRy) }; - } - - bool GenericUsbInput::IsDown(GuButton button) - { - return currentState.Buttons[button]; - } - - bool GenericUsbInput::IsUp(GuButton button) - { - return !IsDown(button); - } - - bool GenericUsbInput::IsTapped(GuButton button) - { - return IsDown(button) && WasUp(button); - } - - bool GenericUsbInput::IsReleased(GuButton button) - { - return IsUp(button) && WasDown(button); - } - - bool GenericUsbInput::WasDown(GuButton button) - { - return lastState.Buttons[button]; - } - - bool GenericUsbInput::WasUp(GuButton button) - { - return !WasDown(button); - } - - bool GenericUsbInput::MatchesDirection(GuJoystick joystick, GuDirection directionEnum, float threshold) - { - switch (directionEnum) - { - case TLAC::Input::GU_DIR_UP: - return joystick.YAxis <= -threshold; - - case TLAC::Input::GU_DIR_RIGHT: - return joystick.XAxis >= +threshold; - - case TLAC::Input::GU_DIR_DOWN: - return joystick.YAxis >= +threshold; - - case TLAC::Input::GU_DIR_LEFT: - return joystick.XAxis <= -threshold; - - default: - return false; - } - } - - bool GenericUsbInput::GetButtonState(GuState &state, GuButton button) - { - if (button >= GU_BUTTON1 && button <= GU_BUTTON13) - return state.DI_JoyState.rgbButtons[button]; - - if (button >= GU_DPAD_UP && button <= GU_DPAD_LEFT) - return state.Dpad.IsDown ? MatchesDirection(state.Dpad.Stick, (GuDirection)(button - GU_DPAD_UP), dpadThreshold) : false; - - if (button >= GU_L_STICK_UP && button <= GU_L_STICK_LEFT) - return MatchesDirection(state.LeftStick, (GuDirection)(button - GU_L_STICK_UP), joystickThreshold); - - if (button >= GU_R_STICK_UP && button <= GU_R_STICK_LEFT) - return MatchesDirection(state.RightStick, (GuDirection)(button - GU_R_STICK_UP), joystickThreshold); - - return false; - } -} From d09e271696460b688dda8ed6fb5e3d79e4f15b4b Mon Sep 17 00:00:00 2001 From: zsccat Date: Thu, 4 Jun 2020 12:58:36 +0000 Subject: [PATCH 07/20] =?UTF-8?q?=E5=88=A0=E9=99=A4=20'source-code/source/?= =?UTF-8?q?plugins/TLAC/Input/DirectInput/GenericUsbInput.h'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TLAC/Input/DirectInput/GenericUsbInput.h | 53 ------------------- 1 file changed, 53 deletions(-) delete mode 100644 source-code/source/plugins/TLAC/Input/DirectInput/GenericUsbInput.h diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsbInput.h b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsbInput.h deleted file mode 100644 index 898b7ce..0000000 --- a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsbInput.h +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once -#include "../Controller.h" -#include "../../IInputDevice.h" -#include "GuState.h" - -namespace TLAC::Input -{ - class GenericUsbInput : public Controller, public IInputDevice - { - public: - GenericUsbInput(); - ~GenericUsbInput(); - - static bool TryInitializeInstance(); - - bool Initialize(); - bool PollInput() override; - - bool IsDown(GuButton button); - bool IsUp(GuButton button); - bool IsTapped(GuButton button); - bool IsReleased(GuButton button); - bool WasDown(GuButton button); - bool WasUp(GuButton button); - - inline GuJoystick GetLeftStick() { return currentState.LeftStick; }; - inline GuJoystick GetRightStick() { return currentState.RightStick; }; - inline GuJoystick GetDpad() { return currentState.Dpad.Stick; }; - - static inline bool InstanceInitialized() { return instance != nullptr; }; - static inline GenericUsbInput* GetInstance() { return instance; }; - static inline void DeleteInstance() { delete instance; instance = nullptr; }; - - private: - static GenericUsbInput* instance; - - GuState lastState; - GuState currentState; - - const float triggerThreshold = 0.5f; - const float joystickThreshold = 0.5f; - const float dpadThreshold = 0.5f; - - inline float NormalizeTrigger(long value) { return (float)value / USHRT_MAX; }; - inline float NormalizeStick(long value) { return (float)value / USHRT_MAX * 2.0f - 1.0f; }; - inline GuJoystick NormalizeStick(long x, long y) { return GuJoystick(NormalizeStick(x), NormalizeStick(y)); }; - - void UpdateInternalGuState(GuState &state); - - bool MatchesDirection(GuJoystick joystick, GuDirection directionEnum, float threshold); - bool GetButtonState(GuState &state, GuButton button); - }; -} \ No newline at end of file From 890da4d042028806ff669f39a2881227844701ef Mon Sep 17 00:00:00 2001 From: zsccat Date: Thu, 4 Jun 2020 12:59:12 +0000 Subject: [PATCH 08/20] =?UTF-8?q?=E5=88=A0=E9=99=A4=20'source-code/source/?= =?UTF-8?q?plugins/TLAC/Input/DirectInput/GuButton.h'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins/TLAC/Input/DirectInput/GuButton.h | 52 ------------------- 1 file changed, 52 deletions(-) delete mode 100644 source-code/source/plugins/TLAC/Input/DirectInput/GuButton.h diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GuButton.h b/source-code/source/plugins/TLAC/Input/DirectInput/GuButton.h deleted file mode 100644 index 1df2e2a..0000000 --- a/source-code/source/plugins/TLAC/Input/DirectInput/GuButton.h +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -namespace TLAC::Input -{ - enum GuDirection - { - GU_DIR_UP, - GU_DIR_RIGHT, - GU_DIR_DOWN, - GU_DIR_LEFT - }; - - enum GuButton : int - { - GU_BUTTON1 = 0, - GU_BUTTON2 = 1, - GU_BUTTON3 = 2, - GU_BUTTON4 = 3, - - GU_BUTTON5 = 4, - GU_BUTTON6 = 5, - - GU_BUTTON7 = 6, - GU_BUTTON8 = 7, - - GU_BUTTON9 = 8, - GU_BUTTON10 = 9, - - GU_BUTTON11 = 10, - GU_BUTTON12 = 11, - - GU_BUTTON13 = 12, - - - GU_DPAD_UP = 14, - GU_DPAD_RIGHT = 15, - GU_DPAD_DOWN = 16, - GU_DPAD_LEFT = 17, - - GU_L_STICK_UP = 18, - GU_L_STICK_RIGHT = 19, - GU_L_STICK_DOWN = 20, - GU_L_STICK_LEFT = 21, - - GU_R_STICK_UP = 22, - GU_R_STICK_RIGHT = 23, - GU_R_STICK_DOWN = 24, - GU_R_STICK_LEFT = 25, - - GU_BUTTON_MAX = 26, - }; -} \ No newline at end of file From 14d9dce68ae1c0ce52ce9afefa848379d3ea8e3e Mon Sep 17 00:00:00 2001 From: zsccat Date: Thu, 4 Jun 2020 12:59:40 +0000 Subject: [PATCH 09/20] =?UTF-8?q?=E5=88=A0=E9=99=A4=20'source-code/source/?= =?UTF-8?q?plugins/TLAC/Input/DirectInput/GuState.cpp'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins/TLAC/Input/DirectInput/GuState.cpp | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 source-code/source/plugins/TLAC/Input/DirectInput/GuState.cpp diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GuState.cpp b/source-code/source/plugins/TLAC/Input/DirectInput/GuState.cpp deleted file mode 100644 index cc60409..0000000 --- a/source-code/source/plugins/TLAC/Input/DirectInput/GuState.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "GuState.h" - -namespace TLAC::Input -{ - GuJoystick::GuJoystick() : XAxis(0.0f), YAxis(0.0f) - { - return; - }; - - GuJoystick::GuJoystick(float xAxis, float yAxis) : XAxis(xAxis), YAxis(yAxis) - { - return; - }; -} \ No newline at end of file From 8019bfe0590242f165268d84d17d74f8f9daccd6 Mon Sep 17 00:00:00 2001 From: zsccat Date: Thu, 4 Jun 2020 13:00:07 +0000 Subject: [PATCH 10/20] =?UTF-8?q?=E5=88=A0=E9=99=A4=20'source-code/source/?= =?UTF-8?q?plugins/TLAC/Input/DirectInput/GuState.h'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugins/TLAC/Input/DirectInput/GuState.h | 39 ------------------- 1 file changed, 39 deletions(-) delete mode 100644 source-code/source/plugins/TLAC/Input/DirectInput/GuState.h diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GuState.h b/source-code/source/plugins/TLAC/Input/DirectInput/GuState.h deleted file mode 100644 index 9060e8d..0000000 --- a/source-code/source/plugins/TLAC/Input/DirectInput/GuState.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once -#include "../DirectInput.h" -#include "GuButton.h" - -namespace TLAC::Input -{ - struct GuJoystick - { - FLOAT XAxis, YAxis; - - GuJoystick(); - GuJoystick(float xAxis, float yAxis); - }; - - struct GuDpad - { - BOOL IsDown; - FLOAT Angle; - GuJoystick Stick; - }; - - struct GuTrigger - { - FLOAT Axis; - }; - - struct GuState - { - DIJOYSTATE2 DI_JoyState; - - BYTE Buttons[GU_BUTTON_MAX]; - - GuDpad Dpad; - GuJoystick LeftStick; - GuJoystick RightStick; - GuTrigger LeftTrigger; - GuTrigger RightTrigger; - }; -} \ No newline at end of file From 51e2f443fc5590c5742860bc07d85cfafb5887a2 Mon Sep 17 00:00:00 2001 From: zsccat Date: Thu, 4 Jun 2020 13:03:00 +0000 Subject: [PATCH 11/20] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20'source-code/source/?= =?UTF-8?q?plugins/TLAC/Input/DirectInput/GenericUsb'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb | 1 + 1 file changed, 1 insertion(+) create mode 100644 source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb new file mode 100644 index 0000000..11eda0f --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb @@ -0,0 +1 @@ +GenericUsb \ No newline at end of file From 104de39e8fbe48f26a673e04d70435d9ee7120c1 Mon Sep 17 00:00:00 2001 From: zsccat Date: Thu, 4 Jun 2020 13:03:25 +0000 Subject: [PATCH 12/20] =?UTF-8?q?=E5=88=A0=E9=99=A4=20'source-code/source/?= =?UTF-8?q?plugins/TLAC/Input/DirectInput/GenericUsb'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb | 1 - 1 file changed, 1 deletion(-) delete mode 100644 source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb deleted file mode 100644 index 11eda0f..0000000 --- a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb +++ /dev/null @@ -1 +0,0 @@ -GenericUsb \ No newline at end of file From 8dba2285b7cd1f1314d1efd753856affe8ac6480 Mon Sep 17 00:00:00 2001 From: zsccat Date: Thu, 4 Jun 2020 13:08:27 +0000 Subject: [PATCH 13/20] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20'source-code/source/?= =?UTF-8?q?plugins/TLAC/Input/DirectInput/GenericUsb/temp'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../source/plugins/TLAC/Input/DirectInput/GenericUsb/temp | 1 + 1 file changed, 1 insertion(+) create mode 100644 source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/temp diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/temp b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/temp new file mode 100644 index 0000000..3602361 --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/temp @@ -0,0 +1 @@ +temp \ No newline at end of file From 7df447f8cbc0590f19efcc33e28be719efcca4a8 Mon Sep 17 00:00:00 2001 From: zsccat Date: Thu, 4 Jun 2020 13:09:25 +0000 Subject: [PATCH 14/20] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=87=B3=20'source-code/source/plugins/TLAC/Input/DirectInput/?= =?UTF-8?q?GenericUsb'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for generic usb controller. --- .../GenericUsb/GenericUsbInput.cpp | 181 ++++++++++++++++++ .../DirectInput/GenericUsb/GenericUsbInput.h | 53 +++++ .../Input/DirectInput/GenericUsb/GuButton.h | 52 +++++ .../Input/DirectInput/GenericUsb/GuState.cpp | 14 ++ .../Input/DirectInput/GenericUsb/GuState.h | 39 ++++ 5 files changed, 339 insertions(+) create mode 100644 source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.cpp create mode 100644 source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.h create mode 100644 source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuButton.h create mode 100644 source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuState.cpp create mode 100644 source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuState.h diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.cpp b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.cpp new file mode 100644 index 0000000..e2a9b22 --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.cpp @@ -0,0 +1,181 @@ +#include "GenericUsbInput.h" +#include "../../../Utilities/Math.h" +#include "../../../framework.h" +#include "../../../FileSystem/ConfigFile.h" +#include + +const std::string GU_CONFIG_FILE_NAME = "genericusbinput.ini"; + +namespace TLAC::Input +{ + GenericUsbInput* GenericUsbInput::instance; + + GenericUsbInput::GenericUsbInput() + { + } + + GenericUsbInput::~GenericUsbInput() + { + DI_Dispose(); + } + + bool GenericUsbInput::TryInitializeInstance() + { + if (InstanceInitialized()) + return true; + + if (!DirectInputInitialized()) + return false; + + GenericUsbInput *genericUsbInput = new GenericUsbInput (); + + bool success = genericUsbInput->Initialize(); + instance = success ? genericUsbInput : nullptr; + + if (!success) + delete genericUsbInput; + + return success; + } + + bool GenericUsbInput::Initialize() + { + HRESULT result = NULL; + + FileSystem::ConfigFile configFile(framework::GetModuleDirectory(), GU_CONFIG_FILE_NAME); + configFile.OpenRead(); + + std::string stt = "0x"; + std::string vid = configFile.GetStringValue("VID"); + std::string pid = configFile.GetStringValue("PID"); + + unsigned int gid = std::strtoul((stt + pid + vid).c_str(), 0, 16); + + GUID GUID_GenericUsb = { gid, 0x0000, 0x0000, { 0x00, 0x00, 0x50, 0x49, 0x44, 0x56, 0x49, 0x44 } }; + + result = DI_CreateDevice(GUID_GenericUsb); + + if (!FAILED(result)) + { + if (FAILED(result = DI_SetDataFormat(&c_dfDIJoystick2))) + return false; + + result = DI_Acquire(); + + return true; + } + else + { + return false; + } + } + + bool GenericUsbInput::PollInput() + { + lastState = currentState; + + HRESULT result = NULL; + result = DI_Poll(); + result = DI_GetDeviceState(sizeof(DIJOYSTATE2), ¤tState.DI_JoyState); + + if (result != DI_OK) + return false; + + UpdateInternalGuState(currentState); + + for (int button = 0; button < GU_BUTTON_MAX; button++) + currentState.Buttons[button] = GetButtonState(currentState, (GuButton)button); + + return true; + } + + void GenericUsbInput::UpdateInternalGuState(GuState &state) + { + if (state.Dpad.IsDown = state.DI_JoyState.rgdwPOV[0] != -1) + { + state.Dpad.Angle = (state.DI_JoyState.rgdwPOV[0] / 100.0f); + + auto direction = Utilities::GetDirection(state.Dpad.Angle); + state.Dpad.Stick = { direction.Y, -direction.X }; + } + else + { + state.Dpad.Angle = 0; + state.Dpad.Stick = GuJoystick(); + } + + state.LeftStick = NormalizeStick(state.DI_JoyState.lX, state.DI_JoyState.lY); + state.RightStick = NormalizeStick(state.DI_JoyState.lZ, state.DI_JoyState.lRz); + + state.LeftTrigger = { NormalizeTrigger(state.DI_JoyState.lRx) }; + state.RightTrigger = { NormalizeTrigger(state.DI_JoyState.lRy) }; + } + + bool GenericUsbInput::IsDown(GuButton button) + { + return currentState.Buttons[button]; + } + + bool GenericUsbInput::IsUp(GuButton button) + { + return !IsDown(button); + } + + bool GenericUsbInput::IsTapped(GuButton button) + { + return IsDown(button) && WasUp(button); + } + + bool GenericUsbInput::IsReleased(GuButton button) + { + return IsUp(button) && WasDown(button); + } + + bool GenericUsbInput::WasDown(GuButton button) + { + return lastState.Buttons[button]; + } + + bool GenericUsbInput::WasUp(GuButton button) + { + return !WasDown(button); + } + + bool GenericUsbInput::MatchesDirection(GuJoystick joystick, GuDirection directionEnum, float threshold) + { + switch (directionEnum) + { + case TLAC::Input::GU_DIR_UP: + return joystick.YAxis <= -threshold; + + case TLAC::Input::GU_DIR_RIGHT: + return joystick.XAxis >= +threshold; + + case TLAC::Input::GU_DIR_DOWN: + return joystick.YAxis >= +threshold; + + case TLAC::Input::GU_DIR_LEFT: + return joystick.XAxis <= -threshold; + + default: + return false; + } + } + + bool GenericUsbInput::GetButtonState(GuState &state, GuButton button) + { + if (button >= GU_BUTTON1 && button <= GU_BUTTON13) + return state.DI_JoyState.rgbButtons[button]; + + if (button >= GU_DPAD_UP && button <= GU_DPAD_LEFT) + return state.Dpad.IsDown ? MatchesDirection(state.Dpad.Stick, (GuDirection)(button - GU_DPAD_UP), dpadThreshold) : false; + + if (button >= GU_L_STICK_UP && button <= GU_L_STICK_LEFT) + return MatchesDirection(state.LeftStick, (GuDirection)(button - GU_L_STICK_UP), joystickThreshold); + + if (button >= GU_R_STICK_UP && button <= GU_R_STICK_LEFT) + return MatchesDirection(state.RightStick, (GuDirection)(button - GU_R_STICK_UP), joystickThreshold); + + return false; + } +} diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.h b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.h new file mode 100644 index 0000000..898b7ce --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.h @@ -0,0 +1,53 @@ +#pragma once +#include "../Controller.h" +#include "../../IInputDevice.h" +#include "GuState.h" + +namespace TLAC::Input +{ + class GenericUsbInput : public Controller, public IInputDevice + { + public: + GenericUsbInput(); + ~GenericUsbInput(); + + static bool TryInitializeInstance(); + + bool Initialize(); + bool PollInput() override; + + bool IsDown(GuButton button); + bool IsUp(GuButton button); + bool IsTapped(GuButton button); + bool IsReleased(GuButton button); + bool WasDown(GuButton button); + bool WasUp(GuButton button); + + inline GuJoystick GetLeftStick() { return currentState.LeftStick; }; + inline GuJoystick GetRightStick() { return currentState.RightStick; }; + inline GuJoystick GetDpad() { return currentState.Dpad.Stick; }; + + static inline bool InstanceInitialized() { return instance != nullptr; }; + static inline GenericUsbInput* GetInstance() { return instance; }; + static inline void DeleteInstance() { delete instance; instance = nullptr; }; + + private: + static GenericUsbInput* instance; + + GuState lastState; + GuState currentState; + + const float triggerThreshold = 0.5f; + const float joystickThreshold = 0.5f; + const float dpadThreshold = 0.5f; + + inline float NormalizeTrigger(long value) { return (float)value / USHRT_MAX; }; + inline float NormalizeStick(long value) { return (float)value / USHRT_MAX * 2.0f - 1.0f; }; + inline GuJoystick NormalizeStick(long x, long y) { return GuJoystick(NormalizeStick(x), NormalizeStick(y)); }; + + void UpdateInternalGuState(GuState &state); + + bool MatchesDirection(GuJoystick joystick, GuDirection directionEnum, float threshold); + bool GetButtonState(GuState &state, GuButton button); + }; +} \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuButton.h b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuButton.h new file mode 100644 index 0000000..1df2e2a --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuButton.h @@ -0,0 +1,52 @@ +#pragma once + +namespace TLAC::Input +{ + enum GuDirection + { + GU_DIR_UP, + GU_DIR_RIGHT, + GU_DIR_DOWN, + GU_DIR_LEFT + }; + + enum GuButton : int + { + GU_BUTTON1 = 0, + GU_BUTTON2 = 1, + GU_BUTTON3 = 2, + GU_BUTTON4 = 3, + + GU_BUTTON5 = 4, + GU_BUTTON6 = 5, + + GU_BUTTON7 = 6, + GU_BUTTON8 = 7, + + GU_BUTTON9 = 8, + GU_BUTTON10 = 9, + + GU_BUTTON11 = 10, + GU_BUTTON12 = 11, + + GU_BUTTON13 = 12, + + + GU_DPAD_UP = 14, + GU_DPAD_RIGHT = 15, + GU_DPAD_DOWN = 16, + GU_DPAD_LEFT = 17, + + GU_L_STICK_UP = 18, + GU_L_STICK_RIGHT = 19, + GU_L_STICK_DOWN = 20, + GU_L_STICK_LEFT = 21, + + GU_R_STICK_UP = 22, + GU_R_STICK_RIGHT = 23, + GU_R_STICK_DOWN = 24, + GU_R_STICK_LEFT = 25, + + GU_BUTTON_MAX = 26, + }; +} \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuState.cpp b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuState.cpp new file mode 100644 index 0000000..cc60409 --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuState.cpp @@ -0,0 +1,14 @@ +#include "GuState.h" + +namespace TLAC::Input +{ + GuJoystick::GuJoystick() : XAxis(0.0f), YAxis(0.0f) + { + return; + }; + + GuJoystick::GuJoystick(float xAxis, float yAxis) : XAxis(xAxis), YAxis(yAxis) + { + return; + }; +} \ No newline at end of file diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuState.h b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuState.h new file mode 100644 index 0000000..9060e8d --- /dev/null +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GuState.h @@ -0,0 +1,39 @@ +#pragma once +#include "../DirectInput.h" +#include "GuButton.h" + +namespace TLAC::Input +{ + struct GuJoystick + { + FLOAT XAxis, YAxis; + + GuJoystick(); + GuJoystick(float xAxis, float yAxis); + }; + + struct GuDpad + { + BOOL IsDown; + FLOAT Angle; + GuJoystick Stick; + }; + + struct GuTrigger + { + FLOAT Axis; + }; + + struct GuState + { + DIJOYSTATE2 DI_JoyState; + + BYTE Buttons[GU_BUTTON_MAX]; + + GuDpad Dpad; + GuJoystick LeftStick; + GuJoystick RightStick; + GuTrigger LeftTrigger; + GuTrigger RightTrigger; + }; +} \ No newline at end of file From 93b93f232a1a70a5ea86700fec5265beeb756c4b Mon Sep 17 00:00:00 2001 From: zsccat Date: Thu, 4 Jun 2020 13:09:36 +0000 Subject: [PATCH 15/20] =?UTF-8?q?=E5=88=A0=E9=99=A4=20'source-code/source/?= =?UTF-8?q?plugins/TLAC/Input/DirectInput/GenericUsb/temp'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../source/plugins/TLAC/Input/DirectInput/GenericUsb/temp | 1 - 1 file changed, 1 deletion(-) delete mode 100644 source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/temp diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/temp b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/temp deleted file mode 100644 index 3602361..0000000 --- a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/temp +++ /dev/null @@ -1 +0,0 @@ -temp \ No newline at end of file From a00dc2f53fa5cc8c4c3e3341a69ed79c298c68d6 Mon Sep 17 00:00:00 2001 From: zsccat Date: Thu, 4 Jun 2020 14:07:23 +0000 Subject: [PATCH 16/20] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=87=B3=20'source-code/source/plugins/TLAC'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add generic usb controller support. --- source-code/source/plugins/TLAC/dllmain.cpp | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/source-code/source/plugins/TLAC/dllmain.cpp b/source-code/source/plugins/TLAC/dllmain.cpp index 8fcf92f..8b60ed5 100644 --- a/source-code/source/plugins/TLAC/dllmain.cpp +++ b/source-code/source/plugins/TLAC/dllmain.cpp @@ -11,6 +11,7 @@ #include "Input/Keyboard/Keyboard.h" #include "Input/DirectInput/DirectInput.h" #include "Input/DirectInput/Ds4/DualShock4.h" +#include "Input/DirectInput/GenericUsb/GenericUsbInput.h" #include "Components/ComponentsManager.h" #include #include @@ -74,6 +75,12 @@ namespace TLAC if (Input::DualShock4::TryInitializeInstance()) printf("[TLAC] UpdateTick(): DualShock4 connected and initialized\n"); } + + if (!Input::GenericUsbInput::InstanceInitialized()) + { + if (Input::GenericUsbInput::TryInitializeInstance()) + printf("[TLAC] UpdateTick(): GenericUsbInput connected and initialized\n"); + } } ComponentsManager.Update(); @@ -96,6 +103,15 @@ namespace TLAC } } + if (Input::GenericUsbInput::GetInstance() != nullptr) + { + if (!Input::GenericUsbInput::GetInstance()->PollInput()) + { + Input::GenericUsbInput::DeleteInstance(); + printf("[TLAC] UpdateTick(): GenericUsbInput connection lost\n"); + } + } + ComponentsManager.UpdateInput(); } @@ -115,6 +131,15 @@ namespace TLAC printf("[TLAC] UpdateTick(): DualShock4 connection lost\n"); } } + + if (Input::GenericUsbInput::GetInstance() != nullptr) + { + if (!Input::GenericUsbInput::GetInstance()->PollInput()) + { + Input::GenericUsbInput::DeleteInstance(); + printf("[TLAC] UpdateTick(): GenericUsbInput connection lost\n"); + } + } } if (HasWindowFocus && !HadWindowFocus) @@ -232,6 +257,7 @@ namespace TLAC delete Input::Keyboard::GetInstance(); delete Input::Mouse::GetInstance(); delete Input::DualShock4::GetInstance(); + delete Input::GenericUsbInput::GetInstance(); Input::DisposeDirectInput(); From d17cbd2e3e5c60363c3c113e89720e44f146af70 Mon Sep 17 00:00:00 2001 From: zsccat Date: Thu, 4 Jun 2020 23:27:18 +0000 Subject: [PATCH 17/20] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=87=B3=20'source-code/source/plugins/TLAC'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add generic usb controller support --- source-code/source/plugins/TLAC/TLAC.vcxproj | 7 +++++++ .../source/plugins/TLAC/TLAC.vcxproj.filters | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/source-code/source/plugins/TLAC/TLAC.vcxproj b/source-code/source/plugins/TLAC/TLAC.vcxproj index 11ad581..53edba2 100644 --- a/source-code/source/plugins/TLAC/TLAC.vcxproj +++ b/source-code/source/plugins/TLAC/TLAC.vcxproj @@ -140,6 +140,7 @@ + @@ -151,6 +152,9 @@ + + + @@ -194,6 +198,7 @@ + @@ -203,6 +208,8 @@ + + diff --git a/source-code/source/plugins/TLAC/TLAC.vcxproj.filters b/source-code/source/plugins/TLAC/TLAC.vcxproj.filters index 79143c4..41ff9d0 100644 --- a/source-code/source/plugins/TLAC/TLAC.vcxproj.filters +++ b/source-code/source/plugins/TLAC/TLAC.vcxproj.filters @@ -201,6 +201,18 @@ Header Files + + Header Files + + + Header Files + + + Header Files + + + Header Files + @@ -341,5 +353,14 @@ Source Files + + Source Files + + + Source Files + + + Source Files + \ No newline at end of file From b82d247368fd35dde641a8c695053551d3642b25 Mon Sep 17 00:00:00 2001 From: zsccat Date: Fri, 5 Jun 2020 01:53:28 +0000 Subject: [PATCH 18/20] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=87=B3=20'source-code/data/plugins'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow to custom key combinations and assign it to a key button. --- source-code/data/plugins/genericusbinput.ini | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source-code/data/plugins/genericusbinput.ini b/source-code/data/plugins/genericusbinput.ini index 2062a67..e58a7b4 100644 --- a/source-code/data/plugins/genericusbinput.ini +++ b/source-code/data/plugins/genericusbinput.ini @@ -4,3 +4,7 @@ VID = 046D PID = C216 + +[customkeymapping] + +GU_BUTTON8 = GU_BUTTON1 + GU_BUTTON2 + GU_BUTTON3 + GU_BUTTON4 From 9f829971bf90a880c8311cdaadab0b4eb8d3d537 Mon Sep 17 00:00:00 2001 From: zsccat Date: Fri, 5 Jun 2020 01:55:02 +0000 Subject: [PATCH 19/20] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=87=B3=20'source-code/source/plugins/TLAC/Input/DirectInput/?= =?UTF-8?q?GenericUsb'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow to custom key combinations and assign it to a key button. --- .../GenericUsb/GenericUsbInput.cpp | 26 ++++++++++++++- .../DirectInput/GenericUsb/GenericUsbInput.h | 32 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.cpp b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.cpp index e2a9b22..8a7983e 100644 --- a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.cpp +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.cpp @@ -1,5 +1,6 @@ #include "GenericUsbInput.h" #include "../../../Utilities/Math.h" +#include "../../../Utilities/Operations.h" #include "../../../framework.h" #include "../../../FileSystem/ConfigFile.h" #include @@ -45,6 +46,8 @@ namespace TLAC::Input FileSystem::ConfigFile configFile(framework::GetModuleDirectory(), GU_CONFIG_FILE_NAME); configFile.OpenRead(); + customKeyMapping = configFile.ConfigMap; + std::string stt = "0x"; std::string vid = configFile.GetStringValue("VID"); std::string pid = configFile.GetStringValue("PID"); @@ -84,7 +87,28 @@ namespace TLAC::Input UpdateInternalGuState(currentState); for (int button = 0; button < GU_BUTTON_MAX; button++) - currentState.Buttons[button] = GetButtonState(currentState, (GuButton)button); + { + bool buttonState = GetButtonState(currentState, (GuButton)button); + currentState.Buttons[button] = buttonState; + + // If custom button is pressed + if (buttonState) + { + // Check whether this button is a custom mapped button + auto customMapping = customKeyMapping.find(buttonNames[button]); + if (customMapping != customKeyMapping.end()) + { + std::vector keys = Utilities::Split(customMapping->second, "+"); + for (std::string key : keys) + { + Utilities::Trim(key); + + auto guButton = KeyConfig::Config::GuMap.find(key.c_str()); + currentState.Buttons[guButton->second] = buttonState; + } + } + } + } return true; } diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.h b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.h index 898b7ce..1178342 100644 --- a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.h +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.h @@ -1,7 +1,9 @@ #pragma once #include "../Controller.h" #include "../../IInputDevice.h" +#include "../../../Input/KeyConfig/Config.h" #include "GuState.h" +#include namespace TLAC::Input { @@ -37,6 +39,36 @@ namespace TLAC::Input GuState lastState; GuState currentState; + std::unordered_map customKeyMapping; + + std::vector buttonNames = { "GU_BUTTON1", + "GU_BUTTON2", + "GU_BUTTON3", + "GU_BUTTON4", + "GU_BUTTON5", + "GU_BUTTON6", + "GU_BUTTON7", + "GU_BUTTON8", + "GU_BUTTON9", + "GU_BUTTON10", + "GU_BUTTON11", + "GU_BUTTON12", + "GU_BUTTON13", + "GU_DPAD_UP", + "GU_DPAD_RIGHT", + "GU_DPAD_DOWN", + "GU_DPAD_LEFT", + "GU_L_STICK_UP", + "GU_L_STICK_RIGHT", + "GU_L_STICK_DOWN", + "GU_L_STICK_LEFT", + "GU_R_STICK_UP", + "GU_R_STICK_RIGHT", + "GU_R_STICK_DOWN", + "GU_R_STICK_LEFT", + "GU_BUTTON_MAX" + }; + const float triggerThreshold = 0.5f; const float joystickThreshold = 0.5f; const float dpadThreshold = 0.5f; From 1dafaac4a5419a2630c95b40dccbdde513c57485 Mon Sep 17 00:00:00 2001 From: zsccat Date: Fri, 5 Jun 2020 10:26:27 +0000 Subject: [PATCH 20/20] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20'README.txt'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 README.txt diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..dd6a156 --- /dev/null +++ b/README.txt @@ -0,0 +1,9 @@ +This is the source code! It can NOT be used to play PDAFT! +If you just wanted to play the game, you downloaded the wrong thing. +Do not click the download button next to the git URL, that's for the source code. + +For information on getting and installing the latest release, +please read the wiki at https://notabug.org/nastys/PD-Loader/wiki +If you've already read it, pay more attention and you'll find the right link. + +You should also read the wiki if you have any issues, before asking questions. \ No newline at end of file