From 93cca23dd6f11c62ddf6976bd5916d1d7244cf8f Mon Sep 17 00:00:00 2001 From: Adityarup Laha <30696515+adityaruplaha@users.noreply.github.com> Date: Thu, 18 Jan 2018 04:00:50 +0530 Subject: [PATCH] Variable tilt clamp (#3366) * Add tilt clamp setting * Updated `clamp` to use variable * Fixed a minor typo * Include possibly necessary header * expose setting in sdl2 * expose setting in qt * incorporate @wwylele 's suggestion in sdl2 * Incorporate @wwylele 's suggestion (?) Please review the code, this is the first time I'm working with `ParamPackage`s so I may just screw up the code. * Forgot to change in qt * Fixed an fatal error * fixed clang format error * remove the old setting * fixed typos cusing errors * removed old setting * Changed init style * Forgot this one * Removed unnecessary header inclusion * Update config.cpp * update qt-config * Update motion_emu.cpp * Update motion_emu.cpp --- src/citra/config.cpp | 5 +++-- src/citra_qt/configuration/config.cpp | 4 +++- src/input_common/motion_emu.cpp | 16 ++++++++++------ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/citra/config.cpp b/src/citra/config.cpp index 45c28ad09..0a84887d9 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp @@ -76,8 +76,9 @@ void Config::ReadValues() { Settings::values.analogs[i] = default_param; } - Settings::values.motion_device = sdl2_config->Get( - "Controls", "motion_device", "engine:motion_emu,update_period:100,sensitivity:0.01"); + Settings::values.motion_device = + sdl2_config->Get("Controls", "motion_device", + "engine:motion_emu,update_period:100,sensitivity:0.01,tilt_clamp:90.0"); Settings::values.touch_device = sdl2_config->Get("Controls", "touch_device", "engine:emu_window"); diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 97993e426..d96405110 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -58,7 +58,9 @@ void Config::ReadValues() { } Settings::values.motion_device = - qt_config->value("motion_device", "engine:motion_emu,update_period:100,sensitivity:0.01") + qt_config + ->value("motion_device", + "engine:motion_emu,update_period:100,sensitivity:0.01,tilt_clamp:90.0") .toString() .toStdString(); Settings::values.touch_device = diff --git a/src/input_common/motion_emu.cpp b/src/input_common/motion_emu.cpp index 59a035e70..27c81e73b 100644 --- a/src/input_common/motion_emu.cpp +++ b/src/input_common/motion_emu.cpp @@ -17,11 +17,12 @@ namespace InputCommon { // Implementation class of the motion emulation device class MotionEmuDevice { public: - MotionEmuDevice(int update_millisecond, float sensitivity) + MotionEmuDevice(int update_millisecond, float sensitivity, float tilt_clamp) : update_millisecond(update_millisecond), update_duration(std::chrono::duration_cast( std::chrono::milliseconds(update_millisecond))), - sensitivity(sensitivity), motion_emu_thread(&MotionEmuDevice::MotionEmuThread, this) {} + sensitivity(sensitivity), tilt_clamp(tilt_clamp), + motion_emu_thread(&MotionEmuDevice::MotionEmuThread, this) {} ~MotionEmuDevice() { if (motion_emu_thread.joinable()) { @@ -44,7 +45,7 @@ public: } else { tilt_direction = mouse_move.Cast(); tilt_angle = MathUtil::Clamp(tilt_direction.Normalize() * sensitivity, 0.0f, - MathUtil::PI * 0.5f); + MathUtil::PI * this->tilt_clamp / 180.0f); } } } @@ -70,6 +71,7 @@ private: std::mutex tilt_mutex; Math::Vec2 tilt_direction; float tilt_angle = 0; + float tilt_clamp = 90; bool is_tilting = false; @@ -126,8 +128,8 @@ private: // can forward all the inputs to the implementation only when it is valid. class MotionEmuDeviceWrapper : public Input::MotionDevice { public: - MotionEmuDeviceWrapper(int update_millisecond, float sensitivity) { - device = std::make_shared(update_millisecond, sensitivity); + MotionEmuDeviceWrapper(int update_millisecond, float sensitivity, float tilt_clamp) { + device = std::make_shared(update_millisecond, sensitivity, tilt_clamp); } std::tuple, Math::Vec3> GetStatus() const { @@ -140,7 +142,9 @@ public: std::unique_ptr MotionEmu::Create(const Common::ParamPackage& params) { int update_period = params.Get("update_period", 100); float sensitivity = params.Get("sensitivity", 0.01f); - auto device_wrapper = std::make_unique(update_period, sensitivity); + float tilt_clamp = params.Get("tilt_clamp", 90.0f); + auto device_wrapper = + std::make_unique(update_period, sensitivity, tilt_clamp); // Previously created device is disconnected here. Having two motion devices for 3DS is not // expected. current_device = device_wrapper->device;