-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActionMap.cpp
49 lines (40 loc) · 1.38 KB
/
ActionMap.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "ActionMap.h"
extern Console console;
ActionMap::ActionMap() {
_input = NULL;
}
ActionState::AState ActionMap::GetState(const std::string & name) const {
std::map<Action, ActionState::AState, ActionComparer>::const_iterator found = _actionMap.find(Action(name));
if (found != _actionMap.end()) {
return found->second;
}
return ActionState::None;
}
void ActionMap::AddActionMapping(Action & action, SDLKey key) {
action.Key = key;
_actionMap[action] = ActionState::Default;
}
void ActionMap::AddActionMapping(Action & action, MOUSE_BSTATE mbState) {
action.MouseButtons = mbState;
_actionMap[action] = ActionState::Default;
}
void ActionMap::UpdateMapping(const InputState & input) {
std::map<Action, ActionState::AState, ActionComparer>::iterator i = _actionMap.begin();
_input = &input;
for (;i != _actionMap.end(); i++) {
if (input.KeyDown(i->first.Key)) {
i->second = ActionState::Pressed;
} else if (input.KeyUp(i->first.Key)) {
i->second = ActionState::Released;
} else {
i->second = ActionState::None;
}
if (i->first.MouseButtons) {
if (i->first.MouseButtons & input.mbPressed) {
i->second = ActionState::Pressed;
} else if (i->first.MouseButtons & input.mbReleased) {
i->second = ActionState::Released;
}
}
}
}