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
25 unsigned int st_pause_ticks, st_pause_count;
27 unsigned int st_get_ticks(void)
29 if(st_pause_count != 0)
30 return /*SDL_GetTicks()*/ - st_pause_ticks /*- SDL_GetTicks()*/ + st_pause_count;
32 return SDL_GetTicks() - st_pause_ticks;
35 void st_pause_ticks_init(void)
41 void st_pause_ticks_start(void)
43 if(st_pause_count == 0)
44 st_pause_count = SDL_GetTicks();
47 void st_pause_ticks_stop(void)
49 if(st_pause_count == 0)
52 st_pause_ticks += SDL_GetTicks() - st_pause_count;
57 Timer::init(bool st_ticks)
61 get_ticks = st_ticks ? st_get_ticks : SDL_GetTicks;
65 Timer::start(unsigned int period_)
74 if(get_ticks == st_get_ticks)
83 if((time != 0) && (time + period > get_ticks()))
104 return (period - (get_ticks() - time));
110 return (get_ticks() - time);
114 Timer::fwrite(FILE* fi)
116 unsigned int diff_ticks;
119 diff_ticks = get_ticks() - time;
123 ::fwrite(&period,sizeof(unsigned int),1,fi);
124 ::fwrite(&diff_ticks,sizeof(unsigned int),1,fi);
125 if(get_ticks == st_get_ticks)
129 ::fwrite(&tick_mode,sizeof(unsigned int),1,fi);
133 Timer::fread(FILE* fi)
135 unsigned int diff_ticks;
138 ::fread(&period,sizeof(unsigned int),1,fi);
139 ::fread(&diff_ticks,sizeof(unsigned int),1,fi);
140 ::fread(&tick_mode,sizeof(unsigned int),1,fi);
143 get_ticks = st_get_ticks;
145 get_ticks = SDL_GetTicks;
148 time = get_ticks() - diff_ticks;