From 7a1e0a7f05a75f64c5ae12c67a3e36d50a4596a7 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Mon, 26 Apr 2010 16:22:52 +0200 Subject: refactor some things with FPSmanager --- src/menu/application.cpp | 35 ++++++++++++++++++++++++++++------- src/menu/application.hpp | 7 +++++++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/menu/application.cpp b/src/menu/application.cpp index 01555afb..00b9a6f3 100644 --- a/src/menu/application.cpp +++ b/src/menu/application.cpp @@ -36,11 +36,10 @@ namespace usdx Application::Application(Control* parent) : DrawableControl(parent), display(NULL), frame(NULL), - running(false), display_width(800), display_height(600) + fps_manager(NULL), running(false), display_width(800), + display_height(600), frames_per_second(50) { SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); - - fps_manager = new FPSmanager(); } Application::~Application() @@ -80,7 +79,6 @@ namespace usdx void Application::set_current_frame(Frame* new_frame) { frame = new_frame; - repaint(display); } void Application::main_loop(SDL_Surface* display) @@ -93,7 +91,7 @@ namespace usdx repaint(display); SDL_Flip(display); - LOG4CXX_ERROR(log, L"repaint"); + LOG4CXX_TRACE(log, L"repaint"); // poll current events while (SDL_PollEvent(&event)) { @@ -124,8 +122,9 @@ namespace usdx throw new std::exception(); } - SDL_initFramerate(fps_manager); - SDL_setFramerate(fps_manager, 50); + init_fps_manager(); + + SDL_setFramerate(fps_manager, frames_per_second); main_loop(display); } @@ -139,4 +138,26 @@ namespace usdx { return display_height; } + + const int Application::get_frames_per_second(void) const + { + return frames_per_second; + } + + void Application::set_frames_per_second(int fps) + { + this->frames_per_second = fps; + + if (fps_manager) { + SDL_setFramerate(fps_manager, frames_per_second); + } + } + + void Application::init_fps_manager(void) + { + if (! fps_manager) { + fps_manager = new FPSmanager(); + SDL_initFramerate(fps_manager); + } + } }; diff --git a/src/menu/application.hpp b/src/menu/application.hpp index b750241a..99036d51 100644 --- a/src/menu/application.hpp +++ b/src/menu/application.hpp @@ -51,11 +51,15 @@ namespace usdx int display_width; int display_height; + int frames_per_second; + /** * This is the main loop. */ void main_loop(SDL_Surface* display); + void init_fps_manager(void); + protected: Application(Control* parent); @@ -73,6 +77,9 @@ namespace usdx const int get_display_width(void) const; const int get_display_height(void) const; + + const int get_frames_per_second(void) const; + void set_frames_per_second(int fps); }; }; -- cgit v1.2.3