mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-11-27 03:54:17 +01:00
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:
parent
0c540f7fe1
commit
93cca23dd6
@ -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");
|
||||
|
||||
|
@ -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 =
|
||||
|
@ -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::steady_clock::duration>(
|
||||
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<float>();
|
||||
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<float> 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<MotionEmuDevice>(update_millisecond, sensitivity);
|
||||
MotionEmuDeviceWrapper(int update_millisecond, float sensitivity, float tilt_clamp) {
|
||||
device = std::make_shared<MotionEmuDevice>(update_millisecond, sensitivity, tilt_clamp);
|
||||
}
|
||||
|
||||
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) {
|
||||
int update_period = params.Get("update_period", 100);
|
||||
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
|
||||
// expected.
|
||||
current_device = device_wrapper->device;
|
||||
|
Loading…
Reference in New Issue
Block a user