VERY experimental Nintendo Switch 2 emulator
C++
kraken: Address comments from review
german7730de38ee7fd9
diff --git a/src/core/hid/hid_types.h b/src/core/hid/hid_types.hindex 8b12f63ad9..3cbe162603 100644--- a/src/core/hid/hid_types.h+++ b/src/core/hid/hid_types.h@@ -564,8 +564,9 @@ struct MouseState {s32 y;s32 delta_x;s32 delta_y;- s32 delta_wheel_x;+ // Axis Order in HW is switched for the wheels32 delta_wheel_y;+ s32 delta_wheel_x;MouseButton button;MouseAttribute attribute;};diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cppindex eaec791399..4b23230e1c 100644--- a/src/core/hle/service/hid/controllers/npad.cpp+++ b/src/core/hle/service/hid/controllers/npad.cpp@@ -345,7 +345,7 @@ void Controller_NPad::RequestPadStateUpdate(Core::HID::NpadIdType npad_id) {constexpr btn right_button_mask = btn::A | btn::B | btn::X | btn::Y | btn::StickR | btn::R |btn::ZR | btn::Plus | btn::StickRLeft | btn::StickRUp |btn::StickRRight | btn::StickRDown;- pad_entry.npad_buttons.raw |= button_state.raw & right_button_mask;+ pad_entry.npad_buttons.raw = button_state.raw & right_button_mask;pad_entry.r_stick = stick_state.right;}diff --git a/src/core/hle/service/hid/ring_lifo.h b/src/core/hle/service/hid/ring_lifo.hindex 6209ed0d15..f0e0bab7fe 100644--- a/src/core/hle/service/hid/ring_lifo.h+++ b/src/core/hle/service/hid/ring_lifo.h@@ -7,7 +7,6 @@#include <array>#include "common/common_types.h"-#include "common/swap.h"namespace Service::HID {constexpr std::size_t max_buffer_size = 17;@@ -21,7 +20,7 @@ struct AtomicStorage {template <typename State>struct Lifo {s64 timestamp{};- s64 total_buffer_count = max_buffer_size;+ s64 total_buffer_count = static_cast<s64>(max_buffer_size);s64 buffer_tail{};s64 buffer_count{};std::array<AtomicStorage<State>, max_buffer_size> entries{};@@ -35,11 +34,11 @@ struct Lifo {}std::size_t GetPreviousEntryIndex() const {- return (buffer_tail + total_buffer_count - 1) % total_buffer_count;+ return static_cast<size_t>((buffer_tail + total_buffer_count - 1) % total_buffer_count);}std::size_t GetNextEntryIndex() const {- return (buffer_tail + 1) % total_buffer_count;+ return static_cast<size_t>((buffer_tail + 1) % total_buffer_count);}void WriteNextEntry(const State& new_state) {diff --git a/src/input_common/drivers/gc_adapter.cpp b/src/input_common/drivers/gc_adapter.cppindex 2550f8cba5..a1b9b6d988 100644--- a/src/input_common/drivers/gc_adapter.cpp+++ b/src/input_common/drivers/gc_adapter.cpp@@ -69,7 +69,7 @@ private:libusb_device_handle* handle{};};-GCAdapter::GCAdapter(const std::string input_engine_) : InputEngine(input_engine_) {+GCAdapter::GCAdapter(const std::string& input_engine_) : InputEngine(input_engine_) {if (usb_adapter_handle) {return;}@@ -486,42 +486,30 @@ std::string GCAdapter::GetUIButtonName(const Common::ParamPackage& params) constswitch (button) {case PadButton::ButtonLeft:return "left";- break;case PadButton::ButtonRight:return "right";- break;case PadButton::ButtonDown:return "down";- break;case PadButton::ButtonUp:return "up";- break;case PadButton::TriggerZ:return "Z";- break;case PadButton::TriggerR:return "R";- break;case PadButton::TriggerL:return "L";- break;case PadButton::ButtonA:return "A";- break;case PadButton::ButtonB:return "B";- break;case PadButton::ButtonX:return "X";- break;case PadButton::ButtonY:return "Y";- break;case PadButton::ButtonStart:return "start";- break;default:- return "Unkown GC";+ return "Unknown GC";}}diff --git a/src/input_common/drivers/gc_adapter.h b/src/input_common/drivers/gc_adapter.hindex fba90352e9..3e4747040f 100644--- a/src/input_common/drivers/gc_adapter.h+++ b/src/input_common/drivers/gc_adapter.h@@ -24,7 +24,7 @@ class LibUSBDeviceHandle;class GCAdapter : public InputCommon::InputEngine {public:- explicit GCAdapter(const std::string input_engine_);+ explicit GCAdapter(const std::string& input_engine_);~GCAdapter();Common::Input::VibrationError SetRumble(diff --git a/src/input_common/drivers/mouse.cpp b/src/input_common/drivers/mouse.cppindex 05fd7f9c0d..9a9a1987d5 100644--- a/src/input_common/drivers/mouse.cpp+++ b/src/input_common/drivers/mouse.cpp@@ -24,7 +24,7 @@ constexpr PadIdentifier identifier = {.pad = 0,};-Mouse::Mouse(const std::string input_engine_) : InputEngine(input_engine_) {+Mouse::Mouse(const std::string& input_engine_) : InputEngine(input_engine_) {PreSetController(identifier);PreSetAxis(identifier, mouse_axis_x);PreSetAxis(identifier, mouse_axis_y);diff --git a/src/input_common/drivers/mouse.h b/src/input_common/drivers/mouse.hindex f7e6db0b5f..11dd76e140 100644--- a/src/input_common/drivers/mouse.h+++ b/src/input_common/drivers/mouse.h@@ -29,7 +29,7 @@ enum class MouseButton {*/class Mouse final : public InputCommon::InputEngine {public:- explicit Mouse(const std::string input_engine_);+ explicit Mouse(const std::string& input_engine_);/*** Signals that mouse has moved.diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cppindex 1e3741e0f8..0b24f1858c 100644--- a/src/input_common/drivers/sdl_driver.cpp+++ b/src/input_common/drivers/sdl_driver.cpp@@ -929,7 +929,7 @@ std::string SDLDriver::GetHatButtonName(u8 direction_value) const {}}-u8 SDLDriver::GetHatButtonId(const std::string direction_name) const {+u8 SDLDriver::GetHatButtonId(const std::string& direction_name) const {Uint8 direction;if (direction_name == "up") {direction = SDL_HAT_UP;diff --git a/src/input_common/drivers/sdl_driver.h b/src/input_common/drivers/sdl_driver.hindex b879df8abf..3faaca9842 100644--- a/src/input_common/drivers/sdl_driver.h+++ b/src/input_common/drivers/sdl_driver.h@@ -56,7 +56,7 @@ public:std::string GetUIName(const Common::ParamPackage& params) const override;std::string GetHatButtonName(u8 direction_value) const override;- u8 GetHatButtonId(const std::string direction_name) const override;+ u8 GetHatButtonId(const std::string& direction_name) const override;Common::Input::VibrationError SetRumble(const PadIdentifier& identifier, const Common::Input::VibrationStatus vibration) override;diff --git a/src/input_common/drivers/tas_input.cpp b/src/input_common/drivers/tas_input.cppindex bb9c236eae..0e01fb0d96 100644--- a/src/input_common/drivers/tas_input.cpp+++ b/src/input_common/drivers/tas_input.cpp@@ -47,7 +47,7 @@ constexpr std::array<std::pair<std::string_view, TasButton>, 20> text_to_tas_but{"KEY_ZR", TasButton::TRIGGER_ZR},};-Tas::Tas(const std::string input_engine_) : InputCommon::InputEngine(input_engine_) {+Tas::Tas(const std::string& input_engine_) : InputCommon::InputEngine(input_engine_) {for (size_t player_index = 0; player_index < PLAYER_NUMBER; player_index++) {PadIdentifier identifier{.guid = Common::UUID{},diff --git a/src/input_common/drivers/tas_input.h b/src/input_common/drivers/tas_input.hindex bfb37a638b..c95a130fcb 100644--- a/src/input_common/drivers/tas_input.h+++ b/src/input_common/drivers/tas_input.h@@ -83,7 +83,7 @@ enum class TasState {class Tas final : public InputCommon::InputEngine {public:- explicit Tas(const std::string input_engine_);+ explicit Tas(const std::string& input_engine_);~Tas();/**diff --git a/src/input_common/drivers/touch_screen.cpp b/src/input_common/drivers/touch_screen.cppindex 377c9ee2b5..45b3086f6a 100644--- a/src/input_common/drivers/touch_screen.cpp+++ b/src/input_common/drivers/touch_screen.cpp@@ -13,7 +13,7 @@ constexpr PadIdentifier identifier = {.pad = 0,};-TouchScreen::TouchScreen(const std::string input_engine_) : InputEngine(input_engine_) {+TouchScreen::TouchScreen(const std::string& input_engine_) : InputEngine(input_engine_) {PreSetController(identifier);}diff --git a/src/input_common/drivers/touch_screen.h b/src/input_common/drivers/touch_screen.hindex 0f4cd0e7ad..25c11e8bfd 100644--- a/src/input_common/drivers/touch_screen.h+++ b/src/input_common/drivers/touch_screen.h@@ -14,7 +14,7 @@ namespace InputCommon {*/class TouchScreen final : public InputCommon::InputEngine {public:- explicit TouchScreen(const std::string input_engine_);+ explicit TouchScreen(const std::string& input_engine_);/*** Signals that mouse has moved.diff --git a/src/input_common/input_engine.cpp b/src/input_common/input_engine.cppindex 139d8d2e61..2b2105376f 100644--- a/src/input_common/input_engine.cpp+++ b/src/input_common/input_engine.cpp@@ -300,8 +300,8 @@ void InputEngine::TriggerOnMotionChange(const PadIdentifier& identifier, int motif (!configuring || !mapping_callback.on_data) {return;}- if (std::abs(value.gyro_x) < 1.0f && std::abs(value.gyro_y) < 1.0f &&- std::abs(value.gyro_z) < 1.0f) {+ if (std::abs(value.gyro_x) < 0.6f && std::abs(value.gyro_y) < 0.6f &&+ std::abs(value.gyro_z) < 0.6f) {return;}mapping_callback.on_data(MappingData{diff --git a/src/input_common/input_engine.h b/src/input_common/input_engine.hindex 5430c0cf8f..c621686e54 100644--- a/src/input_common/input_engine.h+++ b/src/input_common/input_engine.h@@ -166,7 +166,7 @@ public:};/// Retrieves the index number of the given hat button direction- virtual u8 GetHatButtonId([[maybe_unused]] const std::string direction_name) const {+ virtual u8 GetHatButtonId([[maybe_unused]] const std::string& direction_name) const {return 0;};diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cppindex 2313a41894..7390fc5bda 100644--- a/src/yuzu/bootmanager.cpp+++ b/src/yuzu/bootmanager.cpp@@ -613,56 +613,56 @@ int GRenderWindow::QtKeyToSwitchKey(Qt::Key qt_key) {}}-int GRenderWindow::QtModifierToSwitchModdifier(quint32 qt_moddifiers) {- int moddifier = 0;+int GRenderWindow::QtModifierToSwitchModifier(quint32 qt_modifiers) {+ int modifier = 0;// The values are obtained through testing, Qt doesn't seem to provide a proper enum- if ((qt_moddifiers & 0x1) != 0) {- moddifier |= 1 << Settings::NativeKeyboard::LeftShift;+ if ((qt_modifiers & 0x1) != 0) {+ modifier |= 1 << Settings::NativeKeyboard::LeftShift;}- if ((qt_moddifiers & 0x2) != 0) {- moddifier |= 1 << Settings::NativeKeyboard::LeftControl;+ if ((qt_modifiers & 0x2) != 0) {+ modifier |= 1 << Settings::NativeKeyboard::LeftControl;}- if ((qt_moddifiers & 0x4) != 0) {- moddifier |= 1 << Settings::NativeKeyboard::LeftAlt;+ if ((qt_modifiers & 0x4) != 0) {+ modifier |= 1 << Settings::NativeKeyboard::LeftAlt;}- if ((qt_moddifiers & 0x08) != 0) {- moddifier |= 1 << Settings::NativeKeyboard::LeftMeta;+ if ((qt_modifiers & 0x08) != 0) {+ modifier |= 1 << Settings::NativeKeyboard::LeftMeta;}- if ((qt_moddifiers & 0x10) != 0) {- moddifier |= 1 << Settings::NativeKeyboard::RightShift;+ if ((qt_modifiers & 0x10) != 0) {+ modifier |= 1 << Settings::NativeKeyboard::RightShift;}- if ((qt_moddifiers & 0x20) != 0) {- moddifier |= 1 << Settings::NativeKeyboard::RightControl;+ if ((qt_modifiers & 0x20) != 0) {+ modifier |= 1 << Settings::NativeKeyboard::RightControl;}- if ((qt_moddifiers & 0x40) != 0) {- moddifier |= 1 << Settings::NativeKeyboard::RightAlt;+ if ((qt_modifiers & 0x40) != 0) {+ modifier |= 1 << Settings::NativeKeyboard::RightAlt;}- if ((qt_moddifiers & 0x80) != 0) {- moddifier |= 1 << Settings::NativeKeyboard::RightMeta;+ if ((qt_modifiers & 0x80) != 0) {+ modifier |= 1 << Settings::NativeKeyboard::RightMeta;}- if ((qt_moddifiers & 0x100) != 0) {- moddifier |= 1 << Settings::NativeKeyboard::CapsLock;+ if ((qt_modifiers & 0x100) != 0) {+ modifier |= 1 << Settings::NativeKeyboard::CapsLock;}- if ((qt_moddifiers & 0x200) != 0) {- moddifier |= 1 << Settings::NativeKeyboard::NumLock;+ if ((qt_modifiers & 0x200) != 0) {+ modifier |= 1 << Settings::NativeKeyboard::NumLock;}// Verify the last two keys- if ((qt_moddifiers & 0x400) != 0) {- moddifier |= 1 << Settings::NativeKeyboard::Katakana;+ if ((qt_modifiers & 0x400) != 0) {+ modifier |= 1 << Settings::NativeKeyboard::Katakana;}- if ((qt_moddifiers & 0x800) != 0) {- moddifier |= 1 << Settings::NativeKeyboard::Hiragana;+ if ((qt_modifiers & 0x800) != 0) {+ modifier |= 1 << Settings::NativeKeyboard::Hiragana;}- return moddifier;+ return modifier;}void GRenderWindow::keyPressEvent(QKeyEvent* event) {if (!event->isAutoRepeat()) {- const auto moddifier = QtModifierToSwitchModdifier(event->nativeModifiers());+ const auto modifier = QtModifierToSwitchModifier(event->nativeModifiers());// Replace event->key() with event->nativeVirtualKey() since the second one provides raw key// buttonsconst auto key = QtKeyToSwitchKey(Qt::Key(event->key()));- input_subsystem->GetKeyboard()->SetKeyboardModifiers(moddifier);+ input_subsystem->GetKeyboard()->SetKeyboardModifiers(modifier);input_subsystem->GetKeyboard()->PressKeyboardKey(key);// This is used for gamepadsinput_subsystem->GetKeyboard()->PressKey(event->key());@@ -671,9 +671,9 @@ void GRenderWindow::keyPressEvent(QKeyEvent* event) {void GRenderWindow::keyReleaseEvent(QKeyEvent* event) {if (!event->isAutoRepeat()) {- const auto moddifier = QtModifierToSwitchModdifier(event->nativeModifiers());+ const auto modifier = QtModifierToSwitchModifier(event->nativeModifiers());const auto key = QtKeyToSwitchKey(Qt::Key(event->key()));- input_subsystem->GetKeyboard()->SetKeyboardModifiers(moddifier);+ input_subsystem->GetKeyboard()->SetKeyboardModifiers(modifier);input_subsystem->GetKeyboard()->ReleaseKeyboardKey(key);// This is used for gamepadsinput_subsystem->GetKeyboard()->ReleaseKey(event->key());@@ -747,8 +747,8 @@ void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) {}void GRenderWindow::wheelEvent(QWheelEvent* event) {- const int x = event->delta();- const int y = 0;+ const int x = event->angleDelta().x();+ const int y = event->angleDelta().y();input_subsystem->GetMouse()->MouseWheelChange(x, y);}diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.hindex d6b2ab5f3f..81e3c4eb02 100644--- a/src/yuzu/bootmanager.h+++ b/src/yuzu/bootmanager.h@@ -162,7 +162,7 @@ public:static int QtKeyToSwitchKey(Qt::Key qt_keys);/// Converts a Qt modifier keys into NativeKeyboard modifier keys- static int QtModifierToSwitchModdifier(quint32 qt_moddifiers);+ static int QtModifierToSwitchModifier(quint32 qt_modifiers);void keyPressEvent(QKeyEvent* event) override;void keyReleaseEvent(QKeyEvent* event) override;