4 // Copyright (C) 2005 Matthias Braun <matze@braunis.de>
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.
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.
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
20 #ifndef __SUPERTUX_TIMER_H__
21 #define __SUPERTUX_TIMER_H__
23 extern float global_time;
26 * new simpler timer designed to be used in the update functions of objects
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.
38 void start(float period, bool cyclic = false);
39 /** returns true if a period (or more) passed since start call or last
47 /** returns the period of the timer or 0 if it isn't started */
48 float get_period() const
50 float get_timeleft() const
51 { return period - (global_time - cycle_start); }
52 float get_timegone() const
53 { return global_time - cycle_start; }
55 { return period != 0 && get_timeleft() > 0; }