diff options
25 files changed, 282 insertions, 292 deletions
diff --git a/addons/skin.estuary/xml/Includes_Games.xml b/addons/skin.estuary/xml/Includes_Games.xml index 06302dfd13..636d7594f5 100644 --- a/addons/skin.estuary/xml/Includes_Games.xml +++ b/addons/skin.estuary/xml/Includes_Games.xml @@ -352,7 +352,7 @@ <bottom>-20</bottom> <left>-20</left> <right>-20</right> - <ondown>5</ondown> + <ondown>7</ondown> <label>$LOCALIZE[35110]</label> <font>font37</font> <textoffsetx>36</textoffsetx> @@ -433,26 +433,26 @@ </control> </control> <control type="group"> - <description>Area of the dialog for players</description> + <description>Area of the dialog for player controllers</description> <top>136</top> <height>576</height> <control type="image"> - <description>Player list background</description> + <description>Controller list background</description> <top>-20</top> <bottom>-20</bottom> <left>-20</left> <right>-20</right> <texture border="40">buttons/dialogbutton-nofo.png</texture> </control> - <control type="list" id="5"> - <description>Player list</description> + <control type="list" id="7"> + <description>Controller list</description> <onup>3</onup> - <ondown>6</ondown> + <ondown>10</ondown> <pagecontrol>61</pagecontrol> <scrolltime tween="sine">200</scrolltime> <orientation>vertical</orientation> <itemlayout width="1740" height="96"> - <include>GameDialogAgentLayout</include> + <include>AgentControllerList</include> </itemlayout> <focusedlayout width="1740" height="96"> <control type="image"> @@ -461,9 +461,9 @@ <left>-20</left> <right>-20</right> <texture border="40" colordiffuse="button_focus">buttons/dialogbutton-fo.png</texture> - <visible>Control.HasFocus(5)</visible> + <visible>Control.HasFocus(7)</visible> </control> - <include>GameDialogAgentLayout</include> + <include>AgentControllerList</include> </focusedlayout> <!-- Note to skinners: this control can be populated @@ -510,20 +510,20 @@ </control> </control> <control type="scrollbar" id="61"> - <description>Agent list scroll bar</description> + <description>Controller list scroll bar</description> <top>136</top> <height>576</height> <right>-12</right> <width>12</width> <orientation>vertical</orientation> </control> - <control type="grouplist" id="6"> + <control type="grouplist" id="10"> <description>Action buttons</description> <left>-20</left> <right>-20</right> <bottom>-20</bottom> <height>100</height> - <onup>5</onup> + <onup>7</onup> <orientation>horizontal</orientation> <itemgap>dialogbuttons_itemgap</itemgap> <include content="DefaultDialogButton"> @@ -535,9 +535,9 @@ </control> </control> </include> - <include name="GameDialogAgentLayout"> + <include name="AgentControllerList"> <control type="label"> - <description>Player name</description> + <description>Controller name as reported by the driver</description> <top>20</top> <left>20</left> <label>$INFO[ListItem.Label]</label> @@ -546,7 +546,7 @@ <align>left</align> </control> <control type="gamecontrollerlist"> - <description>Player's game controller list. Length should fit 13 listitems (12 players and one "input disabled" indicator).</description> + <description>Controller list which indicates the port a player's controller is connected to. Length should fit 13 listitems (12 controller items and one "input disabled" item).</description> <right>0</right> <width>1248</width> <orientation>horizontal</orientation> diff --git a/cmake/treedata/common/games.txt b/cmake/treedata/common/games.txt index 7549da6056..a669678c13 100644 --- a/cmake/treedata/common/games.txt +++ b/cmake/treedata/common/games.txt @@ -3,7 +3,6 @@ xbmc/games/addons games/addons xbmc/games/addons/cheevos games/addons/cheevos xbmc/games/addons/input games/addons/input xbmc/games/addons/streams games/addons/streams -xbmc/games/agents games/agents xbmc/games/agents/input games/agents/input xbmc/games/agents/windows games/agents/windows xbmc/games/controllers games/controllers diff --git a/xbmc/cores/RetroPlayer/RetroPlayerInput.cpp b/xbmc/cores/RetroPlayer/RetroPlayerInput.cpp index 0e6f813214..7fe19f7987 100644 --- a/xbmc/cores/RetroPlayer/RetroPlayerInput.cpp +++ b/xbmc/cores/RetroPlayer/RetroPlayerInput.cpp @@ -41,7 +41,7 @@ void CRetroPlayerInput::StartAgentManager() if (!m_bAgentManagerStarted) { m_bAgentManagerStarted = true; - m_processInfo.GetRenderContext().StartAgentManager(m_gameClient); + m_processInfo.GetRenderContext().StartAgentInput(m_gameClient); } } @@ -50,7 +50,7 @@ void CRetroPlayerInput::StopAgentManager() if (m_bAgentManagerStarted) { m_bAgentManagerStarted = false; - m_processInfo.GetRenderContext().StopAgentManager(); + m_processInfo.GetRenderContext().StopAgentInput(); } } diff --git a/xbmc/cores/RetroPlayer/rendering/RenderContext.cpp b/xbmc/cores/RetroPlayer/rendering/RenderContext.cpp index 9be9c74fb6..bc5d50fee6 100644 --- a/xbmc/cores/RetroPlayer/rendering/RenderContext.cpp +++ b/xbmc/cores/RetroPlayer/rendering/RenderContext.cpp @@ -9,7 +9,7 @@ #include "RenderContext.h" #include "games/GameServices.h" -#include "games/agents/GameAgentManager.h" +#include "games/agents/input/AgentInput.h" #include "rendering/RenderSystem.h" #include "settings/DisplaySettings.h" #include "settings/MediaSettings.h" @@ -310,12 +310,12 @@ RESOLUTION_INFO& CRenderContext::GetResolutionInfo(RESOLUTION resolution) return m_mediaSettings.GetDefaultGameSettings(); } -void CRenderContext::StartAgentManager(GAME::GameClientPtr gameClient) +void CRenderContext::StartAgentInput(GAME::GameClientPtr gameClient) { - m_gameServices.GameAgentManager().Start(std::move(gameClient)); + m_gameServices.AgentInput().Start(std::move(gameClient)); } -void CRenderContext::StopAgentManager() +void CRenderContext::StopAgentInput() { - m_gameServices.GameAgentManager().Stop(); + m_gameServices.AgentInput().Stop(); } diff --git a/xbmc/cores/RetroPlayer/rendering/RenderContext.h b/xbmc/cores/RetroPlayer/rendering/RenderContext.h index de663a4ad9..3f0c4c7524 100644 --- a/xbmc/cores/RetroPlayer/rendering/RenderContext.h +++ b/xbmc/cores/RetroPlayer/rendering/RenderContext.h @@ -105,8 +105,8 @@ public: ::CGameSettings& GetDefaultGameSettings(); // Agent functions - void StartAgentManager(GAME::GameClientPtr gameClient); - void StopAgentManager(); + void StartAgentInput(GAME::GameClientPtr gameClient); + void StopAgentInput(); private: // Construction parameters diff --git a/xbmc/games/GameServices.cpp b/xbmc/games/GameServices.cpp index da4377a4fd..adacf62c46 100644 --- a/xbmc/games/GameServices.cpp +++ b/xbmc/games/GameServices.cpp @@ -11,7 +11,7 @@ #include "controllers/Controller.h" #include "controllers/ControllerManager.h" #include "games/GameSettings.h" -#include "games/agents/GameAgentManager.h" +#include "games/agents/input/AgentInput.h" #include "profiles/ProfileManager.h" using namespace KODI; @@ -26,7 +26,7 @@ CGameServices::CGameServices(CControllerManager& controllerManager, m_gameRenderManager(renderManager), m_profileManager(profileManager), m_gameSettings(new CGameSettings()), - m_gameAgentManager(new CGameAgentManager(peripheralManager, inputManager)) + m_agentInput(std::make_unique<CAgentInput>(peripheralManager, inputManager)) { } diff --git a/xbmc/games/GameServices.h b/xbmc/games/GameServices.h index 41331e9ad6..a9de3cd14c 100644 --- a/xbmc/games/GameServices.h +++ b/xbmc/games/GameServices.h @@ -30,7 +30,7 @@ class CGUIGameRenderManager; namespace GAME { -class CGameAgentManager; +class CAgentInput; class CControllerManager; class CGameSettings; @@ -70,7 +70,7 @@ public: RETRO::CGUIGameRenderManager& GameRenderManager() { return m_gameRenderManager; } - CGameAgentManager& GameAgentManager() { return *m_gameAgentManager; } + CAgentInput& AgentInput() { return *m_agentInput; } private: // Construction parameters @@ -80,7 +80,7 @@ private: // Game services std::unique_ptr<CGameSettings> m_gameSettings; - std::unique_ptr<CGameAgentManager> m_gameAgentManager; + std::unique_ptr<CAgentInput> m_agentInput; }; } // namespace GAME } // namespace KODI diff --git a/xbmc/games/agents/CMakeLists.txt b/xbmc/games/agents/CMakeLists.txt deleted file mode 100644 index 523f55f1df..0000000000 --- a/xbmc/games/agents/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -set(SOURCES GameAgent.cpp - GameAgentManager.cpp -) - -set(HEADERS GameAgent.h - GameAgentManager.h -) - -core_add_library(games_agents) diff --git a/xbmc/games/agents/GameAgent.cpp b/xbmc/games/agents/input/AgentController.cpp index 93d97c72c1..8f3fe75b2c 100644 --- a/xbmc/games/agents/GameAgent.cpp +++ b/xbmc/games/agents/input/AgentController.cpp @@ -1,14 +1,14 @@ /* - * Copyright (C) 2017-2023 Team Kodi + * Copyright (C) 2017-2024 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 "GameAgent.h" +#include "AgentController.h" -#include "games/agents/input/GameAgentJoystick.h" +#include "AgentJoystick.h" #include "games/controllers/Controller.h" #include "games/controllers/ControllerLayout.h" #include "peripherals/devices/Peripheral.h" @@ -16,29 +16,28 @@ using namespace KODI; using namespace GAME; -CGameAgent::CGameAgent(PERIPHERALS::PeripheralPtr peripheral) - : m_peripheral(std::move(peripheral)), - m_joystick(std::make_unique<CGameAgentJoystick>(m_peripheral)) +CAgentController::CAgentController(PERIPHERALS::PeripheralPtr peripheral) + : m_peripheral(std::move(peripheral)), m_joystick(std::make_unique<CAgentJoystick>(m_peripheral)) { Initialize(); } -CGameAgent::~CGameAgent() +CAgentController::~CAgentController() { Deinitialize(); } -void CGameAgent::Initialize() +void CAgentController::Initialize() { m_joystick->Initialize(); } -void CGameAgent::Deinitialize() +void CAgentController::Deinitialize() { m_joystick->Deinitialize(); } -std::string CGameAgent::GetPeripheralName() const +std::string CAgentController::GetPeripheralName() const { std::string deviceName = m_peripheral->DeviceName(); @@ -53,12 +52,12 @@ std::string CGameAgent::GetPeripheralName() const return deviceName; } -const std::string& CGameAgent::GetPeripheralLocation() const +const std::string& CAgentController::GetPeripheralLocation() const { return m_peripheral->Location(); } -ControllerPtr CGameAgent::GetController() const +ControllerPtr CAgentController::GetController() const { // Use joystick controller if joystick is initialized ControllerPtr controller = m_joystick->Appearance(); @@ -69,12 +68,12 @@ ControllerPtr CGameAgent::GetController() const return m_peripheral->ControllerProfile(); } -CDateTime CGameAgent::LastActive() const +CDateTime CAgentController::LastActive() const { return m_peripheral->LastActive(); } -float CGameAgent::GetActivation() const +float CAgentController::GetActivation() const { return m_joystick->GetActivation(); } diff --git a/xbmc/games/agents/GameAgent.h b/xbmc/games/agents/input/AgentController.h index 6de736619c..ba70986b5b 100644 --- a/xbmc/games/agents/GameAgent.h +++ b/xbmc/games/agents/input/AgentController.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2023 Team Kodi + * Copyright (C) 2017-2024 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later @@ -18,21 +18,21 @@ namespace KODI { namespace GAME { -class CGameAgentJoystick; +class CAgentJoystick; /*! * \ingroup games * - * \brief Class to represent a game player (a.k.a. agent) + * \brief Class to represent the controller of a game player (a.k.a. agent) * * The term "agent" is used to distinguish game players from the myriad of other * uses of the term "player" in Kodi, such as media players and player cores. */ -class CGameAgent +class CAgentController { public: - CGameAgent(PERIPHERALS::PeripheralPtr peripheral); - ~CGameAgent(); + CAgentController(PERIPHERALS::PeripheralPtr peripheral); + ~CAgentController(); // Lifecycle functions void Initialize(); @@ -51,7 +51,7 @@ private: const PERIPHERALS::PeripheralPtr m_peripheral; // Input parameters - std::unique_ptr<CGameAgentJoystick> m_joystick; + std::unique_ptr<CAgentJoystick> m_joystick; }; } // namespace GAME diff --git a/xbmc/games/agents/GameAgentManager.cpp b/xbmc/games/agents/input/AgentInput.cpp index 4ba57a929e..06eeb67419 100644 --- a/xbmc/games/agents/GameAgentManager.cpp +++ b/xbmc/games/agents/input/AgentInput.cpp @@ -1,14 +1,14 @@ /* - * Copyright (C) 2017-2022 Team Kodi + * Copyright (C) 2017-2024 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 "GameAgentManager.h" +#include "AgentInput.h" -#include "GameAgent.h" +#include "AgentController.h" #include "games/addons/GameClient.h" #include "games/addons/input/GameClientInput.h" #include "games/addons/input/GameClientJoystick.h" @@ -25,8 +25,7 @@ using namespace KODI; using namespace GAME; -CGameAgentManager::CGameAgentManager(PERIPHERALS::CPeripherals& peripheralManager, - CInputManager& inputManager) +CAgentInput::CAgentInput(PERIPHERALS::CPeripherals& peripheralManager, CInputManager& inputManager) : m_peripheralManager(peripheralManager), m_inputManager(inputManager) { // Register callbacks @@ -35,7 +34,7 @@ CGameAgentManager::CGameAgentManager(PERIPHERALS::CPeripherals& peripheralManage m_inputManager.RegisterMouseDriverHandler(this); } -CGameAgentManager::~CGameAgentManager() +CAgentInput::~CAgentInput() { // Unregister callbacks in reverse order m_inputManager.UnregisterMouseDriverHandler(this); @@ -43,7 +42,7 @@ CGameAgentManager::~CGameAgentManager() m_peripheralManager.UnregisterObserver(this); } -void CGameAgentManager::Start(GameClientPtr gameClient) +void CAgentInput::Start(GameClientPtr gameClient) { // Initialize state m_gameClient = std::move(gameClient); @@ -53,7 +52,7 @@ void CGameAgentManager::Start(GameClientPtr gameClient) m_gameClient->Input().RegisterObserver(this); } -void CGameAgentManager::Stop() +void CAgentInput::Stop() { // Unregister callbacks in reverse order if (m_gameClient) @@ -79,13 +78,13 @@ void CGameAgentManager::Stop() } // Notify observers if anything changed - NotifyObservers(ObservableMessageGameAgentsChanged); + NotifyObservers(ObservableMessageAgentControllersChanged); // Reset state m_gameClient.reset(); } -void CGameAgentManager::Refresh() +void CAgentInput::Refresh() { if (m_gameClient) { @@ -101,10 +100,10 @@ void CGameAgentManager::Refresh() } // Notify observers if anything changed - NotifyObservers(ObservableMessageGameAgentsChanged); + NotifyObservers(ObservableMessageAgentControllersChanged); } -void CGameAgentManager::Notify(const Observable& obs, const ObservableMessage msg) +void CAgentInput::Notify(const Observable& obs, const ObservableMessage msg) { switch (msg) { @@ -119,31 +118,31 @@ void CGameAgentManager::Notify(const Observable& obs, const ObservableMessage ms } } -bool CGameAgentManager::OnKeyPress(const CKey& key) +bool CAgentInput::OnKeyPress(const CKey& key) { m_bHasKeyboard = true; return false; } -bool CGameAgentManager::OnPosition(int x, int y) +bool CAgentInput::OnPosition(int x, int y) { m_bHasMouse = true; return false; } -bool CGameAgentManager::OnButtonPress(MOUSE::BUTTON_ID button) +bool CAgentInput::OnButtonPress(MOUSE::BUTTON_ID button) { m_bHasMouse = true; return false; } -GameAgentVec CGameAgentManager::GetAgents() const +std::vector<std::shared_ptr<CAgentController>> CAgentInput::GetControllers() const { - std::lock_guard<std::mutex> lock(m_agentMutex); - return m_agents; + std::lock_guard<std::mutex> lock(m_controllerMutex); + return m_controllers; } -std::string CGameAgentManager::GetPortAddress(JOYSTICK::IInputProvider* inputProvider) const +std::string CAgentInput::GetPortAddress(JOYSTICK::IInputProvider* inputProvider) const { auto it = m_portMap.find(inputProvider); if (it != m_portMap.end()) @@ -152,7 +151,7 @@ std::string CGameAgentManager::GetPortAddress(JOYSTICK::IInputProvider* inputPro return ""; } -std::vector<std::string> CGameAgentManager::GetInputPorts() const +std::vector<std::string> CAgentInput::GetInputPorts() const { std::vector<std::string> inputPorts; @@ -165,7 +164,7 @@ std::vector<std::string> CGameAgentManager::GetInputPorts() const return inputPorts; } -float CGameAgentManager::GetPortActivation(const std::string& portAddress) const +float CAgentInput::GetPortActivation(const std::string& portAddress) const { float activation = 0.0f; @@ -175,20 +174,20 @@ float CGameAgentManager::GetPortActivation(const std::string& portAddress) const return activation; } -float CGameAgentManager::GetPeripheralActivation(const std::string& peripheralLocation) const +float CAgentInput::GetPeripheralActivation(const std::string& peripheralLocation) const { - std::lock_guard<std::mutex> lock(m_agentMutex); + std::lock_guard<std::mutex> lock(m_controllerMutex); - for (const GameAgentPtr& agent : m_agents) + for (const std::shared_ptr<CAgentController>& controller : m_controllers) { - if (agent->GetPeripheralLocation() == peripheralLocation) - return agent->GetActivation(); + if (controller->GetPeripheralLocation() == peripheralLocation) + return controller->GetActivation(); } return 0.0f; } -void CGameAgentManager::ProcessJoysticks(PERIPHERALS::EventLockHandlePtr& inputHandlingLock) +void CAgentInput::ProcessJoysticks(PERIPHERALS::EventLockHandlePtr& inputHandlingLock) { // Get system joysticks. // @@ -257,8 +256,8 @@ void CGameAgentManager::ProcessJoysticks(PERIPHERALS::EventLockHandlePtr& inputH }), joysticks.end()); - // Update agents - ProcessAgents(joysticks, inputHandlingLock); + // Update agent controllers + ProcessAgentControllers(joysticks, inputHandlingLock); // Update expired joysticks UpdateExpiredJoysticks(joysticks, inputHandlingLock); @@ -286,7 +285,7 @@ void CGameAgentManager::ProcessJoysticks(PERIPHERALS::EventLockHandlePtr& inputH } } -void CGameAgentManager::ProcessKeyboard() +void CAgentInput::ProcessKeyboard() { if (m_bHasKeyboard && m_gameClient->Input().SupportsKeyboard() && !m_gameClient->Input().IsKeyboardOpen()) @@ -309,7 +308,7 @@ void CGameAgentManager::ProcessKeyboard() } } -void CGameAgentManager::ProcessMouse() +void CAgentInput::ProcessMouse() { if (m_bHasMouse && m_gameClient->Input().SupportsMouse() && !m_gameClient->Input().IsMouseOpen()) { @@ -331,30 +330,30 @@ void CGameAgentManager::ProcessMouse() } } -void CGameAgentManager::ProcessAgents(const PERIPHERALS::PeripheralVector& joysticks, - PERIPHERALS::EventLockHandlePtr& inputHandlingLock) +void CAgentInput::ProcessAgentControllers(const PERIPHERALS::PeripheralVector& joysticks, + PERIPHERALS::EventLockHandlePtr& inputHandlingLock) { - std::lock_guard<std::mutex> lock(m_agentMutex); + std::lock_guard<std::mutex> lock(m_controllerMutex); - // Handle new and existing agents + // Handle new and existing controllers for (const auto& joystick : joysticks) { - auto it = std::find_if(m_agents.begin(), m_agents.end(), - [&joystick](const GameAgentPtr& agent) - { return agent->GetPeripheralLocation() == joystick->Location(); }); + auto it = std::find_if(m_controllers.begin(), m_controllers.end(), + [&joystick](const std::shared_ptr<CAgentController>& controller) + { return controller->GetPeripheralLocation() == joystick->Location(); }); - if (it == m_agents.end()) + if (it == m_controllers.end()) { - // Handle new agent - m_agents.emplace_back(std::make_shared<CGameAgent>(joystick)); + // Handle new controller + m_controllers.emplace_back(std::make_shared<CAgentController>(joystick)); SetChanged(true); } else { - CGameAgent& agent = **it; + CAgentController& agentController = **it; // Check if appearance has changed - ControllerPtr oldController = agent.GetController(); + ControllerPtr oldController = agentController.GetController(); ControllerPtr newController = joystick->ControllerProfile(); std::string oldControllerId = oldController ? oldController->ID() : ""; @@ -365,32 +364,33 @@ void CGameAgentManager::ProcessAgents(const PERIPHERALS::PeripheralVector& joyst if (!inputHandlingLock) inputHandlingLock = m_peripheralManager.RegisterEventLock(); - // Reinitialize agent - agent.Deinitialize(); - agent.Initialize(); + // Reinitialize agent's controller + agentController.Deinitialize(); + agentController.Initialize(); SetChanged(true); } } } - // Remove expired agents + // Remove expired controllers std::vector<std::string> expiredJoysticks; - for (const auto& agent : m_agents) + for (const auto& agentController : m_controllers) { - auto it = std::find_if(joysticks.begin(), joysticks.end(), - [&agent](const PERIPHERALS::PeripheralPtr& joystick) - { return agent->GetPeripheralLocation() == joystick->Location(); }); + auto it = + std::find_if(joysticks.begin(), joysticks.end(), + [&agentController](const PERIPHERALS::PeripheralPtr& joystick) + { return agentController->GetPeripheralLocation() == joystick->Location(); }); if (it == joysticks.end()) - expiredJoysticks.emplace_back(agent->GetPeripheralLocation()); + expiredJoysticks.emplace_back(agentController->GetPeripheralLocation()); } for (const std::string& expiredJoystick : expiredJoysticks) { - auto it = std::find_if(m_agents.begin(), m_agents.end(), - [&expiredJoystick](const GameAgentPtr& agent) - { return agent->GetPeripheralLocation() == expiredJoystick; }); - if (it != m_agents.end()) + auto it = std::find_if(m_controllers.begin(), m_controllers.end(), + [&expiredJoystick](const std::shared_ptr<CAgentController>& controller) + { return controller->GetPeripheralLocation() == expiredJoystick; }); + if (it != m_controllers.end()) { if (!inputHandlingLock) inputHandlingLock = m_peripheralManager.RegisterEventLock(); @@ -399,15 +399,15 @@ void CGameAgentManager::ProcessAgents(const PERIPHERALS::PeripheralVector& joyst (*it)->Deinitialize(); // Remove from list - m_agents.erase(it); + m_controllers.erase(it); SetChanged(true); } } } -void CGameAgentManager::UpdateExpiredJoysticks(const PERIPHERALS::PeripheralVector& joysticks, - PERIPHERALS::EventLockHandlePtr& inputHandlingLock) +void CAgentInput::UpdateExpiredJoysticks(const PERIPHERALS::PeripheralVector& joysticks, + PERIPHERALS::EventLockHandlePtr& inputHandlingLock) { // Make a copy - expired joysticks are removed from m_portMap PortMap portMapCopy = m_portMap; @@ -447,7 +447,7 @@ void CGameAgentManager::UpdateExpiredJoysticks(const PERIPHERALS::PeripheralVect } } -void CGameAgentManager::UpdateConnectedJoysticks( +void CAgentInput::UpdateConnectedJoysticks( const PERIPHERALS::PeripheralVector& joysticks, const PortMap& newPortMap, PERIPHERALS::EventLockHandlePtr& inputHandlingLock, @@ -511,7 +511,7 @@ void CGameAgentManager::UpdateConnectedJoysticks( } } -CGameAgentManager::PortMap CGameAgentManager::MapJoysticks( +CAgentInput::PortMap CAgentInput::MapJoysticks( const PERIPHERALS::PeripheralVector& peripheralJoysticks, const JoystickMap& gameClientjoysticks, CurrentPortMap& currentPorts, @@ -623,9 +623,9 @@ CGameAgentManager::PortMap CGameAgentManager::MapJoysticks( return result; } -void CGameAgentManager::MapJoystick(PERIPHERALS::PeripheralPtr peripheralJoystick, - std::shared_ptr<CGameClientJoystick> gameClientJoystick, - PortMap& result) +void CAgentInput::MapJoystick(PERIPHERALS::PeripheralPtr peripheralJoystick, + std::shared_ptr<CGameClientJoystick> gameClientJoystick, + PortMap& result) { // Upcast peripheral joystick to input provider JOYSTICK::IInputProvider* inputProvider = peripheralJoystick.get(); @@ -637,7 +637,7 @@ void CGameAgentManager::MapJoystick(PERIPHERALS::PeripheralPtr peripheralJoystic result[inputProvider] = std::move(gameClientJoystick); } -void CGameAgentManager::LogPeripheralMap( +void CAgentInput::LogPeripheralMap( const PeripheralMap& peripheralMap, const std::set<PERIPHERALS::PeripheralPtr>& disconnectedPeripherals) { diff --git a/xbmc/games/agents/GameAgentManager.h b/xbmc/games/agents/input/AgentInput.h index 99d8e5698d..19169bd473 100644 --- a/xbmc/games/agents/GameAgentManager.h +++ b/xbmc/games/agents/input/AgentInput.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2022 Team Kodi + * Copyright (C) 2017-2024 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later @@ -7,6 +7,7 @@ */ #pragma once +#include "AgentController.h" #include "games/GameTypes.h" #include "input/keyboard/interfaces/IKeyboardDriverHandler.h" #include "input/mouse/interfaces/IMouseDriverHandler.h" @@ -18,6 +19,7 @@ #include <mutex> #include <set> #include <string> +#include <vector> class CInputManager; @@ -52,15 +54,15 @@ class CGameClientJoystick; * occurs in the static function MapJoysticks(). The strategy is to simply * sort controllers by heuristics and greedily assign to game ports. */ -class CGameAgentManager : public Observable, - public Observer, - KEYBOARD::IKeyboardDriverHandler, - MOUSE::IMouseDriverHandler +class CAgentInput : public Observable, + public Observer, + KEYBOARD::IKeyboardDriverHandler, + MOUSE::IMouseDriverHandler { public: - CGameAgentManager(PERIPHERALS::CPeripherals& peripheralManager, CInputManager& inputManager); + CAgentInput(PERIPHERALS::CPeripherals& peripheralManager, CInputManager& inputManager); - virtual ~CGameAgentManager(); + virtual ~CAgentInput(); // Lifecycle functions void Start(GameClientPtr gameClient); @@ -80,7 +82,7 @@ public: void OnButtonRelease(MOUSE::BUTTON_ID button) override {} // Public interface - GameAgentVec GetAgents() const; + std::vector<std::shared_ptr<CAgentController>> GetControllers() const; std::string GetPortAddress(JOYSTICK::IInputProvider* inputProvider) const; std::vector<std::string> GetInputPorts() const; float GetPortActivation(const std::string& address) const; @@ -105,8 +107,8 @@ private: void ProcessMouse(); // Internal helpers - void ProcessAgents(const PERIPHERALS::PeripheralVector& joysticks, - PERIPHERALS::EventLockHandlePtr& inputHandlingLock); + void ProcessAgentControllers(const PERIPHERALS::PeripheralVector& joysticks, + PERIPHERALS::EventLockHandlePtr& inputHandlingLock); void UpdateExpiredJoysticks(const PERIPHERALS::PeripheralVector& joysticks, PERIPHERALS::EventLockHandlePtr& inputHandlingLock); void UpdateConnectedJoysticks(const PERIPHERALS::PeripheralVector& joysticks, @@ -134,10 +136,10 @@ private: GameClientPtr m_gameClient; bool m_bHasKeyboard = false; bool m_bHasMouse = false; - GameAgentVec m_agents; + std::vector<std::shared_ptr<CAgentController>> m_controllers; // Synchronization parameters - mutable std::mutex m_agentMutex; + mutable std::mutex m_controllerMutex; /*! * \brief Map of input provider to joystick handler diff --git a/xbmc/games/agents/input/GameAgentJoystick.cpp b/xbmc/games/agents/input/AgentJoystick.cpp index 5be3e21bea..5e058a4e30 100644 --- a/xbmc/games/agents/input/GameAgentJoystick.cpp +++ b/xbmc/games/agents/input/AgentJoystick.cpp @@ -1,12 +1,12 @@ /* -* Copyright (C) 2023 Team Kodi +* Copyright (C) 2023-2024 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 "GameAgentJoystick.h" +#include "AgentJoystick.h" #include "games/controllers/Controller.h" #include "games/controllers/input/ControllerActivity.h" @@ -16,15 +16,15 @@ using namespace KODI; using namespace GAME; -CGameAgentJoystick::CGameAgentJoystick(PERIPHERALS::PeripheralPtr peripheral) +CAgentJoystick::CAgentJoystick(PERIPHERALS::PeripheralPtr peripheral) : m_peripheral(std::move(peripheral)), m_controllerActivity(std::make_unique<CControllerActivity>()) { } -CGameAgentJoystick::~CGameAgentJoystick() = default; +CAgentJoystick::~CAgentJoystick() = default; -void CGameAgentJoystick::Initialize() +void CAgentJoystick::Initialize() { // Record appearance to detect changes m_controllerAppearance = m_peripheral->ControllerProfile(); @@ -36,7 +36,7 @@ void CGameAgentJoystick::Initialize() inputProvider->RegisterInputHandler(this, true); } -void CGameAgentJoystick::Deinitialize() +void CAgentJoystick::Deinitialize() { // Upcast peripheral to input interface JOYSTICK::IInputProvider* inputProvider = m_peripheral.get(); @@ -48,12 +48,12 @@ void CGameAgentJoystick::Deinitialize() m_controllerAppearance.reset(); } -float CGameAgentJoystick::GetActivation() const +float CAgentJoystick::GetActivation() const { return m_controllerActivity->GetActivation(); } -std::string CGameAgentJoystick::ControllerID(void) const +std::string CAgentJoystick::ControllerID(void) const { if (m_controllerAppearance) return m_controllerAppearance->ID(); @@ -61,61 +61,61 @@ std::string CGameAgentJoystick::ControllerID(void) const return ""; } -bool CGameAgentJoystick::HasFeature(const std::string& feature) const +bool CAgentJoystick::HasFeature(const std::string& feature) const { return true; // Capture input for all features } -bool CGameAgentJoystick::AcceptsInput(const std::string& feature) const +bool CAgentJoystick::AcceptsInput(const std::string& feature) const { return true; // Accept input for all features } -bool CGameAgentJoystick::OnButtonPress(const std::string& feature, bool bPressed) +bool CAgentJoystick::OnButtonPress(const std::string& feature, bool bPressed) { m_controllerActivity->OnButtonPress(bPressed); return true; } -void CGameAgentJoystick::OnButtonHold(const std::string& feature, unsigned int holdTimeMs) +void CAgentJoystick::OnButtonHold(const std::string& feature, unsigned int holdTimeMs) { m_controllerActivity->OnButtonPress(true); } -bool CGameAgentJoystick::OnButtonMotion(const std::string& feature, - float magnitude, - unsigned int motionTimeMs) +bool CAgentJoystick::OnButtonMotion(const std::string& feature, + float magnitude, + unsigned int motionTimeMs) { m_controllerActivity->OnButtonMotion(magnitude); return true; } -bool CGameAgentJoystick::OnAnalogStickMotion(const std::string& feature, - float x, - float y, - unsigned int motionTimeMs) +bool CAgentJoystick::OnAnalogStickMotion(const std::string& feature, + float x, + float y, + unsigned int motionTimeMs) { m_controllerActivity->OnAnalogStickMotion(x, y); return true; } -bool CGameAgentJoystick::OnWheelMotion(const std::string& feature, - float position, - unsigned int motionTimeMs) +bool CAgentJoystick::OnWheelMotion(const std::string& feature, + float position, + unsigned int motionTimeMs) { m_controllerActivity->OnWheelMotion(position); return true; } -bool CGameAgentJoystick::OnThrottleMotion(const std::string& feature, - float position, - unsigned int motionTimeMs) +bool CAgentJoystick::OnThrottleMotion(const std::string& feature, + float position, + unsigned int motionTimeMs) { m_controllerActivity->OnThrottleMotion(position); return true; } -void CGameAgentJoystick::OnInputFrame() +void CAgentJoystick::OnInputFrame() { m_controllerActivity->OnInputFrame(); } diff --git a/xbmc/games/agents/input/GameAgentJoystick.h b/xbmc/games/agents/input/AgentJoystick.h index 17dc6479c1..b84277df36 100644 --- a/xbmc/games/agents/input/GameAgentJoystick.h +++ b/xbmc/games/agents/input/AgentJoystick.h @@ -1,5 +1,5 @@ /* -* Copyright (C) 2023 Team Kodi +* Copyright (C) 2023-2024 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later @@ -23,12 +23,12 @@ class CControllerActivity; * * \brief Handles game controller events for game agent functionality */ -class CGameAgentJoystick : public JOYSTICK::IInputHandler +class CAgentJoystick : public JOYSTICK::IInputHandler { public: - CGameAgentJoystick(PERIPHERALS::PeripheralPtr peripheral); + CAgentJoystick(PERIPHERALS::PeripheralPtr peripheral); - ~CGameAgentJoystick() override; + ~CAgentJoystick() override; void Initialize(); void Deinitialize(); diff --git a/xbmc/games/agents/input/CMakeLists.txt b/xbmc/games/agents/input/CMakeLists.txt index 495a779cce..598b4161ee 100644 --- a/xbmc/games/agents/input/CMakeLists.txt +++ b/xbmc/games/agents/input/CMakeLists.txt @@ -1,7 +1,11 @@ -set(SOURCES GameAgentJoystick.cpp +set(SOURCES AgentController.cpp + AgentInput.cpp + AgentJoystick.cpp ) -set(HEADERS GameAgentJoystick.h +set(HEADERS AgentController.h + AgentInput.h + AgentJoystick.h ) -core_add_library(games_agent_input) +core_add_library(games_agents_input) diff --git a/xbmc/games/agents/windows/CMakeLists.txt b/xbmc/games/agents/windows/CMakeLists.txt index 712a8b6e78..ff5dd4a2bb 100644 --- a/xbmc/games/agents/windows/CMakeLists.txt +++ b/xbmc/games/agents/windows/CMakeLists.txt @@ -1,11 +1,11 @@ -set(SOURCES GUIAgentList.cpp +set(SOURCES GUIAgentControllerList.cpp GUIAgentWindow.cpp ) -set(HEADERS GUIAgentDefines.h - GUIAgentList.h +set(HEADERS GUIAgentControllerList.h + GUIAgentDefines.h GUIAgentWindow.h - IAgentList.h + IAgentControllerList.h ) core_add_library(games_agents_windows) diff --git a/xbmc/games/agents/windows/GUIAgentList.cpp b/xbmc/games/agents/windows/GUIAgentControllerList.cpp index 3a58102323..0994360d2c 100644 --- a/xbmc/games/agents/windows/GUIAgentList.cpp +++ b/xbmc/games/agents/windows/GUIAgentControllerList.cpp @@ -1,12 +1,12 @@ /* - * Copyright (C) 2022-2023 Team Kodi + * Copyright (C) 2022-2024 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 "GUIAgentList.h" +#include "GUIAgentControllerList.h" #include "FileItem.h" #include "GUIAgentDefines.h" @@ -17,8 +17,8 @@ #include "games/GameServices.h" #include "games/addons/GameClient.h" #include "games/addons/input/GameClientInput.h" -#include "games/agents/GameAgent.h" -#include "games/agents/GameAgentManager.h" +#include "games/agents/input/AgentController.h" +#include "games/agents/input/AgentInput.h" #include "games/controllers/Controller.h" #include "games/controllers/ControllerLayout.h" #include "guilib/GUIBaseContainer.h" @@ -39,31 +39,31 @@ using namespace KODI; using namespace GAME; -CGUIAgentList::CGUIAgentList(CGUIWindow& window) +CGUIAgentControllerList::CGUIAgentControllerList(CGUIWindow& window) : m_guiWindow(window), m_viewControl(std::make_unique<CGUIViewControl>()), m_vecItems(std::make_unique<CFileItemList>()) { } -CGUIAgentList::~CGUIAgentList() +CGUIAgentControllerList::~CGUIAgentControllerList() { Deinitialize(); } -void CGUIAgentList::OnWindowLoaded() +void CGUIAgentControllerList::OnWindowLoaded() { m_viewControl->Reset(); m_viewControl->SetParentWindow(m_guiWindow.GetID()); - m_viewControl->AddView(m_guiWindow.GetControl(CONTROL_AGENT_LIST)); + m_viewControl->AddView(m_guiWindow.GetControl(CONTROL_AGENT_CONTROLLER_LIST)); } -void CGUIAgentList::OnWindowUnload() +void CGUIAgentControllerList::OnWindowUnload() { m_viewControl->Reset(); } -bool CGUIAgentList::Initialize(GameClientPtr gameClient) +bool CGUIAgentControllerList::Initialize(GameClientPtr gameClient) { // Validate parameters if (!gameClient) @@ -80,18 +80,18 @@ bool CGUIAgentList::Initialize(GameClientPtr gameClient) // Register observers if (m_gameClient) m_gameClient->Input().RegisterObserver(this); - CServiceBroker::GetAddonMgr().Events().Subscribe(this, &CGUIAgentList::OnEvent); + CServiceBroker::GetAddonMgr().Events().Subscribe(this, &CGUIAgentControllerList::OnEvent); if (CServiceBroker::IsServiceManagerUp()) - CServiceBroker::GetGameServices().GameAgentManager().RegisterObserver(this); + CServiceBroker::GetGameServices().AgentInput().RegisterObserver(this); return true; } -void CGUIAgentList::Deinitialize() +void CGUIAgentControllerList::Deinitialize() { // Unregister observers in reverse order if (CServiceBroker::IsServiceManagerUp()) - CServiceBroker::GetGameServices().GameAgentManager().UnregisterObserver(this); + CServiceBroker::GetGameServices().AgentInput().UnregisterObserver(this); CServiceBroker::GetAddonMgr().Events().Unsubscribe(this); if (m_gameClient) m_gameClient->Input().UnregisterObserver(this); @@ -103,20 +103,20 @@ void CGUIAgentList::Deinitialize() m_gameClient.reset(); } -bool CGUIAgentList::HasControl(int controlId) const +bool CGUIAgentControllerList::HasControl(int controlId) const { return m_viewControl->HasControl(controlId); } -int CGUIAgentList::GetCurrentControl() const +int CGUIAgentControllerList::GetCurrentControl() const { return m_viewControl->GetCurrentControl(); } -void CGUIAgentList::FrameMove() +void CGUIAgentControllerList::FrameMove() { CGUIBaseContainer* thumbs = - dynamic_cast<CGUIBaseContainer*>(m_guiWindow.GetControl(CONTROL_AGENT_LIST)); + dynamic_cast<CGUIBaseContainer*>(m_guiWindow.GetControl(CONTROL_AGENT_CONTROLLER_LIST)); if (thumbs != nullptr) { const int selectedItem = thumbs->GetSelectedItem(); @@ -129,18 +129,18 @@ void CGUIAgentList::FrameMove() } } -void CGUIAgentList::Refresh() +void CGUIAgentControllerList::Refresh() { // Send a synchronous message to clear the view control m_viewControl->Clear(); CleanupItems(); - CGameAgentManager& agentManager = CServiceBroker::GetGameServices().GameAgentManager(); + CAgentInput& agentInput = CServiceBroker::GetGameServices().AgentInput(); - GameAgentVec agents = agentManager.GetAgents(); - for (const GameAgentPtr& agent : agents) - AddItem(*agent); + std::vector<std::shared_ptr<CAgentController>> agentControllers = agentInput.GetControllers(); + for (const std::shared_ptr<CAgentController>& agentController : agentControllers) + AddItem(*agentController); // Add a "No controllers connected" item if no agents are available if (m_vecItems->IsEmpty()) @@ -166,26 +166,26 @@ void CGUIAgentList::Refresh() } } -void CGUIAgentList::SetFocused() +void CGUIAgentControllerList::SetFocused() { m_viewControl->SetFocused(); } -void CGUIAgentList::OnSelect() +void CGUIAgentControllerList::OnSelect() { const int itemIndex = m_viewControl->GetSelectedItem(); if (itemIndex >= 0) OnItemSelect(static_cast<unsigned int>(itemIndex)); } -void CGUIAgentList::Notify(const Observable& obs, const ObservableMessage msg) +void CGUIAgentControllerList::Notify(const Observable& obs, const ObservableMessage msg) { switch (msg) { - case ObservableMessageGameAgentsChanged: + case ObservableMessageAgentControllersChanged: case ObservableMessageGamePortsChanged: { - CGUIMessage msg(GUI_MSG_REFRESH_LIST, m_guiWindow.GetID(), CONTROL_AGENT_LIST); + CGUIMessage msg(GUI_MSG_REFRESH_LIST, m_guiWindow.GetID(), CONTROL_AGENT_CONTROLLER_LIST); CServiceBroker::GetAppMessenger()->SendGUIMessage(msg, m_guiWindow.GetID()); break; } @@ -194,25 +194,25 @@ void CGUIAgentList::Notify(const Observable& obs, const ObservableMessage msg) } } -void CGUIAgentList::OnEvent(const ADDON::AddonEvent& event) +void CGUIAgentControllerList::OnEvent(const ADDON::AddonEvent& event) { if (typeid(event) == typeid(ADDON::AddonEvents::Enabled) || // Also called on install typeid(event) == typeid(ADDON::AddonEvents::Disabled) || // Not called on uninstall typeid(event) == typeid(ADDON::AddonEvents::ReInstalled) || typeid(event) == typeid(ADDON::AddonEvents::UnInstalled)) { - CGUIMessage msg(GUI_MSG_REFRESH_LIST, m_guiWindow.GetID(), CONTROL_AGENT_LIST); + CGUIMessage msg(GUI_MSG_REFRESH_LIST, m_guiWindow.GetID(), CONTROL_AGENT_CONTROLLER_LIST); msg.SetStringParam(event.addonId); CServiceBroker::GetAppMessenger()->SendGUIMessage(msg, m_guiWindow.GetID()); } } -void CGUIAgentList::AddItem(const CGameAgent& agent) +void CGUIAgentControllerList::AddItem(const CAgentController& agentController) { // Create the list item from agent properties - const std::string label = agent.GetPeripheralName(); - const ControllerPtr controller = agent.GetController(); - const std::string& path = agent.GetPeripheralLocation(); + const std::string label = agentController.GetPeripheralName(); + const ControllerPtr controller = agentController.GetController(); + const std::string& path = agentController.GetPeripheralLocation(); CFileItemPtr item = std::make_shared<CFileItem>(label); item->SetPath(path); @@ -224,12 +224,12 @@ void CGUIAgentList::AddItem(const CGameAgent& agent) m_vecItems->Add(std::move(item)); } -void CGUIAgentList::CleanupItems() +void CGUIAgentControllerList::CleanupItems() { m_vecItems->Clear(); } -void CGUIAgentList::OnItemFocus(unsigned int itemIndex) +void CGUIAgentControllerList::OnItemFocus(unsigned int itemIndex) { // Remember the focused item m_currentItem = itemIndex; @@ -237,10 +237,10 @@ void CGUIAgentList::OnItemFocus(unsigned int itemIndex) // Handle the focused agent CFileItemPtr item = m_vecItems->Get(m_currentItem); if (item) - OnAgentFocus(item->GetPath()); + OnControllerFocus(item->GetPath()); } -void CGUIAgentList::OnAgentFocus(const std::string& focusedAgent) +void CGUIAgentControllerList::OnControllerFocus(const std::string& focusedAgent) { if (!focusedAgent.empty()) { @@ -249,22 +249,22 @@ void CGUIAgentList::OnAgentFocus(const std::string& focusedAgent) } } -void CGUIAgentList::OnItemSelect(unsigned int itemIndex) +void CGUIAgentControllerList::OnItemSelect(unsigned int itemIndex) { // Handle the selected agent CFileItemPtr item = m_vecItems->Get(itemIndex); if (item) - OnAgentSelect(*item); + OnControllerSelect(*item); } -void CGUIAgentList::OnAgentSelect(const CFileItem& selectedAgentItem) +void CGUIAgentControllerList::OnControllerSelect(const CFileItem& selectedAgentItem) { - CGameAgentManager& agentManager = CServiceBroker::GetGameServices().GameAgentManager(); + CAgentInput& agentInput = CServiceBroker::GetGameServices().AgentInput(); - GameAgentVec agents = agentManager.GetAgents(); - for (const GameAgentPtr& agent : agents) + std::vector<std::shared_ptr<CAgentController>> agentControllers = agentInput.GetControllers(); + for (const std::shared_ptr<CAgentController>& agentController : agentControllers) { - PERIPHERALS::PeripheralPtr peripheral = agent->GetPeripheral(); + PERIPHERALS::PeripheralPtr peripheral = agentController->GetPeripheral(); if (peripheral && peripheral->Location() == selectedAgentItem.GetPath()) { if (peripheral->GetSettings().empty()) @@ -278,14 +278,14 @@ void CGUIAgentList::OnAgentSelect(const CFileItem& selectedAgentItem) } else { - ShowAgentDialog(*agent); + ShowControllerDialog(*agentController); } break; } } } -void CGUIAgentList::ShowAgentDialog(const CGameAgent& agent) +void CGUIAgentControllerList::ShowControllerDialog(const CAgentController& agentController) { // Get the dialog PERIPHERALS::CGUIDialogPeripheralSettings* pSettingsDialog = @@ -295,7 +295,7 @@ void CGUIAgentList::ShowAgentDialog(const CGameAgent& agent) if (pSettingsDialog == nullptr) return; - const PERIPHERALS::PeripheralPtr peripheral = agent.GetPeripheral(); + const PERIPHERALS::PeripheralPtr peripheral = agentController.GetPeripheral(); // Get a file item for the peripheral settings dialog CFileItemPtr peripheralItem; diff --git a/xbmc/games/agents/windows/GUIAgentList.h b/xbmc/games/agents/windows/GUIAgentControllerList.h index 45aacbaba3..6637e35877 100644 --- a/xbmc/games/agents/windows/GUIAgentList.h +++ b/xbmc/games/agents/windows/GUIAgentControllerList.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Team Kodi + * Copyright (C) 2022-2024 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later @@ -8,7 +8,7 @@ #pragma once -#include "IAgentList.h" +#include "IAgentControllerList.h" #include "addons/AddonEvents.h" #include "games/GameTypes.h" #include "games/controllers/ControllerTypes.h" @@ -28,16 +28,18 @@ namespace KODI { namespace GAME { +class CAgentController; + /*! * \ingroup games */ -class CGUIAgentList : public IAgentList, public Observer +class CGUIAgentControllerList : public IAgentControllerList, public Observer { public: - CGUIAgentList(CGUIWindow& window); - ~CGUIAgentList() override; + CGUIAgentControllerList(CGUIWindow& window); + ~CGUIAgentControllerList() override; - // Implementation of IAgentList + // Implementation of IAgentControllerList void OnWindowLoaded() override; void OnWindowUnload() override; bool Initialize(GameClientPtr gameClient) override; @@ -57,13 +59,13 @@ private: void OnEvent(const ADDON::AddonEvent& event); // GUI functions - void AddItem(const CGameAgent& agent); + void AddItem(const CAgentController& agentController); void CleanupItems(); void OnItemFocus(unsigned int itemIndex); - void OnAgentFocus(const std::string& focusedAgent); + void OnControllerFocus(const std::string& focusedAgent); void OnItemSelect(unsigned int itemIndex); - void OnAgentSelect(const CFileItem& selectedAgentItem); - void ShowAgentDialog(const CGameAgent& agent); + void OnControllerSelect(const CFileItem& selectedAgentItem); + void ShowControllerDialog(const CAgentController& agentController); // Construction parameters CGUIWindow& m_guiWindow; diff --git a/xbmc/games/agents/windows/GUIAgentDefines.h b/xbmc/games/agents/windows/GUIAgentDefines.h index f5bddc2d76..8c06b206a0 100644 --- a/xbmc/games/agents/windows/GUIAgentDefines.h +++ b/xbmc/games/agents/windows/GUIAgentDefines.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017-2023 Team Kodi + * Copyright (C) 2017-2024 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later @@ -12,7 +12,7 @@ constexpr auto AGENT_DIALOG_XML = "DialogGameControllers.xml"; // GUI control IDs constexpr auto CONTROL_ACTIVE_PORT_LIST = 4; -constexpr auto CONTROL_AGENT_LIST = 5; +constexpr auto CONTROL_AGENT_CONTROLLER_LIST = 7; // GUI button IDs constexpr auto CONTROL_AGENT_CLOSE_BUTTON = 18; diff --git a/xbmc/games/agents/windows/GUIAgentWindow.cpp b/xbmc/games/agents/windows/GUIAgentWindow.cpp index ce899fa0ed..5e65ffcbd4 100644 --- a/xbmc/games/agents/windows/GUIAgentWindow.cpp +++ b/xbmc/games/agents/windows/GUIAgentWindow.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Team Kodi + * Copyright (C) 2022-2024 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later @@ -8,9 +8,8 @@ #include "GUIAgentWindow.h" +#include "GUIAgentControllerList.h" #include "GUIAgentDefines.h" -#include "GUIAgentList.h" -#include "IAgentList.h" #include "ServiceBroker.h" #include "addons/AddonManager.h" #include "addons/IAddon.h" @@ -33,7 +32,7 @@ using namespace GAME; CGUIAgentWindow::CGUIAgentWindow() : CGUIDialog(WINDOW_DIALOG_GAME_AGENTS, AGENT_DIALOG_XML), m_portList(std::make_unique<CGUIActivePortList>(*this, CONTROL_ACTIVE_PORT_LIST, true)), - m_agentList(std::make_unique<CGUIAgentList>(*this)) + m_controllerList(std::make_unique<CGUIAgentControllerList>(*this)) { // Initialize CGUIWindow m_loadType = KEEP_IN_MEMORY; @@ -51,9 +50,10 @@ bool CGUIAgentWindow::OnMessage(CGUIMessage& message) case GUI_MSG_SETFOCUS: { const int controlId = message.GetControlId(); - if (m_agentList->HasControl(controlId) && m_agentList->GetCurrentControl() != controlId) + if (m_controllerList->HasControl(controlId) && + m_controllerList->GetCurrentControl() != controlId) { - FocusAgentList(); + FocusControllerList(); bHandled = true; } break; @@ -67,12 +67,12 @@ bool CGUIAgentWindow::OnMessage(CGUIMessage& message) CloseDialog(); bHandled = true; } - else if (m_agentList->HasControl(controlId)) + else if (m_controllerList->HasControl(controlId)) { const int actionId = message.GetParam1(); if (actionId == ACTION_SELECT_ITEM || actionId == ACTION_MOUSE_LEFT_CLICK) { - OnAgentClick(); + OnControllerClick(); bHandled = true; } } @@ -89,9 +89,9 @@ bool CGUIAgentWindow::OnMessage(CGUIMessage& message) bHandled = true; break; } - case CONTROL_AGENT_LIST: + case CONTROL_AGENT_CONTROLLER_LIST: { - UpdateAgentList(); + UpdateControllerList(); bHandled = true; break; } @@ -115,19 +115,19 @@ void CGUIAgentWindow::FrameMove() { CGUIDialog::FrameMove(); - m_agentList->FrameMove(); + m_controllerList->FrameMove(); } void CGUIAgentWindow::OnWindowLoaded() { CGUIDialog::OnWindowLoaded(); - m_agentList->OnWindowLoaded(); + m_controllerList->OnWindowLoaded(); } void CGUIAgentWindow::OnWindowUnload() { - m_agentList->OnWindowUnload(); + m_controllerList->OnWindowUnload(); CGUIDialog::OnWindowUnload(); } @@ -153,13 +153,13 @@ void CGUIAgentWindow::OnInitWindow() // Initialize GUI m_portList->Initialize(m_gameClient); - m_agentList->Initialize(m_gameClient); + m_controllerList->Initialize(m_gameClient); } void CGUIAgentWindow::OnDeinitWindow(int nextWindowID) { // Deinitialize GUI - m_agentList->Deinitialize(); + m_controllerList->Deinitialize(); m_portList->Deinitialize(); // Deinitialize game properties @@ -178,17 +178,17 @@ void CGUIAgentWindow::UpdateActivePortList() m_portList->Refresh(); } -void CGUIAgentWindow::UpdateAgentList() +void CGUIAgentWindow::UpdateControllerList() { - m_agentList->Refresh(); + m_controllerList->Refresh(); } -void CGUIAgentWindow::FocusAgentList() +void CGUIAgentWindow::FocusControllerList() { - m_agentList->SetFocused(); + m_controllerList->SetFocused(); } -void CGUIAgentWindow::OnAgentClick() +void CGUIAgentWindow::OnControllerClick() { - m_agentList->OnSelect(); + m_controllerList->OnSelect(); } diff --git a/xbmc/games/agents/windows/GUIAgentWindow.h b/xbmc/games/agents/windows/GUIAgentWindow.h index 1834e15bb1..9f3513390e 100644 --- a/xbmc/games/agents/windows/GUIAgentWindow.h +++ b/xbmc/games/agents/windows/GUIAgentWindow.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022-2023 Team Kodi + * Copyright (C) 2022-2024 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later @@ -18,7 +18,7 @@ namespace KODI namespace GAME { class IActivePortList; -class IAgentList; +class IAgentControllerList; /*! * \ingroup games @@ -47,14 +47,14 @@ private: // Actions for port list void UpdateActivePortList(); - // Actions for agent list - void UpdateAgentList(); - void FocusAgentList(); - void OnAgentClick(); + // Actions for controller list + void UpdateControllerList(); + void FocusControllerList(); + void OnControllerClick(); // GUI parameters std::unique_ptr<IActivePortList> m_portList; - std::unique_ptr<IAgentList> m_agentList; + std::unique_ptr<IAgentControllerList> m_controllerList; // Game parameters GameClientPtr m_gameClient; diff --git a/xbmc/games/agents/windows/IAgentList.h b/xbmc/games/agents/windows/IAgentControllerList.h index 94521d5331..e29aa550da 100644 --- a/xbmc/games/agents/windows/IAgentList.h +++ b/xbmc/games/agents/windows/IAgentControllerList.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2023 Team Kodi + * Copyright (C) 2021-2024 Team Kodi * This file is part of Kodi - https://kodi.tv * * SPDX-License-Identifier: GPL-2.0-or-later @@ -17,25 +17,19 @@ namespace GAME /*! * \ingroup games * - * \brief A list populated by game-playing agents (\ref CGameAgent) + * \brief A list populated by the controllers of game-playing agents (\ref CGameAgent) * - * This class manages the behavior of the player list (with control ID 5) in + * This class manages the behavior of the controller list (with control ID 7) in * the player dialog (<b>`GameAgents`</b> window). * - * The list is populated dynamically by the players in the current game. - * - * Currently, this is identical to the connected joysticks, because Kodi doesn't - * yet have a player abstraction. This is planned for a later release along with - * a full-featured Player Manager. - * * The active ports are determined by \ref IActivePortList. * * The list is populated by the \ref CGUIGameControllerProvider. */ -class IAgentList +class IAgentControllerList { public: - virtual ~IAgentList() = default; + virtual ~IAgentControllerList() = default; /*! * \brief Callback when the GUI window is loaded diff --git a/xbmc/games/controllers/guicontrols/GUIGameController.cpp b/xbmc/games/controllers/guicontrols/GUIGameController.cpp index b7a3ce4a1e..8da9ab4608 100644 --- a/xbmc/games/controllers/guicontrols/GUIGameController.cpp +++ b/xbmc/games/controllers/guicontrols/GUIGameController.cpp @@ -12,7 +12,7 @@ #include "ServiceBroker.h" #include "games/GameServices.h" #include "games/addons/input/GameClientTopology.h" -#include "games/agents/GameAgentManager.h" +#include "games/agents/input/AgentInput.h" #include "games/controllers/Controller.h" #include "games/controllers/ControllerLayout.h" #include "guilib/GUIListItem.h" @@ -69,17 +69,16 @@ void CGUIGameController::DoProcess(unsigned int currentTime, CDirtyRegionList& d peripheralLocation = m_peripheralLocation; } - const GAME::CGameAgentManager& agentManager = - CServiceBroker::GetGameServices().GameAgentManager(); + const GAME::CAgentInput& agentInput = CServiceBroker::GetGameServices().AgentInput(); // Highlight the controller if it is active float activation = 0.0f; if (!portAddress.empty()) - activation = agentManager.GetPortActivation(portAddress); + activation = agentInput.GetPortActivation(portAddress); if (!peripheralLocation.empty()) - activation = std::max(agentManager.GetPeripheralActivation(peripheralLocation), activation); + activation = std::max(agentInput.GetPeripheralActivation(peripheralLocation), activation); SetActivation(activation); diff --git a/xbmc/games/controllers/guicontrols/GUIGameControllerList.cpp b/xbmc/games/controllers/guicontrols/GUIGameControllerList.cpp index 71974d729f..f6f22ce6f7 100644 --- a/xbmc/games/controllers/guicontrols/GUIGameControllerList.cpp +++ b/xbmc/games/controllers/guicontrols/GUIGameControllerList.cpp @@ -15,8 +15,8 @@ #include "games/addons/input/GameClientInput.h" #include "games/addons/input/GameClientJoystick.h" #include "games/addons/input/GameClientTopology.h" -#include "games/agents/GameAgent.h" -#include "games/agents/GameAgentManager.h" +#include "games/agents/input/AgentController.h" +#include "games/agents/input/AgentInput.h" #include "games/controllers/Controller.h" #include "games/controllers/listproviders/GUIGameControllerProvider.h" #include "guilib/GUIListItem.h" @@ -65,10 +65,10 @@ void CGUIGameControllerList::UpdateInfo(const CGUIListItem* item) if (item == nullptr) return; - CGameAgentManager& agentManager = CServiceBroker::GetGameServices().GameAgentManager(); + CAgentInput& agentInput = CServiceBroker::GetGameServices().AgentInput(); // Update port count - const std::vector<std::string> inputPorts = agentManager.GetInputPorts(); + const std::vector<std::string> inputPorts = agentInput.GetInputPorts(); m_portCount = inputPorts.size(); // Update port index @@ -148,30 +148,30 @@ void CGUIGameControllerList::UpdatePort(int itemNumber, const std::vector<std::s if (itemNumber < 1) return; - const unsigned int agentIndex = static_cast<unsigned int>(itemNumber - 1); + const unsigned int controllerIndex = static_cast<unsigned int>(itemNumber - 1); - CGameAgentManager& agentManager = CServiceBroker::GetGameServices().GameAgentManager(); + CAgentInput& agentInput = CServiceBroker::GetGameServices().AgentInput(); - GameAgentVec agents = agentManager.GetAgents(); - if (agentIndex < static_cast<unsigned int>(agents.size())) + std::vector<std::shared_ptr<CAgentController>> agentControllers = agentInput.GetControllers(); + if (controllerIndex < static_cast<unsigned int>(agentControllers.size())) { - const GameAgentPtr& agent = agents.at(agentIndex); - UpdatePortIndex(agent->GetPeripheral(), inputPorts); - UpdatePeripheral(agent->GetPeripheral()); + const std::shared_ptr<CAgentController>& agentController = agentControllers.at(controllerIndex); + UpdatePortIndex(agentController->GetPeripheral(), inputPorts); + UpdatePeripheral(agentController->GetPeripheral()); } } void CGUIGameControllerList::UpdatePortIndex(const PERIPHERALS::PeripheralPtr& agentPeripheral, const std::vector<std::string>& inputPorts) { - CGameAgentManager& agentManager = CServiceBroker::GetGameServices().GameAgentManager(); + CAgentInput& agentInput = CServiceBroker::GetGameServices().AgentInput(); // Upcast peripheral to input provider JOYSTICK::IInputProvider* const inputProvider = static_cast<JOYSTICK::IInputProvider*>(agentPeripheral.get()); // See if the input provider has a port address - std::string portAddress = agentManager.GetPortAddress(inputProvider); + std::string portAddress = agentInput.GetPortAddress(inputProvider); if (portAddress.empty()) return; diff --git a/xbmc/utils/Observer.h b/xbmc/utils/Observer.h index 49c9b3c2ab..27a6af4157 100644 --- a/xbmc/utils/Observer.h +++ b/xbmc/utils/Observer.h @@ -25,7 +25,7 @@ typedef enum // Used for example when the subtitle alignment position change ObservableMessagePositionChanged, ObservableMessageGamePortsChanged, - ObservableMessageGameAgentsChanged, + ObservableMessageAgentControllersChanged, } ObservableMessage; class Observer |