]> git.lizzy.rs Git - dragonfireclient.git/blob - src/game.h
Add missing keyname_to_keycode function (needed on Android)
[dragonfireclient.git] / src / game.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef GAME_HEADER
21 #define GAME_HEADER
22
23 #include "irrlichttypes_extrabloated.h"
24 #include <string>
25 #include "client/keys.h"
26 #include "client/joystick_controller.h"
27 #include "keycode.h"
28 #include <list>
29
30 class KeyList : protected std::list<KeyPress>
31 {
32         typedef std::list<KeyPress> super;
33         typedef super::iterator iterator;
34         typedef super::const_iterator const_iterator;
35
36         virtual const_iterator find(const KeyPress &key) const
37         {
38                 const_iterator f(begin());
39                 const_iterator e(end());
40
41                 while (f != e) {
42                         if (*f == key)
43                                 return f;
44
45                         ++f;
46                 }
47
48                 return e;
49         }
50
51         virtual iterator find(const KeyPress &key)
52         {
53                 iterator f(begin());
54                 iterator e(end());
55
56                 while (f != e) {
57                         if (*f == key)
58                                 return f;
59
60                         ++f;
61                 }
62
63                 return e;
64         }
65
66 public:
67         void clear()
68         {
69                 super::clear();
70         }
71
72         void set(const KeyPress &key)
73         {
74                 if (find(key) == end())
75                         push_back(key);
76         }
77
78         void unset(const KeyPress &key)
79         {
80                 iterator p(find(key));
81
82                 if (p != end())
83                         erase(p);
84         }
85
86         void toggle(const KeyPress &key)
87         {
88                 iterator p(this->find(key));
89
90                 if (p != end())
91                         erase(p);
92                 else
93                         push_back(key);
94         }
95
96         bool operator[](const KeyPress &key) const
97         {
98                 return find(key) != end();
99         }
100 };
101
102 class InputHandler
103 {
104 public:
105         InputHandler()
106         {
107         }
108         virtual ~InputHandler()
109         {
110         }
111
112         virtual bool isKeyDown(const KeyPress &keyCode) = 0;
113         virtual bool wasKeyDown(const KeyPress &keyCode) = 0;
114
115         virtual void listenForKey(const KeyPress &keyCode) {}
116         virtual void dontListenForKeys() {}
117
118         virtual v2s32 getMousePos() = 0;
119         virtual void setMousePos(s32 x, s32 y) = 0;
120
121         virtual bool getLeftState() = 0;
122         virtual bool getRightState() = 0;
123
124         virtual bool getLeftClicked() = 0;
125         virtual bool getRightClicked() = 0;
126         virtual void resetLeftClicked() = 0;
127         virtual void resetRightClicked() = 0;
128
129         virtual bool getLeftReleased() = 0;
130         virtual bool getRightReleased() = 0;
131         virtual void resetLeftReleased() = 0;
132         virtual void resetRightReleased() = 0;
133
134         virtual s32 getMouseWheel() = 0;
135
136         virtual void step(float dtime) {}
137
138         virtual void clear() {}
139
140         JoystickController joystick;
141 };
142
143 class ChatBackend;  /* to avoid having to include chat.h */
144 struct SubgameSpec;
145
146 void the_game(bool *kill,
147                 bool random_input,
148                 InputHandler *input,
149                 IrrlichtDevice *device,
150                 const std::string &map_dir,
151                 const std::string &playername,
152                 const std::string &password,
153                 const std::string &address, // If "", local server is used
154                 u16 port,
155                 std::string &error_message,
156                 ChatBackend &chat_backend,
157                 bool *reconnect_requested,
158                 const SubgameSpec &gamespec, // Used for local game
159                 bool simple_singleplayer_mode);
160
161 #endif
162