| author | saiam |
| Mon, 08 Dec 2008 21:00:50 +0000 | |
| changeset 309 | 05a39422c81e |
| parent 300 | 417183866f35 |
| child 311 | 440763821484 |
| permissions | -rw-r--r-- |
| 221 | 1 |
|
2 |
#define INPUT_CC |
|
3 |
||
4 |
#include "Input.hh" |
|
5 |
||
|
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
6 |
template <typename BitEnumType> struct InputKeymapEntry {
|
|
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
7 |
BitEnumType input; |
|
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
8 |
int keycode1, keycode2; |
| 221 | 9 |
}; |
10 |
||
|
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
11 |
InputKeymapEntry<PlayerInputBit> INPUT_PLAYER_KEYMAP[] = {
|
|
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
12 |
{ INPUT_AIM_UP, -CL_KEY_ENTER, CL_KEY_UP },
|
|
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
13 |
{ INPUT_AIM_DOWN, -CL_KEY_ENTER, CL_KEY_DOWN },
|
|
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
14 |
{ INPUT_MOVE_LEFT, -CL_KEY_ENTER, CL_KEY_LEFT },
|
|
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
15 |
{ INPUT_MOVE_RIGHT, -CL_KEY_ENTER, CL_KEY_RIGHT },
|
|
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
16 |
{ INPUT_JUMP, -CL_KEY_ENTER, CL_KEY_RSHIFT },
|
|
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
17 |
{ INPUT_DIG, CL_KEY_LEFT, CL_KEY_RIGHT },
|
|
282
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
237
diff
changeset
|
18 |
{ INPUT_SHOOT, CL_KEY_RCONTROL, 0 },
|
| 237 | 19 |
{ INPUT_CHANGE_PREV, CL_KEY_ENTER, CL_KEY_LEFT },
|
20 |
{ INPUT_CHANGE_NEXT, CL_KEY_ENTER, CL_KEY_RIGHT },
|
|
|
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
21 |
{ INPUT_ROPE, CL_KEY_ENTER, CL_KEY_RSHIFT },
|
|
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
22 |
{ INPUT_UNROPE, -CL_KEY_ENTER, CL_KEY_RSHIFT },
|
|
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
23 |
{ INPUT_ROPE_UP, CL_KEY_ENTER, CL_KEY_UP },
|
|
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
24 |
{ INPUT_ROPE_DOWN, CL_KEY_ENTER, CL_KEY_DOWN },
|
| 300 | 25 |
{ INPUT_SUICIDE, CL_KEY_LCONTROL, CL_KEY_K },
|
|
282
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
237
diff
changeset
|
26 |
{ INPUT_NONE, 0, 0 }
|
|
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
27 |
}; |
|
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
28 |
|
|
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
29 |
InputKeymapEntry<GuiInputBit> INPUT_GUI_KEYMAP[] = {
|
|
282
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
237
diff
changeset
|
30 |
{ GUI_INPUT_QUIT, CL_KEY_ESCAPE, 0 },
|
|
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
237
diff
changeset
|
31 |
{ GUI_INPUT_DISPLAY_WEAPON, CL_KEY_ENTER, 0 },
|
|
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
237
diff
changeset
|
32 |
{ GUI_INPUT_DEBUG_PLAYER, CL_KEY_I, 0 },
|
|
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
33 |
}; |
| 230 | 34 |
|
| 235 | 35 |
Input::Input (CL_InputDevice &keyboard) : |
36 |
keyboard(keyboard) |
|
37 |
{
|
|
38 |
||
39 |
} |
|
40 |
||
41 |
bool Input::checkKeycode (int keycode) {
|
|
| 230 | 42 |
if (keycode > 0) |
43 |
return keyboard.get_keycode(keycode); |
|
44 |
||
45 |
else if (keycode < 0) |
|
46 |
return !keyboard.get_keycode(-keycode); |
|
47 |
||
48 |
else // == 0 |
|
49 |
return true; |
|
50 |
} |
|
51 |
||
| 235 | 52 |
template <typename BitEnumType, typename BitMaskType> BitMaskType Input::buildMask (InputKeymapEntry<BitEnumType> *keymap) {
|
|
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
53 |
BitMaskType input_mask = 0; |
| 230 | 54 |
|
|
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
55 |
for (InputKeymapEntry<BitEnumType> *e = keymap; (e->keycode1 || e->keycode2) && e->input; e++) {
|
| 235 | 56 |
if (checkKeycode(e->keycode1) && checkKeycode(e->keycode2)) |
|
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
57 |
input_mask |= e->input; |
| 230 | 58 |
} |
59 |
||
|
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
60 |
return input_mask; |
| 230 | 61 |
} |
|
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
62 |
|
| 235 | 63 |
PlayerInput Input::readPlayerInput (void) {
|
64 |
return buildMask<PlayerInputBit, PlayerInput>(INPUT_PLAYER_KEYMAP); |
|
|
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
65 |
} |
|
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
66 |
|
| 235 | 67 |
GuiInput Input::readGuiInput (void) {
|
68 |
return buildMask<GuiInputBit, GuiInput>(INPUT_GUI_KEYMAP); |
|
|
233
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
69 |
} |
|
ff4ecea83cf5
start using CL_ResourceManager, change most draw methods to take a Graphics*, implment even better input handling, and draw weapon names
terom
parents:
230
diff
changeset
|
70 |