author | terom |
Mon, 08 Dec 2008 12:02:20 +0000 | |
changeset 282 | e0e4dfc3e528 |
parent 237 | 3d5465bcb67d |
child 300 | 417183866f35 |
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 }, |
282
e0e4dfc3e528
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents:
237
diff
changeset
|
25 |
{ 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
|
26 |
}; |
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 |
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
|
29 |
{ 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
|
30 |
{ 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
|
31 |
{ 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
|
32 |
}; |
230 | 33 |
|
235 | 34 |
Input::Input (CL_InputDevice &keyboard) : |
35 |
keyboard(keyboard) |
|
36 |
{ |
|
37 |
||
38 |
} |
|
39 |
||
40 |
bool Input::checkKeycode (int keycode) { |
|
230 | 41 |
if (keycode > 0) |
42 |
return keyboard.get_keycode(keycode); |
|
43 |
||
44 |
else if (keycode < 0) |
|
45 |
return !keyboard.get_keycode(-keycode); |
|
46 |
||
47 |
else // == 0 |
|
48 |
return true; |
|
49 |
} |
|
50 |
||
235 | 51 |
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
|
52 |
BitMaskType input_mask = 0; |
230 | 53 |
|
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
|
54 |
for (InputKeymapEntry<BitEnumType> *e = keymap; (e->keycode1 || e->keycode2) && e->input; e++) { |
235 | 55 |
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
|
56 |
input_mask |= e->input; |
230 | 57 |
} |
58 |
||
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
|
59 |
return input_mask; |
230 | 60 |
} |
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
|
61 |
|
235 | 62 |
PlayerInput Input::readPlayerInput (void) { |
63 |
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
|
64 |
} |
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 |
|
235 | 66 |
GuiInput Input::readGuiInput (void) { |
67 |
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
|
68 |
} |
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 |