Corrected collition with bag of money
[supertux.git] / src / timer.c
1 //
2 // C Implementation: timer
3 //
4 // Description: 
5 //
6 //
7 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12
13 #include <SDL/SDL.h>
14 #include "defines.h"
15 #include "timer.h"
16
17 unsigned int st_pause_ticks, st_pause_count;
18
19 unsigned int st_get_ticks(void)
20 {
21 if(st_pause_count != 0)
22 return SDL_GetTicks() - st_pause_ticks - SDL_GetTicks() + st_pause_count;
23 else
24 return SDL_GetTicks() - st_pause_ticks;
25 }
26
27 void st_pause_ticks_init(void)
28 {
29 st_pause_ticks = 0;
30 st_pause_count = 0;
31 }
32
33 void st_pause_ticks_start(void)
34 {
35 st_pause_count = SDL_GetTicks();
36 }
37
38 void st_pause_ticks_stop(void)
39 {
40 st_pause_ticks += SDL_GetTicks() - st_pause_count;
41 st_pause_count = 0;
42 }
43
44 void timer_init(timer_type* ptimer)
45 {
46   ptimer->period = 0;
47   ptimer->time = 0;
48 }
49
50 void timer_start(timer_type* ptimer, unsigned int period)
51 {
52   ptimer->time = st_get_ticks();
53   ptimer->period = period;
54 }
55
56 void timer_stop(timer_type* ptimer)
57 {
58  timer_init(ptimer);
59 }
60
61 int timer_check(timer_type* ptimer)
62 {
63   if((ptimer->time != 0) && (ptimer->time + ptimer->period > st_get_ticks()))
64     return YES;
65   else
66     {
67       ptimer->time = 0;
68       return NO;
69     }
70 }
71
72 int timer_started(timer_type* ptimer)
73 {
74   if(ptimer->time != 0)
75     return YES;
76   else
77     return NO;
78 }
79
80 int timer_get_left(timer_type* ptimer)
81 {
82   return (ptimer->period - (st_get_ticks() - ptimer->time));
83 }
84
85 int timer_get_gone(timer_type* ptimer)
86 {
87   return (st_get_ticks() - ptimer->time);
88 }