]> git.localhorst.tv Git - l2e.git/blob - src/app/Input.h
removed useless comments
[l2e.git] / src / app / Input.h
1 #ifndef APP_INPUT_H_
2 #define APP_INPUT_H_
3
4 #include <SDL.h>
5 #include <map>
6
7 namespace app {
8
9 /// Maps SDL key events to virtual buttons.
10 /// Records the state and whether it was pressed/released in the current
11 /// iteration.
12 /// Multiple buttons can be passed by ORing them bitwise.
13 /// The MapKey(SDLKey, Button) function introduces a mapping for the given key
14 /// to the given virtual button. Each key can be assigned to one button only,
15 /// but there is no limit (well, except for memory, I guess) on how many keys
16 /// may map to the same button.
17 /// Each iteration should first call ResetInteractiveState() to drop the just
18 /// pressed/released information and then pass each SDL_KeyboardEvent to
19 /// HandleKeyboardEvent(const SDL_KeyboardEvent &).
20 /// The four DEBUG_? buttons do not map to any real SNES/Lufia 2 button and may
21 /// be used for debugging or non-gameplay-related input.
22 class Input {
23
24 public:
25         enum Button {
26                 PAD_UP = 0x0001,
27                 PAD_RIGHT = 0x0002,
28                 PAD_DOWN = 0x0004,
29                 PAD_LEFT = 0x0008,
30                 ACTION_A = 0x0010,
31                 ACTION_B = 0x0020,
32                 ACTION_X = 0x0040,
33                 ACTION_Y = 0x0080,
34                 START = 0x0100,
35                 SELECT = 0x0200,
36                 SHOULDER_RIGHT = 0x0400,
37                 SHOULDER_LEFT = 0x0800,
38
39                 DEBUG_1 = 0x1000,
40                 DEBUG_2 = 0x2000,
41                 DEBUG_3 = 0x4000,
42                 DEBUG_4 = 0x8000,
43         };
44
45 public:
46         Input();
47
48 public:
49         bool IsDown(int b) const {
50                 return down & b;
51         }
52         bool JustPressed(int b) const {
53                 return pressed & b;
54         }
55         bool JustReleased(int b) const {
56                 return released & b;
57         }
58
59 public:
60         void ResetInteractiveState() {
61                 pressed = 0;
62                 released = 0;
63         }
64         void HandleKeyboardEvent(const SDL_KeyboardEvent &);
65
66 public:
67         void MapKey(SDLKey k, Button b) {
68                 mapping[k] = b;
69         }
70
71 private:
72         std::map<SDLKey, Button> mapping;
73         Uint16 down;
74         Uint16 pressed;
75         Uint16 released;
76
77 };
78
79 }
80
81 #endif