Browse Source
Merge pull request #8510 from german77/vibration
input_common: sdl: lower vibration frequency and use it's own unique thread
pull/15/merge
liamwhite
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
12 additions and
3 deletions
-
src/core/hle/service/hid/controllers/npad.cpp
-
src/input_common/drivers/sdl_driver.cpp
-
src/input_common/drivers/sdl_driver.h
|
|
|
@ -838,11 +838,11 @@ bool Controller_NPad::VibrateControllerAtIndex(Core::HID::NpadIdType npad_id, |
|
|
|
|
|
|
|
const auto now = steady_clock::now(); |
|
|
|
|
|
|
|
// Filter out non-zero vibrations that are within 10ms of each other.
|
|
|
|
// Filter out non-zero vibrations that are within 15ms of each other.
|
|
|
|
if ((vibration_value.low_amplitude != 0.0f || vibration_value.high_amplitude != 0.0f) && |
|
|
|
duration_cast<milliseconds>( |
|
|
|
now - controller.vibration[device_index].last_vibration_timepoint) < |
|
|
|
milliseconds(10)) { |
|
|
|
milliseconds(15)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -438,10 +438,17 @@ SDLDriver::SDLDriver(std::string input_engine_) : InputEngine(std::move(input_en |
|
|
|
using namespace std::chrono_literals; |
|
|
|
while (initialized) { |
|
|
|
SDL_PumpEvents(); |
|
|
|
SendVibrations(); |
|
|
|
std::this_thread::sleep_for(1ms); |
|
|
|
} |
|
|
|
}); |
|
|
|
vibration_thread = std::thread([this] { |
|
|
|
Common::SetCurrentThreadName("yuzu:input:SDL_Vibration"); |
|
|
|
using namespace std::chrono_literals; |
|
|
|
while (initialized) { |
|
|
|
SendVibrations(); |
|
|
|
std::this_thread::sleep_for(10ms); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
// Because the events for joystick connection happens before we have our event watcher added, we
|
|
|
|
// can just open all the joysticks right here
|
|
|
|
@ -457,6 +464,7 @@ SDLDriver::~SDLDriver() { |
|
|
|
initialized = false; |
|
|
|
if (start_thread) { |
|
|
|
poll_thread.join(); |
|
|
|
vibration_thread.join(); |
|
|
|
SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -128,5 +128,6 @@ private: |
|
|
|
std::atomic<bool> initialized = false; |
|
|
|
|
|
|
|
std::thread poll_thread; |
|
|
|
std::thread vibration_thread; |
|
|
|
}; |
|
|
|
} // namespace InputCommon |