Fixed typo.
[supertux.git] / lib / special / timer.h
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 // 
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 //  02111-1307, USA.
20
21 #ifndef SUPERTUX_TIMER_H
22 #define SUPERTUX_TIMER_H
23
24 namespace SuperTux
25   {
26
27   extern unsigned int st_pause_ticks, st_pause_count;
28
29   /// Time a game is running. (Non-pause mode, etc.)
30   unsigned int st_get_ticks(void);
31
32   void st_pause_ticks_init(void);
33   void st_pause_ticks_start(void);
34   void st_pause_ticks_stop(void);
35   bool st_pause_ticks_started(void);
36
37   /// Timer
38   /** This class can be used as stop watch
39       for example. It's also possible to calculate
40       frames per seconds and things like that with it.
41       It's a general timing class, but it
42       can esspecially be used together with st_get_ticks(). */
43   class Timer
44     {
45     public:
46       unsigned int period;
47       unsigned int time;
48       unsigned int (*get_ticks) (void);
49
50     public:
51       Timer();
52
53       /// Initialize the timer.
54       /** @param st_ticks: If true internally st_get_ticks() is used, else SDL_GetTicks() is used. */
55       void init(bool st_ticks);
56
57       /// Start the timer with the given period (in ms).
58       void start(unsigned int period);
59
60       /// Stop the timer.
61       void stop();
62
63       /// Check if the timer is started and within its period.
64       /** If one of these requirements isn't the case the timer
65           is automatically reseted. */
66       int check();
67
68       /// Is the timer started?
69       int started();
70
71       /// Get time left until the last timing period is finished.
72       /** The returned value can be negative. */
73       int get_left();
74
75       /// Get the gone time, since last timer start.
76       /** The returned value can be negative. */
77       int  get_gone();
78
79       /// Write the timer value to a file (For save games in example).
80       void fwrite(FILE* fi);
81       /// Read a timer value from a file (From save games in example).
82       void fread(FILE* fi);
83     };
84
85 } //namespace SuperTux
86
87 #endif /*SUPERTUX_TIMER_H*/
88
89 /* Local Variables: */
90 /* mode:c++ */
91 /* End: */