massive cleaning of file section headers
[physics.git] / src / input / inputManager.cpp
CommitLineData
f7b3b2eb
PG
1#include "inputManager.h"
2#include "../debug.h"
3
617dcc71
PG
4
5/// ***** Private Variables *****
6
f7b3b2eb
PG
7enum State
8{
9 isR,
10 wasP,
11 isP,
12 wasR
13};
14
15static const int keySize = 323;
16static State keyState[keySize];
17
617dcc71
PG
18/// ***** Initializers/Cleaners *****
19
f7b3b2eb
PG
20void inputInit()
21{
22 for(int i=0; i< keySize; i++)
23 keyState[i] = isR;
24}
617dcc71
PG
25void inputClean()
26{
27
28}
29
30/// ***** Public Methods *****
f7b3b2eb
PG
31
32void inputUpdate()
33{
34 SDL_Event event;
35
36 for(int i=0; i< keySize; i++)
37 {
38 if(keyState[i] == wasR)
39 keyState[i] = isR;
40 else if(keyState[i] == wasP)
41 keyState[i] = isP;
42 }
43
44 while(SDL_PollEvent(&event))
45 {
46 switch(event.type)
47 {
48 case SDL_KEYUP:
49 keyState[event.key.keysym.sym] = wasR;
50 break;
51 case SDL_KEYDOWN:
52 keyState[event.key.keysym.sym] = wasP;
53 break;
54 }
55 }
56}
57
58bool isPressed(Uint8 key)
59{
60 return keyState[key] == isP || keyState[key] == wasP;
61}
62bool isReleased(Uint8 key)
63{
64 return keyState[key] == isR || keyState[key] == wasR;
65}
66
67bool wasPressed(Uint8 key)
68{
69 return keyState[key] == wasP;
70}
71bool wasReleased(Uint8 key)
72{
73 return keyState[key] == wasR;
74}