forked from od-contrib/commander
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaxis_direction.cpp
47 lines (45 loc) · 1.42 KB
/
axis_direction.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
#include "axis_direction.h"
#include <SDL.h>
AxisDirection AxisDirectionRepeater::Get(AxisDirection axis_direction)
{
const int now = SDL_GetTicks();
switch (axis_direction.x) {
case AxisDirectionX::LEFT:
last_right_ = 0;
if (now - last_left_ < min_interval_ms_) {
axis_direction.x = AxisDirectionX::NONE;
} else {
last_left_ = now;
}
break;
case AxisDirectionX::RIGHT:
last_left_ = 0;
if (now - last_right_ < min_interval_ms_) {
axis_direction.x = AxisDirectionX::NONE;
} else {
last_right_ = now;
}
break;
case AxisDirectionX::NONE: last_left_ = last_right_ = 0; break;
}
switch (axis_direction.y) {
case AxisDirectionY::UP:
last_down_ = 0;
if (now - last_up_ < min_interval_ms_) {
axis_direction.y = AxisDirectionY::NONE;
} else {
last_up_ = now;
}
break;
case AxisDirectionY::DOWN:
last_up_ = 0;
if (now - last_down_ < min_interval_ms_) {
axis_direction.y = AxisDirectionY::NONE;
} else {
last_down_ = now;
}
break;
case AxisDirectionY::NONE: last_up_ = last_down_ = 0; break;
}
return axis_direction;
}