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 unsigned int st_pause_ticks, st_pause_count;
26 unsigned int st_get_ticks(void)
28 if(st_pause_count != 0)
29 return /*SDL_GetTicks()*/ - st_pause_ticks /*- SDL_GetTicks()*/ + st_pause_count;
31 return SDL_GetTicks() - st_pause_ticks;
34 void st_pause_ticks_init(void)
40 void st_pause_ticks_start(void)
42 if(st_pause_count == 0)
43 st_pause_count = SDL_GetTicks();
46 void st_pause_ticks_stop(void)
48 if(st_pause_count == 0)
51 st_pause_ticks += SDL_GetTicks() - st_pause_count;
55 bool st_pause_ticks_started(void)
57 if(st_pause_count == 0)
69 Timer::init(bool st_ticks)
73 get_ticks = st_ticks ? st_get_ticks : SDL_GetTicks;
77 Timer::start(unsigned int period_)
86 if(get_ticks == st_get_ticks)
95 if((time != 0) && (time + period > get_ticks()))
116 return (period - (get_ticks() - time));
122 return (get_ticks() - time);
126 Timer::fwrite(FILE* fi)
128 unsigned int diff_ticks;
131 diff_ticks = get_ticks() - time;
135 ::fwrite(&period,sizeof(unsigned int),1,fi);
136 ::fwrite(&diff_ticks,sizeof(unsigned int),1,fi);
137 if(get_ticks == st_get_ticks)
141 ::fwrite(&tick_mode,sizeof(unsigned int),1,fi);
145 Timer::fread(FILE* fi)
147 unsigned int diff_ticks;
150 ::fread(&period,sizeof(unsigned int),1,fi);
151 ::fread(&diff_ticks,sizeof(unsigned int),1,fi);
152 ::fread(&tick_mode,sizeof(unsigned int),1,fi);
155 get_ticks = st_get_ticks;
157 get_ticks = SDL_GetTicks;
160 time = get_ticks() - diff_ticks;