-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputSystem.cpp
More file actions
42 lines (35 loc) · 841 Bytes
/
InputSystem.cpp
File metadata and controls
42 lines (35 loc) · 841 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
#include "InputSystem.h"
#include "controller.hpp"
InputSystem &InputSystem::GetInstance()
{
static InputSystem instance;
return instance;
}
InputSystem::InputSystem()
{
for (int i = 0; i < 256; i++)
oldKeyboardState[i] = 0;
}
void InputSystem::PollKeyboard()
{
// save old keyboard state
for (int i = 0; i < 256; i++)
oldKeyboardState[i] = keyboardState[i];
// poll current keyboard state
const uint8_t *newKeyboardState = SDL_GetKeyboardState(0);
for (int i = 0; i < 256; i++)
keyboardState[i] = newKeyboardState[i];
}
InputSystem::KeyState InputSystem::GetKeyState(SDL_Scancode key)
{
if (keyboardState[key])
if (oldKeyboardState[key])
return KeyState::PRESSED;
else
return KeyState::JUST_PRESSED;
else
if (oldKeyboardState[key])
return KeyState::JUST_RELEASED;
else
return KeyState::RELEASED;
}