supertux
game_controller_manager.hpp
1 // SuperTux
2 // Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HEADER_SUPERTUX_CONTROL_GAME_CONTROLLER_MANAGER_HPP
18 #define HEADER_SUPERTUX_CONTROL_GAME_CONTROLLER_MANAGER_HPP
19 
20 #include <array>
21 #include <vector>
22 #include <unordered_map>
23 
24 #include "control/controller.hpp"
25 
26 class InputManager;
27 struct SDL_ControllerAxisEvent;
28 struct SDL_ControllerButtonEvent;
29 struct _SDL_GameController;
30 typedef struct _SDL_GameController SDL_GameController;
31 
38 {
39 public:
42 
43  void process_button_event(const SDL_ControllerButtonEvent& ev);
44  void process_axis_event(const SDL_ControllerAxisEvent& ev);
45 
46  void on_controller_added(int joystick_index);
47  void on_controller_removed(int instance_id);
48 
49  void on_player_removed(int player_id);
50  bool has_corresponding_game_controller(int player_id) const;
51 
53  int rumble(SDL_GameController* controller) const;
54 
55  void bind_controller(SDL_GameController* controller, int player_id);
56 
57  std::unordered_map<SDL_GameController*, int>& get_controller_mapping() { return m_game_controllers; }
58 
59 private:
60  InputManager* m_parent;
61  int m_deadzone;
62  std::unordered_map<SDL_GameController*, int> m_game_controllers;
63  std::array<bool, static_cast<int>(Control::CONTROLCOUNT)> m_stick_state;
64  std::array<bool, static_cast<int>(Control::CONTROLCOUNT)> m_button_state;
65 
66 private:
68  GameControllerManager& operator=(const GameControllerManager&) = delete;
69 };
70 
71 #endif
72 
73 /* EOF */
Definition: input_manager.hpp:39
int rumble(SDL_GameController *controller) const
Definition: game_controller_manager.cpp:327
Manages GameControllers.
Definition: game_controller_manager.hpp:37