updating Nolok contrib templates
[supertux.git] / lib / special / frame_rate.cpp
index a4b1b77..cff4071 100644 (file)
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
+#include <config.h>
+
 #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<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 +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();
+}