]> Dogcows Code - chaz/yoink/blobdiff - src/moof/video.cc
further implementing runloop support
[chaz/yoink] / src / moof / video.cc
index 32278cc77ca25422e72595fffab04eeb692040b2..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();
 }
 
@@ -321,7 +345,7 @@ video::attributes::attributes(const settings& settings)
        settings.get("fullscreen", is_fullscreen);
        settings.get("resizable", is_resizable);
        settings.get("showcursor", is_cursor_visible);
-       settings.get("grab", is_cursor_captured);
+       settings.get("capturecursor", is_cursor_captured);
 
        std::vector<int> dimensions;
        settings.get("videomode", dimensions);
@@ -337,12 +361,11 @@ video::attributes::attributes(const settings& settings)
 
                if (modes == (SDL_Rect**)0)
                {
-                       log_error("no native video mode");
+                       throw std::runtime_error("can't find appropriate video mode");
                }
                else if (modes == (SDL_Rect**)-1)
                {
-                       log_warning("any resolution allowed; "
-                                                  "choosing default 800x600");
+                       log_warning("any resolution allowed; choosing default 800x600");
                        mode[0] = 800;
                        mode[1] = 600;
                }
@@ -350,8 +373,8 @@ video::attributes::attributes(const settings& settings)
                {
                        mode[0] = (*modes)->w;
                        mode[1] = (*modes)->h;
-                       log_info << "choosing native resolution "
-                                       << mode[0] << "x" << mode[1] << std::endl;
+                       log_info << "choosing native resolution: "
+                                        << mode[0] << "x" << mode[1] << std::endl;
                }
        }
        if (dimensions.size() > 2) mode[2] = dimensions[2];
This page took 0.022204 seconds and 4 git commands to generate.