SuperTuxKart
Loading...
Searching...
No Matches
input_manager.hpp
1// SuperTuxKart - a fun racing game with go-kart
2//
3// Copyright (C) 2004-2015 Steve Baker <sjbaker1@airmail.net>
4// Copyright (C) 2006-2015 SuperTuxKart-Team
5//
6// This program is free software; you can redistribute it and/or
7// modify it under the terms of the GNU General Public License
8// as published by the Free Software Foundation; either version 3
9// of the License, or (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with this program; if not, write to the Free Software
18// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20#ifndef HEADER_INPUT_MANAGER_HPP
21#define HEADER_INPUT_MANAGER_HPP
22
23#include <map>
24#include <memory>
25#include <string>
26#include <vector>
27#include <set>
28
29#include "guiengine/event_handler.hpp"
30#include "input/input.hpp"
31#include "utils/no_copy.hpp"
32
33#ifndef SERVER_ONLY
34#include <SDL_events.h>
35#endif
36
37class DeviceManager;
38class SDLController;
39
44class InputManager: public NoCopy
45{
46public:
47 enum InputDriverMode
48 {
49 MENU = 0,
50 INGAME,
51 INPUT_SENSE_KEYBOARD,
52 INPUT_SENSE_GAMEPAD,
53 BOOTSTRAP
54 };
55
56 // to put a delay before a new gamepad axis move is considered in menu
57 std::map<int, float> m_gamepads_timer;
58
59private:
60
61 DeviceManager *m_device_manager;
62 std::set<std::tuple<int, int>> m_sensed_input_high_gamepad;
63 std::set<int> m_sensed_input_high_kbd;
64 std::set<int> m_sensed_input_zero_gamepad;
65
66 InputDriverMode m_mode;
67
70
71 /* Helper values to store and track the relative mouse movements. If these
72 * values exceed the deadzone value the input is reported to the game. This
73 * makes the mouse behave like an analog axis on a gamepad/joystick.
74 */
75 int m_mouse_val_x, m_mouse_val_y;
76
77 void handleStaticAction(int id0, int value);
78 void inputSensing(Input::InputType type, int deviceID, int btnID,
79 Input::AxisDirection axisDirection, int value);
80
81#ifndef SERVER_ONLY
82 std::map<int, std::unique_ptr<SDLController> > m_sdl_controller;
83#endif
84
85public:
88 // void initGamePadDevices();
89
90 //void input();
91 GUIEngine::EventPropagation input(const irr::SEvent& event);
92
93 DeviceManager* getDeviceManager() { return m_device_manager; }
94
95 void setMode(InputDriverMode);
96 bool isInMode(InputDriverMode);
97 InputDriverMode getMode() { return m_mode; }
98
101 void setMasterPlayerOnly(bool enabled);
102
105 bool masterPlayerOnly() const;
106
107 void update(float dt);
108
111 int getPlayerKeyboardID() const;
112#ifdef SERVER_ONLY
113 size_t getGamepadCount() const { return 0; }
114#else
118 size_t getGamepadCount() const { return m_sdl_controller.size(); }
120 const irr::SEvent& getEventForGamePad(unsigned i) const;
121
122 void handleJoystick(SDL_Event& event);
123
124 SDLController* getSDLController(unsigned i);
125#endif
126
127 void dispatchInput(Input::InputType, int deviceID, int btnID,
128 Input::AxisDirection direction, int value,
129 bool shift_mask = false);
130 void addJoystick();
131};
132
133extern InputManager *input_manager;
134
135#endif
This class holds the list of all known devices (ands their configurations), as well as the list of cu...
Definition: device_manager.hpp:63
Class to handle input.
Definition: input_manager.hpp:45
size_t getGamepadCount() const
Returns number of active connected gamepad (with SDL), notice the disconnected gamepad will not be re...
Definition: input_manager.hpp:118
bool isInMode(InputDriverMode)
Queries the input driver whether it is in the given expected mode.
Definition: input_manager.cpp:1289
void setMasterPlayerOnly(bool enabled)
When this mode is enabled, only the master player will be able to play with menus (only works in 'ass...
Definition: input_manager.cpp:925
bool m_master_player_only
When at true, only the master player can play with menus.
Definition: input_manager.hpp:69
GUIEngine::EventPropagation input(const irr::SEvent &event)
Called on keyboard events [indirectly] by irrLicht.
Definition: input_manager.cpp:955
bool masterPlayerOnly() const
Returns whether only the master player should be allowed to perform changes in menus.
Definition: input_manager.cpp:937
InputManager()
Initialise input.
Definition: input_manager.cpp:104
const irr::SEvent & getEventForGamePad(unsigned i) const
Returns irrlicht joystick for gamepad visualization.
Definition: input_manager.cpp:269
void setMode(InputDriverMode)
Sets the mode of the input driver.
Definition: input_manager.cpp:1315
void inputSensing(Input::InputType type, int deviceID, int btnID, Input::AxisDirection axisDirection, int value)
Handles input when an input sensing mode (when configuring input)
Definition: input_manager.cpp:422
~InputManager()
Destructor.
Definition: input_manager.cpp:279
int getPlayerKeyboardID() const
Returns the ID of the player that plays with the keyboard, or -1 if none.
Definition: input_manager.cpp:569
void dispatchInput(Input::InputType, int deviceID, int btnID, Input::AxisDirection direction, int value, bool shift_mask=false)
Handles the conversion from some input to a GameAction and its distribution to the currently active m...
Definition: input_manager.cpp:603
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
Definition: sdl_controller.hpp:36