Debian Codegraph @

src/game/inputhandler.hpp

raw symbols SCIP
1 // This file is part of Dust Racing 2D.
2 // Copyright (C) 2015 Jussi Lind <[email protected]>
3 //
4 // Dust Racing 2D 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 // Dust Racing 2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
15
16 #ifndef INPUTHANDLER_HPP
17 #define INPUTHANDLER_HPP
18
19 #include <bitset>
20 #include <vector>
21
22 //! Handler for players' interactions.
23 class InputHandler
24 {
25 public:
26 //! Possible actions.
27 enum class Action : int
28 {
29 Left = 0,
30 Right,
31 Up,
32 Down,
33 EndOfEnum
34 };
35
36 //! Constructor.
37 InputHandler(size_t maxPlayers);
38
39 //! Set state of the given action of the given player.
40 void setActionState(size_t playerIndex, Action action, bool state);
41
42 //! Get state of the given action of the given player.
43 bool getActionState(size_t playerIndex, Action action) const;
44
45 //! Reset the current actions.
46 void reset();
47
48 //! Enable/disable controls. Enabled by default.
49 static void setEnabled(bool state);
50
51 //! Return true if enabled.
52 static bool enabled();
53
54 private:
55 typedef std::vector<std::bitset<static_cast<int>(Action::EndOfEnum)>> ActionVector;
56
57 ActionVector m_playerActions;
58
59 static bool m_enabled;
60 };
61
62 #endif // INPUTHANDLER_HPP