summaryrefslogtreecommitdiff
path: root/src/input_common/mouse/mouse_input.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/mouse/mouse_input.cpp')
-rw-r--r--src/input_common/mouse/mouse_input.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/input_common/mouse/mouse_input.cpp b/src/input_common/mouse/mouse_input.cpp
index a335e6da1..3b052ffb2 100644
--- a/src/input_common/mouse/mouse_input.cpp
+++ b/src/input_common/mouse/mouse_input.cpp
@@ -2,25 +2,23 @@
2// Licensed under GPLv2+ 2// Licensed under GPLv2+
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <stop_token>
6#include <thread>
7
5#include "common/settings.h" 8#include "common/settings.h"
6#include "input_common/mouse/mouse_input.h" 9#include "input_common/mouse/mouse_input.h"
7 10
8namespace MouseInput { 11namespace MouseInput {
9 12
10Mouse::Mouse() { 13Mouse::Mouse() {
11 update_thread = std::thread(&Mouse::UpdateThread, this); 14 update_thread = std::jthread([this](std::stop_token stop_token) { UpdateThread(stop_token); });
12} 15}
13 16
14Mouse::~Mouse() { 17Mouse::~Mouse() = default;
15 update_thread_running = false;
16 if (update_thread.joinable()) {
17 update_thread.join();
18 }
19}
20 18
21void Mouse::UpdateThread() { 19void Mouse::UpdateThread(std::stop_token stop_token) {
22 constexpr int update_time = 10; 20 constexpr int update_time = 10;
23 while (update_thread_running) { 21 while (!stop_token.stop_requested()) {
24 for (MouseInfo& info : mouse_info) { 22 for (MouseInfo& info : mouse_info) {
25 const Common::Vec3f angular_direction{ 23 const Common::Vec3f angular_direction{
26 -info.tilt_direction.y, 24 -info.tilt_direction.y,