diff options
Diffstat (limited to 'src/input_common')
-rw-r--r-- | src/input_common/drivers/mouse.cpp | 89 | ||||
-rw-r--r-- | src/input_common/drivers/mouse.h | 2 | ||||
-rw-r--r-- | src/input_common/drivers/sdl_driver.cpp | 46 | ||||
-rw-r--r-- | src/input_common/drivers/sdl_driver.h | 7 |
4 files changed, 60 insertions, 84 deletions
diff --git a/src/input_common/drivers/mouse.cpp b/src/input_common/drivers/mouse.cpp index f07cf8a0e..9fb824baf 100644 --- a/src/input_common/drivers/mouse.cpp +++ b/src/input_common/drivers/mouse.cpp @@ -12,9 +12,13 @@ namespace InputCommon { constexpr int update_time = 10; -constexpr float default_stick_sensitivity = 0.0044f; -constexpr float default_motion_sensitivity = 0.0003f; +constexpr float default_panning_sensitivity = 0.0010f; +constexpr float default_stick_sensitivity = 0.0006f; +constexpr float default_deadzone_counterweight = 0.01f; +constexpr float default_motion_panning_sensitivity = 2.5f; +constexpr float default_motion_sensitivity = 0.416f; constexpr float maximum_rotation_speed = 2.0f; +constexpr float maximum_stick_range = 1.5f; constexpr int mouse_axis_x = 0; constexpr int mouse_axis_y = 1; constexpr int wheel_axis_x = 2; @@ -81,7 +85,7 @@ void Mouse::UpdateThread(std::stop_token stop_token) { } void Mouse::UpdateStickInput() { - if (!Settings::values.mouse_panning) { + if (!IsMousePanningEnabled()) { return; } @@ -89,26 +93,13 @@ void Mouse::UpdateStickInput() { // Prevent input from exceeding the max range (1.0f) too much, // but allow some room to make it easier to sustain - if (length > 1.2f) { + if (length > maximum_stick_range) { last_mouse_change /= length; - last_mouse_change *= 1.2f; + last_mouse_change *= maximum_stick_range; } - auto mouse_change = last_mouse_change; - - // Bind the mouse change to [0 <= deadzone_counterweight <= 1,1] - if (length < 1.0f) { - const float deadzone_h_counterweight = - Settings::values.mouse_panning_deadzone_x_counterweight.GetValue(); - const float deadzone_v_counterweight = - Settings::values.mouse_panning_deadzone_y_counterweight.GetValue(); - mouse_change /= length; - mouse_change.x *= length + (1 - length) * deadzone_h_counterweight * 0.01f; - mouse_change.y *= length + (1 - length) * deadzone_v_counterweight * 0.01f; - } - - SetAxis(identifier, mouse_axis_x, mouse_change.x); - SetAxis(identifier, mouse_axis_y, -mouse_change.y); + SetAxis(identifier, mouse_axis_x, last_mouse_change.x); + SetAxis(identifier, mouse_axis_y, -last_mouse_change.y); // Decay input over time const float clamped_length = std::min(1.0f, length); @@ -120,14 +111,13 @@ void Mouse::UpdateStickInput() { } void Mouse::UpdateMotionInput() { - // This may need its own sensitivity instead of using the average - const float sensitivity = (Settings::values.mouse_panning_x_sensitivity.GetValue() + - Settings::values.mouse_panning_y_sensitivity.GetValue()) / - 2.0f * default_motion_sensitivity; + const float sensitivity = + IsMousePanningEnabled() ? default_motion_panning_sensitivity : default_motion_sensitivity; const float rotation_velocity = std::sqrt(last_motion_change.x * last_motion_change.x + last_motion_change.y * last_motion_change.y); + // Clamp rotation speed if (rotation_velocity > maximum_rotation_speed / sensitivity) { const float multiplier = maximum_rotation_speed / rotation_velocity / sensitivity; last_motion_change.x = last_motion_change.x * multiplier; @@ -144,7 +134,7 @@ void Mouse::UpdateMotionInput() { .delta_timestamp = update_time * 1000, }; - if (Settings::values.mouse_panning) { + if (IsMousePanningEnabled()) { last_motion_change.x = 0; last_motion_change.y = 0; } @@ -154,33 +144,43 @@ void Mouse::UpdateMotionInput() { } void Mouse::Move(int x, int y, int center_x, int center_y) { - if (Settings::values.mouse_panning) { + if (IsMousePanningEnabled()) { const auto mouse_change = (Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y)).Cast<float>(); const float x_sensitivity = - Settings::values.mouse_panning_x_sensitivity.GetValue() * default_stick_sensitivity; + Settings::values.mouse_panning_x_sensitivity.GetValue() * default_panning_sensitivity; const float y_sensitivity = - Settings::values.mouse_panning_y_sensitivity.GetValue() * default_stick_sensitivity; - - last_motion_change += {-mouse_change.y, -mouse_change.x, 0}; - last_mouse_change.x += mouse_change.x * x_sensitivity * 0.09f; - last_mouse_change.y += mouse_change.y * y_sensitivity * 0.09f; + Settings::values.mouse_panning_y_sensitivity.GetValue() * default_panning_sensitivity; + const float deadzone_counterweight = + Settings::values.mouse_panning_deadzone_counterweight.GetValue() * + default_deadzone_counterweight; + + last_motion_change += {-mouse_change.y * x_sensitivity, -mouse_change.x * y_sensitivity, 0}; + last_mouse_change.x += mouse_change.x * x_sensitivity; + last_mouse_change.y += mouse_change.y * y_sensitivity; + + // Bind the mouse change to [0 <= deadzone_counterweight <= 1.0] + const float length = last_mouse_change.Length(); + if (length < deadzone_counterweight && length != 0.0f) { + last_mouse_change /= length; + last_mouse_change *= deadzone_counterweight; + } return; } if (button_pressed) { const auto mouse_move = Common::MakeVec<int>(x, y) - mouse_origin; - const float x_sensitivity = Settings::values.mouse_panning_x_sensitivity.GetValue(); - const float y_sensitivity = Settings::values.mouse_panning_y_sensitivity.GetValue(); - SetAxis(identifier, mouse_axis_x, - static_cast<float>(mouse_move.x) * x_sensitivity * 0.0012f); - SetAxis(identifier, mouse_axis_y, - static_cast<float>(-mouse_move.y) * y_sensitivity * 0.0012f); + const float x_sensitivity = + Settings::values.mouse_panning_x_sensitivity.GetValue() * default_stick_sensitivity; + const float y_sensitivity = + Settings::values.mouse_panning_y_sensitivity.GetValue() * default_stick_sensitivity; + SetAxis(identifier, mouse_axis_x, static_cast<float>(mouse_move.x) * x_sensitivity); + SetAxis(identifier, mouse_axis_y, static_cast<float>(-mouse_move.y) * y_sensitivity); last_motion_change = { - static_cast<float>(-mouse_move.y) / 50.0f, - static_cast<float>(-mouse_move.x) / 50.0f, + static_cast<float>(-mouse_move.y) * x_sensitivity, + static_cast<float>(-mouse_move.x) * y_sensitivity, last_motion_change.z, }; } @@ -220,7 +220,7 @@ void Mouse::ReleaseButton(MouseButton button) { SetButton(real_mouse_identifier, static_cast<int>(button), false); SetButton(touch_identifier, static_cast<int>(button), false); - if (!Settings::values.mouse_panning) { + if (!IsMousePanningEnabled()) { SetAxis(identifier, mouse_axis_x, 0); SetAxis(identifier, mouse_axis_y, 0); } @@ -234,7 +234,7 @@ void Mouse::ReleaseButton(MouseButton button) { void Mouse::MouseWheelChange(int x, int y) { wheel_position.x += x; wheel_position.y += y; - last_motion_change.z += static_cast<f32>(y) / 100.0f; + last_motion_change.z += static_cast<f32>(y); SetAxis(identifier, wheel_axis_x, static_cast<f32>(wheel_position.x)); SetAxis(identifier, wheel_axis_y, static_cast<f32>(wheel_position.y)); } @@ -244,6 +244,11 @@ void Mouse::ReleaseAllButtons() { button_pressed = false; } +bool Mouse::IsMousePanningEnabled() { + // Disable mouse panning when a real mouse is connected + return Settings::values.mouse_panning && !Settings::values.mouse_enabled; +} + std::vector<Common::ParamPackage> Mouse::GetInputDevices() const { std::vector<Common::ParamPackage> devices; devices.emplace_back(Common::ParamPackage{ diff --git a/src/input_common/drivers/mouse.h b/src/input_common/drivers/mouse.h index 0e8edcce1..2b93a40b9 100644 --- a/src/input_common/drivers/mouse.h +++ b/src/input_common/drivers/mouse.h @@ -99,6 +99,8 @@ private: void UpdateStickInput(); void UpdateMotionInput(); + bool IsMousePanningEnabled(); + Common::Input::ButtonNames GetUIButtonName(const Common::ParamPackage& params) const; Common::Vec2<int> mouse_origin; diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp index 9f26392b1..66e3ae9af 100644 --- a/src/input_common/drivers/sdl_driver.cpp +++ b/src/input_common/drivers/sdl_driver.cpp @@ -523,6 +523,8 @@ SDLDriver::SDLDriver(std::string input_engine_) : InputEngine(std::move(input_en } SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_SWITCH_PLAYER_LED, "1"); + // Share the same button mapping with non-Nintendo controllers + SDL_SetHint(SDL_HINT_GAMECONTROLLER_USE_BUTTON_LABELS, "0"); // Disable hidapi driver for xbox. Already default on Windows, this causes conflict with native // driver on Linux. @@ -800,16 +802,9 @@ ButtonMapping SDLDriver::GetButtonMappingForDevice(const Common::ParamPackage& p // This list is missing ZL/ZR since those are not considered buttons in SDL GameController. // We will add those afterwards - // This list also excludes Screenshot since there's not really a mapping for that ButtonBindings switch_to_sdl_button; - if (SDL_GameControllerGetType(controller) == SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO || - SDL_GameControllerGetType(controller) == SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_LEFT || - SDL_GameControllerGetType(controller) == SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT) { - switch_to_sdl_button = GetNintendoButtonBinding(joystick); - } else { - switch_to_sdl_button = GetDefaultButtonBinding(); - } + switch_to_sdl_button = GetDefaultButtonBinding(joystick); // Add the missing bindings for ZL/ZR static constexpr ZButtonBindings switch_to_sdl_axis{{ @@ -830,32 +825,9 @@ ButtonMapping SDLDriver::GetButtonMappingForDevice(const Common::ParamPackage& p return GetSingleControllerMapping(joystick, switch_to_sdl_button, switch_to_sdl_axis); } -ButtonBindings SDLDriver::GetDefaultButtonBinding() const { - return { - std::pair{Settings::NativeButton::A, SDL_CONTROLLER_BUTTON_B}, - {Settings::NativeButton::B, SDL_CONTROLLER_BUTTON_A}, - {Settings::NativeButton::X, SDL_CONTROLLER_BUTTON_Y}, - {Settings::NativeButton::Y, SDL_CONTROLLER_BUTTON_X}, - {Settings::NativeButton::LStick, SDL_CONTROLLER_BUTTON_LEFTSTICK}, - {Settings::NativeButton::RStick, SDL_CONTROLLER_BUTTON_RIGHTSTICK}, - {Settings::NativeButton::L, SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, - {Settings::NativeButton::R, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER}, - {Settings::NativeButton::Plus, SDL_CONTROLLER_BUTTON_START}, - {Settings::NativeButton::Minus, SDL_CONTROLLER_BUTTON_BACK}, - {Settings::NativeButton::DLeft, SDL_CONTROLLER_BUTTON_DPAD_LEFT}, - {Settings::NativeButton::DUp, SDL_CONTROLLER_BUTTON_DPAD_UP}, - {Settings::NativeButton::DRight, SDL_CONTROLLER_BUTTON_DPAD_RIGHT}, - {Settings::NativeButton::DDown, SDL_CONTROLLER_BUTTON_DPAD_DOWN}, - {Settings::NativeButton::SL, SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, - {Settings::NativeButton::SR, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER}, - {Settings::NativeButton::Home, SDL_CONTROLLER_BUTTON_GUIDE}, - {Settings::NativeButton::Screenshot, SDL_CONTROLLER_BUTTON_MISC1}, - }; -} - -ButtonBindings SDLDriver::GetNintendoButtonBinding( +ButtonBindings SDLDriver::GetDefaultButtonBinding( const std::shared_ptr<SDLJoystick>& joystick) const { - // Default SL/SR mapping for pro controllers + // Default SL/SR mapping for other controllers auto sl_button = SDL_CONTROLLER_BUTTON_LEFTSHOULDER; auto sr_button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER; @@ -869,10 +841,10 @@ ButtonBindings SDLDriver::GetNintendoButtonBinding( } return { - std::pair{Settings::NativeButton::A, SDL_CONTROLLER_BUTTON_A}, - {Settings::NativeButton::B, SDL_CONTROLLER_BUTTON_B}, - {Settings::NativeButton::X, SDL_CONTROLLER_BUTTON_X}, - {Settings::NativeButton::Y, SDL_CONTROLLER_BUTTON_Y}, + std::pair{Settings::NativeButton::A, SDL_CONTROLLER_BUTTON_B}, + {Settings::NativeButton::B, SDL_CONTROLLER_BUTTON_A}, + {Settings::NativeButton::X, SDL_CONTROLLER_BUTTON_Y}, + {Settings::NativeButton::Y, SDL_CONTROLLER_BUTTON_X}, {Settings::NativeButton::LStick, SDL_CONTROLLER_BUTTON_LEFTSTICK}, {Settings::NativeButton::RStick, SDL_CONTROLLER_BUTTON_RIGHTSTICK}, {Settings::NativeButton::L, SDL_CONTROLLER_BUTTON_LEFTSHOULDER}, diff --git a/src/input_common/drivers/sdl_driver.h b/src/input_common/drivers/sdl_driver.h index ffde169b3..fcba4e3c6 100644 --- a/src/input_common/drivers/sdl_driver.h +++ b/src/input_common/drivers/sdl_driver.h @@ -100,11 +100,8 @@ private: int axis_y, float offset_x, float offset_y) const; - /// Returns the default button bindings list for generic controllers - ButtonBindings GetDefaultButtonBinding() const; - - /// Returns the default button bindings list for nintendo controllers - ButtonBindings GetNintendoButtonBinding(const std::shared_ptr<SDLJoystick>& joystick) const; + /// Returns the default button bindings list + ButtonBindings GetDefaultButtonBinding(const std::shared_ptr<SDLJoystick>& joystick) const; /// Returns the button mappings from a single controller ButtonMapping GetSingleControllerMapping(const std::shared_ptr<SDLJoystick>& joystick, |