VERY experimental Nintendo Switch 2 emulator
C++
Always initialize keyboard input
germanb92717bec6a7
diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cppindex af6c1633a8..ee7a58b1c0 100644--- a/src/core/frontend/emu_window.cpp+++ b/src/core/frontend/emu_window.cpp@@ -28,12 +28,11 @@ private:public:explicit Device(std::weak_ptr<TouchState>&& touch_state) : touch_state(touch_state) {}Input::TouchStatus GetStatus() const override {- Input::TouchStatus touch_status{};if (auto state = touch_state.lock()) {std::lock_guard guard{state->mutex};- touch_status = state->status;+ return state->status;}- return touch_status;+ return {};}private:diff --git a/src/core/frontend/emu_window.h b/src/core/frontend/emu_window.hindex f8db42ab4f..2436c65802 100644--- a/src/core/frontend/emu_window.h+++ b/src/core/frontend/emu_window.h@@ -117,12 +117,13 @@ public:* Signal that a touch pressed event has occurred (e.g. mouse click pressed)* @param framebuffer_x Framebuffer x-coordinate that was pressed* @param framebuffer_y Framebuffer y-coordinate that was pressed- * @param id Touch event id+ * @param id Touch event ID*/void TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y, std::size_t id);- /** Signal that a touch released event has occurred (e.g. mouse click released)- *@param id Touch event id+ /**+ * Signal that a touch released event has occurred (e.g. mouse click released)+ * @param id Touch event ID*/void TouchReleased(std::size_t id);@@ -130,7 +131,7 @@ public:* Signal that a touch movement event has occurred (e.g. mouse was moved over the emu window)* @param framebuffer_x Framebuffer x-coordinate* @param framebuffer_y Framebuffer y-coordinate- * @param id Touch event id+ * @param id Touch event ID*/void TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y, std::size_t id);diff --git a/src/core/hle/service/hid/controllers/touchscreen.cpp b/src/core/hle/service/hid/controllers/touchscreen.cppindex cd318f25b8..5219f2dadd 100644--- a/src/core/hle/service/hid/controllers/touchscreen.cpp+++ b/src/core/hle/service/hid/controllers/touchscreen.cpp@@ -100,11 +100,7 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timinvoid Controller_Touchscreen::OnLoadInputDevices() {touch_mouse_device = Input::CreateDevice<Input::TouchDevice>("engine:emu_window");touch_udp_device = Input::CreateDevice<Input::TouchDevice>("engine:cemuhookudp");- if (Settings::values.use_touch_from_button) {- touch_btn_device = Input::CreateDevice<Input::TouchDevice>("engine:touch_from_button");- } else {- touch_btn_device.reset();- }+ touch_btn_device = Input::CreateDevice<Input::TouchDevice>("engine:touch_from_button");}std::optional<std::size_t> Controller_Touchscreen::GetUnusedFingerID() const {diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cppindex 5e39fdce24..e7e50d789b 100644--- a/src/input_common/udp/client.cpp+++ b/src/input_common/udp/client.cpp@@ -136,9 +136,7 @@ static void SocketLoop(Socket* socket) {Client::Client() {LOG_INFO(Input, "Udp Initialization started");- for (std::size_t id = 0; id < MAX_TOUCH_FINGERS; ++id) {- finger_id[id] = MAX_TOUCH_FINGERS;- }+ finger_id.fill(MAX_TOUCH_FINGERS);ReloadSockets();}@@ -347,17 +345,17 @@ void Client::UpdateTouchInput(Response::TouchPad& touch_pad, std::size_t client,const u16 min_y = static_cast<u16>(touch_param.Get("min_y", 50));const u16 max_x = static_cast<u16>(touch_param.Get("max_x", 1800));const u16 max_y = static_cast<u16>(touch_param.Get("max_y", 850));-+ const std::size_t touch_id = client * 2 + id;if (touch_pad.is_active) {- if (finger_id[client * 2 + id] == MAX_TOUCH_FINGERS) {+ if (finger_id[touch_id] == MAX_TOUCH_FINGERS) {const auto first_free_id = GetUnusedFingerID();if (!first_free_id) {// Invalid finger id skip to next inputreturn;}- finger_id[client * 2 + id] = first_free_id.value();+ finger_id[touch_id] = *first_free_id;}- auto& [x, y, pressed] = touch_status[finger_id[client * 2 + id]];+ auto& [x, y, pressed] = touch_status[finger_id[touch_id]];x = static_cast<float>(std::clamp(static_cast<u16>(touch_pad.x), min_x, max_x) - min_x) /static_cast<float>(max_x - min_x);y = static_cast<float>(std::clamp(static_cast<u16>(touch_pad.y), min_y, max_y) - min_y) /@@ -366,9 +364,9 @@ void Client::UpdateTouchInput(Response::TouchPad& touch_pad, std::size_t client,return;}- if (finger_id[client * 2 + id] != MAX_TOUCH_FINGERS) {- touch_status[finger_id[client * 2 + id]] = {};- finger_id[client * 2 + id] = MAX_TOUCH_FINGERS;+ if (finger_id[touch_id] != MAX_TOUCH_FINGERS) {+ touch_status[finger_id[touch_id]] = {};+ finger_id[touch_id] = MAX_TOUCH_FINGERS;}}diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cppindex 1f91514ef4..4528eb1965 100644--- a/src/yuzu/bootmanager.cpp+++ b/src/yuzu/bootmanager.cpp@@ -475,7 +475,7 @@ bool GRenderWindow::TouchStart(const QTouchEvent::TouchPoint& touch_point) {bool GRenderWindow::TouchUpdate(const QTouchEvent::TouchPoint& touch_point) {for (std::size_t id = 0; id < touch_ids.size(); ++id) {- if (touch_ids[id] == touch_point.id() + 1) {+ if (touch_ids[id] == static_cast<std::size_t>(touch_point.id() + 1)) {const auto [x, y] = ScaleTouch(touch_point.pos());this->TouchMoved(x, y, id + 1);return true;@@ -486,8 +486,9 @@ bool GRenderWindow::TouchUpdate(const QTouchEvent::TouchPoint& touch_point) {bool GRenderWindow::TouchExist(std::size_t id,const QList<QTouchEvent::TouchPoint>& touch_points) const {- return std::any_of(touch_points.begin(), touch_points.end(),- [id](const auto& point) { return id == point.id() + 1; });+ return std::any_of(touch_points.begin(), touch_points.end(), [id](const auto& point) {+ return id == static_cast<std::size_t>(point.id() + 1);+ });}bool GRenderWindow::event(QEvent* event) {