fix miniswig using wrong stack numbers in functions with HSQUIRRELVM arguments
[supertux.git] / src / timer.hpp
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2005 Matthias Braun <matze@braunis.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 #ifndef __SUPERTUX_TIMER_H__
21 #define __SUPERTUX_TIMER_H__
22
23 extern float game_time;
24
25 /**
26  * new simpler timer designed to be used in the update functions of objects
27  */
28 class Timer
29 {
30 public:
31   Timer();
32   ~Timer();
33
34   /** start the timer with the given period (in seconds).
35    * If cyclic=true then the timer willl be reset after each period.
36    * Set period to zero if you want to disable the timer.
37    */
38   void start(float period, bool cyclic = false);
39   /** returns true if a period (or more) passed since start call or last
40    * successfull check
41    */
42   bool check();
43   /** stop the timer */
44   void stop()
45   { start(0); }
46
47   /** returns the period of the timer or 0 if it isn't started */
48   float get_period() const
49   { return period; }
50   float get_timeleft() const
51   { return period - (game_time - cycle_start); }
52   float get_timegone() const
53   { return game_time - cycle_start; }
54   bool started() const
55   { return period != 0 && get_timeleft() > 0; }
56
57 private:
58   float period;
59   float cycle_start;
60   bool cyclic;
61 };
62
63 #endif
64