diff options
Diffstat (limited to 'src/timer.h')
-rw-r--r-- | src/timer.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/timer.h b/src/timer.h new file mode 100644 index 0000000..ec34f3e --- /dev/null +++ b/src/timer.h | |||
@@ -0,0 +1,32 @@ | |||
1 | #ifndef TIMER_H_45E2F1F9 | ||
2 | #define TIMER_H_45E2F1F9 | ||
3 | |||
4 | class Timer { | ||
5 | public: | ||
6 | |||
7 | Timer(int dt) : dt_(dt) {} | ||
8 | |||
9 | void accumulate(int t) { | ||
10 | acc_ += t; | ||
11 | } | ||
12 | |||
13 | bool step() { | ||
14 | if (acc_ > dt_) { | ||
15 | acc_ -= dt_; | ||
16 | return true; | ||
17 | } else { | ||
18 | return false; | ||
19 | } | ||
20 | } | ||
21 | |||
22 | void reset() { | ||
23 | acc_ = 0; | ||
24 | } | ||
25 | |||
26 | private: | ||
27 | |||
28 | int dt_; | ||
29 | int acc_ = 0; | ||
30 | }; | ||
31 | |||
32 | #endif /* end of include guard: TIMER_H_45E2F1F9 */ | ||