diff options
| author | 2016-12-29 21:18:36 +0200 | |
|---|---|---|
| committer | 2016-12-29 21:18:36 +0200 | |
| commit | d7d40b3c56df8e31d018477a5bd2abe3a6e4e550 (patch) | |
| tree | 1a512e19bc5bfb918249218a2396f747896abee9 | |
| parent | Frontend: emulate motion sensor (diff) | |
| download | yuzu-d7d40b3c56df8e31d018477a5bd2abe3a6e4e550.tar.gz yuzu-d7d40b3c56df8e31d018477a5bd2abe3a6e4e550.tar.xz yuzu-d7d40b3c56df8e31d018477a5bd2abe3a6e4e550.zip | |
Frontend: make motion sensor interfaced thread-safe
Diffstat (limited to '')
| -rw-r--r-- | src/core/frontend/emu_window.cpp | 3 | ||||
| -rw-r--r-- | src/core/frontend/emu_window.h | 7 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp index 13c7f3de2..1541cc39d 100644 --- a/src/core/frontend/emu_window.cpp +++ b/src/core/frontend/emu_window.cpp | |||
| @@ -93,6 +93,8 @@ void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) { | |||
| 93 | void EmuWindow::AccelerometerChanged(float x, float y, float z) { | 93 | void EmuWindow::AccelerometerChanged(float x, float y, float z) { |
| 94 | constexpr float coef = 512; | 94 | constexpr float coef = 512; |
| 95 | 95 | ||
| 96 | std::lock_guard<std::mutex> lock(accel_mutex); | ||
| 97 | |||
| 96 | // TODO(wwylele): do a time stretch as it in GyroscopeChanged | 98 | // TODO(wwylele): do a time stretch as it in GyroscopeChanged |
| 97 | // The time stretch formula should be like | 99 | // The time stretch formula should be like |
| 98 | // stretched_vector = (raw_vector - gravity) * stretch_ratio + gravity | 100 | // stretched_vector = (raw_vector - gravity) * stretch_ratio + gravity |
| @@ -106,6 +108,7 @@ void EmuWindow::GyroscopeChanged(float x, float y, float z) { | |||
| 106 | float coef = GetGyroscopeRawToDpsCoefficient(); | 108 | float coef = GetGyroscopeRawToDpsCoefficient(); |
| 107 | float stretch = | 109 | float stretch = |
| 108 | FULL_FPS / Common::Profiling::GetTimingResultsAggregator()->GetAggregatedResults().fps; | 110 | FULL_FPS / Common::Profiling::GetTimingResultsAggregator()->GetAggregatedResults().fps; |
| 111 | std::lock_guard<std::mutex> lock(gyro_mutex); | ||
| 109 | gyro_x = x * coef * stretch; | 112 | gyro_x = x * coef * stretch; |
| 110 | gyro_y = y * coef * stretch; | 113 | gyro_y = y * coef * stretch; |
| 111 | gyro_z = z * coef * stretch; | 114 | gyro_z = z * coef * stretch; |
diff --git a/src/core/frontend/emu_window.h b/src/core/frontend/emu_window.h index 2cdbf1742..1ba64c92b 100644 --- a/src/core/frontend/emu_window.h +++ b/src/core/frontend/emu_window.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <mutex> | ||
| 7 | #include <tuple> | 8 | #include <tuple> |
| 8 | #include <utility> | 9 | #include <utility> |
| 9 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| @@ -155,10 +156,10 @@ public: | |||
| 155 | * 1 unit of return value = 1/512 g (measured by hw test), | 156 | * 1 unit of return value = 1/512 g (measured by hw test), |
| 156 | * where g is the gravitational acceleration (9.8 m/sec2). | 157 | * where g is the gravitational acceleration (9.8 m/sec2). |
| 157 | * @note This should be called by the core emu thread to get a state set by the window thread. | 158 | * @note This should be called by the core emu thread to get a state set by the window thread. |
| 158 | * @todo Fix this function to be thread-safe. | ||
| 159 | * @return std::tuple of (x, y, z) | 159 | * @return std::tuple of (x, y, z) |
| 160 | */ | 160 | */ |
| 161 | std::tuple<s16, s16, s16> GetAccelerometerState() { | 161 | std::tuple<s16, s16, s16> GetAccelerometerState() { |
| 162 | std::lock_guard<std::mutex> lock(accel_mutex); | ||
| 162 | return std::make_tuple(accel_x, accel_y, accel_z); | 163 | return std::make_tuple(accel_x, accel_y, accel_z); |
| 163 | } | 164 | } |
| 164 | 165 | ||
| @@ -173,10 +174,10 @@ public: | |||
| 173 | * 1 unit of return value = (1/coef) deg/sec, | 174 | * 1 unit of return value = (1/coef) deg/sec, |
| 174 | * where coef is the return value of GetGyroscopeRawToDpsCoefficient(). | 175 | * where coef is the return value of GetGyroscopeRawToDpsCoefficient(). |
| 175 | * @note This should be called by the core emu thread to get a state set by the window thread. | 176 | * @note This should be called by the core emu thread to get a state set by the window thread. |
| 176 | * @todo Fix this function to be thread-safe. | ||
| 177 | * @return std::tuple of (x, y, z) | 177 | * @return std::tuple of (x, y, z) |
| 178 | */ | 178 | */ |
| 179 | std::tuple<s16, s16, s16> GetGyroscopeState() { | 179 | std::tuple<s16, s16, s16> GetGyroscopeState() { |
| 180 | std::lock_guard<std::mutex> lock(gyro_mutex); | ||
| 180 | return std::make_tuple(gyro_x, gyro_y, gyro_z); | 181 | return std::make_tuple(gyro_x, gyro_y, gyro_z); |
| 181 | } | 182 | } |
| 182 | 183 | ||
| @@ -306,10 +307,12 @@ private: | |||
| 306 | s16 circle_pad_x; ///< Circle pad X-position in native 3DS pixel coordinates (-156 - 156) | 307 | s16 circle_pad_x; ///< Circle pad X-position in native 3DS pixel coordinates (-156 - 156) |
| 307 | s16 circle_pad_y; ///< Circle pad Y-position in native 3DS pixel coordinates (-156 - 156) | 308 | s16 circle_pad_y; ///< Circle pad Y-position in native 3DS pixel coordinates (-156 - 156) |
| 308 | 309 | ||
| 310 | std::mutex accel_mutex; | ||
| 309 | s16 accel_x; ///< Accelerometer X-axis value in native 3DS units | 311 | s16 accel_x; ///< Accelerometer X-axis value in native 3DS units |
| 310 | s16 accel_y; ///< Accelerometer Y-axis value in native 3DS units | 312 | s16 accel_y; ///< Accelerometer Y-axis value in native 3DS units |
| 311 | s16 accel_z; ///< Accelerometer Z-axis value in native 3DS units | 313 | s16 accel_z; ///< Accelerometer Z-axis value in native 3DS units |
| 312 | 314 | ||
| 315 | std::mutex gyro_mutex; | ||
| 313 | s16 gyro_x; ///< Gyroscope X-axis value in native 3DS units | 316 | s16 gyro_x; ///< Gyroscope X-axis value in native 3DS units |
| 314 | s16 gyro_y; ///< Gyroscope Y-axis value in native 3DS units | 317 | s16 gyro_y; ///< Gyroscope Y-axis value in native 3DS units |
| 315 | s16 gyro_z; ///< Gyroscope Z-axis value in native 3DS units | 318 | s16 gyro_z; ///< Gyroscope Z-axis value in native 3DS units |