From 8042ce7e1999e7953db804f852799cb33d08f91c Mon Sep 17 00:00:00 2001 From: Narr the Reg Date: Thu, 5 Jan 2023 19:16:55 -0600 Subject: input_common: Create an update engine --- src/input_common/main.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/input_common/main.cpp') 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 @@ namespace InputCommon { +/// Dummy engine to get periodic updates +class UpdateEngine final : public InputEngine { +public: + explicit UpdateEngine(std::string input_engine_) : InputEngine(std::move(input_engine_)) { + PreSetController(identifier); + } + + void PumpEvents() { + SetButton(identifier, 0, last_state); + last_state = !last_state; + } + +private: + static constexpr PadIdentifier identifier = { + .guid = Common::UUID{}, + .port = 0, + .pad = 0, + }; + + bool last_state{}; +}; + struct InputSubsystem::Impl { template void RegisterEngine(std::string name, std::shared_ptr& engine) { @@ -45,6 +67,7 @@ struct InputSubsystem::Impl { void Initialize() { mapping_factory = std::make_shared(); + RegisterEngine("updater", update_engine); RegisterEngine("keyboard", keyboard); RegisterEngine("mouse", mouse); RegisterEngine("touch", touch_screen); @@ -74,6 +97,7 @@ struct InputSubsystem::Impl { } void Shutdown() { + UnregisterEngine(update_engine); UnregisterEngine(keyboard); UnregisterEngine(mouse); UnregisterEngine(touch_screen); @@ -252,6 +276,7 @@ struct InputSubsystem::Impl { } void PumpEvents() const { + update_engine->PumpEvents(); #ifdef HAVE_SDL2 sdl->PumpEvents(); #endif @@ -263,6 +288,7 @@ struct InputSubsystem::Impl { std::shared_ptr mapping_factory; + std::shared_ptr update_engine; std::shared_ptr keyboard; std::shared_ptr mouse; std::shared_ptr touch_screen; -- cgit v1.2.3