added supertux autopackage .spec file
[supertux.git] / src / timer.cpp
1 #include <config.h>
2
3 #include <math.h>
4 #include "timer.h"
5
6 float global_time = 0;
7
8 Timer2::Timer2()
9   : period(0), cycle_start(0), cyclic(false)
10 {
11 }
12
13 Timer2::~Timer2()
14 {
15 }
16
17 void
18 Timer2::start(float period, bool cyclic)
19 {
20   this->period = period;
21   this->cyclic = cyclic;
22   cycle_start = global_time;
23 }
24
25 bool
26 Timer2::check()
27 {
28   if(period == 0)
29     return false;
30   
31   if(global_time - cycle_start >= period) {
32     if(cyclic) {
33       cycle_start = global_time - fmodf(global_time - cycle_start, period);
34     } else {
35       period = 0;
36     }
37     return true;
38   }
39
40   return false;
41 }
42