diff options
| author | 2016-12-29 21:18:36 +0200 | |
|---|---|---|
| committer | 2016-12-29 21:18:36 +0200 | |
| commit | d7d40b3c56df8e31d018477a5bd2abe3a6e4e550 (patch) | |
| tree | 1a512e19bc5bfb918249218a2396f747896abee9 /src/core/frontend/emu_window.h | |
| 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 'src/core/frontend/emu_window.h')
| -rw-r--r-- | src/core/frontend/emu_window.h | 7 |
1 files changed, 5 insertions, 2 deletions
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 |