Introduction of SuperTux namespace.
[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 extern unsigned int st_pause_ticks, st_pause_count;
25
26 /// Time a game is running. (Non-pause mode, etc.)
27 unsigned int st_get_ticks(void);
28
29 void st_pause_ticks_init(void);
30 void st_pause_ticks_start(void);
31 void st_pause_ticks_stop(void);
32 bool st_pause_ticks_started(void);
33
34 /// Timer
35 /** This class can be used as stop watch
36     for example. It's also possible to calculate
37     frames per seconds and things like that with it.
38     It's a general timing class, but it
39     can esspecially be used together with st_get_ticks(). */
40 class Timer
41 {
42  public:
43   unsigned int period;
44   unsigned int time;
45   unsigned int (*get_ticks) (void);  
46
47  public:
48   Timer();
49   
50   /// Initialize the timer.
51   /** @Param st_ticks: If true internally st_get_ticks() is used, else SDL_GetTicks() is used. */
52   void init(bool st_ticks);
53   
54   /// Start the timer with the given period (in ms).
55   void start(unsigned int period);
56   
57   /// Stop the timer.
58   void stop();
59
60   /// Check if the timer is started and within its period.
61   /** If one of these requirements isn't the case the timer
62       is automatically reseted. */  
63   int check();
64   
65   /// Is the timer started?
66   int started();
67
68   /// Get time left until the last timing period is finished. 
69   /** The returned value can be negative. */    
70   int get_left();
71
72   /// Get the gone time, since last timer start. 
73   /** The returned value can be negative. */
74   int  get_gone();
75   
76   /// Write the timer value to a file (For save games in example).
77   void fwrite(FILE* fi);
78   /// Read a timer value from a file (From save games in example).
79   void fread(FILE* fi);
80 };
81
82 #endif /*SUPERTUX_TIMER_H*/
83
84 /* Local Variables: */
85 /* mode:c++ */
86 /* End: */