X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=lib%2Fspecial%2Fframe_rate.cpp;h=cff40710d5c2d21dbe41936e24702cce83ef12b6;hb=b7257628126eb59bdca2052e9369d61edcda6b0f;hp=a4b1b7737f59a6a5284947045d01fbcaeef60dc5;hpb=2e973e2cf1dc2af448a0c27d067b00addb968538;p=supertux.git diff --git a/lib/special/frame_rate.cpp b/lib/special/frame_rate.cpp index a4b1b7737..cff40710d 100644 --- a/lib/special/frame_rate.cpp +++ b/lib/special/frame_rate.cpp @@ -16,16 +16,19 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include + #include "SDL.h" -#include "../special/frame_rate.h" -#include "../special/timer.h" +#include "frame_rate.h" +#include "timer.h" using namespace SuperTux; FrameRate::FrameRate(double fps) { set_fps(fps); + set_frame_limit(true); } void FrameRate::start() @@ -38,6 +41,11 @@ void FrameRate::set_fps(double fps) frame_ms = static_cast(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 +60,15 @@ void FrameRate::update() /* 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(); +}