[Super-tux-commit] supertux/lib/special timer.cpp,1.3,1.4 timer.h,1.3,1.4
Brought to you by:
wkendrick
From: Tobias G. <to...@us...> - 2004-07-27 13:25:14
|
Update of /cvsroot/super-tux/supertux/lib/special In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25595/lib/special Modified Files: timer.cpp timer.h Log Message: C++ifyied SuperTux ticks. Index: timer.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/timer.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- timer.h 21 Jul 2004 16:51:52 -0000 1.3 +++ timer.h 27 Jul 2004 13:25:05 -0000 1.4 @@ -24,22 +24,29 @@ namespace SuperTux { - extern unsigned int st_pause_ticks, st_pause_count; + class Ticks + { + public: + /// Time a game is running. (Non-pause mode, etc.) + static unsigned int get(void); - /// Time a game is running. (Non-pause mode, etc.) - unsigned int st_get_ticks(void); + static void pause_init(void); + static void pause_start(void); + static void pause_stop(void); + static bool pause_started(void); - void st_pause_ticks_init(void); - void st_pause_ticks_start(void); - void st_pause_ticks_stop(void); - bool st_pause_ticks_started(void); + private: + static unsigned int pause_ticks; + static unsigned int pause_count; + + }; /// Timer /** This class can be used as stop watch for example. It's also possible to calculate frames per seconds and things like that with it. It's a general timing class, but it - can esspecially be used together with st_get_ticks(). */ + can esspecially be used together with Ticks::get(). */ class Timer { public: @@ -51,8 +58,8 @@ Timer(); /// Initialize the timer. - /** @param st_ticks: If true internally st_get_ticks() is used, else SDL_GetTicks() is used. */ - void init(bool st_ticks); + /** @param st_ticks: If true internally Ticks::get() is used, else SDL_GetTicks() is used. */ + void init(bool game_ticks); /// Start the timer with the given period (in ms). void start(unsigned int period); Index: timer.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/timer.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- timer.cpp 22 Jul 2004 19:07:50 -0000 1.3 +++ timer.cpp 27 Jul 2004 13:25:05 -0000 1.4 @@ -23,40 +23,40 @@ using namespace SuperTux; -unsigned int SuperTux::st_pause_ticks, SuperTux::st_pause_count; +unsigned int Ticks::pause_ticks, Ticks::pause_count; -unsigned int SuperTux::st_get_ticks(void) +unsigned int Ticks::get(void) { - if(st_pause_count != 0) - return /*SDL_GetTicks()*/ - st_pause_ticks /*- SDL_GetTicks()*/ + st_pause_count; + if(pause_count != 0) + return /*SDL_GetTicks()*/ - pause_ticks /*- SDL_GetTicks()*/ + pause_count; else - return SDL_GetTicks() - st_pause_ticks; + return SDL_GetTicks() - pause_ticks; } -void SuperTux::st_pause_ticks_init(void) +void Ticks::pause_init(void) { - st_pause_ticks = 0; - st_pause_count = 0; + pause_ticks = 0; + pause_count = 0; } -void SuperTux::st_pause_ticks_start(void) +void Ticks::pause_start(void) { - if(st_pause_count == 0) - st_pause_count = SDL_GetTicks(); + if(pause_count == 0) + pause_count = SDL_GetTicks(); } -void SuperTux::st_pause_ticks_stop(void) +void Ticks::pause_stop(void) { -if(st_pause_count == 0) +if(pause_count == 0) return; - st_pause_ticks += SDL_GetTicks() - st_pause_count; - st_pause_count = 0; + pause_ticks += SDL_GetTicks() - pause_count; + pause_count = 0; } -bool SuperTux::st_pause_ticks_started(void) +bool Ticks::pause_started(void) { -if(st_pause_count == 0) +if(pause_count == 0) return false; else return true; @@ -68,11 +68,11 @@ } void -Timer::init(bool st_ticks) +Timer::init(bool game_ticks) { period = 0; time = 0; - get_ticks = st_ticks ? st_get_ticks : SDL_GetTicks; + get_ticks = game_ticks ? Ticks::get : SDL_GetTicks; } void @@ -85,7 +85,7 @@ void Timer::stop() { - if(get_ticks == st_get_ticks) + if(get_ticks == get_ticks) init(true); else init(false); @@ -136,7 +136,7 @@ ::fwrite(&period,sizeof(unsigned int),1,fi); ::fwrite(&diff_ticks,sizeof(unsigned int),1,fi); - if(get_ticks == st_get_ticks) + if(get_ticks == get_ticks) tick_mode = true; else tick_mode = false; @@ -154,7 +154,7 @@ ::fread(&tick_mode,sizeof(unsigned int),1,fi); if (tick_mode) - get_ticks = st_get_ticks; + get_ticks = get_ticks; else get_ticks = SDL_GetTicks; |