summaryrefslogtreecommitdiffstats
path: root/src/input_common
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2022-05-28 09:55:53 +0200
committerGitHub <noreply@github.com>2022-05-28 09:55:53 +0200
commitd879741ec6e6396331965dc2683d3de0d8b3880f (patch)
tree049fb06784cc394ca40e3981d6286b23eb8f386b /src/input_common
parentMerge pull request #8372 from german77/touch (diff)
parentinput_common: Make vibration request async (diff)
downloadyuzu-d879741ec6e6396331965dc2683d3de0d8b3880f.tar
yuzu-d879741ec6e6396331965dc2683d3de0d8b3880f.tar.gz
yuzu-d879741ec6e6396331965dc2683d3de0d8b3880f.tar.bz2
yuzu-d879741ec6e6396331965dc2683d3de0d8b3880f.tar.lz
yuzu-d879741ec6e6396331965dc2683d3de0d8b3880f.tar.xz
yuzu-d879741ec6e6396331965dc2683d3de0d8b3880f.tar.zst
yuzu-d879741ec6e6396331965dc2683d3de0d8b3880f.zip
Diffstat (limited to 'src/input_common')
-rw-r--r--src/input_common/drivers/sdl_driver.cpp23
-rw-r--r--src/input_common/drivers/sdl_driver.h12
2 files changed, 33 insertions, 2 deletions
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp
index a5c63e74a..1a14ef10b 100644
--- a/src/input_common/drivers/sdl_driver.cpp
+++ b/src/input_common/drivers/sdl_driver.cpp
@@ -434,6 +434,7 @@ 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);
}
});
@@ -531,13 +532,31 @@ Common::Input::VibrationError SDLDriver::SetRumble(
.type = Common::Input::VibrationAmplificationType::Exponential,
};
- if (!joystick->RumblePlay(new_vibration)) {
- return Common::Input::VibrationError::Unknown;
+ if (vibration.type == Common::Input::VibrationAmplificationType::Test) {
+ if (!joystick->RumblePlay(new_vibration)) {
+ return Common::Input::VibrationError::Unknown;
+ }
+ return Common::Input::VibrationError::None;
}
+ vibration_queue.Push(VibrationRequest{
+ .identifier = identifier,
+ .vibration = new_vibration,
+ });
+
return Common::Input::VibrationError::None;
}
+void SDLDriver::SendVibrations() {
+ while (!vibration_queue.Empty()) {
+ VibrationRequest request;
+ vibration_queue.Pop(request);
+ const auto joystick = GetSDLJoystickByGUID(request.identifier.guid.RawString(),
+ static_cast<int>(request.identifier.port));
+ joystick->RumblePlay(request.vibration);
+ }
+}
+
Common::ParamPackage SDLDriver::BuildAnalogParamPackageForButton(int port, std::string guid,
s32 axis, float value) const {
Common::ParamPackage params{};
diff --git a/src/input_common/drivers/sdl_driver.h b/src/input_common/drivers/sdl_driver.h
index dcd0d1e64..c82632506 100644
--- a/src/input_common/drivers/sdl_driver.h
+++ b/src/input_common/drivers/sdl_driver.h
@@ -12,6 +12,7 @@
#include <SDL.h>
#include "common/common_types.h"
+#include "common/threadsafe_queue.h"
#include "input_common/input_engine.h"
union SDL_Event;
@@ -64,12 +65,20 @@ public:
const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) override;
private:
+ struct VibrationRequest {
+ PadIdentifier identifier;
+ Common::Input::VibrationStatus vibration;
+ };
+
void InitJoystick(int joystick_index);
void CloseJoystick(SDL_Joystick* sdl_joystick);
/// Needs to be called before SDL_QuitSubSystem.
void CloseJoysticks();
+ /// Takes all vibrations from the queue and sends the command to the controller
+ void SendVibrations();
+
Common::ParamPackage BuildAnalogParamPackageForButton(int port, std::string guid, s32 axis,
float value = 0.1f) const;
Common::ParamPackage BuildButtonParamPackageForButton(int port, std::string guid,
@@ -107,6 +116,9 @@ private:
/// Returns true if the button is on the left joycon
bool IsButtonOnLeftSide(Settings::NativeButton::Values button) const;
+ /// Queue of vibration request to controllers
+ Common::SPSCQueue<VibrationRequest> vibration_queue;
+
/// Map of GUID of a list of corresponding virtual Joysticks
std::unordered_map<std::string, std::vector<std::shared_ptr<SDLJoystick>>> joystick_map;
std::mutex joystick_map_mutex;