-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputHandler.cpp
More file actions
49 lines (41 loc) · 789 Bytes
/
Copy pathInputHandler.cpp
File metadata and controls
49 lines (41 loc) · 789 Bytes
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 "InputHandler.h"
std::map<sf::Keyboard::Key,KeyState> InputHandler::Key_={};
InputHandler::InputHandler()
{
if (Key_.empty())
{
for (auto I=0; I<sf::Keyboard::KeyCount;I++)
{
Key_[static_cast<sf::Keyboard::Key>(I)]=KeyState::Released;
}
}
}
void InputHandler::Notify(const sf::Keyboard::Key Key)
{
for (auto& Sub :Subs) {
Sub->Update(Key);
}
}
void InputHandler::Subscribe(Observer* Sub)
{
Subs.push_back(Sub);
}
void InputHandler::HandleInput()
{
for(auto I=0; I<sf::Keyboard::KeyCount;I++)
{
auto Key=static_cast<sf::Keyboard::Key>(I);
if (sf::Keyboard::isKeyPressed(Key))
{
if (Key_[Key]==KeyState::Released)
{
Key_[Key]=KeyState::Pressed;
InputHandler::Notify(Key);
}
}
else
{
Key_[Key]=KeyState::Released;
}
}
}