]> Dogcows Code - chaz/yoink/blobdiff - src/moof/video.cc
further implementing runloop support
[chaz/yoink] / src / moof / video.cc
index aa49b03c249b9d2927d0b43e52adfd5a8a8b357b..263ea882bcfce6751078674436ffe155aa555aab 100644 (file)
@@ -9,6 +9,7 @@
 *
 **************************************************************************/
 
+#include <sstream>
 #include <stdexcept>
 
 #include "dispatcher.hh"
@@ -54,6 +55,8 @@ void video::init()
        mode(attributes_.mode);
 
        if (!current_) make_current();
+
+       show_fps(false);
 }
 
 void video::recreate_context()
@@ -158,14 +161,16 @@ bool video::iconify()
 
 void video::caption(const std::string& caption)
 {
+       caption_ = caption;
        SDL_WM_SetCaption(caption.c_str(), 0);
 }
 
-std::string video::caption() const
+const std::string& video::caption() const
 {
-       char* caption;
-       SDL_WM_GetCaption(&caption, 0);
-       return std::string(caption);
+       return caption_;
+       //char* caption;
+       //SDL_WM_GetCaption(&caption, 0);
+       //return std::string(caption);
 }
 
 
@@ -261,8 +266,27 @@ void video::toggle_cursor_captured()
 }
 
 
-void video::swap()
+void video::swap(scalar t)
 {
+       if (show_fps_)
+       {
+               scalar dt = t - last_swap_;
+               last_swap_ = t;
+
+               fps_accumulator_ += dt;
+               if (SCALAR(1.0) <= fps_accumulator_)
+               {
+                       std::ostringstream stream;
+                       stream << caption_ << " - " << fps_counter_ << " fps";
+                       SDL_WM_SetCaption(stream.str().c_str(), 0);
+
+                       fps_accumulator_ -= SCALAR(1.0);
+                       fps_counter_ = 0;
+               }
+
+               ++fps_counter_;
+       }
+
        SDL_GL_SwapBuffers();
 }
 
This page took 0.01765 seconds and 4 git commands to generate.