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
22 #include "../special/timer.h"
24 using namespace SuperTux;
26 unsigned int Ticks::pause_ticks, Ticks::pause_count;
28 unsigned int Ticks::get(void)
31 return /*SDL_GetTicks()*/ - pause_ticks /*- SDL_GetTicks()*/ + pause_count;
33 return SDL_GetTicks() - pause_ticks;
36 void Ticks::pause_init(void)
42 void Ticks::pause_start(void)
45 pause_count = SDL_GetTicks();
48 void Ticks::pause_stop(void)
53 pause_ticks += SDL_GetTicks() - pause_count;
57 bool Ticks::pause_started(void)
71 Timer::init(bool game_ticks)
75 get_ticks = game_ticks ? Ticks::get : SDL_GetTicks;
79 Timer::start(unsigned int period_)
88 if(get_ticks == get_ticks)
97 if((time != 0) && (time + period > get_ticks()))
118 return (period - (get_ticks() - time));
124 return (get_ticks() - time);
128 Timer::fwrite(FILE* fi)
130 unsigned int diff_ticks;
133 diff_ticks = get_ticks() - time;
137 ::fwrite(&period,sizeof(unsigned int),1,fi);
138 ::fwrite(&diff_ticks,sizeof(unsigned int),1,fi);
139 if(get_ticks == get_ticks)
143 ::fwrite(&tick_mode,sizeof(unsigned int),1,fi);
147 Timer::fread(FILE* fi)
149 unsigned int diff_ticks;
152 ::fread(&period,sizeof(unsigned int),1,fi);
153 ::fread(&diff_ticks,sizeof(unsigned int),1,fi);
154 ::fread(&tick_mode,sizeof(unsigned int),1,fi);
157 get_ticks = get_ticks;
159 get_ticks = SDL_GetTicks;
162 time = get_ticks() - diff_ticks;