From ef90aeeefc38003a37b2616ef23e20024b1fe526 Mon Sep 17 00:00:00 2001 From: Garrett Brown Date: Fri, 22 Oct 2021 22:42:00 -0700 Subject: Controllers: Refactor input code into new subdir --- cmake/treedata/common/games.txt | 2 +- xbmc/games/addons/input/GameClientController.cpp | 6 +- xbmc/games/addons/input/GameClientController.h | 1 + xbmc/games/addons/input/GameClientDevice.cpp | 4 +- xbmc/games/addons/input/GameClientDevice.h | 4 +- xbmc/games/addons/input/GameClientInput.cpp | 2 +- xbmc/games/addons/input/GameClientJoystick.cpp | 8 +- xbmc/games/addons/input/GameClientJoystick.h | 4 +- xbmc/games/addons/input/GameClientPort.cpp | 4 +- xbmc/games/addons/input/GameClientPort.h | 4 +- xbmc/games/controllers/CMakeLists.txt | 6 - xbmc/games/controllers/Controller.cpp | 14 +- xbmc/games/controllers/Controller.h | 12 +- xbmc/games/controllers/ControllerFeature.cpp | 162 --------------------- xbmc/games/controllers/ControllerFeature.h | 65 --------- xbmc/games/controllers/ControllerLayout.cpp | 12 +- xbmc/games/controllers/ControllerLayout.h | 10 +- xbmc/games/controllers/ControllerPort.cpp | 66 --------- xbmc/games/controllers/ControllerPort.h | 64 -------- xbmc/games/controllers/ControllerTopology.cpp | 56 ------- xbmc/games/controllers/ControllerTopology.h | 61 -------- .../guicontrols/GUICardinalFeatureButton.cpp | 2 +- .../guicontrols/GUICardinalFeatureButton.h | 2 +- .../controllers/guicontrols/GUIFeatureButton.cpp | 2 +- .../controllers/guicontrols/GUIFeatureButton.h | 8 +- .../controllers/guicontrols/GUIFeatureFactory.cpp | 2 +- .../controllers/guicontrols/GUIFeatureFactory.h | 4 +- .../guicontrols/GUIScalarFeatureButton.cpp | 2 +- .../guicontrols/GUIScalarFeatureButton.h | 2 +- .../controllers/guicontrols/GUISelectKeyButton.cpp | 8 +- .../controllers/guicontrols/GUISelectKeyButton.h | 10 +- .../controllers/guicontrols/GUIThrottleButton.cpp | 2 +- .../controllers/guicontrols/GUIThrottleButton.h | 2 +- .../controllers/guicontrols/GUIWheelButton.cpp | 2 +- .../games/controllers/guicontrols/GUIWheelButton.h | 2 +- xbmc/games/controllers/input/CMakeLists.txt | 15 ++ xbmc/games/controllers/input/InputSink.cpp | 67 +++++++++ xbmc/games/controllers/input/InputSink.h | 52 +++++++ xbmc/games/controllers/input/PhysicalFeature.cpp | 162 +++++++++++++++++++++ xbmc/games/controllers/input/PhysicalFeature.h | 65 +++++++++ xbmc/games/controllers/input/PhysicalPort.cpp | 66 +++++++++ xbmc/games/controllers/input/PhysicalPort.h | 64 ++++++++ xbmc/games/controllers/input/PhysicalTopology.cpp | 56 +++++++ xbmc/games/controllers/input/PhysicalTopology.h | 61 ++++++++ xbmc/games/controllers/input/PortInput.cpp | 129 ++++++++++++++++ xbmc/games/controllers/input/PortInput.h | 76 ++++++++++ xbmc/games/controllers/types/ControllerNode.cpp | 2 +- xbmc/games/controllers/types/PortNode.cpp | 10 +- xbmc/games/controllers/types/PortNode.h | 4 +- .../controllers/windows/GUIConfigurationWizard.cpp | 8 +- .../controllers/windows/GUIConfigurationWizard.h | 6 +- xbmc/games/controllers/windows/GUIFeatureList.cpp | 18 +-- xbmc/games/controllers/windows/GUIFeatureList.h | 10 +- .../controllers/windows/IConfigurationWindow.h | 8 +- xbmc/games/ports/CMakeLists.txt | 7 - xbmc/games/ports/InputSink.cpp | 67 --------- xbmc/games/ports/InputSink.h | 52 ------- xbmc/games/ports/Port.cpp | 123 ---------------- xbmc/games/ports/Port.h | 76 ---------- xbmc/input/joysticks/generic/ButtonMapping.cpp | 2 +- 60 files changed, 916 insertions(+), 907 deletions(-) delete mode 100644 xbmc/games/controllers/ControllerFeature.cpp delete mode 100644 xbmc/games/controllers/ControllerFeature.h delete mode 100644 xbmc/games/controllers/ControllerPort.cpp delete mode 100644 xbmc/games/controllers/ControllerPort.h delete mode 100644 xbmc/games/controllers/ControllerTopology.cpp delete mode 100644 xbmc/games/controllers/ControllerTopology.h create mode 100644 xbmc/games/controllers/input/CMakeLists.txt create mode 100644 xbmc/games/controllers/input/InputSink.cpp create mode 100644 xbmc/games/controllers/input/InputSink.h create mode 100644 xbmc/games/controllers/input/PhysicalFeature.cpp create mode 100644 xbmc/games/controllers/input/PhysicalFeature.h create mode 100644 xbmc/games/controllers/input/PhysicalPort.cpp create mode 100644 xbmc/games/controllers/input/PhysicalPort.h create mode 100644 xbmc/games/controllers/input/PhysicalTopology.cpp create mode 100644 xbmc/games/controllers/input/PhysicalTopology.h create mode 100644 xbmc/games/controllers/input/PortInput.cpp create mode 100644 xbmc/games/controllers/input/PortInput.h delete mode 100644 xbmc/games/ports/CMakeLists.txt delete mode 100644 xbmc/games/ports/InputSink.cpp delete mode 100644 xbmc/games/ports/InputSink.h delete mode 100644 xbmc/games/ports/Port.cpp delete mode 100644 xbmc/games/ports/Port.h diff --git a/cmake/treedata/common/games.txt b/cmake/treedata/common/games.txt index 7ae2d35ae5..e72c9de9f9 100644 --- a/cmake/treedata/common/games.txt +++ b/cmake/treedata/common/games.txt @@ -5,10 +5,10 @@ xbmc/games/addons/streams games/addons/streams xbmc/games/controllers games/controllers xbmc/games/controllers/dialogs games/controllers/dialogs xbmc/games/controllers/guicontrols games/controllers/guicontrols +xbmc/games/controllers/input games/controllers/input xbmc/games/controllers/types games/controllers/types xbmc/games/controllers/windows games/controllers/windows xbmc/games/dialogs games/dialogs xbmc/games/dialogs/osd games/dialogs/osd -xbmc/games/ports games/ports xbmc/games/tags games/tags xbmc/games/windows games/windows diff --git a/xbmc/games/addons/input/GameClientController.cpp b/xbmc/games/addons/input/GameClientController.cpp index 24a09862f3..435e277e2a 100644 --- a/xbmc/games/addons/input/GameClientController.cpp +++ b/xbmc/games/addons/input/GameClientController.cpp @@ -22,9 +22,9 @@ #include "GameClientInput.h" #include "games/controllers/Controller.h" -#include "games/controllers/ControllerFeature.h" #include "games/controllers/ControllerLayout.h" -#include "games/controllers/ControllerTopology.h" +#include "games/controllers/input/PhysicalFeature.h" +#include "games/controllers/input/PhysicalTopology.h" #include #include @@ -36,7 +36,7 @@ CGameClientController::CGameClientController(CGameClientInput& input, Controller : m_input(input), m_controller(std::move(controller)), m_controllerId(m_controller->ID()) { // Generate arrays of features - for (const CControllerFeature& feature : m_controller->Features()) + for (const CPhysicalFeature& feature : m_controller->Features()) { // Skip feature if not supported by the game client if (!m_input.HasFeature(m_controller->ID(), feature.Name())) diff --git a/xbmc/games/addons/input/GameClientController.h b/xbmc/games/addons/input/GameClientController.h index ef39e20031..5445868ef7 100644 --- a/xbmc/games/addons/input/GameClientController.h +++ b/xbmc/games/addons/input/GameClientController.h @@ -23,6 +23,7 @@ #include "addons/kodi-dev-kit/include/kodi/addon-instance/Game.h" #include "games/controllers/ControllerTypes.h" +#include #include namespace KODI diff --git a/xbmc/games/addons/input/GameClientDevice.cpp b/xbmc/games/addons/input/GameClientDevice.cpp index 317447da50..9918f7b2ca 100644 --- a/xbmc/games/addons/input/GameClientDevice.cpp +++ b/xbmc/games/addons/input/GameClientDevice.cpp @@ -13,7 +13,7 @@ #include "addons/kodi-dev-kit/include/kodi/addon-instance/Game.h" #include "games/GameServices.h" #include "games/controllers/Controller.h" -#include "games/controllers/ControllerTopology.h" +#include "games/controllers/input/PhysicalTopology.h" #include "utils/StringUtils.h" #include @@ -51,7 +51,7 @@ CGameClientDevice::CGameClientDevice(const ControllerPtr& controller) : m_contro CGameClientDevice::~CGameClientDevice() = default; void CGameClientDevice::AddPort(const game_input_port& logicalPort, - const CControllerPort& physicalPort) + const CPhysicalPort& physicalPort) { std::unique_ptr port(new CGameClientPort(logicalPort, physicalPort)); m_ports.emplace_back(std::move(port)); diff --git a/xbmc/games/addons/input/GameClientDevice.h b/xbmc/games/addons/input/GameClientDevice.h index 778f595d68..403d76c853 100644 --- a/xbmc/games/addons/input/GameClientDevice.h +++ b/xbmc/games/addons/input/GameClientDevice.h @@ -20,7 +20,7 @@ namespace KODI { namespace GAME { -class CControllerPort; +class CPhysicalPort; /*! * \ingroup games @@ -65,7 +65,7 @@ private: * \param logicalPort The logical port Game API struct * \param physicalPort The physical port definition */ - void AddPort(const game_input_port& logicalPort, const CControllerPort& physicalPort); + void AddPort(const game_input_port& logicalPort, const CPhysicalPort& physicalPort); // Helper function static ControllerPtr GetController(const char* controllerId); diff --git a/xbmc/games/addons/input/GameClientInput.cpp b/xbmc/games/addons/input/GameClientInput.cpp index c399bd6a00..56b71ca318 100644 --- a/xbmc/games/addons/input/GameClientInput.cpp +++ b/xbmc/games/addons/input/GameClientInput.cpp @@ -21,7 +21,7 @@ #include "games/addons/GameClient.h" #include "games/addons/GameClientCallbacks.h" #include "games/controllers/Controller.h" -#include "games/controllers/ControllerTopology.h" +#include "games/controllers/input/PhysicalTopology.h" #include "input/joysticks/JoystickTypes.h" #include "peripherals/EventLockHandle.h" #include "peripherals/Peripherals.h" diff --git a/xbmc/games/addons/input/GameClientJoystick.cpp b/xbmc/games/addons/input/GameClientJoystick.cpp index 6c1a77fc74..291dc6755b 100644 --- a/xbmc/games/addons/input/GameClientJoystick.cpp +++ b/xbmc/games/addons/input/GameClientJoystick.cpp @@ -11,7 +11,7 @@ #include "GameClientInput.h" #include "games/addons/GameClient.h" #include "games/controllers/Controller.h" -#include "games/ports/Port.h" +#include "games/controllers/input/PortInput.h" #include "input/joysticks/interfaces/IInputReceiver.h" #include "utils/log.h" @@ -26,7 +26,7 @@ CGameClientJoystick::CGameClientJoystick(CGameClient& gameClient, : m_gameClient(gameClient), m_portAddress(portAddress), m_controller(controller), - m_port(new CPort(this)) + m_portInput(new CPortInput(this)) { assert(m_controller.get() != NULL); } @@ -35,12 +35,12 @@ CGameClientJoystick::~CGameClientJoystick() = default; void CGameClientJoystick::RegisterInput(JOYSTICK::IInputProvider* inputProvider) { - m_port->RegisterInput(inputProvider); + m_portInput->RegisterInput(inputProvider); } void CGameClientJoystick::UnregisterInput(JOYSTICK::IInputProvider* inputProvider) { - m_port->UnregisterInput(inputProvider); + m_portInput->UnregisterInput(inputProvider); } std::string CGameClientJoystick::ControllerID(void) const diff --git a/xbmc/games/addons/input/GameClientJoystick.h b/xbmc/games/addons/input/GameClientJoystick.h index a43746ba72..fc1a1c4edd 100644 --- a/xbmc/games/addons/input/GameClientJoystick.h +++ b/xbmc/games/addons/input/GameClientJoystick.h @@ -23,7 +23,7 @@ class IInputProvider; namespace GAME { class CGameClient; -class CPort; +class CPortInput; /*! * \ingroup games @@ -80,7 +80,7 @@ private: const ControllerPtr m_controller; // Input parameters - std::unique_ptr m_port; + std::unique_ptr m_portInput; }; } // namespace GAME } // namespace KODI diff --git a/xbmc/games/addons/input/GameClientPort.cpp b/xbmc/games/addons/input/GameClientPort.cpp index edce03a16a..df78efce92 100644 --- a/xbmc/games/addons/input/GameClientPort.cpp +++ b/xbmc/games/addons/input/GameClientPort.cpp @@ -12,7 +12,7 @@ #include "addons/kodi-dev-kit/include/kodi/addon-instance/Game.h" #include "games/addons/GameClientTranslator.h" #include "games/controllers/Controller.h" -#include "games/controllers/ControllerTopology.h" +#include "games/controllers/input/PhysicalTopology.h" #include "utils/StringUtils.h" #include @@ -44,7 +44,7 @@ CGameClientPort::CGameClientPort(const ControllerVector& controllers) } CGameClientPort::CGameClientPort(const game_input_port& logicalPort, - const CControllerPort& physicalPort) + const CPhysicalPort& physicalPort) : m_type(PORT_TYPE::CONTROLLER), m_portId(physicalPort.ID()) { if (logicalPort.accepted_devices != nullptr) diff --git a/xbmc/games/addons/input/GameClientPort.h b/xbmc/games/addons/input/GameClientPort.h index 728236b0d9..435565e876 100644 --- a/xbmc/games/addons/input/GameClientPort.h +++ b/xbmc/games/addons/input/GameClientPort.h @@ -20,7 +20,7 @@ namespace KODI { namespace GAME { -class CControllerPort; +class CPhysicalPort; /*! * \ingroup games @@ -60,7 +60,7 @@ public: * Obviously, the controllers specified by the logical port must be a subset * of the controllers supported by the physical port. */ - CGameClientPort(const game_input_port& logicalPort, const CControllerPort& physicalPort); + CGameClientPort(const game_input_port& logicalPort, const CPhysicalPort& physicalPort); /*! * \brief Destructor diff --git a/xbmc/games/controllers/CMakeLists.txt b/xbmc/games/controllers/CMakeLists.txt index 400b25b9f8..b00e1caa4a 100644 --- a/xbmc/games/controllers/CMakeLists.txt +++ b/xbmc/games/controllers/CMakeLists.txt @@ -1,19 +1,13 @@ set(SOURCES Controller.cpp - ControllerFeature.cpp ControllerLayout.cpp ControllerManager.cpp - ControllerPort.cpp - ControllerTopology.cpp ControllerTranslator.cpp) set(HEADERS Controller.h ControllerDefinitions.h - ControllerFeature.h ControllerIDs.h ControllerLayout.h ControllerManager.h - ControllerPort.h - ControllerTopology.h ControllerTranslator.h ControllerTypes.h) diff --git a/xbmc/games/controllers/Controller.cpp b/xbmc/games/controllers/Controller.cpp index 6d1ff9333c..178a131f66 100644 --- a/xbmc/games/controllers/Controller.cpp +++ b/xbmc/games/controllers/Controller.cpp @@ -10,8 +10,8 @@ #include "ControllerDefinitions.h" #include "ControllerLayout.h" -#include "ControllerTopology.h" #include "URL.h" +#include "games/controllers/input/PhysicalTopology.h" #include "utils/XBMCTinyXML.h" #include "utils/XMLUtils.h" #include "utils/log.h" @@ -30,7 +30,7 @@ struct FeatureTypeEqual { } - bool operator()(const CControllerFeature& feature) const + bool operator()(const CPhysicalFeature& feature) const { if (type == FEATURE_TYPE::UNKNOWN) return true; // Match all feature types @@ -61,16 +61,16 @@ CController::CController(const ADDON::AddonInfoPtr& addonInfo) CController::~CController() = default; -const CControllerFeature& CController::GetFeature(const std::string& name) const +const CPhysicalFeature& CController::GetFeature(const std::string& name) const { auto it = std::find_if(m_features.begin(), m_features.end(), - [&name](const CControllerFeature& feature) { return name == feature.Name(); }); + [&name](const CPhysicalFeature& feature) { return name == feature.Name(); }); if (it != m_features.end()) return *it; - static const CControllerFeature invalid{}; + static const CPhysicalFeature invalid{}; return invalid; } @@ -86,7 +86,7 @@ unsigned int CController::FeatureCount( void CController::GetFeatures(std::vector& features, FEATURE_TYPE type /* = FEATURE_TYPE::UNKNOWN */) const { - for (const CControllerFeature& feature : m_features) + for (const CPhysicalFeature& feature : m_features) { if (type == FEATURE_TYPE::UNKNOWN || type == feature.Type()) features.push_back(feature.Name()); @@ -150,7 +150,7 @@ bool CController::LoadLayout(void) return m_bLoaded; } -const CControllerTopology& CController::Topology() const +const CPhysicalTopology& CController::Topology() const { return m_layout->Topology(); } diff --git a/xbmc/games/controllers/Controller.h b/xbmc/games/controllers/Controller.h index 532e4dc2a0..2dd7c18b4f 100644 --- a/xbmc/games/controllers/Controller.h +++ b/xbmc/games/controllers/Controller.h @@ -8,9 +8,9 @@ #pragma once -#include "ControllerFeature.h" #include "ControllerTypes.h" #include "addons/Addon.h" +#include "games/controllers/input/PhysicalFeature.h" #include "input/joysticks/JoystickTypes.h" #include @@ -23,7 +23,7 @@ namespace KODI namespace GAME { class CControllerLayout; -class CControllerTopology; +class CPhysicalTopology; using JOYSTICK::FEATURE_TYPE; @@ -41,7 +41,7 @@ public: * * \return The features */ - const std::vector& Features(void) const { return m_features; } + const std::vector& Features(void) const { return m_features; } /*! * \brief Get a feature by its name @@ -50,7 +50,7 @@ public: * * \return The feature, or a feature of type FEATURE_TYPE::UNKNOWN if the name is invalid */ - const CControllerFeature& GetFeature(const std::string& name) const; + const CPhysicalFeature& GetFeature(const std::string& name) const; /*! * \brief Get the count of controller features matching the specified types @@ -108,11 +108,11 @@ public: * * \return The physical topology of the controller */ - const CControllerTopology& Topology() const; + const CPhysicalTopology& Topology() const; private: std::unique_ptr m_layout; - std::vector m_features; + std::vector m_features; bool m_bLoaded = false; }; diff --git a/xbmc/games/controllers/ControllerFeature.cpp b/xbmc/games/controllers/ControllerFeature.cpp deleted file mode 100644 index d6d6a4369f..0000000000 --- a/xbmc/games/controllers/ControllerFeature.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (C) 2015-2018 Team Kodi - * This file is part of Kodi - https://kodi.tv - * - * SPDX-License-Identifier: GPL-2.0-or-later - * See LICENSES/README.md for more information. - */ - -#include "ControllerFeature.h" - -#include "Controller.h" -#include "ControllerDefinitions.h" -#include "ControllerTranslator.h" -#include "guilib/LocalizeStrings.h" -#include "utils/XMLUtils.h" -#include "utils/log.h" - -#include - -using namespace KODI; -using namespace GAME; -using namespace JOYSTICK; - -CControllerFeature::CControllerFeature(int labelId) -{ - Reset(); - m_labelId = labelId; -} - -void CControllerFeature::Reset(void) -{ - *this = CControllerFeature(); -} - -CControllerFeature& CControllerFeature::operator=(const CControllerFeature& rhs) -{ - if (this != &rhs) - { - m_controller = rhs.m_controller; - m_type = rhs.m_type; - m_category = rhs.m_category; - m_categoryLabelId = rhs.m_categoryLabelId; - m_strName = rhs.m_strName; - m_labelId = rhs.m_labelId; - m_inputType = rhs.m_inputType; - m_keycode = rhs.m_keycode; - } - return *this; -} - -std::string CControllerFeature::CategoryLabel() const -{ - std::string categoryLabel; - - if (m_categoryLabelId >= 0 && m_controller != nullptr) - categoryLabel = g_localizeStrings.GetAddonString(m_controller->ID(), m_categoryLabelId); - - if (categoryLabel.empty()) - categoryLabel = g_localizeStrings.Get(m_categoryLabelId); - - return categoryLabel; -} - -std::string CControllerFeature::Label() const -{ - std::string label; - - if (m_labelId >= 0 && m_controller != nullptr) - label = g_localizeStrings.GetAddonString(m_controller->ID(), m_labelId); - - if (label.empty()) - label = g_localizeStrings.Get(m_labelId); - - return label; -} - -bool CControllerFeature::Deserialize(const TiXmlElement* pElement, - const CController* controller, - FEATURE_CATEGORY category, - int categoryLabelId) -{ - Reset(); - - if (!pElement) - return false; - - std::string strType(pElement->Value()); - - // Type - m_type = CControllerTranslator::TranslateFeatureType(strType); - if (m_type == FEATURE_TYPE::UNKNOWN) - { - CLog::Log(LOGDEBUG, "Invalid feature: <{}> ", pElement->Value()); - return false; - } - - // Cagegory was obtained from parent XML node - m_category = category; - m_categoryLabelId = categoryLabelId; - - // Name - m_strName = XMLUtils::GetAttribute(pElement, LAYOUT_XML_ATTR_FEATURE_NAME); - if (m_strName.empty()) - { - CLog::Log(LOGERROR, "<{}> tag has no \"{}\" attribute", strType, LAYOUT_XML_ATTR_FEATURE_NAME); - return false; - } - - // Label ID - std::string strLabel = XMLUtils::GetAttribute(pElement, LAYOUT_XML_ATTR_FEATURE_LABEL); - if (strLabel.empty()) - CLog::Log(LOGDEBUG, "<{}> tag has no \"{}\" attribute", strType, LAYOUT_XML_ATTR_FEATURE_LABEL); - else - std::istringstream(strLabel) >> m_labelId; - - // Input type - if (m_type == FEATURE_TYPE::SCALAR) - { - std::string strInputType = XMLUtils::GetAttribute(pElement, LAYOUT_XML_ATTR_INPUT_TYPE); - if (strInputType.empty()) - { - CLog::Log(LOGERROR, "<{}> tag has no \"{}\" attribute", strType, LAYOUT_XML_ATTR_INPUT_TYPE); - return false; - } - else - { - m_inputType = CControllerTranslator::TranslateInputType(strInputType); - if (m_inputType == INPUT_TYPE::UNKNOWN) - { - CLog::Log(LOGERROR, "<{}> tag - attribute \"{}\" is invalid: \"{}\"", strType, - LAYOUT_XML_ATTR_INPUT_TYPE, strInputType); - return false; - } - } - } - - // Keycode - if (m_type == FEATURE_TYPE::KEY) - { - std::string strSymbol = XMLUtils::GetAttribute(pElement, LAYOUT_XML_ATTR_KEY_SYMBOL); - if (strSymbol.empty()) - { - CLog::Log(LOGERROR, "<{}> tag has no \"{}\" attribute", strType, LAYOUT_XML_ATTR_KEY_SYMBOL); - return false; - } - else - { - m_keycode = CControllerTranslator::TranslateKeysym(strSymbol); - if (m_keycode == XBMCK_UNKNOWN) - { - CLog::Log(LOGERROR, "<{}> tag - attribute \"{}\" is invalid: \"{}\"", strType, - LAYOUT_XML_ATTR_KEY_SYMBOL, strSymbol); - return false; - } - } - } - - // Save controller for string translation - m_controller = controller; - - return true; -} diff --git a/xbmc/games/controllers/ControllerFeature.h b/xbmc/games/controllers/ControllerFeature.h deleted file mode 100644 index fd81a71bf3..0000000000 --- a/xbmc/games/controllers/ControllerFeature.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2015-2018 Team Kodi - * This file is part of Kodi - https://kodi.tv - * - * SPDX-License-Identifier: GPL-2.0-or-later - * See LICENSES/README.md for more information. - */ - -#pragma once - -#include "ControllerTypes.h" -#include "input/joysticks/JoystickTypes.h" -#include "input/keyboard/KeyboardTypes.h" - -#include - -class TiXmlElement; - -namespace KODI -{ -namespace GAME -{ - -class CControllerFeature -{ -public: - CControllerFeature() = default; - CControllerFeature(int labelId); - CControllerFeature(const CControllerFeature& other) { *this = other; } - - void Reset(void); - - CControllerFeature& operator=(const CControllerFeature& rhs); - - JOYSTICK::FEATURE_TYPE Type(void) const { return m_type; } - JOYSTICK::FEATURE_CATEGORY Category(void) const { return m_category; } - const std::string& Name(void) const { return m_strName; } - - // GUI properties - std::string Label(void) const; - int LabelID(void) const { return m_labelId; } - std::string CategoryLabel(void) const; - - // Input properties - JOYSTICK::INPUT_TYPE InputType(void) const { return m_inputType; } - KEYBOARD::KeySymbol Keycode() const { return m_keycode; } - - bool Deserialize(const TiXmlElement* pElement, - const CController* controller, - JOYSTICK::FEATURE_CATEGORY category, - int categoryLabelId); - -private: - const CController* m_controller = nullptr; // Used for translating addon-specific labels - JOYSTICK::FEATURE_TYPE m_type = JOYSTICK::FEATURE_TYPE::UNKNOWN; - JOYSTICK::FEATURE_CATEGORY m_category = JOYSTICK::FEATURE_CATEGORY::UNKNOWN; - int m_categoryLabelId = -1; - std::string m_strName; - int m_labelId = -1; - JOYSTICK::INPUT_TYPE m_inputType = JOYSTICK::INPUT_TYPE::UNKNOWN; - KEYBOARD::KeySymbol m_keycode = XBMCK_UNKNOWN; -}; - -} // namespace GAME -} // namespace KODI diff --git a/xbmc/games/controllers/ControllerLayout.cpp b/xbmc/games/controllers/ControllerLayout.cpp index d0e793ea88..85816c1c71 100644 --- a/xbmc/games/controllers/ControllerLayout.cpp +++ b/xbmc/games/controllers/ControllerLayout.cpp @@ -10,8 +10,8 @@ #include "Controller.h" #include "ControllerDefinitions.h" -#include "ControllerTopology.h" #include "ControllerTranslator.h" +#include "games/controllers/input/PhysicalTopology.h" #include "guilib/LocalizeStrings.h" #include "utils/URIUtils.h" #include "utils/XMLUtils.h" @@ -22,7 +22,7 @@ using namespace KODI; using namespace GAME; -CControllerLayout::CControllerLayout() : m_topology(new CControllerTopology) +CControllerLayout::CControllerLayout() : m_topology(new CPhysicalTopology) { } @@ -31,7 +31,7 @@ CControllerLayout::CControllerLayout(const CControllerLayout& other) m_labelId(other.m_labelId), m_icon(other.m_icon), m_strImage(other.m_strImage), - m_topology(new CControllerTopology(*other.m_topology)) + m_topology(new CPhysicalTopology(*other.m_topology)) { } @@ -89,7 +89,7 @@ std::string CControllerLayout::ImagePath(void) const void CControllerLayout::Deserialize(const TiXmlElement* pElement, const CController* controller, - std::vector& features) + std::vector& features) { if (pElement == nullptr || controller == nullptr) return; @@ -138,7 +138,7 @@ void CControllerLayout::Deserialize(const TiXmlElement* pElement, for (const TiXmlElement* pFeature = pChild->FirstChildElement(); pFeature != nullptr; pFeature = pFeature->NextSiblingElement()) { - CControllerFeature feature; + CPhysicalFeature feature; if (feature.Deserialize(pFeature, controller, category, categoryLabelId)) features.push_back(feature); @@ -147,7 +147,7 @@ void CControllerLayout::Deserialize(const TiXmlElement* pElement, else if (pChild->ValueStr() == LAYOUT_XML_ELM_TOPOLOGY) { // Topology - CControllerTopology topology; + CPhysicalTopology topology; if (topology.Deserialize(pChild)) *m_topology = std::move(topology); } diff --git a/xbmc/games/controllers/ControllerLayout.h b/xbmc/games/controllers/ControllerLayout.h index 4b78b872b5..1589837483 100644 --- a/xbmc/games/controllers/ControllerLayout.h +++ b/xbmc/games/controllers/ControllerLayout.h @@ -19,8 +19,8 @@ namespace KODI namespace GAME { class CController; -class CControllerFeature; -class CControllerTopology; +class CPhysicalFeature; +class CPhysicalTopology; class CControllerLayout { @@ -67,7 +67,7 @@ public: * * \return The physical topology of the controller */ - const CControllerTopology& Topology(void) const { return *m_topology; } + const CPhysicalTopology& Topology(void) const { return *m_topology; } /*! * \brief Deserialize the specified XML element @@ -78,14 +78,14 @@ public: */ void Deserialize(const TiXmlElement* pLayoutElement, const CController* controller, - std::vector& features); + std::vector& features); private: const CController* m_controller = nullptr; int m_labelId = -1; std::string m_icon; std::string m_strImage; - std::unique_ptr m_topology; + std::unique_ptr m_topology; }; } // namespace GAME diff --git a/xbmc/games/controllers/ControllerPort.cpp b/xbmc/games/controllers/ControllerPort.cpp deleted file mode 100644 index 9db20a6c6c..0000000000 --- a/xbmc/games/controllers/ControllerPort.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2017-2021 Team Kodi - * This file is part of Kodi - https://kodi.tv - * - * SPDX-License-Identifier: GPL-2.0-or-later - * See LICENSES/README.md for more information. - */ - -#include "ControllerPort.h" - -#include "ControllerDefinitions.h" -#include "utils/XMLUtils.h" -#include "utils/log.h" - -#include -#include - -using namespace KODI; -using namespace GAME; - -CControllerPort::CControllerPort(std::string portId, std::vector accepts) - : m_portId(std::move(portId)), m_accepts(std::move(accepts)) -{ -} - -void CControllerPort::Reset() -{ - CControllerPort defaultPort; - *this = std::move(defaultPort); -} - -bool CControllerPort::IsCompatible(const std::string& controllerId) const -{ - return std::find(m_accepts.begin(), m_accepts.end(), controllerId) != m_accepts.end(); -} - -bool CControllerPort::Deserialize(const TiXmlElement* pElement) -{ - if (pElement == nullptr) - return false; - - Reset(); - - m_portId = XMLUtils::GetAttribute(pElement, LAYOUT_XML_ATTR_PORT_ID); - - for (const TiXmlElement* pChild = pElement->FirstChildElement(); pChild != nullptr; - pChild = pChild->NextSiblingElement()) - { - if (pChild->ValueStr() == LAYOUT_XML_ELM_ACCEPTS) - { - std::string controller = XMLUtils::GetAttribute(pChild, LAYOUT_XML_ATTR_CONTROLLER); - - if (!controller.empty()) - m_accepts.emplace_back(std::move(controller)); - else - CLog::Log(LOGWARNING, "<{}> tag is missing \"{}\" attribute", LAYOUT_XML_ELM_ACCEPTS, - LAYOUT_XML_ATTR_CONTROLLER); - } - else - { - CLog::Log(LOGDEBUG, "Unknown physical topology port tag: <{}>", pChild->ValueStr()); - } - } - - return true; -} diff --git a/xbmc/games/controllers/ControllerPort.h b/xbmc/games/controllers/ControllerPort.h deleted file mode 100644 index 1bb87ed3f4..0000000000 --- a/xbmc/games/controllers/ControllerPort.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2017-2021 Team Kodi - * This file is part of Kodi - https://kodi.tv - * - * SPDX-License-Identifier: GPL-2.0-or-later - * See LICENSES/README.md for more information. - */ - -#pragma once - -#include -#include - -class TiXmlElement; - -namespace KODI -{ -namespace GAME -{ - -class CControllerPort -{ -public: - CControllerPort() = default; - - /*! - * \brief Create a controller port - * - * \param portId The port's ID - * \param accepts A list of controller IDs that this port accepts - */ - CControllerPort(std::string portId, std::vector accepts); - - void Reset(); - - /*! - * \brief Get the ID of the port - * - * \return The port's ID, e.g. "1", as a string - */ - const std::string& ID() const { return m_portId; } - - /*! - * \brief Get the controllers that can connect to this port - * - * \return A list of controllers that are physically compatible with this port - */ - const std::vector& Accepts() const { return m_accepts; } - - /*! - * \brief Check if the controller is compatible with this port - * - * \return True if the controller is accepted, false otherwise - */ - bool IsCompatible(const std::string& controllerId) const; - - bool Deserialize(const TiXmlElement* pElement); - -private: - std::string m_portId; - std::vector m_accepts; -}; -} // namespace GAME -} // namespace KODI diff --git a/xbmc/games/controllers/ControllerTopology.cpp b/xbmc/games/controllers/ControllerTopology.cpp deleted file mode 100644 index 826aa3ac2f..0000000000 --- a/xbmc/games/controllers/ControllerTopology.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2017-2018 Team Kodi - * This file is part of Kodi - https://kodi.tv - * - * SPDX-License-Identifier: GPL-2.0-or-later - * See LICENSES/README.md for more information. - */ - -#include "ControllerTopology.h" - -#include "ControllerDefinitions.h" -#include "utils/XMLUtils.h" -#include "utils/log.h" - -#include - -using namespace KODI; -using namespace GAME; - -CControllerTopology::CControllerTopology(bool bProvidesInput, std::vector ports) - : m_bProvidesInput(bProvidesInput), m_ports(std::move(ports)) -{ -} - -void CControllerTopology::Reset() -{ - CControllerTopology defaultTopology; - *this = std::move(defaultTopology); -} - -bool CControllerTopology::Deserialize(const TiXmlElement* pElement) -{ - Reset(); - - if (pElement == nullptr) - return false; - - m_bProvidesInput = (XMLUtils::GetAttribute(pElement, LAYOUT_XML_ATTR_PROVIDES_INPUT) != "false"); - - for (const TiXmlElement* pChild = pElement->FirstChildElement(); pChild != nullptr; - pChild = pChild->NextSiblingElement()) - { - if (pChild->ValueStr() == LAYOUT_XML_ELM_PORT) - { - CControllerPort port; - if (port.Deserialize(pChild)) - m_ports.emplace_back(std::move(port)); - } - else - { - CLog::Log(LOGDEBUG, "Unknown physical topology tag: <{}>", pChild->ValueStr()); - } - } - - return true; -} diff --git a/xbmc/games/controllers/ControllerTopology.h b/xbmc/games/controllers/ControllerTopology.h deleted file mode 100644 index 6ab42ad101..0000000000 --- a/xbmc/games/controllers/ControllerTopology.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2017-2018 Team Kodi - * This file is part of Kodi - https://kodi.tv - * - * SPDX-License-Identifier: GPL-2.0-or-later - * See LICENSES/README.md for more information. - */ - -#pragma once - -#include "ControllerPort.h" - -#include - -class TiXmlElement; - -namespace KODI -{ -namespace GAME -{ - -/*! - * \brief Represents the physical topology of controller add-ons - * - * The physical topology of a controller defines how many ports it has and - * whether it can provide player input (hubs like the Super Multitap don't - * provide input). - */ -class CControllerTopology -{ -public: - CControllerTopology() = default; - CControllerTopology(bool bProvidesInput, std::vector ports); - - void Reset(); - - /*! - * \brief Check if the controller can provide player input - * - * This allows hubs to specify that they provide no input - * - * \return True if the controller can provide player input, false otherwise - */ - bool ProvidesInput() const { return m_bProvidesInput; } - - /*! - * \brief Get a list of ports provided by this controller - * - * \return The ports - */ - const std::vector& Ports() const { return m_ports; } - - bool Deserialize(const TiXmlElement* pElement); - -private: - bool m_bProvidesInput = true; - std::vector m_ports; -}; - -} // namespace GAME -} // namespace KODI diff --git a/xbmc/games/controllers/guicontrols/GUICardinalFeatureButton.cpp b/xbmc/games/controllers/guicontrols/GUICardinalFeatureButton.cpp index f78bcfb1c7..3c8732cbae 100644 --- a/xbmc/games/controllers/guicontrols/GUICardinalFeatureButton.cpp +++ b/xbmc/games/controllers/guicontrols/GUICardinalFeatureButton.cpp @@ -17,7 +17,7 @@ using namespace GAME; CGUICardinalFeatureButton::CGUICardinalFeatureButton(const CGUIButtonControl& buttonTemplate, IConfigurationWizard* wizard, - const CControllerFeature& feature, + const CPhysicalFeature& feature, unsigned int index) : CGUIFeatureButton(buttonTemplate, wizard, feature, index) { diff --git a/xbmc/games/controllers/guicontrols/GUICardinalFeatureButton.h b/xbmc/games/controllers/guicontrols/GUICardinalFeatureButton.h index 70c544e342..48eb0e885d 100644 --- a/xbmc/games/controllers/guicontrols/GUICardinalFeatureButton.h +++ b/xbmc/games/controllers/guicontrols/GUICardinalFeatureButton.h @@ -19,7 +19,7 @@ class CGUICardinalFeatureButton : public CGUIFeatureButton public: CGUICardinalFeatureButton(const CGUIButtonControl& buttonTemplate, IConfigurationWizard* wizard, - const CControllerFeature& feature, + const CPhysicalFeature& feature, unsigned int index); ~CGUICardinalFeatureButton() override = default; diff --git a/xbmc/games/controllers/guicontrols/GUIFeatureButton.cpp b/xbmc/games/controllers/guicontrols/GUIFeatureButton.cpp index f128fa5f33..688f3c29df 100644 --- a/xbmc/games/controllers/guicontrols/GUIFeatureButton.cpp +++ b/xbmc/games/controllers/guicontrols/GUIFeatureButton.cpp @@ -21,7 +21,7 @@ using namespace std::chrono_literals; CGUIFeatureButton::CGUIFeatureButton(const CGUIButtonControl& buttonTemplate, IConfigurationWizard* wizard, - const CControllerFeature& feature, + const CPhysicalFeature& feature, unsigned int index) : CGUIButtonControl(buttonTemplate), m_feature(feature), m_wizard(wizard) { diff --git a/xbmc/games/controllers/guicontrols/GUIFeatureButton.h b/xbmc/games/controllers/guicontrols/GUIFeatureButton.h index 4f0e4a920a..b69f521b7f 100644 --- a/xbmc/games/controllers/guicontrols/GUIFeatureButton.h +++ b/xbmc/games/controllers/guicontrols/GUIFeatureButton.h @@ -8,7 +8,7 @@ #pragma once -#include "games/controllers/ControllerFeature.h" +#include "games/controllers/input/PhysicalFeature.h" #include "games/controllers/windows/IConfigurationWindow.h" #include "guilib/GUIButtonControl.h" @@ -23,7 +23,7 @@ class CGUIFeatureButton : public CGUIButtonControl, public IFeatureButton public: CGUIFeatureButton(const CGUIButtonControl& buttonTemplate, IConfigurationWizard* wizard, - const CControllerFeature& feature, + const CPhysicalFeature& feature, unsigned int index); ~CGUIFeatureButton() override = default; @@ -32,7 +32,7 @@ public: void OnUnFocus() override; // partial implementation of IFeatureButton - const CControllerFeature& Feature() const override { return m_feature; } + const CPhysicalFeature& Feature() const override { return m_feature; } INPUT::CARDINAL_DIRECTION GetCardinalDirection() const override { return INPUT::CARDINAL_DIRECTION::NONE; @@ -59,7 +59,7 @@ protected: return static_cast(static_cast(state) + 1); } - const CControllerFeature m_feature; + const CPhysicalFeature m_feature; private: IConfigurationWizard* const m_wizard; diff --git a/xbmc/games/controllers/guicontrols/GUIFeatureFactory.cpp b/xbmc/games/controllers/guicontrols/GUIFeatureFactory.cpp index dfba9a1205..2cce0337b2 100644 --- a/xbmc/games/controllers/guicontrols/GUIFeatureFactory.cpp +++ b/xbmc/games/controllers/guicontrols/GUIFeatureFactory.cpp @@ -20,7 +20,7 @@ using namespace GAME; CGUIButtonControl* CGUIFeatureFactory::CreateButton(BUTTON_TYPE type, const CGUIButtonControl& buttonTemplate, IConfigurationWizard* wizard, - const CControllerFeature& feature, + const CPhysicalFeature& feature, unsigned int index) { switch (type) diff --git a/xbmc/games/controllers/guicontrols/GUIFeatureFactory.h b/xbmc/games/controllers/guicontrols/GUIFeatureFactory.h index 69d7df9f74..e35070dbae 100644 --- a/xbmc/games/controllers/guicontrols/GUIFeatureFactory.h +++ b/xbmc/games/controllers/guicontrols/GUIFeatureFactory.h @@ -16,7 +16,7 @@ namespace KODI { namespace GAME { -class CControllerFeature; +class CPhysicalFeature; class IConfigurationWizard; class CGUIFeatureFactory @@ -30,7 +30,7 @@ public: static CGUIButtonControl* CreateButton(BUTTON_TYPE type, const CGUIButtonControl& buttonTemplate, IConfigurationWizard* wizard, - const CControllerFeature& feature, + const CPhysicalFeature& feature, unsigned int index); }; } // namespace GAME diff --git a/xbmc/games/controllers/guicontrols/GUIScalarFeatureButton.cpp b/xbmc/games/controllers/guicontrols/GUIScalarFeatureButton.cpp index c61945b18e..5358aea90f 100644 --- a/xbmc/games/controllers/guicontrols/GUIScalarFeatureButton.cpp +++ b/xbmc/games/controllers/guicontrols/GUIScalarFeatureButton.cpp @@ -17,7 +17,7 @@ using namespace GAME; CGUIScalarFeatureButton::CGUIScalarFeatureButton(const CGUIButtonControl& buttonTemplate, IConfigurationWizard* wizard, - const CControllerFeature& feature, + const CPhysicalFeature& feature, unsigned int index) : CGUIFeatureButton(buttonTemplate, wizard, feature, index) { diff --git a/xbmc/games/controllers/guicontrols/GUIScalarFeatureButton.h b/xbmc/games/controllers/guicontrols/GUIScalarFeatureButton.h index 8881225d0e..6505684fb9 100644 --- a/xbmc/games/controllers/guicontrols/GUIScalarFeatureButton.h +++ b/xbmc/games/controllers/guicontrols/GUIScalarFeatureButton.h @@ -19,7 +19,7 @@ class CGUIScalarFeatureButton : public CGUIFeatureButton public: CGUIScalarFeatureButton(const CGUIButtonControl& buttonTemplate, IConfigurationWizard* wizard, - const CControllerFeature& feature, + const CPhysicalFeature& feature, unsigned int index); ~CGUIScalarFeatureButton() override = default; diff --git a/xbmc/games/controllers/guicontrols/GUISelectKeyButton.cpp b/xbmc/games/controllers/guicontrols/GUISelectKeyButton.cpp index 0ad3640b48..ea4a65622e 100644 --- a/xbmc/games/controllers/guicontrols/GUISelectKeyButton.cpp +++ b/xbmc/games/controllers/guicontrols/GUISelectKeyButton.cpp @@ -22,7 +22,7 @@ CGUISelectKeyButton::CGUISelectKeyButton(const CGUIButtonControl& buttonTemplate { } -const CControllerFeature& CGUISelectKeyButton::Feature(void) const +const CPhysicalFeature& CGUISelectKeyButton::Feature(void) const { if (m_state == STATE::NEED_INPUT) return m_selectedKey; @@ -70,7 +70,7 @@ bool CGUISelectKeyButton::IsFinished(void) const return m_state >= STATE::FINISHED; } -void CGUISelectKeyButton::SetKey(const CControllerFeature& key) +void CGUISelectKeyButton::SetKey(const CPhysicalFeature& key) { m_selectedKey = key; } @@ -81,7 +81,7 @@ void CGUISelectKeyButton::Reset(void) m_selectedKey.Reset(); } -CControllerFeature CGUISelectKeyButton::GetFeature() +CPhysicalFeature CGUISelectKeyButton::GetFeature() { - return CControllerFeature(35168); // "Select key" + return CPhysicalFeature(35168); // "Select key" } diff --git a/xbmc/games/controllers/guicontrols/GUISelectKeyButton.h b/xbmc/games/controllers/guicontrols/GUISelectKeyButton.h index 9232886ae7..e96f78b005 100644 --- a/xbmc/games/controllers/guicontrols/GUISelectKeyButton.h +++ b/xbmc/games/controllers/guicontrols/GUISelectKeyButton.h @@ -9,7 +9,7 @@ #pragma once #include "GUIFeatureButton.h" -#include "games/controllers/ControllerFeature.h" +#include "games/controllers/input/PhysicalFeature.h" namespace KODI { @@ -25,16 +25,16 @@ public: ~CGUISelectKeyButton() override = default; // implementation of IFeatureButton - const CControllerFeature& Feature(void) const override; + const CPhysicalFeature& Feature(void) const override; bool AllowWizard() const override { return false; } bool PromptForInput(CEvent& waitEvent) override; bool IsFinished() const override; bool NeedsKey() const override { return m_state == STATE::NEED_KEY; } - void SetKey(const CControllerFeature& key) override; + void SetKey(const CPhysicalFeature& key) override; void Reset() override; private: - static CControllerFeature GetFeature(); + static CPhysicalFeature GetFeature(); enum class STATE { @@ -45,7 +45,7 @@ private: STATE m_state = STATE::NEED_KEY; - CControllerFeature m_selectedKey; + CPhysicalFeature m_selectedKey; }; } // namespace GAME } // namespace KODI diff --git a/xbmc/games/controllers/guicontrols/GUIThrottleButton.cpp b/xbmc/games/controllers/guicontrols/GUIThrottleButton.cpp index 02c7d18fbc..69f32a166c 100644 --- a/xbmc/games/controllers/guicontrols/GUIThrottleButton.cpp +++ b/xbmc/games/controllers/guicontrols/GUIThrottleButton.cpp @@ -17,7 +17,7 @@ using namespace GAME; CGUIThrottleButton::CGUIThrottleButton(const CGUIButtonControl& buttonTemplate, IConfigurationWizard* wizard, - const CControllerFeature& feature, + const CPhysicalFeature& feature, unsigned int index) : CGUIFeatureButton(buttonTemplate, wizard, feature, index) { diff --git a/xbmc/games/controllers/guicontrols/GUIThrottleButton.h b/xbmc/games/controllers/guicontrols/GUIThrottleButton.h index effc98f689..72b7ee39e7 100644 --- a/xbmc/games/controllers/guicontrols/GUIThrottleButton.h +++ b/xbmc/games/controllers/guicontrols/GUIThrottleButton.h @@ -19,7 +19,7 @@ class CGUIThrottleButton : public CGUIFeatureButton public: CGUIThrottleButton(const CGUIButtonControl& buttonTemplate, IConfigurationWizard* wizard, - const CControllerFeature& feature, + const CPhysicalFeature& feature, unsigned int index); ~CGUIThrottleButton() override = default; diff --git a/xbmc/games/controllers/guicontrols/GUIWheelButton.cpp b/xbmc/games/controllers/guicontrols/GUIWheelButton.cpp index 9df07fb568..63c3819802 100644 --- a/xbmc/games/controllers/guicontrols/GUIWheelButton.cpp +++ b/xbmc/games/controllers/guicontrols/GUIWheelButton.cpp @@ -17,7 +17,7 @@ using namespace GAME; CGUIWheelButton::CGUIWheelButton(const CGUIButtonControl& buttonTemplate, IConfigurationWizard* wizard, - const CControllerFeature& feature, + const CPhysicalFeature& feature, unsigned int index) : CGUIFeatureButton(buttonTemplate, wizard, feature, index) { diff --git a/xbmc/games/controllers/guicontrols/GUIWheelButton.h b/xbmc/games/controllers/guicontrols/GUIWheelButton.h index b099c17c8d..937703aac3 100644 --- a/xbmc/games/controllers/guicontrols/GUIWheelButton.h +++ b/xbmc/games/controllers/guicontrols/GUIWheelButton.h @@ -19,7 +19,7 @@ class CGUIWheelButton : public CGUIFeatureButton public: CGUIWheelButton(const CGUIButtonControl& buttonTemplate, IConfigurationWizard* wizard, - const CControllerFeature& feature, + const CPhysicalFeature& feature, unsigned int index); ~CGUIWheelButton() override = default; diff --git a/xbmc/games/controllers/input/CMakeLists.txt b/xbmc/games/controllers/input/CMakeLists.txt new file mode 100644 index 0000000000..a6bb1ecb14 --- /dev/null +++ b/xbmc/games/controllers/input/CMakeLists.txt @@ -0,0 +1,15 @@ +set(SOURCES InputSink.cpp + PhysicalFeature.cpp + PhysicalPort.cpp + PhysicalTopology.cpp + PortInput.cpp +) + +set(HEADERS InputSink.h + PhysicalFeature.h + PhysicalPort.h + PhysicalTopology.h + PortInput.h +) + +core_add_library(games_controller_input) diff --git a/xbmc/games/controllers/input/InputSink.cpp b/xbmc/games/controllers/input/InputSink.cpp new file mode 100644 index 0000000000..a48b4b9880 --- /dev/null +++ b/xbmc/games/controllers/input/InputSink.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2017-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "InputSink.h" + +#include "games/controllers/ControllerIDs.h" + +using namespace KODI; +using namespace GAME; + +CInputSink::CInputSink(JOYSTICK::IInputHandler* gameInput) : m_gameInput(gameInput) +{ +} + +std::string CInputSink::ControllerID(void) const +{ + return DEFAULT_CONTROLLER_ID; +} + +bool CInputSink::AcceptsInput(const std::string& feature) const +{ + return m_gameInput->AcceptsInput(feature); +} + +bool CInputSink::OnButtonPress(const std::string& feature, bool bPressed) +{ + return true; +} + +bool CInputSink::OnButtonMotion(const std::string& feature, + float magnitude, + unsigned int motionTimeMs) +{ + return true; +} + +bool CInputSink::OnAnalogStickMotion(const std::string& feature, + float x, + float y, + unsigned int motionTimeMs) +{ + return true; +} + +bool CInputSink::OnAccelerometerMotion(const std::string& feature, float x, float y, float z) +{ + return true; +} + +bool CInputSink::OnWheelMotion(const std::string& feature, + float position, + unsigned int motionTimeMs) +{ + return true; +} + +bool CInputSink::OnThrottleMotion(const std::string& feature, + float position, + unsigned int motionTimeMs) +{ + return true; +} diff --git a/xbmc/games/controllers/input/InputSink.h b/xbmc/games/controllers/input/InputSink.h new file mode 100644 index 0000000000..bd2d629dc3 --- /dev/null +++ b/xbmc/games/controllers/input/InputSink.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2017-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "input/joysticks/interfaces/IInputHandler.h" + +namespace KODI +{ +namespace GAME +{ +class CGameClient; + +class CInputSink : public JOYSTICK::IInputHandler +{ +public: + explicit CInputSink(JOYSTICK::IInputHandler* gameInput); + + ~CInputSink() override = default; + + // Implementation of IInputHandler + std::string ControllerID() const override; + bool HasFeature(const std::string& feature) const override { return true; } + bool AcceptsInput(const std::string& feature) const override; + bool OnButtonPress(const std::string& feature, bool bPressed) override; + void OnButtonHold(const std::string& feature, unsigned int holdTimeMs) override {} + bool OnButtonMotion(const std::string& feature, + float magnitude, + unsigned int motionTimeMs) override; + bool OnAnalogStickMotion(const std::string& feature, + float x, + float y, + unsigned int motionTimeMs) override; + bool OnAccelerometerMotion(const std::string& feature, float x, float y, float z) override; + bool OnWheelMotion(const std::string& feature, + float position, + unsigned int motionTimeMs) override; + bool OnThrottleMotion(const std::string& feature, + float position, + unsigned int motionTimeMs) override; + +private: + // Construction parameters + JOYSTICK::IInputHandler* m_gameInput; +}; +} // namespace GAME +} // namespace KODI diff --git a/xbmc/games/controllers/input/PhysicalFeature.cpp b/xbmc/games/controllers/input/PhysicalFeature.cpp new file mode 100644 index 0000000000..24e0c41030 --- /dev/null +++ b/xbmc/games/controllers/input/PhysicalFeature.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2015-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "PhysicalFeature.h" + +#include "games/controllers/Controller.h" +#include "games/controllers/ControllerDefinitions.h" +#include "games/controllers/ControllerTranslator.h" +#include "guilib/LocalizeStrings.h" +#include "utils/XMLUtils.h" +#include "utils/log.h" + +#include + +using namespace KODI; +using namespace GAME; +using namespace JOYSTICK; + +CPhysicalFeature::CPhysicalFeature(int labelId) +{ + Reset(); + m_labelId = labelId; +} + +void CPhysicalFeature::Reset(void) +{ + *this = CPhysicalFeature(); +} + +CPhysicalFeature& CPhysicalFeature::operator=(const CPhysicalFeature& rhs) +{ + if (this != &rhs) + { + m_controller = rhs.m_controller; + m_type = rhs.m_type; + m_category = rhs.m_category; + m_categoryLabelId = rhs.m_categoryLabelId; + m_strName = rhs.m_strName; + m_labelId = rhs.m_labelId; + m_inputType = rhs.m_inputType; + m_keycode = rhs.m_keycode; + } + return *this; +} + +std::string CPhysicalFeature::CategoryLabel() const +{ + std::string categoryLabel; + + if (m_categoryLabelId >= 0 && m_controller != nullptr) + categoryLabel = g_localizeStrings.GetAddonString(m_controller->ID(), m_categoryLabelId); + + if (categoryLabel.empty()) + categoryLabel = g_localizeStrings.Get(m_categoryLabelId); + + return categoryLabel; +} + +std::string CPhysicalFeature::Label() const +{ + std::string label; + + if (m_labelId >= 0 && m_controller != nullptr) + label = g_localizeStrings.GetAddonString(m_controller->ID(), m_labelId); + + if (label.empty()) + label = g_localizeStrings.Get(m_labelId); + + return label; +} + +bool CPhysicalFeature::Deserialize(const TiXmlElement* pElement, + const CController* controller, + FEATURE_CATEGORY category, + int categoryLabelId) +{ + Reset(); + + if (!pElement) + return false; + + std::string strType(pElement->Value()); + + // Type + m_type = CControllerTranslator::TranslateFeatureType(strType); + if (m_type == FEATURE_TYPE::UNKNOWN) + { + CLog::Log(LOGDEBUG, "Invalid feature: <{}> ", pElement->Value()); + return false; + } + + // Cagegory was obtained from parent XML node + m_category = category; + m_categoryLabelId = categoryLabelId; + + // Name + m_strName = XMLUtils::GetAttribute(pElement, LAYOUT_XML_ATTR_FEATURE_NAME); + if (m_strName.empty()) + { + CLog::Log(LOGERROR, "<{}> tag has no \"{}\" attribute", strType, LAYOUT_XML_ATTR_FEATURE_NAME); + return false; + } + + // Label ID + std::string strLabel = XMLUtils::GetAttribute(pElement, LAYOUT_XML_ATTR_FEATURE_LABEL); + if (strLabel.empty()) + CLog::Log(LOGDEBUG, "<{}> tag has no \"{}\" attribute", strType, LAYOUT_XML_ATTR_FEATURE_LABEL); + else + std::istringstream(strLabel) >> m_labelId; + + // Input type + if (m_type == FEATURE_TYPE::SCALAR) + { + std::string strInputType = XMLUtils::GetAttribute(pElement, LAYOUT_XML_ATTR_INPUT_TYPE); + if (strInputType.empty()) + { + CLog::Log(LOGERROR, "<{}> tag has no \"{}\" attribute", strType, LAYOUT_XML_ATTR_INPUT_TYPE); + return false; + } + else + { + m_inputType = CControllerTranslator::TranslateInputType(strInputType); + if (m_inputType == INPUT_TYPE::UNKNOWN) + { + CLog::Log(LOGERROR, "<{}> tag - attribute \"{}\" is invalid: \"{}\"", strType, + LAYOUT_XML_ATTR_INPUT_TYPE, strInputType); + return false; + } + } + } + + // Keycode + if (m_type == FEATURE_TYPE::KEY) + { + std::string strSymbol = XMLUtils::GetAttribute(pElement, LAYOUT_XML_ATTR_KEY_SYMBOL); + if (strSymbol.empty()) + { + CLog::Log(LOGERROR, "<{}> tag has no \"{}\" attribute", strType, LAYOUT_XML_ATTR_KEY_SYMBOL); + return false; + } + else + { + m_keycode = CControllerTranslator::TranslateKeysym(strSymbol); + if (m_keycode == XBMCK_UNKNOWN) + { + CLog::Log(LOGERROR, "<{}> tag - attribute \"{}\" is invalid: \"{}\"", strType, + LAYOUT_XML_ATTR_KEY_SYMBOL, strSymbol); + return false; + } + } + } + + // Save controller for string translation + m_controller = controller; + + return true; +} diff --git a/xbmc/games/controllers/input/PhysicalFeature.h b/xbmc/games/controllers/input/PhysicalFeature.h new file mode 100644 index 0000000000..6319a63a5e --- /dev/null +++ b/xbmc/games/controllers/input/PhysicalFeature.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2015-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "games/controllers/ControllerTypes.h" +#include "input/joysticks/JoystickTypes.h" +#include "input/keyboard/KeyboardTypes.h" + +#include + +class TiXmlElement; + +namespace KODI +{ +namespace GAME +{ + +class CPhysicalFeature +{ +public: + CPhysicalFeature() = default; + CPhysicalFeature(int labelId); + CPhysicalFeature(const CPhysicalFeature& other) { *this = other; } + + void Reset(void); + + CPhysicalFeature& operator=(const CPhysicalFeature& rhs); + + JOYSTICK::FEATURE_TYPE Type(void) const { return m_type; } + JOYSTICK::FEATURE_CATEGORY Category(void) const { return m_category; } + const std::string& Name(void) const { return m_strName; } + + // GUI properties + std::string Label(void) const; + int LabelID(void) const { return m_labelId; } + std::string CategoryLabel(void) const; + + // Input properties + JOYSTICK::INPUT_TYPE InputType(void) const { return m_inputType; } + KEYBOARD::KeySymbol Keycode() const { return m_keycode; } + + bool Deserialize(const TiXmlElement* pElement, + const CController* controller, + JOYSTICK::FEATURE_CATEGORY category, + int categoryLabelId); + +private: + const CController* m_controller = nullptr; // Used for translating addon-specific labels + JOYSTICK::FEATURE_TYPE m_type = JOYSTICK::FEATURE_TYPE::UNKNOWN; + JOYSTICK::FEATURE_CATEGORY m_category = JOYSTICK::FEATURE_CATEGORY::UNKNOWN; + int m_categoryLabelId = -1; + std::string m_strName; + int m_labelId = -1; + JOYSTICK::INPUT_TYPE m_inputType = JOYSTICK::INPUT_TYPE::UNKNOWN; + KEYBOARD::KeySymbol m_keycode = XBMCK_UNKNOWN; +}; + +} // namespace GAME +} // namespace KODI diff --git a/xbmc/games/controllers/input/PhysicalPort.cpp b/xbmc/games/controllers/input/PhysicalPort.cpp new file mode 100644 index 0000000000..9c53c76199 --- /dev/null +++ b/xbmc/games/controllers/input/PhysicalPort.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2017-2021 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "PhysicalPort.h" + +#include "games/controllers/ControllerDefinitions.h" +#include "utils/XMLUtils.h" +#include "utils/log.h" + +#include +#include + +using namespace KODI; +using namespace GAME; + +CPhysicalPort::CPhysicalPort(std::string portId, std::vector accepts) + : m_portId(std::move(portId)), m_accepts(std::move(accepts)) +{ +} + +void CPhysicalPort::Reset() +{ + CPhysicalPort defaultPort; + *this = std::move(defaultPort); +} + +bool CPhysicalPort::IsCompatible(const std::string& controllerId) const +{ + return std::find(m_accepts.begin(), m_accepts.end(), controllerId) != m_accepts.end(); +} + +bool CPhysicalPort::Deserialize(const TiXmlElement* pElement) +{ + if (pElement == nullptr) + return false; + + Reset(); + + m_portId = XMLUtils::GetAttribute(pElement, LAYOUT_XML_ATTR_PORT_ID); + + for (const TiXmlElement* pChild = pElement->FirstChildElement(); pChild != nullptr; + pChild = pChild->NextSiblingElement()) + { + if (pChild->ValueStr() == LAYOUT_XML_ELM_ACCEPTS) + { + std::string controller = XMLUtils::GetAttribute(pChild, LAYOUT_XML_ATTR_CONTROLLER); + + if (!controller.empty()) + m_accepts.emplace_back(std::move(controller)); + else + CLog::Log(LOGWARNING, "<{}> tag is missing \"{}\" attribute", LAYOUT_XML_ELM_ACCEPTS, + LAYOUT_XML_ATTR_CONTROLLER); + } + else + { + CLog::Log(LOGDEBUG, "Unknown physical topology port tag: <{}>", pChild->ValueStr()); + } + } + + return true; +} diff --git a/xbmc/games/controllers/input/PhysicalPort.h b/xbmc/games/controllers/input/PhysicalPort.h new file mode 100644 index 0000000000..83fe3a503c --- /dev/null +++ b/xbmc/games/controllers/input/PhysicalPort.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2017-2021 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include +#include + +class TiXmlElement; + +namespace KODI +{ +namespace GAME +{ + +class CPhysicalPort +{ +public: + CPhysicalPort() = default; + + /*! + * \brief Create a controller port + * + * \param portId The port's ID + * \param accepts A list of controller IDs that this port accepts + */ + CPhysicalPort(std::string portId, std::vector accepts); + + void Reset(); + + /*! + * \brief Get the ID of the port + * + * \return The port's ID, e.g. "1", as a string + */ + const std::string& ID() const { return m_portId; } + + /*! + * \brief Get the controllers that can connect to this port + * + * \return A list of controllers that are physically compatible with this port + */ + const std::vector& Accepts() const { return m_accepts; } + + /*! + * \brief Check if the controller is compatible with this port + * + * \return True if the controller is accepted, false otherwise + */ + bool IsCompatible(const std::string& controllerId) const; + + bool Deserialize(const TiXmlElement* pElement); + +private: + std::string m_portId; + std::vector m_accepts; +}; +} // namespace GAME +} // namespace KODI diff --git a/xbmc/games/controllers/input/PhysicalTopology.cpp b/xbmc/games/controllers/input/PhysicalTopology.cpp new file mode 100644 index 0000000000..2fecb5ac11 --- /dev/null +++ b/xbmc/games/controllers/input/PhysicalTopology.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2017-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "PhysicalTopology.h" + +#include "games/controllers/ControllerDefinitions.h" +#include "utils/XMLUtils.h" +#include "utils/log.h" + +#include + +using namespace KODI; +using namespace GAME; + +CPhysicalTopology::CPhysicalTopology(bool bProvidesInput, std::vector ports) + : m_bProvidesInput(bProvidesInput), m_ports(std::move(ports)) +{ +} + +void CPhysicalTopology::Reset() +{ + CPhysicalTopology defaultTopology; + *this = std::move(defaultTopology); +} + +bool CPhysicalTopology::Deserialize(const TiXmlElement* pElement) +{ + Reset(); + + if (pElement == nullptr) + return false; + + m_bProvidesInput = (XMLUtils::GetAttribute(pElement, LAYOUT_XML_ATTR_PROVIDES_INPUT) != "false"); + + for (const TiXmlElement* pChild = pElement->FirstChildElement(); pChild != nullptr; + pChild = pChild->NextSiblingElement()) + { + if (pChild->ValueStr() == LAYOUT_XML_ELM_PORT) + { + CPhysicalPort port; + if (port.Deserialize(pChild)) + m_ports.emplace_back(std::move(port)); + } + else + { + CLog::Log(LOGDEBUG, "Unknown physical topology tag: <{}>", pChild->ValueStr()); + } + } + + return true; +} diff --git a/xbmc/games/controllers/input/PhysicalTopology.h b/xbmc/games/controllers/input/PhysicalTopology.h new file mode 100644 index 0000000000..bc76bb91b2 --- /dev/null +++ b/xbmc/games/controllers/input/PhysicalTopology.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2017-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "PhysicalPort.h" + +#include + +class TiXmlElement; + +namespace KODI +{ +namespace GAME +{ + +/*! + * \brief Represents the physical topology of controller add-ons + * + * The physical topology of a controller defines how many ports it has and + * whether it can provide player input (hubs like the Super Multitap don't + * provide input). + */ +class CPhysicalTopology +{ +public: + CPhysicalTopology() = default; + CPhysicalTopology(bool bProvidesInput, std::vector ports); + + void Reset(); + + /*! + * \brief Check if the controller can provide player input + * + * This allows hubs to specify that they provide no input + * + * \return True if the controller can provide player input, false otherwise + */ + bool ProvidesInput() const { return m_bProvidesInput; } + + /*! + * \brief Get a list of ports provided by this controller + * + * \return The ports + */ + const std::vector& Ports() const { return m_ports; } + + bool Deserialize(const TiXmlElement* pElement); + +private: + bool m_bProvidesInput = true; + std::vector m_ports; +}; + +} // namespace GAME +} // namespace KODI diff --git a/xbmc/games/controllers/input/PortInput.cpp b/xbmc/games/controllers/input/PortInput.cpp new file mode 100644 index 0000000000..dffd39a2c7 --- /dev/null +++ b/xbmc/games/controllers/input/PortInput.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2017-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#include "PortInput.h" + +#include "InputSink.h" +#include "games/addons/GameClient.h" +#include "guilib/WindowIDs.h" +#include "input/joysticks/keymaps/KeymapHandling.h" +#include "peripherals/devices/Peripheral.h" + +using namespace KODI; +using namespace GAME; + +CPortInput::CPortInput(JOYSTICK::IInputHandler* gameInput) + : m_gameInput(gameInput), m_inputSink(new CInputSink(gameInput)) +{ +} + +CPortInput::~CPortInput() = default; + +void CPortInput::RegisterInput(JOYSTICK::IInputProvider* provider) +{ + // Give input sink the lowest priority by registering it before the other + // input handlers + provider->RegisterInputHandler(m_inputSink.get(), false); + + // Register input handler + provider->RegisterInputHandler(this, false); + + // Register GUI input + m_appInput.reset(new JOYSTICK::CKeymapHandling(provider, false, this)); +} + +void CPortInput::UnregisterInput(JOYSTICK::IInputProvider* provider) +{ + // Unregister in reverse order + if (provider == nullptr) + m_appInput->UnregisterInputProvider(); + m_appInput.reset(); + + if (provider != nullptr) + { + provider->UnregisterInputHandler(this); + provider->UnregisterInputHandler(m_inputSink.get()); + } +} + +std::string CPortInput::ControllerID() const +{ + return m_gameInput->ControllerID(); +} + +bool CPortInput::AcceptsInput(const std::string& feature) const +{ + return m_gameInput->AcceptsInput(feature); +} + +bool CPortInput::OnButtonPress(const std::string& feature, bool bPressed) +{ + if (bPressed && !m_gameInput->AcceptsInput(feature)) + return false; + + return m_gameInput->OnButtonPress(feature, bPressed); +} + +void CPortInput::OnButtonHold(const std::string& feature, unsigned int holdTimeMs) +{ + m_gameInput->OnButtonHold(feature, holdTimeMs); +} + +bool CPortInput::OnButtonMotion(const std::string& feature, + float magnitude, + unsigned int motionTimeMs) +{ + if (magnitude > 0.0f && !m_gameInput->AcceptsInput(feature)) + return false; + + return m_gameInput->OnButtonMotion(feature, magnitude, motionTimeMs); +} + +bool CPortInput::OnAnalogStickMotion(const std::string& feature, + float x, + float y, + unsigned int motionTimeMs) +{ + if ((x != 0.0f || y != 0.0f) && !m_gameInput->AcceptsInput(feature)) + return false; + + return m_gameInput->OnAnalogStickMotion(feature, x, y, motionTimeMs); +} + +bool CPortInput::OnAccelerometerMotion(const std::string& feature, float x, float y, float z) +{ + if (!m_gameInput->AcceptsInput(feature)) + return false; + + return m_gameInput->OnAccelerometerMotion(feature, x, y, z); +} + +bool CPortInput::OnWheelMotion(const std::string& feature, + float position, + unsigned int motionTimeMs) +{ + if ((position != 0.0f) && !m_gameInput->AcceptsInput(feature)) + return false; + + return m_gameInput->OnWheelMotion(feature, position, motionTimeMs); +} + +bool CPortInput::OnThrottleMotion(const std::string& feature, + float position, + unsigned int motionTimeMs) +{ + if ((position != 0.0f) && !m_gameInput->AcceptsInput(feature)) + return false; + + return m_gameInput->OnThrottleMotion(feature, position, motionTimeMs); +} + +int CPortInput::GetWindowID() const +{ + return WINDOW_FULLSCREEN_GAME; +} diff --git a/xbmc/games/controllers/input/PortInput.h b/xbmc/games/controllers/input/PortInput.h new file mode 100644 index 0000000000..4e296a376c --- /dev/null +++ b/xbmc/games/controllers/input/PortInput.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2017-2018 Team Kodi + * This file is part of Kodi - https://kodi.tv + * + * SPDX-License-Identifier: GPL-2.0-or-later + * See LICENSES/README.md for more information. + */ + +#pragma once + +#include "input/KeymapEnvironment.h" +#include "input/joysticks/interfaces/IInputHandler.h" + +#include + +namespace KODI +{ +namespace JOYSTICK +{ +class CKeymapHandling; +class IInputProvider; +} // namespace JOYSTICK + +namespace GAME +{ +class CPortInput : public JOYSTICK::IInputHandler, public IKeymapEnvironment +{ +public: + CPortInput(JOYSTICK::IInputHandler* gameInput); + ~CPortInput() override; + + void RegisterInput(JOYSTICK::IInputProvider* provider); + void UnregisterInput(JOYSTICK::IInputProvider* provider); + + JOYSTICK::IInputHandler* InputHandler() { return m_gameInput; } + + // Implementation of IInputHandler + std::string ControllerID() const override; + bool HasFeature(const std::string& feature) const override { return true; } + bool AcceptsInput(const std::string& feature) const override; + bool OnButtonPress(const std::string& feature, bool bPressed) override; + void OnButtonHold(const std::string& feature, unsigned int holdTimeMs) override; + bool OnButtonMotion(const std::string& feature, + float magnitude, + unsigned int motionTimeMs) override; + bool OnAnalogStickMotion(const std::string& feature, + float x, + float y, + unsigned int motionTimeMs) override; + bool OnAccelerometerMotion(const std::string& feature, float x, float y, float z) override; + bool OnWheelMotion(const std::string& feature, + float position, + unsigned int motionTimeMs) override; + bool OnThrottleMotion(const std::string& feature, + float position, + unsigned int motionTimeMs) override; + + // Implementation of IKeymapEnvironment + int GetWindowID() const override; + void SetWindowID(int windowId) override {} + int GetFallthrough(int windowId) const override { return -1; } + bool UseGlobalFallthrough() const override { return false; } + bool UseEasterEgg() const override { return false; } + +private: + // Construction parameters + JOYSTICK::IInputHandler* const m_gameInput; + + // Handles input to Kodi + std::unique_ptr m_appInput; + + // Prevents input falling through to Kodi when not handled by the game + std::unique_ptr m_inputSink; +}; +} // namespace GAME +} // namespace KODI diff --git a/xbmc/games/controllers/types/ControllerNode.cpp b/xbmc/games/controllers/types/ControllerNode.cpp index 50530d2642..c147ddc644 100644 --- a/xbmc/games/controllers/types/ControllerNode.cpp +++ b/xbmc/games/controllers/types/ControllerNode.cpp @@ -11,7 +11,7 @@ #include "ControllerHub.h" #include "PortNode.h" #include "games/controllers/Controller.h" -#include "games/controllers/ControllerTopology.h" +#include "games/controllers/input/PhysicalTopology.h" #include #include diff --git a/xbmc/games/controllers/types/PortNode.cpp b/xbmc/games/controllers/types/PortNode.cpp index b3df64764d..12a560f37f 100644 --- a/xbmc/games/controllers/types/PortNode.cpp +++ b/xbmc/games/controllers/types/PortNode.cpp @@ -9,7 +9,7 @@ #include "PortNode.h" #include "games/controllers/Controller.h" -#include "games/controllers/ControllerPort.h" +#include "games/controllers/input/PhysicalPort.h" #include "games/controllers/types/ControllerHub.h" #include @@ -87,7 +87,7 @@ void CPortNode::SetCompatibleControllers(ControllerNodeVec controllers) bool CPortNode::IsControllerAccepted(const std::string& controllerId) const { // Base case - CControllerPort port; + CPhysicalPort port; GetPort(port); if (port.IsCompatible(controllerId)) return true; @@ -107,7 +107,7 @@ bool CPortNode::IsControllerAccepted(const std::string& portAddress, if (m_address == portAddress) { // Base case - CControllerPort port; + CPhysicalPort port; GetPort(port); if (port.IsCompatible(controllerId)) bAccepted = true; @@ -127,11 +127,11 @@ bool CPortNode::IsControllerAccepted(const std::string& portAddress, return bAccepted; } -void CPortNode::GetPort(CControllerPort& port) const +void CPortNode::GetPort(CPhysicalPort& port) const { std::vector accepts; for (const CControllerNode& node : m_controllers) accepts.emplace_back(node.Controller()->ID()); - port = CControllerPort(m_portId, std::move(accepts)); + port = CPhysicalPort(m_portId, std::move(accepts)); } diff --git a/xbmc/games/controllers/types/PortNode.h b/xbmc/games/controllers/types/PortNode.h index 7104c7b9e4..3935fd9810 100644 --- a/xbmc/games/controllers/types/PortNode.h +++ b/xbmc/games/controllers/types/PortNode.h @@ -18,7 +18,7 @@ namespace KODI { namespace GAME { -class CControllerPort; +class CPhysicalPort; /*! * \brief Collection of nodes that can be connected to this port @@ -102,7 +102,7 @@ public: bool IsControllerAccepted(const std::string& portAddress, const std::string& controllerId) const; private: - void GetPort(CControllerPort& port) const; + void GetPort(CPhysicalPort& port) const; bool m_bConnected = false; unsigned int m_active = 0; diff --git a/xbmc/games/controllers/windows/GUIConfigurationWizard.cpp b/xbmc/games/controllers/windows/GUIConfigurationWizard.cpp index 7d319a5bc5..c3cad36f8a 100644 --- a/xbmc/games/controllers/windows/GUIConfigurationWizard.cpp +++ b/xbmc/games/controllers/windows/GUIConfigurationWizard.cpp @@ -10,9 +10,9 @@ #include "ServiceBroker.h" #include "games/controllers/Controller.h" -#include "games/controllers/ControllerFeature.h" #include "games/controllers/dialogs/GUIDialogAxisDetection.h" #include "games/controllers/guicontrols/GUIFeatureButton.h" +#include "games/controllers/input/PhysicalFeature.h" #include "input/IKeymap.h" #include "input/InputManager.h" #include "input/joysticks/JoystickUtils.h" @@ -104,7 +104,7 @@ bool CGUIConfigurationWizard::Abort(bool bWait /* = true */) return bWasRunning; } -void CGUIConfigurationWizard::RegisterKey(const CControllerFeature& key) +void CGUIConfigurationWizard::RegisterKey(const CPhysicalFeature& key) { if (key.Keycode() != XBMCK_UNKNOWN) m_keyMap[key.Keycode()] = key; @@ -266,7 +266,7 @@ bool CGUIConfigurationWizard::MapPrimitive(JOYSTICK::IButtonMap* buttonMap, auto it = m_keyMap.find(primitive.Keycode()); if (it != m_keyMap.end()) { - const CControllerFeature& key = it->second; + const CPhysicalFeature& key = it->second; currentButton->SetKey(key); m_inputEvent.Set(); } @@ -279,7 +279,7 @@ bool CGUIConfigurationWizard::MapPrimitive(JOYSTICK::IButtonMap* buttonMap, } else { - const CControllerFeature& feature = currentButton->Feature(); + const CPhysicalFeature& feature = currentButton->Feature(); if (primitive.Type() == PRIMITIVE_TYPE::RELATIVE_POINTER && feature.Type() != FEATURE_TYPE::RELPOINTER) diff --git a/xbmc/games/controllers/windows/GUIConfigurationWizard.h b/xbmc/games/controllers/windows/GUIConfigurationWizard.h index a9bc9de4bc..b69badf5c9 100644 --- a/xbmc/games/controllers/windows/GUIConfigurationWizard.h +++ b/xbmc/games/controllers/windows/GUIConfigurationWizard.h @@ -9,7 +9,7 @@ #pragma once #include "IConfigurationWindow.h" -#include "games/controllers/ControllerFeature.h" +#include "games/controllers/input/PhysicalFeature.h" #include "input/XBMC_keysym.h" #include "input/joysticks/DriverPrimitive.h" #include "input/joysticks/interfaces/IButtonMapper.h" @@ -50,7 +50,7 @@ public: const std::vector& buttons) override; void OnUnfocus(IFeatureButton* button) override; bool Abort(bool bWait = true) override; - void RegisterKey(const CControllerFeature& key) override; + void RegisterKey(const CPhysicalFeature& key) override; void UnregisterKeys() override; // implementation of IButtonMapper @@ -111,7 +111,7 @@ private: // Keyboard handling std::unique_ptr m_actionMap; - std::map m_keyMap; // Keycode -> feature + std::map m_keyMap; // Keycode -> feature }; } // namespace GAME } // namespace KODI diff --git a/xbmc/games/controllers/windows/GUIFeatureList.cpp b/xbmc/games/controllers/windows/GUIFeatureList.cpp index 617b83a977..d43c16d1ee 100644 --- a/xbmc/games/controllers/windows/GUIFeatureList.cpp +++ b/xbmc/games/controllers/windows/GUIFeatureList.cpp @@ -13,11 +13,11 @@ #include "games/addons/GameClient.h" #include "games/addons/input/GameClientInput.h" #include "games/controllers/Controller.h" -#include "games/controllers/ControllerFeature.h" #include "games/controllers/guicontrols/GUIFeatureButton.h" #include "games/controllers/guicontrols/GUIFeatureControls.h" #include "games/controllers/guicontrols/GUIFeatureFactory.h" #include "games/controllers/guicontrols/GUIFeatureTranslator.h" +#include "games/controllers/input/PhysicalFeature.h" #include "guilib/GUIButtonControl.h" #include "guilib/GUIControlGroupList.h" #include "guilib/GUIImage.h" @@ -87,7 +87,7 @@ void CGUIFeatureList::Load(const ControllerPtr& controller) m_controller = controller; // Get features - const std::vector& features = controller->Features(); + const std::vector& features = controller->Features(); // Split into groups auto featureGroups = GetFeatureGroups(features); @@ -184,13 +184,13 @@ void CGUIFeatureList::CleanupButtons(void) } std::vector CGUIFeatureList::GetFeatureGroups( - const std::vector& features) const + const std::vector& features) const { std::vector groups; // Get group names std::vector groupNames; - for (const CControllerFeature& feature : features) + for (const CPhysicalFeature& feature : features) { // Skip features not supported by the game client if (m_gameClient) @@ -258,13 +258,13 @@ bool CGUIFeatureList::HasButton(JOYSTICK::FEATURE_TYPE type) const } std::vector CGUIFeatureList::GetButtons( - const std::vector& features, unsigned int startIndex) + const std::vector& features, unsigned int startIndex) { std::vector buttons; // Create buttons unsigned int buttonIndex = startIndex; - for (const CControllerFeature& feature : features) + for (const CPhysicalFeature& feature : features) { BUTTON_TYPE buttonType = CGUIFeatureTranslator::GetButtonType(feature.Type()); @@ -283,15 +283,15 @@ std::vector CGUIFeatureList::GetButtons( } CGUIButtonControl* CGUIFeatureList::GetSelectKeyButton( - const std::vector& features, unsigned int buttonIndex) + const std::vector& features, unsigned int buttonIndex) { // Expose keycodes to the wizard - for (const CControllerFeature& feature : features) + for (const CPhysicalFeature& feature : features) { if (feature.Type() == JOYSTICK::FEATURE_TYPE::KEY) m_wizard->RegisterKey(feature); } return CGUIFeatureFactory::CreateButton(BUTTON_TYPE::SELECT_KEY, *m_guiButtonTemplate, m_wizard, - CControllerFeature(), buttonIndex); + CPhysicalFeature(), buttonIndex); } diff --git a/xbmc/games/controllers/windows/GUIFeatureList.h b/xbmc/games/controllers/windows/GUIFeatureList.h index c01f07ff70..c7df54f09f 100644 --- a/xbmc/games/controllers/windows/GUIFeatureList.h +++ b/xbmc/games/controllers/windows/GUIFeatureList.h @@ -10,8 +10,8 @@ #include "IConfigurationWindow.h" #include "games/GameTypes.h" -#include "games/controllers/ControllerFeature.h" #include "games/controllers/ControllerTypes.h" +#include "games/controllers/input/PhysicalFeature.h" #include "input/joysticks/JoystickTypes.h" class CGUIButtonControl; @@ -47,17 +47,17 @@ private: struct FeatureGroup { std::string groupName; - std::vector features; + std::vector features; /*! * True if this group is a button that allows the user to map a key of * their choosing. */ bool bIsVirtualKey = false; }; - std::vector GetFeatureGroups(const std::vector& features) const; - std::vector GetButtons(const std::vector& features, + std::vector GetFeatureGroups(const std::vector& features) const; + std::vector GetButtons(const std::vector& features, unsigned int startIndex); - CGUIButtonControl* GetSelectKeyButton(const std::vector& features, + CGUIButtonControl* GetSelectKeyButton(const std::vector& features, unsigned int buttonIndex); // GUI stuff diff --git a/xbmc/games/controllers/windows/IConfigurationWindow.h b/xbmc/games/controllers/windows/IConfigurationWindow.h index 6620de39be..017adf0f87 100644 --- a/xbmc/games/controllers/windows/IConfigurationWindow.h +++ b/xbmc/games/controllers/windows/IConfigurationWindow.h @@ -40,7 +40,7 @@ namespace KODI { namespace GAME { -class CControllerFeature; +class CPhysicalFeature; /*! * \brief A list populated by installed controllers @@ -151,7 +151,7 @@ public: /*! * \brief Get the feature represented by this button */ - virtual const CControllerFeature& Feature(void) const = 0; + virtual const CPhysicalFeature& Feature(void) const = 0; /*! * \brief Allow the wizard to include this feature in a list of buttons @@ -207,7 +207,7 @@ public: * * \param key The key that was pressed */ - virtual void SetKey(const CControllerFeature& key) {} + virtual void SetKey(const CPhysicalFeature& key) {} /*! * \brief Reset button after prompting for input has finished @@ -251,7 +251,7 @@ public: * This should be called before Run(). It allows the user to choose a key * to map instead of scrolling through a long list. */ - virtual void RegisterKey(const CControllerFeature& key) = 0; + virtual void RegisterKey(const CPhysicalFeature& key) = 0; /*! * \brief Unregister all registered keys diff --git a/xbmc/games/ports/CMakeLists.txt b/xbmc/games/ports/CMakeLists.txt deleted file mode 100644 index d9c6db3045..0000000000 --- a/xbmc/games/ports/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -set(SOURCES InputSink.cpp - Port.cpp) - -set(HEADERS InputSink.h - Port.h) - -core_add_library(gameports) diff --git a/xbmc/games/ports/InputSink.cpp b/xbmc/games/ports/InputSink.cpp deleted file mode 100644 index a48b4b9880..0000000000 --- a/xbmc/games/ports/InputSink.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2017-2018 Team Kodi - * This file is part of Kodi - https://kodi.tv - * - * SPDX-License-Identifier: GPL-2.0-or-later - * See LICENSES/README.md for more information. - */ - -#include "InputSink.h" - -#include "games/controllers/ControllerIDs.h" - -using namespace KODI; -using namespace GAME; - -CInputSink::CInputSink(JOYSTICK::IInputHandler* gameInput) : m_gameInput(gameInput) -{ -} - -std::string CInputSink::ControllerID(void) const -{ - return DEFAULT_CONTROLLER_ID; -} - -bool CInputSink::AcceptsInput(const std::string& feature) const -{ - return m_gameInput->AcceptsInput(feature); -} - -bool CInputSink::OnButtonPress(const std::string& feature, bool bPressed) -{ - return true; -} - -bool CInputSink::OnButtonMotion(const std::string& feature, - float magnitude, - unsigned int motionTimeMs) -{ - return true; -} - -bool CInputSink::OnAnalogStickMotion(const std::string& feature, - float x, - float y, - unsigned int motionTimeMs) -{ - return true; -} - -bool CInputSink::OnAccelerometerMotion(const std::string& feature, float x, float y, float z) -{ - return true; -} - -bool CInputSink::OnWheelMotion(const std::string& feature, - float position, - unsigned int motionTimeMs) -{ - return true; -} - -bool CInputSink::OnThrottleMotion(const std::string& feature, - float position, - unsigned int motionTimeMs) -{ - return true; -} diff --git a/xbmc/games/ports/InputSink.h b/xbmc/games/ports/InputSink.h deleted file mode 100644 index bd2d629dc3..0000000000 --- a/xbmc/games/ports/InputSink.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2017-2018 Team Kodi - * This file is part of Kodi - https://kodi.tv - * - * SPDX-License-Identifier: GPL-2.0-or-later - * See LICENSES/README.md for more information. - */ - -#pragma once - -#include "input/joysticks/interfaces/IInputHandler.h" - -namespace KODI -{ -namespace GAME -{ -class CGameClient; - -class CInputSink : public JOYSTICK::IInputHandler -{ -public: - explicit CInputSink(JOYSTICK::IInputHandler* gameInput); - - ~CInputSink() override = default; - - // Implementation of IInputHandler - std::string ControllerID() const override; - bool HasFeature(const std::string& feature) const override { return true; } - bool AcceptsInput(const std::string& feature) const override; - bool OnButtonPress(const std::string& feature, bool bPressed) override; - void OnButtonHold(const std::string& feature, unsigned int holdTimeMs) override {} - bool OnButtonMotion(const std::string& feature, - float magnitude, - unsigned int motionTimeMs) override; - bool OnAnalogStickMotion(const std::string& feature, - float x, - float y, - unsigned int motionTimeMs) override; - bool OnAccelerometerMotion(const std::string& feature, float x, float y, float z) override; - bool OnWheelMotion(const std::string& feature, - float position, - unsigned int motionTimeMs) override; - bool OnThrottleMotion(const std::string& feature, - float position, - unsigned int motionTimeMs) override; - -private: - // Construction parameters - JOYSTICK::IInputHandler* m_gameInput; -}; -} // namespace GAME -} // namespace KODI diff --git a/xbmc/games/ports/Port.cpp b/xbmc/games/ports/Port.cpp deleted file mode 100644 index 855d5d2492..0000000000 --- a/xbmc/games/ports/Port.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (C) 2017-2018 Team Kodi - * This file is part of Kodi - https://kodi.tv - * - * SPDX-License-Identifier: GPL-2.0-or-later - * See LICENSES/README.md for more information. - */ - -#include "Port.h" - -#include "InputSink.h" -#include "games/addons/GameClient.h" -#include "guilib/WindowIDs.h" -#include "input/joysticks/keymaps/KeymapHandling.h" -#include "peripherals/devices/Peripheral.h" - -using namespace KODI; -using namespace GAME; - -CPort::CPort(JOYSTICK::IInputHandler* gameInput) - : m_gameInput(gameInput), m_inputSink(new CInputSink(gameInput)) -{ -} - -CPort::~CPort() = default; - -void CPort::RegisterInput(JOYSTICK::IInputProvider* provider) -{ - // Give input sink the lowest priority by registering it before the other - // input handlers - provider->RegisterInputHandler(m_inputSink.get(), false); - - // Register input handler - provider->RegisterInputHandler(this, false); - - // Register GUI input - m_appInput.reset(new JOYSTICK::CKeymapHandling(provider, false, this)); -} - -void CPort::UnregisterInput(JOYSTICK::IInputProvider* provider) -{ - // Unregister in reverse order - if (provider == nullptr) - m_appInput->UnregisterInputProvider(); - m_appInput.reset(); - - if (provider != nullptr) - { - provider->UnregisterInputHandler(this); - provider->UnregisterInputHandler(m_inputSink.get()); - } -} - -std::string CPort::ControllerID() const -{ - return m_gameInput->ControllerID(); -} - -bool CPort::AcceptsInput(const std::string& feature) const -{ - return m_gameInput->AcceptsInput(feature); -} - -bool CPort::OnButtonPress(const std::string& feature, bool bPressed) -{ - if (bPressed && !m_gameInput->AcceptsInput(feature)) - return false; - - return m_gameInput->OnButtonPress(feature, bPressed); -} - -void CPort::OnButtonHold(const std::string& feature, unsigned int holdTimeMs) -{ - m_gameInput->OnButtonHold(feature, holdTimeMs); -} - -bool CPort::OnButtonMotion(const std::string& feature, float magnitude, unsigned int motionTimeMs) -{ - if (magnitude > 0.0f && !m_gameInput->AcceptsInput(feature)) - return false; - - return m_gameInput->OnButtonMotion(feature, magnitude, motionTimeMs); -} - -bool CPort::OnAnalogStickMotion(const std::string& feature, - float x, - float y, - unsigned int motionTimeMs) -{ - if ((x != 0.0f || y != 0.0f) && !m_gameInput->AcceptsInput(feature)) - return false; - - return m_gameInput->OnAnalogStickMotion(feature, x, y, motionTimeMs); -} - -bool CPort::OnAccelerometerMotion(const std::string& feature, float x, float y, float z) -{ - if (!m_gameInput->AcceptsInput(feature)) - return false; - - return m_gameInput->OnAccelerometerMotion(feature, x, y, z); -} - -bool CPort::OnWheelMotion(const std::string& feature, float position, unsigned int motionTimeMs) -{ - if ((position != 0.0f) && !m_gameInput->AcceptsInput(feature)) - return false; - - return m_gameInput->OnWheelMotion(feature, position, motionTimeMs); -} - -bool CPort::OnThrottleMotion(const std::string& feature, float position, unsigned int motionTimeMs) -{ - if ((position != 0.0f) && !m_gameInput->AcceptsInput(feature)) - return false; - - return m_gameInput->OnThrottleMotion(feature, position, motionTimeMs); -} - -int CPort::GetWindowID() const -{ - return WINDOW_FULLSCREEN_GAME; -} diff --git a/xbmc/games/ports/Port.h b/xbmc/games/ports/Port.h deleted file mode 100644 index a65ce9e28e..0000000000 --- a/xbmc/games/ports/Port.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2017-2018 Team Kodi - * This file is part of Kodi - https://kodi.tv - * - * SPDX-License-Identifier: GPL-2.0-or-later - * See LICENSES/README.md for more information. - */ - -#pragma once - -#include "input/KeymapEnvironment.h" -#include "input/joysticks/interfaces/IInputHandler.h" - -#include - -namespace KODI -{ -namespace JOYSTICK -{ -class CKeymapHandling; -class IInputProvider; -} // namespace JOYSTICK - -namespace GAME -{ -class CPort : public JOYSTICK::IInputHandler, public IKeymapEnvironment -{ -public: - CPort(JOYSTICK::IInputHandler* gameInput); - ~CPort() override; - - void RegisterInput(JOYSTICK::IInputProvider* provider); - void UnregisterInput(JOYSTICK::IInputProvider* provider); - - JOYSTICK::IInputHandler* InputHandler() { return m_gameInput; } - - // Implementation of IInputHandler - std::string ControllerID() const override; - bool HasFeature(const std::string& feature) const override { return true; } - bool AcceptsInput(const std::string& feature) const override; - bool OnButtonPress(const std::string& feature, bool bPressed) override; - void OnButtonHold(const std::string& feature, unsigned int holdTimeMs) override; - bool OnButtonMotion(const std::string& feature, - float magnitude, - unsigned int motionTimeMs) override; - bool OnAnalogStickMotion(const std::string& feature, - float x, - float y, - unsigned int motionTimeMs) override; - bool OnAccelerometerMotion(const std::string& feature, float x, float y, float z) override; - bool OnWheelMotion(const std::string& feature, - float position, - unsigned int motionTimeMs) override; - bool OnThrottleMotion(const std::string& feature, - float position, - unsigned int motionTimeMs) override; - - // Implementation of IKeymapEnvironment - int GetWindowID() const override; - void SetWindowID(int windowId) override {} - int GetFallthrough(int windowId) const override { return -1; } - bool UseGlobalFallthrough() const override { return false; } - bool UseEasterEgg() const override { return false; } - -private: - // Construction parameters - JOYSTICK::IInputHandler* const m_gameInput; - - // Handles input to Kodi - std::unique_ptr m_appInput; - - // Prevents input falling through to Kodi when not handled by the game - std::unique_ptr m_inputSink; -}; -} // namespace GAME -} // namespace KODI diff --git a/xbmc/input/joysticks/generic/ButtonMapping.cpp b/xbmc/input/joysticks/generic/ButtonMapping.cpp index b3ca8a4505..5ef4cc30ed 100644 --- a/xbmc/input/joysticks/generic/ButtonMapping.cpp +++ b/xbmc/input/joysticks/generic/ButtonMapping.cpp @@ -10,8 +10,8 @@ #include "ServiceBroker.h" #include "games/controllers/Controller.h" -#include "games/controllers/ControllerFeature.h" #include "games/controllers/ControllerManager.h" +#include "games/controllers/input/PhysicalFeature.h" #include "input/IKeymap.h" #include "input/InputTranslator.h" #include "input/Key.h" -- cgit v1.2.3