SuperTuxKart
gamepad_config.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2010-2015 SuperTuxKart-Team
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef HEADER_GAMEPD_CONFIG_HPP
20 #define HEADER_GAMEPD_CONFIG_HPP
21 
22 #include "input/binding.hpp"
23 #include "input/device_config.hpp"
24 #include "input/input.hpp"
25 #include "utils/cpp2011.hpp"
26 #include "utils/no_copy.hpp"
27 
28 #include <iosfwd>
29 #include <irrString.h>
30 #include <map>
31 #include <set>
32 #include <string>
33 #include <string>
34 #include <tuple>
35 
36 using namespace irr;
37 class SDLController;
38 
43 {
44 
45 private:
48 
51 
54 
57 
61 
62  bool m_use_force_feedback;
63  int m_auto_center;
64 
65  std::map<std::tuple<int, Input::AxisDirection>, int> m_sdl_mapping;
66 
67  std::set<int> m_digital_axes;
68 
69  bool getMappingTuple(const std::string& rhs,
70  std::tuple<int, Input::AxisDirection>& t);
71  void setBindingFromTuple(const PlayerAction action,
72  std::tuple<int, Input::AxisDirection>& t);
73 public:
74 
75  GamepadConfig ();
76  GamepadConfig(const std::string &name,
77  const int axis_count=0,
78  const int button_ount=0);
79  virtual ~GamepadConfig() {}
80 
81  core::stringw toString();
82 
83  virtual void save(std::ofstream& stream) OVERRIDE;
84  void setDefaultBinds ();
85  virtual core::stringw getBindingAsString(const PlayerAction action) const OVERRIDE;
86  virtual bool load(const XMLNode *config) OVERRIDE;
87  // ------------------------------------------------------------------------
89  virtual bool isAnalog(Input::InputType type, int id) const OVERRIDE;
90 
91  // ------------------------------------------------------------------------
94  virtual bool desensitize() const OVERRIDE { return m_desensitize;}
95 
96  // ------------------------------------------------------------------------
98  virtual int getNumberOfButtons() const OVERRIDE { return m_button_count; }
99 
100  // ------------------------------------------------------------------------
102  void setNumberOfButtons(int count) { m_button_count = count; }
103 
104  // ------------------------------------------------------------------------
106  virtual int getNumberOfAxes() const OVERRIDE { return m_axis_count; }
107 
108  // ------------------------------------------------------------------------
110  void setNumberOfAxis(int count) { m_axis_count = count; }
111 
112  // ------------------------------------------------------------------------
114  int getDeadzone() const { return m_deadzone; }
115  // ------------------------------------------------------------------------
116  virtual bool isGamePad() const OVERRIDE { return true; }
117  // ------------------------------------------------------------------------
118  virtual bool isKeyboard() const OVERRIDE { return false; }
119  // ------------------------------------------------------------------------
120  void initSDLController(const std::string& mapping, int buttons, int axes,
121  int hats);
122  // ------------------------------------------------------------------------
123  void initSDLMapping();
124  // ------------------------------------------------------------------------
125  bool useForceFeedback() const { return m_use_force_feedback; }
126  // ------------------------------------------------------------------------
127  void setForceFeedback(bool val) { m_use_force_feedback = val; }
128  // ------------------------------------------------------------------------
129  int getAutoCenterStrength() const { return m_auto_center; }
130  // ------------------------------------------------------------------------
131  void setAutoCenter(bool val) { m_auto_center = val; }
132 }; // class GamepadConfig
133 
134 #endif
int getDeadzone() const
Return deadzone of this configuration.
Definition: gamepad_config.hpp:114
contains the key bindings information related to one input device
Definition: device_config.hpp:41
PlayerAction
types of input events / what actions the players can do
Definition: input.hpp:116
void setNumberOfAxis(int count)
Sets the number of axis this device has.
Definition: gamepad_config.hpp:110
Definition: three_d_animation.hpp:32
bool m_desensitize
If set to true, map any analog axis from x in [0,1] to x^x –> at values close to 0 the joystick will...
Definition: gamepad_config.hpp:60
int m_axis_count
Number of axis this device has.
Definition: gamepad_config.hpp:47
virtual bool desensitize() const OVERRIDE
Returns true if this device should desensitize its input at values close to 0 (to avoid &#39;oversteering...
Definition: gamepad_config.hpp:94
specialisation of DeviceConfig for gamepad type devices
Definition: gamepad_config.hpp:42
int m_button_count
Number of buttons this device has.
Definition: gamepad_config.hpp:53
Definition: sdl_controller.hpp:35
int m_deadzone
Deadzone of this gamepad.
Definition: gamepad_config.hpp:56
virtual int getNumberOfButtons() const OVERRIDE
Returns the number of buttons in this configuration.
Definition: gamepad_config.hpp:98
utility class used to parse XML files
Definition: xml_node.hpp:47
void setNumberOfButtons(int count)
Sets the number of buttons this device has.
Definition: gamepad_config.hpp:102
int m_hat_count
Number of hat this device has.
Definition: gamepad_config.hpp:50
virtual int getNumberOfAxes() const OVERRIDE
Returns the number of axis of this configufation.
Definition: gamepad_config.hpp:106