diff options
| author | 2023-01-05 19:16:55 -0600 | |
|---|---|---|
| committer | 2023-01-05 19:24:29 -0600 | |
| commit | 8042ce7e1999e7953db804f852799cb33d08f91c (patch) | |
| tree | 96ab15b1de43b16cae51d873332c67e301b4afcc /src | |
| parent | Merge pull request #9518 from gidoly/revert-9504-pg2 (diff) | |
| download | yuzu-8042ce7e1999e7953db804f852799cb33d08f91c.tar.gz yuzu-8042ce7e1999e7953db804f852799cb33d08f91c.tar.xz yuzu-8042ce7e1999e7953db804f852799cb33d08f91c.zip | |
input_common: Create an update engine
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/input.h | 3 | ||||
| -rw-r--r-- | src/core/hid/emulated_controller.cpp | 10 | ||||
| -rw-r--r-- | src/input_common/helpers/stick_from_buttons.cpp | 17 | ||||
| -rw-r--r-- | src/input_common/main.cpp | 26 |
4 files changed, 37 insertions, 19 deletions
diff --git a/src/common/input.h b/src/common/input.h index fc14fd7bf..d27b1d772 100644 --- a/src/common/input.h +++ b/src/common/input.h | |||
| @@ -292,9 +292,6 @@ class InputDevice { | |||
| 292 | public: | 292 | public: |
| 293 | virtual ~InputDevice() = default; | 293 | virtual ~InputDevice() = default; |
| 294 | 294 | ||
| 295 | // Request input device to update if necessary | ||
| 296 | virtual void SoftUpdate() {} | ||
| 297 | |||
| 298 | // Force input device to update data regardless of the current state | 295 | // Force input device to update data regardless of the current state |
| 299 | virtual void ForceUpdate() {} | 296 | virtual void ForceUpdate() {} |
| 300 | 297 | ||
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 71364c323..7a01f3f4c 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -1434,16 +1434,6 @@ AnalogSticks EmulatedController::GetSticks() const { | |||
| 1434 | return {}; | 1434 | return {}; |
| 1435 | } | 1435 | } |
| 1436 | 1436 | ||
| 1437 | // Some drivers like stick from buttons need constant refreshing | ||
| 1438 | for (auto& device : stick_devices) { | ||
| 1439 | if (!device) { | ||
| 1440 | continue; | ||
| 1441 | } | ||
| 1442 | lock.unlock(); | ||
| 1443 | device->SoftUpdate(); | ||
| 1444 | lock.lock(); | ||
| 1445 | } | ||
| 1446 | |||
| 1447 | return controller.analog_stick_state; | 1437 | return controller.analog_stick_state; |
| 1448 | } | 1438 | } |
| 1449 | 1439 | ||
diff --git a/src/input_common/helpers/stick_from_buttons.cpp b/src/input_common/helpers/stick_from_buttons.cpp index 82aa6ac2f..f3a0b3419 100644 --- a/src/input_common/helpers/stick_from_buttons.cpp +++ b/src/input_common/helpers/stick_from_buttons.cpp | |||
| @@ -13,11 +13,11 @@ class Stick final : public Common::Input::InputDevice { | |||
| 13 | public: | 13 | public: |
| 14 | using Button = std::unique_ptr<Common::Input::InputDevice>; | 14 | using Button = std::unique_ptr<Common::Input::InputDevice>; |
| 15 | 15 | ||
| 16 | Stick(Button up_, Button down_, Button left_, Button right_, Button modifier_, | 16 | Stick(Button up_, Button down_, Button left_, Button right_, Button modifier_, Button updater_, |
| 17 | float modifier_scale_, float modifier_angle_) | 17 | float modifier_scale_, float modifier_angle_) |
| 18 | : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)), | 18 | : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)), |
| 19 | right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_), | 19 | right(std::move(right_)), modifier(std::move(modifier_)), updater(std::move(updater_)), |
| 20 | modifier_angle(modifier_angle_) { | 20 | modifier_scale(modifier_scale_), modifier_angle(modifier_angle_) { |
| 21 | up->SetCallback({ | 21 | up->SetCallback({ |
| 22 | .on_change = | 22 | .on_change = |
| 23 | [this](const Common::Input::CallbackStatus& callback_) { | 23 | [this](const Common::Input::CallbackStatus& callback_) { |
| @@ -48,6 +48,9 @@ public: | |||
| 48 | UpdateModButtonStatus(callback_); | 48 | UpdateModButtonStatus(callback_); |
| 49 | }, | 49 | }, |
| 50 | }); | 50 | }); |
| 51 | updater->SetCallback({ | ||
| 52 | .on_change = [this](const Common::Input::CallbackStatus& callback_) { SoftUpdate(); }, | ||
| 53 | }); | ||
| 51 | last_x_axis_value = 0.0f; | 54 | last_x_axis_value = 0.0f; |
| 52 | last_y_axis_value = 0.0f; | 55 | last_y_axis_value = 0.0f; |
| 53 | } | 56 | } |
| @@ -248,7 +251,7 @@ public: | |||
| 248 | modifier->ForceUpdate(); | 251 | modifier->ForceUpdate(); |
| 249 | } | 252 | } |
| 250 | 253 | ||
| 251 | void SoftUpdate() override { | 254 | void SoftUpdate() { |
| 252 | Common::Input::CallbackStatus status{ | 255 | Common::Input::CallbackStatus status{ |
| 253 | .type = Common::Input::InputType::Stick, | 256 | .type = Common::Input::InputType::Stick, |
| 254 | .stick_status = GetStatus(), | 257 | .stick_status = GetStatus(), |
| @@ -308,6 +311,7 @@ private: | |||
| 308 | Button left; | 311 | Button left; |
| 309 | Button right; | 312 | Button right; |
| 310 | Button modifier; | 313 | Button modifier; |
| 314 | Button updater; | ||
| 311 | float modifier_scale{}; | 315 | float modifier_scale{}; |
| 312 | float modifier_angle{}; | 316 | float modifier_angle{}; |
| 313 | float angle{}; | 317 | float angle{}; |
| @@ -331,11 +335,12 @@ std::unique_ptr<Common::Input::InputDevice> StickFromButton::Create( | |||
| 331 | auto left = Common::Input::CreateInputDeviceFromString(params.Get("left", null_engine)); | 335 | auto left = Common::Input::CreateInputDeviceFromString(params.Get("left", null_engine)); |
| 332 | auto right = Common::Input::CreateInputDeviceFromString(params.Get("right", null_engine)); | 336 | auto right = Common::Input::CreateInputDeviceFromString(params.Get("right", null_engine)); |
| 333 | auto modifier = Common::Input::CreateInputDeviceFromString(params.Get("modifier", null_engine)); | 337 | auto modifier = Common::Input::CreateInputDeviceFromString(params.Get("modifier", null_engine)); |
| 338 | auto updater = Common::Input::CreateInputDeviceFromString("engine:updater,button:0"); | ||
| 334 | auto modifier_scale = params.Get("modifier_scale", 0.5f); | 339 | auto modifier_scale = params.Get("modifier_scale", 0.5f); |
| 335 | auto modifier_angle = params.Get("modifier_angle", 5.5f); | 340 | auto modifier_angle = params.Get("modifier_angle", 5.5f); |
| 336 | return std::make_unique<Stick>(std::move(up), std::move(down), std::move(left), | 341 | return std::make_unique<Stick>(std::move(up), std::move(down), std::move(left), |
| 337 | std::move(right), std::move(modifier), modifier_scale, | 342 | std::move(right), std::move(modifier), std::move(updater), |
| 338 | modifier_angle); | 343 | modifier_scale, modifier_angle); |
| 339 | } | 344 | } |
| 340 | 345 | ||
| 341 | } // namespace InputCommon | 346 | } // namespace InputCommon |
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 4dc92f482..e0b2131ed 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -28,6 +28,28 @@ | |||
| 28 | 28 | ||
| 29 | namespace InputCommon { | 29 | namespace InputCommon { |
| 30 | 30 | ||
| 31 | /// Dummy engine to get periodic updates | ||
| 32 | class UpdateEngine final : public InputEngine { | ||
| 33 | public: | ||
| 34 | explicit UpdateEngine(std::string input_engine_) : InputEngine(std::move(input_engine_)) { | ||
| 35 | PreSetController(identifier); | ||
| 36 | } | ||
| 37 | |||
| 38 | void PumpEvents() { | ||
| 39 | SetButton(identifier, 0, last_state); | ||
| 40 | last_state = !last_state; | ||
| 41 | } | ||
| 42 | |||
| 43 | private: | ||
| 44 | static constexpr PadIdentifier identifier = { | ||
| 45 | .guid = Common::UUID{}, | ||
| 46 | .port = 0, | ||
| 47 | .pad = 0, | ||
| 48 | }; | ||
| 49 | |||
| 50 | bool last_state{}; | ||
| 51 | }; | ||
| 52 | |||
| 31 | struct InputSubsystem::Impl { | 53 | struct InputSubsystem::Impl { |
| 32 | template <typename Engine> | 54 | template <typename Engine> |
| 33 | void RegisterEngine(std::string name, std::shared_ptr<Engine>& engine) { | 55 | void RegisterEngine(std::string name, std::shared_ptr<Engine>& engine) { |
| @@ -45,6 +67,7 @@ struct InputSubsystem::Impl { | |||
| 45 | void Initialize() { | 67 | void Initialize() { |
| 46 | mapping_factory = std::make_shared<MappingFactory>(); | 68 | mapping_factory = std::make_shared<MappingFactory>(); |
| 47 | 69 | ||
| 70 | RegisterEngine("updater", update_engine); | ||
| 48 | RegisterEngine("keyboard", keyboard); | 71 | RegisterEngine("keyboard", keyboard); |
| 49 | RegisterEngine("mouse", mouse); | 72 | RegisterEngine("mouse", mouse); |
| 50 | RegisterEngine("touch", touch_screen); | 73 | RegisterEngine("touch", touch_screen); |
| @@ -74,6 +97,7 @@ struct InputSubsystem::Impl { | |||
| 74 | } | 97 | } |
| 75 | 98 | ||
| 76 | void Shutdown() { | 99 | void Shutdown() { |
| 100 | UnregisterEngine(update_engine); | ||
| 77 | UnregisterEngine(keyboard); | 101 | UnregisterEngine(keyboard); |
| 78 | UnregisterEngine(mouse); | 102 | UnregisterEngine(mouse); |
| 79 | UnregisterEngine(touch_screen); | 103 | UnregisterEngine(touch_screen); |
| @@ -252,6 +276,7 @@ struct InputSubsystem::Impl { | |||
| 252 | } | 276 | } |
| 253 | 277 | ||
| 254 | void PumpEvents() const { | 278 | void PumpEvents() const { |
| 279 | update_engine->PumpEvents(); | ||
| 255 | #ifdef HAVE_SDL2 | 280 | #ifdef HAVE_SDL2 |
| 256 | sdl->PumpEvents(); | 281 | sdl->PumpEvents(); |
| 257 | #endif | 282 | #endif |
| @@ -263,6 +288,7 @@ struct InputSubsystem::Impl { | |||
| 263 | 288 | ||
| 264 | std::shared_ptr<MappingFactory> mapping_factory; | 289 | std::shared_ptr<MappingFactory> mapping_factory; |
| 265 | 290 | ||
| 291 | std::shared_ptr<UpdateEngine> update_engine; | ||
| 266 | std::shared_ptr<Keyboard> keyboard; | 292 | std::shared_ptr<Keyboard> keyboard; |
| 267 | std::shared_ptr<Mouse> mouse; | 293 | std::shared_ptr<Mouse> mouse; |
| 268 | std::shared_ptr<TouchScreen> touch_screen; | 294 | std::shared_ptr<TouchScreen> touch_screen; |