4 // Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.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
26 using namespace SuperTux;
28 unsigned int Ticks::pause_ticks, Ticks::pause_count;
30 unsigned int Ticks::get(void)
33 return /*SDL_GetTicks()*/ - pause_ticks /*- SDL_GetTicks()*/ + pause_count;
35 return SDL_GetTicks() - pause_ticks;
38 void Ticks::pause_init(void)
44 void Ticks::pause_start(void)
47 pause_count = SDL_GetTicks();
50 void Ticks::pause_stop(void)
55 pause_ticks += SDL_GetTicks() - pause_count;
59 bool Ticks::pause_started(void)
73 Timer::init(bool game_ticks)
77 get_ticks = game_ticks ? Ticks::get : SDL_GetTicks;
81 Timer::start(unsigned int period_)
90 if(get_ticks == get_ticks)
99 if((time != 0) && (time + period > get_ticks()))
120 return (period - (get_ticks() - time));
126 return (get_ticks() - time);
130 Timer::fwrite(FILE* fi)
132 unsigned int diff_ticks;
135 diff_ticks = get_ticks() - time;
139 ::fwrite(&period,sizeof(unsigned int),1,fi);
140 ::fwrite(&diff_ticks,sizeof(unsigned int),1,fi);
141 if(get_ticks == get_ticks)
145 ::fwrite(&tick_mode,sizeof(unsigned int),1,fi);
149 Timer::fread(FILE* fi)
151 unsigned int diff_ticks;
154 ::fread(&period,sizeof(unsigned int),1,fi);
155 ::fread(&diff_ticks,sizeof(unsigned int),1,fi);
156 ::fread(&tick_mode,sizeof(unsigned int),1,fi);
159 get_ticks = get_ticks;
161 get_ticks = SDL_GetTicks;
164 time = get_ticks() - diff_ticks;