xbmc
GameAgentManager.h
1 /*
2  * Copyright (C) 2017-2022 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 #pragma once
9 
10 #include "games/GameTypes.h"
11 #include "input/keyboard/interfaces/IKeyboardDriverHandler.h"
12 #include "input/mouse/interfaces/IMouseDriverHandler.h"
13 #include "peripherals/PeripheralTypes.h"
14 #include "utils/Observer.h"
15 
16 #include <map>
17 #include <memory>
18 #include <string>
19 
20 class CInputManager;
21 
22 namespace PERIPHERALS
23 {
24 class CPeripheral;
25 class CPeripherals;
26 } // namespace PERIPHERALS
27 
28 namespace KODI
29 {
30 namespace JOYSTICK
31 {
32 class IInputProvider;
33 }
34 
35 namespace GAME
36 {
37 class CGameAgent;
38 class CGameClient;
39 class CGameClientJoystick;
40 
54  public Observer,
57 {
58 public:
59  CGameAgentManager(PERIPHERALS::CPeripherals& peripheralManager, CInputManager& inputManager);
60 
61  virtual ~CGameAgentManager();
62 
63  // Lifecycle functions
64  void Start(GameClientPtr gameClient);
65  void Stop();
66  void Refresh();
67 
68  // Implementation of Observer
69  void Notify(const Observable& obs, const ObservableMessage msg) override;
70 
71  // Implementation of IKeyboardDriverHandler
72  bool OnKeyPress(const CKey& key) override;
73  void OnKeyRelease(const CKey& key) override {}
74 
75  // Implementation of IMouseDriverHandler
76  bool OnPosition(int x, int y) override;
77  bool OnButtonPress(MOUSE::BUTTON_ID button) override;
78  void OnButtonRelease(MOUSE::BUTTON_ID button) override {}
79 
80 private:
82  using PortAddress = std::string;
83  using JoystickMap = std::map<PortAddress, std::shared_ptr<CGameClientJoystick>>;
84  using PortMap = std::map<JOYSTICK::IInputProvider*, std::shared_ptr<CGameClientJoystick>>;
85 
86  // Internal interface
87  void ProcessJoysticks(PERIPHERALS::EventLockHandlePtr& inputHandlingLock);
88  void ProcessKeyboard();
89  void ProcessMouse();
90 
91  // Internal helpers
92  void UpdateExpiredJoysticks(const PERIPHERALS::PeripheralVector& joysticks,
93  PERIPHERALS::EventLockHandlePtr& inputHandlingLock);
94  void UpdateConnectedJoysticks(const PERIPHERALS::PeripheralVector& joysticks,
95  const PortMap& newPortMap,
96  PERIPHERALS::EventLockHandlePtr& inputHandlingLock);
97 
98  // Static functionals
99  static PortMap MapJoysticks(const PERIPHERALS::PeripheralVector& peripheralJoysticks,
100  const JoystickMap& gameClientjoysticks,
101  int playerLimit);
102 
103  // Construction parameters
104  PERIPHERALS::CPeripherals& m_peripheralManager;
105  CInputManager& m_inputManager;
106 
107  // State parameters
108  GameClientPtr m_gameClient;
109  bool m_bHasKeyboard = false;
110  bool m_bHasMouse = false;
111 
124  PortMap m_portMap;
125 };
126 } // namespace GAME
127 } // namespace KODI
Main input processing class.
Definition: InputManager.h:63
Definition: RetroPlayerInput.h:15
Class to manage game-playing agents for a running game client.
Definition: GameAgentManager.h:53
void OnKeyRelease(const CKey &key) override
A key has been released.
Definition: GameAgentManager.h:73
Controller configuration window.
Definition: AudioDecoder.h:18
Definition: Observer.h:31
Interface for handling mouse driver events.
Definition: IMouseDriverHandler.h:21
void OnButtonRelease(MOUSE::BUTTON_ID button) override
A mouse button has been released.
Definition: GameAgentManager.h:78
Interface for handling keyboard events.
Definition: IKeyboardDriverHandler.h:21
Definition: Observer.h:44
Definition: Key.h:135
Definition: Peripherals.h:49