[Super-tux-commit] supertux/lib/special frame_rate.cpp,1.1,1.2 frame_rate.h,1.1,1.2
Brought to you by:
wkendrick
From: Tobias G. <to...@us...> - 2004-07-29 11:05:36
|
Update of /cvsroot/super-tux/supertux/lib/special In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13751/lib/special Modified Files: frame_rate.cpp frame_rate.h Log Message: - FrameRate class is more flexible - All "game-loops" use the FrameRate class now Index: frame_rate.h =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/frame_rate.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- frame_rate.h 28 Jul 2004 23:06:11 -0000 1.1 +++ frame_rate.h 29 Jul 2004 11:05:28 -0000 1.2 @@ -29,12 +29,15 @@ FrameRate(double fps); void start(); void set_fps(double fps); + void set_frame_limit(bool); double get(); void update(); + void smooth_hanger(); private: unsigned int last_update_time; unsigned int update_time; unsigned int frame_ms; + bool frame_limit; }; } //namespace SuperTux Index: frame_rate.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/lib/special/frame_rate.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- frame_rate.cpp 28 Jul 2004 23:06:11 -0000 1.1 +++ frame_rate.cpp 29 Jul 2004 11:05:28 -0000 1.2 @@ -26,6 +26,7 @@ FrameRate::FrameRate(double fps) { set_fps(fps); + set_frame_limit(true); } void FrameRate::start() @@ -38,6 +39,11 @@ frame_ms = static_cast<unsigned int>(1000.f/fps); } +void FrameRate::set_frame_limit(bool set_limit) +{ + frame_limit = set_limit; +} + double FrameRate::get() { return ((double)(update_time-last_update_time))/(double)frame_ms; @@ -52,10 +58,15 @@ /* Pause till next frame, if the machine running the game is too fast: */ /* FIXME: Works great for in OpenGl mode, where the CPU doesn't have to do that much. But the results in SDL mode aren't perfect (thought the 100 FPS are reached), even on an AMD2500+. */ - if(last_update_time >= update_time - (frame_ms+2)) + if(frame_limit && last_update_time >= update_time - (frame_ms+2)) { SDL_Delay(frame_ms); update_time = Ticks::get(); } } +void FrameRate::smooth_hanger() +{ + if( (update_time - last_update_time) > frame_ms*100) + update_time = last_update_time = Ticks::get(); +} |