From 9117f778b3566de10e98ecf401302ac8acca9fca Mon Sep 17 00:00:00 2001 From: Redacted Date: Thu, 12 Jun 2025 03:49:54 -0400 Subject: [PATCH] Add jstick member functions missing on Windows implementation. --- include/jstick.hpp | 15 ++++++------- src/platform/windows/jstick_xinput.cpp | 30 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/include/jstick.hpp b/include/jstick.hpp index ffc03c0..343534e 100644 --- a/include/jstick.hpp +++ b/include/jstick.hpp @@ -49,8 +49,7 @@ namespace jstick { - enum class XBoxButton : uint8_t - { + enum class XBoxButton : uint8_t { ButtonA = 0, ButtonB = 1, ButtonX = 2, @@ -62,7 +61,6 @@ namespace jstick { TheBigOne = 8, ThumbL = 9, ThumbR = 10, - DPadDown = 11, DPadRight = 12, DPadUp = 13, @@ -72,27 +70,26 @@ namespace jstick { /// This event is fired when a new joystick device is detected. // TODO: Call JoystickConnected for each device found on library runtime start. inline Event JoystickConnected; - /// This event is fired when a joystick device is unplugged or otherwise dropped. inline Event JoystickDisconnected; - /// This event is fired when a joystick button is pressed. inline Event ButtonPressed; - /// This event is fired when a xbox button is pressed. inline Event ButtonReleased; + /// inline Event LeftThumbstickMoved; + /// inline Event RightThumbstickMoved; + /// inline Event DPadMoved; + /// inline Event LeftTriggerMoved; + /// inline Event RightTriggerMoved; - //Event AxisMoved; - bool Initialize(); bool Cleanup(); - /// @return true if the input system treats the DPad as a Vector2 axis, or false if treated as four buttons. bool GetDPadIsAxisOrButtons(); diff --git a/src/platform/windows/jstick_xinput.cpp b/src/platform/windows/jstick_xinput.cpp index 2b64906..a14c0c8 100644 --- a/src/platform/windows/jstick_xinput.cpp +++ b/src/platform/windows/jstick_xinput.cpp @@ -22,6 +22,25 @@ bool jstick::Cleanup() { return true; } void jstick::JoystickServiceUpdate() { } +// XInput cannot tell us what type of device it is, so assume it's a legitimate Microsoft XB360 controller. +std::string jstick::GetDeviceName(int hwid) { return "Microsoft X-Box 360 pad"; } + +jstick::ControllerType jstick::GetDeviceTypeFromName(const std::string &name) { + // On Windows, we assume the standard controller, we have no way of knowing specifics currently. + // ~josh. + return ControllerType::XBox; +} + +int jstick::NumJoysticksDetected() { + // TODO: Check it properly!! + if (JoystickDetected()) + return 1; + return 0; +} + + + + Vector2 jstick::GetDPadAxis(float deadzone, int hwid) { // "Synthesize" a DPad vector based upon whether the buttons are pressed. @@ -150,6 +169,17 @@ Vector2 jstick::GetRightThumbstickAxis(float deadzone, int hwid) return Vector2(state.Gamepad.sThumbRX, state.Gamepad.sThumbRY); } +int jstick::Connect(int hwid) +{ + return hwid; +} + +bool jstick::Disconnect(int hwid) { + return true; +} + +bool jstick::Connected(int hwid) { return true; } + Vector2 jstick::GetRightThumbstickAxisNormalized(float deadzone, int hwid) { Vector2 axisL = jstick::GetLeftThumbstickAxis(deadzone, hwid);