diff options
Diffstat (limited to 'src/input_common')
-rw-r--r-- | src/input_common/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/input_common/drivers/keyboard.cpp | 35 | ||||
-rw-r--r-- | src/input_common/drivers/keyboard.h (renamed from src/input_common/keyboard.h) | 29 | ||||
-rw-r--r-- | src/input_common/keyboard.cpp | 121 | ||||
-rw-r--r-- | src/input_common/main.cpp | 263 | ||||
-rw-r--r-- | src/input_common/main.h | 89 |
6 files changed, 53 insertions, 488 deletions
diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index 90e7618ce..0fcf7a9d7 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt @@ -1,6 +1,6 @@ add_library(input_common STATIC - keyboard.cpp - keyboard.h + drivers/keyboard.cpp + drivers/keyboard.h helpers/stick_from_buttons.cpp helpers/stick_from_buttons.h helpers/touch_from_buttons.cpp diff --git a/src/input_common/drivers/keyboard.cpp b/src/input_common/drivers/keyboard.cpp new file mode 100644 index 000000000..b00a4b8d9 --- /dev/null +++ b/src/input_common/drivers/keyboard.cpp @@ -0,0 +1,35 @@ +// Copyright 2021 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included + +#include "common/param_package.h" +#include "input_common/drivers/keyboard.h" + +namespace InputCommon { + +Keyboard::Keyboard(const std::string& input_engine_) : InputEngine(input_engine_) { + PreSetController(identifier); +} + +void Keyboard::PressKey(int key_code) { + SetButton(identifier, key_code, true); +} + +void Keyboard::ReleaseKey(int key_code) { + SetButton(identifier, key_code, false); +} + +void Keyboard::ReleaseAllKeys() { + ResetButtonState(); +} + +std::vector<Common::ParamPackage> Keyboard::GetInputDevices() const { + std::vector<Common::ParamPackage> devices; + devices.emplace_back(Common::ParamPackage{ + {"engine", "keyboard"}, + {"display", "Keyboard Only"}, + }); + return devices; +} + +} // namespace InputCommon diff --git a/src/input_common/keyboard.h b/src/input_common/drivers/keyboard.h index 861950472..a3e0d8a61 100644 --- a/src/input_common/keyboard.h +++ b/src/input_common/drivers/keyboard.h @@ -1,30 +1,20 @@ -// Copyright 2017 Citra Emulator Project +// Copyright 2021 yuzu Emulator Project // Licensed under GPLv2 or any later version -// Refer to the license.txt file included. +// Refer to the license.txt file included #pragma once -#include <memory> -#include "core/frontend/input.h" +#include "input_common/input_engine.h" namespace InputCommon { -class KeyButtonList; - /** * A button device factory representing a keyboard. It receives keyboard events and forward them * to all button devices it created. */ -class Keyboard final : public Input::Factory<Input::ButtonDevice> { +class Keyboard final : public InputCommon::InputEngine { public: - Keyboard(); - - /** - * Creates a button device from a keyboard key - * @param params contains parameters for creating the device: - * - "code": the code of the key to bind with the button - */ - std::unique_ptr<Input::ButtonDevice> Create(const Common::ParamPackage& params) override; + explicit Keyboard(const std::string& input_engine_); /** * Sets the status of all buttons bound with the key to pressed @@ -40,8 +30,15 @@ public: void ReleaseAllKeys(); + /// Used for automapping features + std::vector<Common::ParamPackage> GetInputDevices() const override; + private: - std::shared_ptr<KeyButtonList> key_button_list; + const PadIdentifier identifier = { + .guid = Common::UUID{""}, + .port = 0, + .pad = 0, + }; }; } // namespace InputCommon diff --git a/src/input_common/keyboard.cpp b/src/input_common/keyboard.cpp deleted file mode 100644 index 8261e76fd..000000000 --- a/src/input_common/keyboard.cpp +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright 2017 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include <atomic> -#include <list> -#include <mutex> -#include <utility> -#include "input_common/keyboard.h" - -namespace InputCommon { - -class KeyButton final : public Input::ButtonDevice { -public: - explicit KeyButton(std::shared_ptr<KeyButtonList> key_button_list_, bool toggle_) - : key_button_list(std::move(key_button_list_)), toggle(toggle_) {} - - ~KeyButton() override; - - bool GetStatus() const override { - if (toggle) { - return toggled_status.load(std::memory_order_relaxed); - } - return status.load(); - } - - void ToggleButton() { - if (lock) { - return; - } - lock = true; - const bool old_toggle_status = toggled_status.load(); - toggled_status.store(!old_toggle_status); - } - - void UnlockButton() { - lock = false; - } - - friend class KeyButtonList; - -private: - std::shared_ptr<KeyButtonList> key_button_list; - std::atomic<bool> status{false}; - std::atomic<bool> toggled_status{false}; - bool lock{false}; - const bool toggle; -}; - -struct KeyButtonPair { - int key_code; - KeyButton* key_button; -}; - -class KeyButtonList { -public: - void AddKeyButton(int key_code, KeyButton* key_button) { - std::lock_guard guard{mutex}; - list.push_back(KeyButtonPair{key_code, key_button}); - } - - void RemoveKeyButton(const KeyButton* key_button) { - std::lock_guard guard{mutex}; - list.remove_if( - [key_button](const KeyButtonPair& pair) { return pair.key_button == key_button; }); - } - - void ChangeKeyStatus(int key_code, bool pressed) { - std::lock_guard guard{mutex}; - for (const KeyButtonPair& pair : list) { - if (pair.key_code == key_code) { - pair.key_button->status.store(pressed); - if (pressed) { - pair.key_button->ToggleButton(); - } else { - pair.key_button->UnlockButton(); - } - pair.key_button->TriggerOnChange(); - } - } - } - - void ChangeAllKeyStatus(bool pressed) { - std::lock_guard guard{mutex}; - for (const KeyButtonPair& pair : list) { - pair.key_button->status.store(pressed); - } - } - -private: - std::mutex mutex; - std::list<KeyButtonPair> list; -}; - -Keyboard::Keyboard() : key_button_list{std::make_shared<KeyButtonList>()} {} - -KeyButton::~KeyButton() { - key_button_list->RemoveKeyButton(this); -} - -std::unique_ptr<Input::ButtonDevice> Keyboard::Create(const Common::ParamPackage& params) { - const int key_code = params.Get("code", 0); - const bool toggle = params.Get("toggle", false); - std::unique_ptr<KeyButton> button = std::make_unique<KeyButton>(key_button_list, toggle); - key_button_list->AddKeyButton(key_code, button.get()); - return button; -} - -void Keyboard::PressKey(int key_code) { - key_button_list->ChangeKeyStatus(key_code, true); -} - -void Keyboard::ReleaseKey(int key_code) { - key_button_list->ChangeKeyStatus(key_code, false); -} - -void Keyboard::ReleaseAllKeys() { - key_button_list->ChangeAllKeyStatus(false); -} - -} // namespace InputCommon diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 7a5c29b40..da501b6cc 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -6,17 +6,7 @@ #include <thread> #include "common/param_package.h" #include "common/settings.h" -#include "input_common/gcadapter/gc_adapter.h" -#include "input_common/gcadapter/gc_poller.h" -#include "input_common/keyboard.h" #include "input_common/main.h" -#include "input_common/motion_from_button.h" -#include "input_common/mouse/mouse_input.h" -#include "input_common/mouse/mouse_poller.h" -#include "input_common/tas/tas_input.h" -#include "input_common/tas/tas_poller.h" -#include "input_common/udp/client.h" -#include "input_common/udp/udp.h" #ifdef HAVE_SDL2 #include "input_common/sdl/sdl.h" #endif @@ -25,82 +15,9 @@ namespace InputCommon { struct InputSubsystem::Impl { void Initialize() { - gcadapter = std::make_shared<GCAdapter::Adapter>(); - gcbuttons = std::make_shared<GCButtonFactory>(gcadapter); - Input::RegisterFactory<Input::ButtonDevice>("gcpad", gcbuttons); - gcanalog = std::make_shared<GCAnalogFactory>(gcadapter); - Input::RegisterFactory<Input::AnalogDevice>("gcpad", gcanalog); - gcvibration = std::make_shared<GCVibrationFactory>(gcadapter); - Input::RegisterFactory<Input::VibrationDevice>("gcpad", gcvibration); - - keyboard = std::make_shared<Keyboard>(); - Input::RegisterFactory<Input::ButtonDevice>("keyboard", keyboard); - Input::RegisterFactory<Input::MotionDevice>("keyboard", - std::make_shared<MotionFromButton>()); - -#ifdef HAVE_SDL2 - sdl = SDL::Init(); -#endif - - udp = std::make_shared<InputCommon::CemuhookUDP::Client>(); - udpmotion = std::make_shared<UDPMotionFactory>(udp); - Input::RegisterFactory<Input::MotionDevice>("cemuhookudp", udpmotion); - udptouch = std::make_shared<UDPTouchFactory>(udp); - Input::RegisterFactory<Input::TouchDevice>("cemuhookudp", udptouch); - - mouse = std::make_shared<MouseInput::Mouse>(); - mousebuttons = std::make_shared<MouseButtonFactory>(mouse); - Input::RegisterFactory<Input::ButtonDevice>("mouse", mousebuttons); - mouseanalog = std::make_shared<MouseAnalogFactory>(mouse); - Input::RegisterFactory<Input::AnalogDevice>("mouse", mouseanalog); - mousemotion = std::make_shared<MouseMotionFactory>(mouse); - Input::RegisterFactory<Input::MotionDevice>("mouse", mousemotion); - mousetouch = std::make_shared<MouseTouchFactory>(mouse); - Input::RegisterFactory<Input::TouchDevice>("mouse", mousetouch); - - tas = std::make_shared<TasInput::Tas>(); - tasbuttons = std::make_shared<TasButtonFactory>(tas); - Input::RegisterFactory<Input::ButtonDevice>("tas", tasbuttons); - tasanalog = std::make_shared<TasAnalogFactory>(tas); - Input::RegisterFactory<Input::AnalogDevice>("tas", tasanalog); } void Shutdown() { - Input::UnregisterFactory<Input::ButtonDevice>("keyboard"); - Input::UnregisterFactory<Input::MotionDevice>("keyboard"); - keyboard.reset(); -#ifdef HAVE_SDL2 - sdl.reset(); -#endif - Input::UnregisterFactory<Input::ButtonDevice>("gcpad"); - Input::UnregisterFactory<Input::AnalogDevice>("gcpad"); - Input::UnregisterFactory<Input::VibrationDevice>("gcpad"); - - gcbuttons.reset(); - gcanalog.reset(); - gcvibration.reset(); - - Input::UnregisterFactory<Input::MotionDevice>("cemuhookudp"); - Input::UnregisterFactory<Input::TouchDevice>("cemuhookudp"); - - udpmotion.reset(); - udptouch.reset(); - - Input::UnregisterFactory<Input::ButtonDevice>("mouse"); - Input::UnregisterFactory<Input::AnalogDevice>("mouse"); - Input::UnregisterFactory<Input::MotionDevice>("mouse"); - Input::UnregisterFactory<Input::TouchDevice>("mouse"); - - mousebuttons.reset(); - mouseanalog.reset(); - mousemotion.reset(); - mousetouch.reset(); - - Input::UnregisterFactory<Input::ButtonDevice>("tas"); - Input::UnregisterFactory<Input::AnalogDevice>("tas"); - - tasbuttons.reset(); - tasanalog.reset(); } [[nodiscard]] std::vector<Common::ParamPackage> GetInputDevices() const { @@ -108,19 +25,7 @@ struct InputSubsystem::Impl { Common::ParamPackage{{"display", "Any"}, {"class", "any"}}, Common::ParamPackage{{"display", "Keyboard/Mouse"}, {"class", "keyboard"}}, }; - if (Settings::values.tas_enable) { - devices.emplace_back( - Common::ParamPackage{{"display", "TAS Controller"}, {"class", "tas"}}); - } -#ifdef HAVE_SDL2 - auto sdl_devices = sdl->GetInputDevices(); - devices.insert(devices.end(), sdl_devices.begin(), sdl_devices.end()); -#endif - auto udp_devices = udp->GetInputDevices(); - devices.insert(devices.end(), udp_devices.begin(), udp_devices.end()); - auto gcpad_devices = gcadapter->GetInputDevices(); - devices.insert(devices.end(), gcpad_devices.begin(), gcpad_devices.end()); - return devices; + return {}; } [[nodiscard]] AnalogMapping GetAnalogMappingForDevice( @@ -128,17 +33,6 @@ struct InputSubsystem::Impl { if (!params.Has("class") || params.Get("class", "") == "any") { return {}; } - if (params.Get("class", "") == "gcpad") { - return gcadapter->GetAnalogMappingForDevice(params); - } - if (params.Get("class", "") == "tas") { - return tas->GetAnalogMappingForDevice(params); - } -#ifdef HAVE_SDL2 - if (params.Get("class", "") == "sdl") { - return sdl->GetAnalogMappingForDevice(params); - } -#endif return {}; } @@ -147,17 +41,6 @@ struct InputSubsystem::Impl { if (!params.Has("class") || params.Get("class", "") == "any") { return {}; } - if (params.Get("class", "") == "gcpad") { - return gcadapter->GetButtonMappingForDevice(params); - } - if (params.Get("class", "") == "tas") { - return tas->GetButtonMappingForDevice(params); - } -#ifdef HAVE_SDL2 - if (params.Get("class", "") == "sdl") { - return sdl->GetButtonMappingForDevice(params); - } -#endif return {}; } @@ -166,37 +49,9 @@ struct InputSubsystem::Impl { if (!params.Has("class") || params.Get("class", "") == "any") { return {}; } - if (params.Get("class", "") == "cemuhookudp") { - // TODO return the correct motion device - return {}; - } -#ifdef HAVE_SDL2 - if (params.Get("class", "") == "sdl") { - return sdl->GetMotionMappingForDevice(params); - } -#endif return {}; } - std::shared_ptr<Keyboard> keyboard; -#ifdef HAVE_SDL2 - std::unique_ptr<SDL::State> sdl; -#endif - std::shared_ptr<GCButtonFactory> gcbuttons; - std::shared_ptr<GCAnalogFactory> gcanalog; - std::shared_ptr<GCVibrationFactory> gcvibration; - std::shared_ptr<UDPMotionFactory> udpmotion; - std::shared_ptr<UDPTouchFactory> udptouch; - std::shared_ptr<MouseButtonFactory> mousebuttons; - std::shared_ptr<MouseAnalogFactory> mouseanalog; - std::shared_ptr<MouseMotionFactory> mousemotion; - std::shared_ptr<MouseTouchFactory> mousetouch; - std::shared_ptr<TasButtonFactory> tasbuttons; - std::shared_ptr<TasAnalogFactory> tasanalog; - std::shared_ptr<CemuhookUDP::Client> udp; - std::shared_ptr<GCAdapter::Adapter> gcadapter; - std::shared_ptr<MouseInput::Mouse> mouse; - std::shared_ptr<TasInput::Tas> tas; }; InputSubsystem::InputSubsystem() : impl{std::make_unique<Impl>()} {} @@ -211,30 +66,6 @@ void InputSubsystem::Shutdown() { impl->Shutdown(); } -Keyboard* InputSubsystem::GetKeyboard() { - return impl->keyboard.get(); -} - -const Keyboard* InputSubsystem::GetKeyboard() const { - return impl->keyboard.get(); -} - -MouseInput::Mouse* InputSubsystem::GetMouse() { - return impl->mouse.get(); -} - -const MouseInput::Mouse* InputSubsystem::GetMouse() const { - return impl->mouse.get(); -} - -TasInput::Tas* InputSubsystem::GetTas() { - return impl->tas.get(); -} - -const TasInput::Tas* InputSubsystem::GetTas() const { - return impl->tas.get(); -} - std::vector<Common::ParamPackage> InputSubsystem::GetInputDevices() const { return impl->GetInputDevices(); } @@ -251,100 +82,12 @@ MotionMapping InputSubsystem::GetMotionMappingForDevice(const Common::ParamPacka return impl->GetMotionMappingForDevice(device); } -GCAnalogFactory* InputSubsystem::GetGCAnalogs() { - return impl->gcanalog.get(); -} - -const GCAnalogFactory* InputSubsystem::GetGCAnalogs() const { - return impl->gcanalog.get(); -} - -GCButtonFactory* InputSubsystem::GetGCButtons() { - return impl->gcbuttons.get(); -} - -const GCButtonFactory* InputSubsystem::GetGCButtons() const { - return impl->gcbuttons.get(); -} - -UDPMotionFactory* InputSubsystem::GetUDPMotions() { - return impl->udpmotion.get(); -} - -const UDPMotionFactory* InputSubsystem::GetUDPMotions() const { - return impl->udpmotion.get(); -} - -UDPTouchFactory* InputSubsystem::GetUDPTouch() { - return impl->udptouch.get(); -} - -const UDPTouchFactory* InputSubsystem::GetUDPTouch() const { - return impl->udptouch.get(); -} - -MouseButtonFactory* InputSubsystem::GetMouseButtons() { - return impl->mousebuttons.get(); -} - -const MouseButtonFactory* InputSubsystem::GetMouseButtons() const { - return impl->mousebuttons.get(); -} - -MouseAnalogFactory* InputSubsystem::GetMouseAnalogs() { - return impl->mouseanalog.get(); -} - -const MouseAnalogFactory* InputSubsystem::GetMouseAnalogs() const { - return impl->mouseanalog.get(); -} - -MouseMotionFactory* InputSubsystem::GetMouseMotions() { - return impl->mousemotion.get(); -} - -const MouseMotionFactory* InputSubsystem::GetMouseMotions() const { - return impl->mousemotion.get(); -} - -MouseTouchFactory* InputSubsystem::GetMouseTouch() { - return impl->mousetouch.get(); -} - -const MouseTouchFactory* InputSubsystem::GetMouseTouch() const { - return impl->mousetouch.get(); -} - -TasButtonFactory* InputSubsystem::GetTasButtons() { - return impl->tasbuttons.get(); -} - -const TasButtonFactory* InputSubsystem::GetTasButtons() const { - return impl->tasbuttons.get(); -} - -TasAnalogFactory* InputSubsystem::GetTasAnalogs() { - return impl->tasanalog.get(); -} - -const TasAnalogFactory* InputSubsystem::GetTasAnalogs() const { - return impl->tasanalog.get(); -} - void InputSubsystem::ReloadInputDevices() { - if (!impl->udp) { - return; - } - impl->udp->ReloadSockets(); } -std::vector<std::unique_ptr<Polling::DevicePoller>> InputSubsystem::GetPollers( - [[maybe_unused]] Polling::DeviceType type) const { -#ifdef HAVE_SDL2 - return impl->sdl->GetPollers(type); -#else +std::vector<std::unique_ptr<Polling::DevicePoller>> InputSubsystem::GetPollers([ + [maybe_unused]] Polling::DeviceType type) const { return {}; -#endif } std::string GenerateKeyboardParam(int key_code) { diff --git a/src/input_common/main.h b/src/input_common/main.h index eb247e164..b504ebe54 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h @@ -63,18 +63,6 @@ public: }; } // namespace Polling -class GCAnalogFactory; -class GCButtonFactory; -class UDPMotionFactory; -class UDPTouchFactory; -class MouseButtonFactory; -class MouseAnalogFactory; -class MouseMotionFactory; -class MouseTouchFactory; -class TasButtonFactory; -class TasAnalogFactory; -class Keyboard; - /** * Given a ParamPackage for a Device returned from `GetInputDevices`, attempt to get the default * mapping for the device. This is currently only implemented for the SDL backend devices. @@ -100,23 +88,6 @@ public: /// Unregisters all built-in input device factories and shuts them down. void Shutdown(); - /// Retrieves the underlying keyboard device. - [[nodiscard]] Keyboard* GetKeyboard(); - - /// Retrieves the underlying keyboard device. - [[nodiscard]] const Keyboard* GetKeyboard() const; - - /// Retrieves the underlying mouse device. - [[nodiscard]] MouseInput::Mouse* GetMouse(); - - /// Retrieves the underlying mouse device. - [[nodiscard]] const MouseInput::Mouse* GetMouse() const; - - /// Retrieves the underlying tas device. - [[nodiscard]] TasInput::Tas* GetTas(); - - /// Retrieves the underlying tas device. - [[nodiscard]] const TasInput::Tas* GetTas() const; /** * Returns all available input devices that this Factory can create a new device with. * Each returned ParamPackage should have a `display` field used for display, a class field for @@ -134,66 +105,6 @@ public: /// Retrieves the motion mappings for the given device. [[nodiscard]] MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& device) const; - /// Retrieves the underlying GameCube analog handler. - [[nodiscard]] GCAnalogFactory* GetGCAnalogs(); - - /// Retrieves the underlying GameCube analog handler. - [[nodiscard]] const GCAnalogFactory* GetGCAnalogs() const; - - /// Retrieves the underlying GameCube button handler. - [[nodiscard]] GCButtonFactory* GetGCButtons(); - - /// Retrieves the underlying GameCube button handler. - [[nodiscard]] const GCButtonFactory* GetGCButtons() const; - - /// Retrieves the underlying udp motion handler. - [[nodiscard]] UDPMotionFactory* GetUDPMotions(); - - /// Retrieves the underlying udp motion handler. - [[nodiscard]] const UDPMotionFactory* GetUDPMotions() const; - - /// Retrieves the underlying udp touch handler. - [[nodiscard]] UDPTouchFactory* GetUDPTouch(); - - /// Retrieves the underlying udp touch handler. - [[nodiscard]] const UDPTouchFactory* GetUDPTouch() const; - - /// Retrieves the underlying mouse button handler. - [[nodiscard]] MouseButtonFactory* GetMouseButtons(); - - /// Retrieves the underlying mouse button handler. - [[nodiscard]] const MouseButtonFactory* GetMouseButtons() const; - - /// Retrieves the underlying mouse analog handler. - [[nodiscard]] MouseAnalogFactory* GetMouseAnalogs(); - - /// Retrieves the underlying mouse analog handler. - [[nodiscard]] const MouseAnalogFactory* GetMouseAnalogs() const; - - /// Retrieves the underlying mouse motion handler. - [[nodiscard]] MouseMotionFactory* GetMouseMotions(); - - /// Retrieves the underlying mouse motion handler. - [[nodiscard]] const MouseMotionFactory* GetMouseMotions() const; - - /// Retrieves the underlying mouse touch handler. - [[nodiscard]] MouseTouchFactory* GetMouseTouch(); - - /// Retrieves the underlying mouse touch handler. - [[nodiscard]] const MouseTouchFactory* GetMouseTouch() const; - - /// Retrieves the underlying tas button handler. - [[nodiscard]] TasButtonFactory* GetTasButtons(); - - /// Retrieves the underlying tas button handler. - [[nodiscard]] const TasButtonFactory* GetTasButtons() const; - - /// Retrieves the underlying tas analogs handler. - [[nodiscard]] TasAnalogFactory* GetTasAnalogs(); - - /// Retrieves the underlying tas analogs handler. - [[nodiscard]] const TasAnalogFactory* GetTasAnalogs() const; - /// Reloads the input devices void ReloadInputDevices(); |