From f6b80688834c1f143441682a155f296fde7d0468 Mon Sep 17 00:00:00 2001 From: Mr_Goldberg Date: Sat, 2 Apr 2022 04:33:34 -0400 Subject: [PATCH] Controller fixes. Fix joystick dpad emulation diagonal direction. Always activate an action set by default. --- dll/steam_controller.h | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/dll/steam_controller.h b/dll/steam_controller.h index abed1c97..1d30c09c 100644 --- a/dll/steam_controller.h +++ b/dll/steam_controller.h @@ -91,6 +91,7 @@ enum EXTRA_GAMEPAD_BUTTONS { #define JOY_ID_START 10 #define STICK_DPAD 3 +#define DEADZONE_BUTTON_STICK 0.3 class Steam_Controller : public ISteamController001, @@ -332,9 +333,9 @@ bool Init(bool bExplicitlyCallRunFrame) for (int i = 1; i < 5; ++i) { struct Controller_Action cont_action(i); - //Activate the action set if there is only one present. - //TODO: I don't know if one gets activated by default when there's more than one - if (action_handles.size() == 1) { + //Activate the first action set. + //TODO: check exactly what decides which gets activated by default + if (action_handles.size() >= 1) { cont_action.activate_action_set(action_handles.begin()->second, controller_maps); } @@ -522,6 +523,7 @@ void ActivateActionSet( ControllerHandle_t controllerHandle, ControllerActionSet ControllerActionSetHandle_t GetCurrentActionSet( ControllerHandle_t controllerHandle ) { + //TODO: should return zero if no action set specifically activated with ActivateActionSet PRINT_DEBUG("Steam_Controller::GetCurrentActionSet %llu\n", controllerHandle); auto controller = controllers.find(controllerHandle); if (controller == controllers.end()) return 0; @@ -606,17 +608,31 @@ ControllerDigitalActionData_t GetDigitalActionData( ControllerHandle_t controlle case BUTTON_STICK_LEFT_UP: case BUTTON_STICK_LEFT_DOWN: case BUTTON_STICK_LEFT_LEFT: - case BUTTON_STICK_LEFT_RIGHT: - pressed = GamepadStickLength(device, STICK_LEFT) > 0.1 && - ((int)GamepadStickDir(device, STICK_LEFT) == ((button - BUTTON_STICK_LEFT_UP) + 1)); + case BUTTON_STICK_LEFT_RIGHT: { + float x = 0, y = 0, len = GamepadStickLength(device, STICK_LEFT); + GamepadStickNormXY(device, STICK_LEFT, &x, &y); + x *= len; + y *= len; + if (button == BUTTON_STICK_LEFT_UP) pressed = y > DEADZONE_BUTTON_STICK; + if (button == BUTTON_STICK_LEFT_DOWN) pressed = y < -DEADZONE_BUTTON_STICK; + if (button == BUTTON_STICK_LEFT_RIGHT) pressed = x > DEADZONE_BUTTON_STICK; + if (button == BUTTON_STICK_LEFT_LEFT) pressed = x < -DEADZONE_BUTTON_STICK; break; + } case BUTTON_STICK_RIGHT_UP: case BUTTON_STICK_RIGHT_DOWN: case BUTTON_STICK_RIGHT_LEFT: - case BUTTON_STICK_RIGHT_RIGHT: - pressed = GamepadStickLength(device, STICK_RIGHT) > 0.1 && - ((int)GamepadStickDir(device, STICK_RIGHT) == ((button - BUTTON_STICK_RIGHT_UP) + 1)); + case BUTTON_STICK_RIGHT_RIGHT: { + float x = 0, y = 0, len = GamepadStickLength(device, STICK_RIGHT); + GamepadStickNormXY(device, STICK_RIGHT, &x, &y); + x *= len; + y *= len; + if (button == BUTTON_STICK_RIGHT_UP) pressed = y > DEADZONE_BUTTON_STICK; + if (button == BUTTON_STICK_RIGHT_DOWN) pressed = y < -DEADZONE_BUTTON_STICK; + if (button == BUTTON_STICK_RIGHT_RIGHT) pressed = x > DEADZONE_BUTTON_STICK; + if (button == BUTTON_STICK_RIGHT_LEFT) pressed = x < -DEADZONE_BUTTON_STICK; break; + } default: break; }