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