author | Tero Marttila <terom@fixme.fi> |
Tue, 27 Jan 2009 00:25:58 +0200 | |
changeset 439 | 9823e6cd1086 |
parent 300 | 417183866f35 |
permissions | -rw-r--r-- |
205 | 1 |
#ifndef TIMER_HH |
2 |
#define TIMER_HH |
|
3 |
||
4 |
#include <ClanLib/core.h> |
|
5 |
||
300 | 6 |
#include "Types.hh" |
205 | 7 |
|
283
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
205
diff
changeset
|
8 |
/** |
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
205
diff
changeset
|
9 |
* Used to implement Physics ticks and Graphics frames. This will attempt to trigger sig_tick every <interval> ms, |
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
205
diff
changeset
|
10 |
* but if we miss some ticks or something else, then the tick_length passed to sig_tick will be longer than interval... |
7540b0859579
start adding some documentation, most core classes (outside of Network) are now doxygen-enabled
terom
parents:
205
diff
changeset
|
11 |
*/ |
205 | 12 |
class Timer : public CL_KeepAlive { |
13 |
protected: |
|
300 | 14 |
/** |
15 |
* The target tick interval |
|
16 |
*/ |
|
205 | 17 |
TimeMS interval; |
18 |
||
300 | 19 |
/** |
20 |
* Number of ticks so far, updated by keep_alive |
|
21 |
*/ |
|
205 | 22 |
TickCount ticks; |
300 | 23 |
|
24 |
/** |
|
25 |
* Is the timer running? |
|
26 |
*/ |
|
205 | 27 |
bool enabled; |
300 | 28 |
|
29 |
/** |
|
30 |
* Single-shot mode? |
|
31 |
*/ |
|
32 |
bool single_shot; |
|
205 | 33 |
|
300 | 34 |
/** |
35 |
* Time of last tick, set to current time by start/fire_once/keep_alive |
|
36 |
*/ |
|
205 | 37 |
TimeMS last_tick; |
300 | 38 |
|
39 |
/** The tick signal */ |
|
205 | 40 |
CL_Signal_v1<TimeMS> _sig_tick; |
41 |
||
42 |
public: |
|
300 | 43 |
/** |
44 |
* Prepare a timer, sig_tick will be fired every interval ms after the timer is started. |
|
45 |
* |
|
46 |
* @param interval interval in milliseconds |
|
205 | 47 |
*/ |
48 |
Timer (TimeMS interval); |
|
49 |
||
50 |
/* |
|
51 |
* Returns the tick counter |
|
52 |
*/ |
|
53 |
TickCount get_ticks (void); |
|
54 |
||
300 | 55 |
/** |
56 |
* Start the timer in continuous-call mode, this should be called once keepalive starts getting called. |
|
205 | 57 |
*/ |
58 |
void start (void); |
|
300 | 59 |
|
60 |
/** |
|
61 |
* Tick the timer, but only once |
|
62 |
*/ |
|
63 |
void fire_once (void); |
|
205 | 64 |
|
65 |
private: |
|
300 | 66 |
/** |
67 |
* If interval time has elapsed, fire sig_tick |
|
68 |
*/ |
|
205 | 69 |
void keep_alive (void); |
70 |
||
71 |
public: |
|
300 | 72 |
/** |
73 |
* Triggered approximately every interval MS, but the given interval may also be longer if we've skipped ticks |
|
74 |
*/ |
|
205 | 75 |
CL_Signal_v1<TimeMS>& sig_tick (void) { return _sig_tick; } |
76 |
}; |
|
77 |
||
78 |
#endif |