Controller fixes.

Fix joystick dpad emulation diagonal direction.

Always activate an action set by default.
This commit is contained in:
Mr_Goldberg 2022-04-02 04:33:34 -04:00
parent 5533a9d5b0
commit f6b8068883
No known key found for this signature in database
GPG key ID: 8597D87419DEF278

View file

@ -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;
}