mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-10-01 14:59:13 +00:00
[core/hle/services/am] nuke ButtonPoller and Mouse thread (#4229)
Signed-off-by: lizzie <[email protected]> - [x] I have read and followed the [Contribution Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/CONTRIBUTING.md#code-contributions). - [x] I have read and followed the [AI Policy](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/AI.md) - [x] I have read and followed the [Coding Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/Coding.md) to the best of my ability. ------------------- doesn't even do anything now, please check if controller i/o is affected by this change this should also fix latency issues with the mouse the ButtonPoller thread isn't longer required since we update the state immediately with the .on_change callback registered Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4229 Reviewed-by: CamilleLaVey <[email protected]>
This commit is contained in:
1 parent
e69415c07b
commit
39763e7321
8 files changed
+21
-35
No files matched your search
@@ -41,7 +41,6 @@ ButtonPoller::ButtonPoller(Core::System& system, WindowSystem& window_system) {
|
|||||||
Core::HID::ControllerUpdateCallback engine_callback{
|
Core::HID::ControllerUpdateCallback engine_callback{
|
||||||
.on_change = [this, &window_system](Core::HID::ControllerTriggerType type) {
|
.on_change = [this, &window_system](Core::HID::ControllerTriggerType type) {
|
||||||
if (type == Core::HID::ControllerTriggerType::Button) {
|
if (type == Core::HID::ControllerTriggerType::Button) {
|
||||||
std::unique_lock lk{m_mutex};
|
|
||||||
OnButtonStateChanged(window_system);
|
OnButtonStateChanged(window_system);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -52,29 +51,11 @@ ButtonPoller::ButtonPoller(Core::System& system, WindowSystem& window_system) {
|
|||||||
m_handheld_key = m_handheld->SetCallback(engine_callback);
|
m_handheld_key = m_handheld->SetCallback(engine_callback);
|
||||||
m_player1 = system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Player1);
|
m_player1 = system.HIDCore().GetEmulatedController(Core::HID::NpadIdType::Player1);
|
||||||
m_player1_key = m_player1->SetCallback(engine_callback);
|
m_player1_key = m_player1->SetCallback(engine_callback);
|
||||||
|
|
||||||
m_thread = std::jthread([this, &window_system](std::stop_token stop_token) {
|
|
||||||
Common::SetCurrentThreadName("ButtonPoller");
|
|
||||||
while (!stop_token.stop_requested()) {
|
|
||||||
using namespace std::chrono_literals;
|
|
||||||
std::unique_lock lk{m_mutex};
|
|
||||||
m_cv.wait_for(lk, 50ms);
|
|
||||||
if (stop_token.stop_requested())
|
|
||||||
break;
|
|
||||||
OnButtonStateChanged(window_system);
|
|
||||||
std::this_thread::sleep_for(5ms);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ButtonPoller::~ButtonPoller() {
|
ButtonPoller::~ButtonPoller() {
|
||||||
m_handheld->DeleteCallback(m_handheld_key);
|
m_handheld->DeleteCallback(m_handheld_key);
|
||||||
m_player1->DeleteCallback(m_player1_key);
|
m_player1->DeleteCallback(m_player1_key);
|
||||||
m_cv.notify_all();
|
|
||||||
if (m_thread.joinable()) {
|
|
||||||
m_thread.request_stop();
|
|
||||||
m_thread.join();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ButtonPoller::OnButtonStateChanged(WindowSystem& window_system) {
|
void ButtonPoller::OnButtonStateChanged(WindowSystem& window_system) {
|
||||||
|
|||||||
@@ -33,9 +33,6 @@ public:
|
|||||||
void OnButtonStateChanged(WindowSystem& window_system);
|
void OnButtonStateChanged(WindowSystem& window_system);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::mutex m_mutex;
|
|
||||||
std::condition_variable m_cv;
|
|
||||||
std::jthread m_thread;
|
|
||||||
std::optional<std::chrono::steady_clock::time_point> m_home_button_press_start{};
|
std::optional<std::chrono::steady_clock::time_point> m_home_button_press_start{};
|
||||||
std::optional<std::chrono::steady_clock::time_point> m_capture_button_press_start{};
|
std::optional<std::chrono::steady_clock::time_point> m_capture_button_press_start{};
|
||||||
std::optional<std::chrono::steady_clock::time_point> m_power_button_press_start{};
|
std::optional<std::chrono::steady_clock::time_point> m_power_button_press_start{};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
@@ -72,15 +72,6 @@ Mouse::Mouse(std::string input_engine_) : InputEngine(std::move(input_engine_))
|
|||||||
wheel_position = {};
|
wheel_position = {};
|
||||||
last_mouse_change = {};
|
last_mouse_change = {};
|
||||||
last_motion_change = {};
|
last_motion_change = {};
|
||||||
|
|
||||||
update_thread = std::jthread([this](std::stop_token stop_token) {
|
|
||||||
Common::SetCurrentThreadName("Mouse");
|
|
||||||
while (!stop_token.stop_requested()) {
|
|
||||||
UpdateStickInput();
|
|
||||||
UpdateMotionInput();
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(update_time));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mouse::UpdateStickInput() {
|
void Mouse::UpdateStickInput() {
|
||||||
@@ -185,6 +176,11 @@ void Mouse::Move(int x, int y, int center_x, int center_y) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Mouse::NotifyChanged() {
|
||||||
|
UpdateStickInput();
|
||||||
|
UpdateMotionInput();
|
||||||
|
}
|
||||||
|
|
||||||
void Mouse::MouseMove(f32 touch_x, f32 touch_y) {
|
void Mouse::MouseMove(f32 touch_x, f32 touch_y) {
|
||||||
SetAxis(real_mouse_identifier, mouse_axis_x, touch_x);
|
SetAxis(real_mouse_identifier, mouse_axis_x, touch_x);
|
||||||
SetAxis(real_mouse_identifier, mouse_axis_y, touch_y);
|
SetAxis(real_mouse_identifier, mouse_axis_y, touch_y);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
|
||||||
@@ -93,6 +93,9 @@ public:
|
|||||||
|
|
||||||
void ReleaseAllButtons();
|
void ReleaseAllButtons();
|
||||||
|
|
||||||
|
/// @brief Notifies we changed something about the mouse state and we must update
|
||||||
|
void NotifyChanged();
|
||||||
|
|
||||||
std::vector<Common::ParamPackage> GetInputDevices() const override;
|
std::vector<Common::ParamPackage> GetInputDevices() const override;
|
||||||
AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) override;
|
AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) override;
|
||||||
Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override;
|
Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override;
|
||||||
@@ -110,7 +113,6 @@ private:
|
|||||||
Common::Vec3<float> last_motion_change;
|
Common::Vec3<float> last_motion_change;
|
||||||
Common::Vec2<int> wheel_position;
|
Common::Vec2<int> wheel_position;
|
||||||
bool button_pressed = false;
|
bool button_pressed = false;
|
||||||
std::jthread update_thread;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace InputCommon
|
} // namespace InputCommon
|
||||||
@@ -487,6 +487,7 @@ void GRenderWindow::mousePressEvent(QMouseEvent* event) {
|
|||||||
input_subsystem->GetMouse()->PressMouseButton(button);
|
input_subsystem->GetMouse()->PressMouseButton(button);
|
||||||
input_subsystem->GetMouse()->PressButton(pos.x(), pos.y(), button);
|
input_subsystem->GetMouse()->PressButton(pos.x(), pos.y(), button);
|
||||||
input_subsystem->GetMouse()->PressTouchButton(touch_x, touch_y, button);
|
input_subsystem->GetMouse()->PressTouchButton(touch_x, touch_y, button);
|
||||||
|
input_subsystem->GetMouse()->NotifyChanged();
|
||||||
|
|
||||||
emit MouseActivity();
|
emit MouseActivity();
|
||||||
}
|
}
|
||||||
@@ -507,6 +508,7 @@ void GRenderWindow::mouseMoveEvent(QMouseEvent* event) {
|
|||||||
input_subsystem->GetMouse()->MouseMove(touch_x, touch_y);
|
input_subsystem->GetMouse()->MouseMove(touch_x, touch_y);
|
||||||
input_subsystem->GetMouse()->TouchMove(touch_x, touch_y);
|
input_subsystem->GetMouse()->TouchMove(touch_x, touch_y);
|
||||||
input_subsystem->GetMouse()->Move(pos.x(), pos.y(), center_x, center_y);
|
input_subsystem->GetMouse()->Move(pos.x(), pos.y(), center_x, center_y);
|
||||||
|
input_subsystem->GetMouse()->NotifyChanged();
|
||||||
|
|
||||||
// Center mouse for mouse panning
|
// Center mouse for mouse panning
|
||||||
if (Settings::values.mouse_panning && !Settings::values.mouse_enabled) {
|
if (Settings::values.mouse_panning && !Settings::values.mouse_enabled) {
|
||||||
@@ -532,6 +534,7 @@ void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) {
|
|||||||
|
|
||||||
const auto button = QtButtonToMouseButton(event->button());
|
const auto button = QtButtonToMouseButton(event->button());
|
||||||
input_subsystem->GetMouse()->ReleaseButton(button);
|
input_subsystem->GetMouse()->ReleaseButton(button);
|
||||||
|
input_subsystem->GetMouse()->NotifyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::ConstrainMouse() {
|
void GRenderWindow::ConstrainMouse() {
|
||||||
@@ -564,6 +567,7 @@ void GRenderWindow::wheelEvent(QWheelEvent* event) {
|
|||||||
const int x = event->angleDelta().x();
|
const int x = event->angleDelta().x();
|
||||||
const int y = event->angleDelta().y();
|
const int y = event->angleDelta().y();
|
||||||
input_subsystem->GetMouse()->MouseWheelChange(x, y);
|
input_subsystem->GetMouse()->MouseWheelChange(x, y);
|
||||||
|
input_subsystem->GetMouse()->NotifyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::TouchBeginEvent(const QTouchEvent* event) {
|
void GRenderWindow::TouchBeginEvent(const QTouchEvent* event) {
|
||||||
@@ -710,8 +714,9 @@ bool GRenderWindow::event(QEvent* event) {
|
|||||||
void GRenderWindow::focusOutEvent(QFocusEvent* event) {
|
void GRenderWindow::focusOutEvent(QFocusEvent* event) {
|
||||||
QWidget::focusOutEvent(event);
|
QWidget::focusOutEvent(event);
|
||||||
input_subsystem->GetKeyboard()->ReleaseAllKeys();
|
input_subsystem->GetKeyboard()->ReleaseAllKeys();
|
||||||
input_subsystem->GetMouse()->ReleaseAllButtons();
|
|
||||||
input_subsystem->GetTouchScreen()->ReleaseAllTouch();
|
input_subsystem->GetTouchScreen()->ReleaseAllTouch();
|
||||||
|
input_subsystem->GetMouse()->ReleaseAllButtons();
|
||||||
|
input_subsystem->GetMouse()->NotifyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::resizeEvent(QResizeEvent* event) {
|
void GRenderWindow::resizeEvent(QResizeEvent* event) {
|
||||||
|
|||||||
@@ -1546,12 +1546,14 @@ void ConfigureInputPlayer::mousePressEvent(QMouseEvent* event) {
|
|||||||
|
|
||||||
const auto button = GRenderWindow::QtButtonToMouseButton(event->button());
|
const auto button = GRenderWindow::QtButtonToMouseButton(event->button());
|
||||||
input_subsystem->GetMouse()->PressButton(0, 0, button);
|
input_subsystem->GetMouse()->PressButton(0, 0, button);
|
||||||
|
input_subsystem->GetMouse()->NotifyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureInputPlayer::wheelEvent(QWheelEvent* event) {
|
void ConfigureInputPlayer::wheelEvent(QWheelEvent* event) {
|
||||||
const int x = event->angleDelta().x();
|
const int x = event->angleDelta().x();
|
||||||
const int y = event->angleDelta().y();
|
const int y = event->angleDelta().y();
|
||||||
input_subsystem->GetMouse()->MouseWheelChange(x, y);
|
input_subsystem->GetMouse()->MouseWheelChange(x, y);
|
||||||
|
input_subsystem->GetMouse()->NotifyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureInputPlayer::keyPressEvent(QKeyEvent* event) {
|
void ConfigureInputPlayer::keyPressEvent(QKeyEvent* event) {
|
||||||
|
|||||||
@@ -378,6 +378,7 @@ void ConfigureRingController::mousePressEvent(QMouseEvent* event) {
|
|||||||
|
|
||||||
const auto button = GRenderWindow::QtButtonToMouseButton(event->button());
|
const auto button = GRenderWindow::QtButtonToMouseButton(event->button());
|
||||||
input_subsystem->GetMouse()->PressButton(0, 0, button);
|
input_subsystem->GetMouse()->PressButton(0, 0, button);
|
||||||
|
input_subsystem->GetMouse()->NotifyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureRingController::keyPressEvent(QKeyEvent* event) {
|
void ConfigureRingController::keyPressEvent(QKeyEvent* event) {
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ void EmuWindow_SDL3::OnMouseButton(u32 button, u8 state, s32 x, s32 y) {
|
|||||||
} else {
|
} else {
|
||||||
input_subsystem->GetMouse()->ReleaseButton(mouse_button);
|
input_subsystem->GetMouse()->ReleaseButton(mouse_button);
|
||||||
}
|
}
|
||||||
|
input_subsystem->GetMouse()->NotifyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuWindow_SDL3::OnMouseMotion(s32 x, s32 y) {
|
void EmuWindow_SDL3::OnMouseMotion(s32 x, s32 y) {
|
||||||
@@ -81,6 +82,7 @@ void EmuWindow_SDL3::OnMouseMotion(s32 x, s32 y) {
|
|||||||
input_subsystem->GetMouse()->Move(x, y, 0, 0);
|
input_subsystem->GetMouse()->Move(x, y, 0, 0);
|
||||||
input_subsystem->GetMouse()->MouseMove(touch_x, touch_y);
|
input_subsystem->GetMouse()->MouseMove(touch_x, touch_y);
|
||||||
input_subsystem->GetMouse()->TouchMove(touch_x, touch_y);
|
input_subsystem->GetMouse()->TouchMove(touch_x, touch_y);
|
||||||
|
input_subsystem->GetMouse()->NotifyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuWindow_SDL3::OnFingerDown(float x, float y, std::size_t id) {
|
void EmuWindow_SDL3::OnFingerDown(float x, float y, std::size_t id) {
|
||||||
|
|||||||
Reference in new issue
Block a user