aboutsummaryrefslogtreecommitdiffstats
path: root/src/menu
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2010-04-26 16:22:52 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-05 17:17:48 +0100
commit7a1e0a7f05a75f64c5ae12c67a3e36d50a4596a7 (patch)
treeb1052b4ee533f187bcb523e4e8d7db047b3a3262 /src/menu
parenta17ab6c52cf7f8db93558d1d822aa59713b20210 (diff)
downloadusdx-7a1e0a7f05a75f64c5ae12c67a3e36d50a4596a7.tar.gz
usdx-7a1e0a7f05a75f64c5ae12c67a3e36d50a4596a7.tar.xz
usdx-7a1e0a7f05a75f64c5ae12c67a3e36d50a4596a7.zip
refactor some things with FPSmanager
Diffstat (limited to 'src/menu')
-rw-r--r--src/menu/application.cpp35
-rw-r--r--src/menu/application.hpp7
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);
};
};