From 870d26f9d80b5086657569eec4a4b43087424c2f Mon Sep 17 00:00:00 2001 From: Megamouse Date: Fri, 12 Feb 2021 01:55:32 +0100 Subject: [PATCH] Input: replace a bunch of static_pointer_cast --- rpcs3/Input/evdev_joystick_handler.cpp | 12 ++++++------ rpcs3/Input/evdev_joystick_handler.h | 2 +- rpcs3/Input/hid_pad_handler.h | 9 +++------ rpcs3/Input/mm_joystick_handler.cpp | 8 ++++---- rpcs3/Input/xinput_pad_handler.cpp | 8 ++++---- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/rpcs3/Input/evdev_joystick_handler.cpp b/rpcs3/Input/evdev_joystick_handler.cpp index 84296bb753..fecd067238 100644 --- a/rpcs3/Input/evdev_joystick_handler.cpp +++ b/rpcs3/Input/evdev_joystick_handler.cpp @@ -136,7 +136,7 @@ std::string evdev_joystick_handler::get_device_name(const libevdev* dev) bool evdev_joystick_handler::update_device(const std::shared_ptr& device) { - auto evdev_device = std::static_pointer_cast(device); + EvdevDevice* evdev_device = static_cast(device.get()); if (!evdev_device) return false; @@ -193,7 +193,7 @@ void evdev_joystick_handler::Close() { for (auto& binding : bindings) { - auto evdev_device = std::static_pointer_cast(binding.first); + EvdevDevice* evdev_device = static_cast(binding.first.get()); if (evdev_device) { auto& dev = evdev_device->device; @@ -424,7 +424,7 @@ void evdev_joystick_handler::get_next_button_press(const std::string& padId, con // https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/InputCommon/ControllerInterface/evdev/evdev.cpp // https://github.com/reicast/reicast-emulator/blob/master/core/linux-dist/evdev.cpp // http://www.infradead.org/~mchehab/kernel_docs_pdf/linux-input.pdf -void evdev_joystick_handler::SetRumble(std::shared_ptr device, u16 large, u16 small) +void evdev_joystick_handler::SetRumble(EvdevDevice* device, u16 large, u16 small) { if (!device || !device->has_rumble || device->effect_id == -2) return; @@ -658,7 +658,7 @@ int evdev_joystick_handler::add_device(const std::string& device, const std::sha // It's a joystick. Now let's make sure we don't already have this one. if (std::any_of(bindings.begin(), bindings.end(), [&path](std::pair, std::shared_ptr> binding) { - const auto device = std::static_pointer_cast(binding.first); + EvdevDevice* device = static_cast(binding.first.get()); return device && path == device->path; })) { @@ -703,7 +703,7 @@ PadHandlerBase::connection evdev_joystick_handler::update_connection(const std:: if (!update_device(device)) return connection::disconnected; - auto evdev_device = std::static_pointer_cast(device); + EvdevDevice* evdev_device = static_cast(device.get()); if (!evdev_device || !evdev_device->device) return connection::disconnected; @@ -859,7 +859,7 @@ void evdev_joystick_handler::get_mapping(const std::shared_ptr& devic void evdev_joystick_handler::apply_pad_data(const std::shared_ptr& device, const std::shared_ptr& pad) { - auto evdev_device = std::static_pointer_cast(device); + EvdevDevice* evdev_device = static_cast(device.get()); if (!evdev_device) return; diff --git a/rpcs3/Input/evdev_joystick_handler.h b/rpcs3/Input/evdev_joystick_handler.h index 5e4aa77da6..0e92177239 100644 --- a/rpcs3/Input/evdev_joystick_handler.h +++ b/rpcs3/Input/evdev_joystick_handler.h @@ -374,7 +374,7 @@ private: int add_device(const std::string& device, const std::shared_ptr& pad, bool in_settings = false); int GetButtonInfo(const input_event& evt, const std::shared_ptr& device, int& button_code); std::unordered_map> GetButtonValues(const std::shared_ptr& device); - void SetRumble(std::shared_ptr device, u16 large, u16 small); + void SetRumble(EvdevDevice* device, u16 large, u16 small); // Search axis_orientations map for the direction by index, returns -1 if not found, 0 for positive and 1 for negative int FindAxisDirection(const std::unordered_map& map, int index); diff --git a/rpcs3/Input/hid_pad_handler.h b/rpcs3/Input/hid_pad_handler.h index 71b1335111..2e849f3fa5 100644 --- a/rpcs3/Input/hid_pad_handler.h +++ b/rpcs3/Input/hid_pad_handler.h @@ -5,6 +5,8 @@ #include "hidapi.h" +#include + struct CalibData { s16 bias; @@ -84,12 +86,7 @@ protected: const s32 rem = calibData.sens_numer % calibData.sens_denom; const s32 output = (quot * biased) + ((rem * biased) / calibData.sens_denom); - if (output > INT16_MAX) - return INT16_MAX; - else if (output < INT16_MIN) - return INT16_MIN; - else - return static_cast(output); + return static_cast(std::clamp(output, INT16_MIN, INT16_MAX)); } inline s16 read_s16(const void* buf) diff --git a/rpcs3/Input/mm_joystick_handler.cpp b/rpcs3/Input/mm_joystick_handler.cpp index c10a3f2ab5..d35208829b 100644 --- a/rpcs3/Input/mm_joystick_handler.cpp +++ b/rpcs3/Input/mm_joystick_handler.cpp @@ -125,7 +125,7 @@ std::array mm_joystick_handler::get_m { std::array mapping{ 0 }; - auto joy_device = std::static_pointer_cast(device); + MMJOYDevice* joy_device = static_cast(device.get()); if (!joy_device) return mapping; @@ -429,7 +429,7 @@ std::unordered_map mm_joystick_handler::GetButtonValues(const JOYINFOE std::unordered_map mm_joystick_handler::get_button_values(const std::shared_ptr& device) { - auto dev = std::static_pointer_cast(device); + MMJOYDevice* dev = static_cast(device.get()); if (!dev) return std::unordered_map(); return GetButtonValues(dev->device_info, dev->device_caps); @@ -508,14 +508,14 @@ bool mm_joystick_handler::get_is_right_stick(u64 keyCode) PadHandlerBase::connection mm_joystick_handler::update_connection(const std::shared_ptr& device) { - auto dev = std::static_pointer_cast(device); + MMJOYDevice* dev = static_cast(device.get()); if (!dev) return connection::disconnected; const auto old_status = dev->device_status; dev->device_status = joyGetPosEx(dev->device_id, &dev->device_info); - if (dev->device_status == JOYERR_NOERROR && (old_status == JOYERR_NOERROR || GetMMJOYDevice(dev->device_id, dev.get()))) + if (dev->device_status == JOYERR_NOERROR && (old_status == JOYERR_NOERROR || GetMMJOYDevice(dev->device_id, dev))) { return connection::connected; } diff --git a/rpcs3/Input/xinput_pad_handler.cpp b/rpcs3/Input/xinput_pad_handler.cpp index 2729316935..bec0aa5ca9 100644 --- a/rpcs3/Input/xinput_pad_handler.cpp +++ b/rpcs3/Input/xinput_pad_handler.cpp @@ -162,7 +162,7 @@ int xinput_pad_handler::GetDeviceNumber(const std::string& padId) std::unordered_map xinput_pad_handler::get_button_values(const std::shared_ptr& device) { PadButtonValues values; - auto dev = std::static_pointer_cast(device); + XInputDevice* dev = static_cast(device.get()); if (!dev || dev->state != ERROR_SUCCESS) // the state has to be aquired with update_connection before calling this function return values; @@ -426,7 +426,7 @@ bool xinput_pad_handler::get_is_right_stick(u64 keyCode) PadHandlerBase::connection xinput_pad_handler::update_connection(const std::shared_ptr& device) { - auto dev = std::static_pointer_cast(device); + XInputDevice* dev = static_cast(device.get()); if (!dev) return connection::disconnected; @@ -451,7 +451,7 @@ PadHandlerBase::connection xinput_pad_handler::update_connection(const std::shar void xinput_pad_handler::get_extended_info(const std::shared_ptr& device, const std::shared_ptr& pad) { - auto dev = std::static_pointer_cast(device); + XInputDevice* dev = static_cast(device.get()); if (!dev || !pad) return; @@ -478,7 +478,7 @@ void xinput_pad_handler::get_extended_info(const std::shared_ptr& dev void xinput_pad_handler::apply_pad_data(const std::shared_ptr& device, const std::shared_ptr& pad) { - auto dev = std::static_pointer_cast(device); + XInputDevice* dev = static_cast(device.get()); if (!dev || !pad) return;