-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.h
54 lines (40 loc) · 958 Bytes
/
timer.h
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
50
51
52
53
54
#ifndef __TIMER_H__
#define __TIMER_H__
#include "defines.h"
/**
* A millisecond timer. It can be instantiated with a turnback argument, which
* allows the caller to measure time in intervals.
*/
class Timer {
u64 startTime;
u64 turnback;
public:
/**
* Instantiates and starts a timer with no turnback ability.
*/
Timer() : Timer(0) { }
/**
* Instantiates and starts a timer with the given turnback interval in milliseconds.
*/
Timer(u64 turnback);
/**
* Resets the timer to 0.
*/
void reset();
/**
* @return The number of milliseconds elapsed since the last reset.
*/
u64 get();
/**
* If the timer indicates more than <turnback> milliseconds, turns it back
* by turnback milliseconds and returns true. Otherwise leaves the timer
* unchanged and returns false.
*/
bool ticked();
private:
/**
* @return the UNIX timestamp in milliseconds.
*/
u64 getTimestamp();
};
#endif