205
|
1 |
#ifndef TIMER_HH
|
|
2 |
#define TIMER_HH
|
|
3 |
|
|
4 |
#include <ClanLib/core.h>
|
|
5 |
|
|
6 |
typedef unsigned long TimeMS;
|
|
7 |
typedef uint32_t TickCount;
|
|
8 |
|
|
9 |
class Timer : public CL_KeepAlive {
|
|
10 |
protected:
|
|
11 |
// the target tick interval
|
|
12 |
TimeMS interval;
|
|
13 |
|
|
14 |
// number of ticks
|
|
15 |
TickCount ticks;
|
|
16 |
|
|
17 |
bool enabled;
|
|
18 |
|
|
19 |
// time of last tick
|
|
20 |
TimeMS last_tick;
|
|
21 |
|
|
22 |
CL_Signal_v1<TimeMS> _sig_tick;
|
|
23 |
|
|
24 |
public:
|
|
25 |
/*
|
|
26 |
* Interval is in milliseconds
|
|
27 |
*/
|
|
28 |
Timer (TimeMS interval);
|
|
29 |
|
|
30 |
/*
|
|
31 |
* Returns the tick counter
|
|
32 |
*/
|
|
33 |
TickCount get_ticks (void);
|
|
34 |
|
|
35 |
/*
|
|
36 |
* Start the timer, this should be called once keepalive starts getting called
|
|
37 |
*/
|
|
38 |
void start (void);
|
|
39 |
|
|
40 |
private:
|
|
41 |
void keep_alive (void);
|
|
42 |
|
|
43 |
public:
|
|
44 |
CL_Signal_v1<TimeMS>& sig_tick (void) { return _sig_tick; }
|
|
45 |
};
|
|
46 |
|
|
47 |
#endif
|