X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Fvideo.cc;h=263ea882bcfce6751078674436ffe155aa555aab;hp=32278cc77ca25422e72595fffab04eeb692040b2;hb=af88821a172c4dfd138b91b2a5148ae50b502fa2;hpb=831f04d4bc19a390415ac0bbac4331c7a65509bc diff --git a/src/moof/video.cc b/src/moof/video.cc index 32278cc..263ea88 100644 --- a/src/moof/video.cc +++ b/src/moof/video.cc @@ -9,6 +9,7 @@ * **************************************************************************/ +#include #include #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 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];