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
This commit is contained in:
Adityarup Laha 2018-01-18 04:00:50 +05:30 committed by bunnei
parent 0c540f7fe1
commit 93cca23dd6
3 changed files with 16 additions and 9 deletions

View file

@ -76,8 +76,9 @@ void Config::ReadValues() {
Settings::values.analogs[i] = default_param; Settings::values.analogs[i] = default_param;
} }
Settings::values.motion_device = sdl2_config->Get( Settings::values.motion_device =
"Controls", "motion_device", "engine:motion_emu,update_period:100,sensitivity:0.01"); sdl2_config->Get("Controls", "motion_device",
"engine:motion_emu,update_period:100,sensitivity:0.01,tilt_clamp:90.0");
Settings::values.touch_device = Settings::values.touch_device =
sdl2_config->Get("Controls", "touch_device", "engine:emu_window"); sdl2_config->Get("Controls", "touch_device", "engine:emu_window");

View file

@ -58,7 +58,9 @@ void Config::ReadValues() {
} }
Settings::values.motion_device = 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() .toString()
.toStdString(); .toStdString();
Settings::values.touch_device = Settings::values.touch_device =

View file

@ -17,11 +17,12 @@ namespace InputCommon {
// Implementation class of the motion emulation device // Implementation class of the motion emulation device
class MotionEmuDevice { class MotionEmuDevice {
public: public:
MotionEmuDevice(int update_millisecond, float sensitivity) MotionEmuDevice(int update_millisecond, float sensitivity, float tilt_clamp)
: update_millisecond(update_millisecond), : update_millisecond(update_millisecond),
update_duration(std::chrono::duration_cast<std::chrono::steady_clock::duration>( update_duration(std::chrono::duration_cast<std::chrono::steady_clock::duration>(
std::chrono::milliseconds(update_millisecond))), 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() { ~MotionEmuDevice() {
if (motion_emu_thread.joinable()) { if (motion_emu_thread.joinable()) {
@ -44,7 +45,7 @@ public:
} else { } else {
tilt_direction = mouse_move.Cast<float>(); tilt_direction = mouse_move.Cast<float>();
tilt_angle = MathUtil::Clamp(tilt_direction.Normalize() * sensitivity, 0.0f, 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; std::mutex tilt_mutex;
Math::Vec2<float> tilt_direction; Math::Vec2<float> tilt_direction;
float tilt_angle = 0; float tilt_angle = 0;
float tilt_clamp = 90;
bool is_tilting = false; bool is_tilting = false;
@ -126,8 +128,8 @@ private:
// can forward all the inputs to the implementation only when it is valid. // can forward all the inputs to the implementation only when it is valid.
class MotionEmuDeviceWrapper : public Input::MotionDevice { class MotionEmuDeviceWrapper : public Input::MotionDevice {
public: public:
MotionEmuDeviceWrapper(int update_millisecond, float sensitivity) { MotionEmuDeviceWrapper(int update_millisecond, float sensitivity, float tilt_clamp) {
device = std::make_shared<MotionEmuDevice>(update_millisecond, sensitivity); device = std::make_shared<MotionEmuDevice>(update_millisecond, sensitivity, tilt_clamp);
} }
std::tuple<Math::Vec3<float>, Math::Vec3<float>> GetStatus() const { std::tuple<Math::Vec3<float>, Math::Vec3<float>> GetStatus() const {
@ -140,7 +142,9 @@ public:
std::unique_ptr<Input::MotionDevice> MotionEmu::Create(const Common::ParamPackage& params) { std::unique_ptr<Input::MotionDevice> MotionEmu::Create(const Common::ParamPackage& params) {
int update_period = params.Get("update_period", 100); int update_period = params.Get("update_period", 100);
float sensitivity = params.Get("sensitivity", 0.01f); float sensitivity = params.Get("sensitivity", 0.01f);
auto device_wrapper = std::make_unique<MotionEmuDeviceWrapper>(update_period, sensitivity); float tilt_clamp = params.Get("tilt_clamp", 90.0f);
auto device_wrapper =
std::make_unique<MotionEmuDeviceWrapper>(update_period, sensitivity, tilt_clamp);
// Previously created device is disconnected here. Having two motion devices for 3DS is not // Previously created device is disconnected here. Having two motion devices for 3DS is not
// expected. // expected.
current_device = device_wrapper->device; current_device = device_wrapper->device;