Gameplay has been repaired a bit. A menu effect was added. OpenGL works without SDL_O...
[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, int st_ticks)
45 {
46   ptimer->period = 0;
47   ptimer->time = 0;
48   
49   if(st_ticks == YES)
50   ptimer->get_ticks = st_get_ticks;
51   else
52   ptimer->get_ticks = SDL_GetTicks;
53  
54 }
55
56 void timer_start(timer_type* ptimer, unsigned int period)
57 {
58   ptimer->time = ptimer->get_ticks();
59   ptimer->period = period;
60 }
61
62 void timer_stop(timer_type* ptimer)
63 {
64 if(ptimer->get_ticks == st_get_ticks)
65  timer_init(ptimer,YES);
66 else
67  timer_init(ptimer,NO);
68 }
69
70 int timer_check(timer_type* ptimer)
71 {
72   if((ptimer->time != 0) && (ptimer->time + ptimer->period > ptimer->get_ticks()))
73     return YES;
74   else
75     {
76       ptimer->time = 0;
77       return NO;
78     }
79 }
80
81 int timer_started(timer_type* ptimer)
82 {
83   if(ptimer->time != 0)
84     return YES;
85   else
86     return NO;
87 }
88
89 int timer_get_left(timer_type* ptimer)
90 {
91   return (ptimer->period - (ptimer->get_ticks() - ptimer->time));
92 }
93
94 int timer_get_gone(timer_type* ptimer)
95 {
96   return (ptimer->get_ticks() - ptimer->time);
97 }