Added support for motion

This commit is contained in:
SSimco
2024-09-02 14:25:04 +03:00
parent d0eac6f470
commit 81c0e4a465
13 changed files with 177 additions and 8 deletions
+6
View File
@@ -967,3 +967,9 @@ void InputManager::update_thread()
std::this_thread::yield();
}
}
MotionSample InputManager::get_device_motion_sample() const
{
std::shared_lock lock(m_device_motion.m_mutex);
return m_device_motion.m_motion_sample;
}
+8
View File
@@ -98,6 +98,14 @@ public:
std::optional<glm::ivec2> get_right_down_mouse_info(bool* is_pad);
std::atomic<float> m_mouse_wheel;
struct DeviceMotion
{
mutable std::shared_mutex m_mutex;
MotionSample m_motion_sample;
bool m_device_motion_enabled;
} m_device_motion{};
MotionSample get_device_motion_sample() const;
private:
void update_thread();
+5 -4
View File
@@ -1,5 +1,6 @@
#include "input/emulated/VPADController.h"
#include "input/api/Controller.h"
#include <mutex>
#if HAS_SDL
#include "input/api/SDL/SDLController.h"
#endif // HAS_SDL
@@ -237,10 +238,11 @@ void VPADController::update_touch(VPADStatus_t& status)
void VPADController::update_motion(VPADStatus_t& status)
{
if (has_motion())
auto& input_manager = InputManager::instance();
bool has_device_motion = input_manager.m_device_motion.m_device_motion_enabled;
if (has_motion() || has_device_motion)
{
auto motionSample = get_motion_data();
MotionSample motionSample = has_device_motion ? input_manager.get_device_motion_sample() : get_motion_data();
glm::vec3 acc;
motionSample.getVPADAccelerometer(&acc[0]);
//const auto& acc = motionSample.getVPADAccelerometer();
@@ -281,7 +283,6 @@ void VPADController::update_motion(VPADStatus_t& status)
}
bool pad_view;
auto& input_manager = InputManager::instance();
if (const auto right_mouse = input_manager.get_right_down_mouse_info(&pad_view))
{
const Vector2<float> mousePos(right_mouse->x, right_mouse->y);