- DrawingContext context;
-
- unsigned int frame_count;
- float fps_fps;
- Uint32 fps_ticks = SDL_GetTicks();
- Uint32 fps_nextframe_ticks = SDL_GetTicks();
- Uint32 ticks;
- bool skipdraw = false;
-
- running = true;
- while(running) {
- if(next_screen.get() != NULL) {
- if(nextpush && current_screen.get() != NULL) {
- current_screen->leave();
- screen_stack.push_back(current_screen.release());
- }
-
- next_screen->setup();
- ScriptManager::instance->fire_wakeup_event(ScriptManager::SCREEN_SWITCHED);
- current_screen.reset(next_screen.release());
- next_screen.reset(NULL);
- nextpush = false;
+ char str[60];
+ snprintf(str, sizeof(str), "%3.1f", fps_fps);
+ const char* fpstext = "FPS";
+ context.draw_text(white_text, fpstext, Vector(SCREEN_WIDTH - white_text->get_text_width(fpstext) - gold_text->get_text_width(" 99999") - BORDER_X, BORDER_Y + 20), LEFT_ALLIGN, LAYER_HUD);
+ context.draw_text(gold_text, str, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y + 20), RIGHT_ALLIGN, LAYER_HUD);
+}
+
+void
+MainLoop::draw(DrawingContext& context)
+{
+ static Uint32 fps_ticks = SDL_GetTicks();
+ static int frame_count = 0;
+
+ current_screen->draw(context);
+ if(Menu::current() != NULL)
+ Menu::current()->draw(context);
+ if(screen_fade.get() != NULL)
+ screen_fade->draw(context);
+ Console::instance->draw(context);
+
+ if(config->show_fps)
+ draw_fps(context, fps);
+
+ context.do_drawing();
+
+ /* Calculate frames per second */
+ if(config->show_fps)
+ {
+ ++frame_count;
+
+ if(SDL_GetTicks() - fps_ticks >= 500)
+ {
+ fps = (float) frame_count / .5;
+ frame_count = 0;
+ fps_ticks = SDL_GetTicks();
+ }
+ }
+}
+
+void
+MainLoop::update_gamelogic(float elapsed_time)
+{
+ Scripting::update_debugger();
+ Scripting::TimeScheduler::instance->update(game_time);
+ current_screen->update(elapsed_time);
+ if(screen_fade.get() != NULL)
+ screen_fade->update(elapsed_time);
+ Console::instance->update(elapsed_time);
+}
+
+void
+MainLoop::process_events()
+{
+ main_controller->update();
+ SDL_Event event;
+ while(SDL_PollEvent(&event)) {
+ main_controller->process_event(event);
+ if(Menu::current() != NULL)
+ Menu::current()->event(event);
+ if(event.type == SDL_QUIT)
+ quit();
+ }
+}
+
+void
+MainLoop::handle_screen_switch()
+{
+ while( (next_screen.get() != NULL || nextpop) &&
+ (screen_fade.get() == NULL || screen_fade->done())) {
+ if(current_screen.get() != NULL) {
+ current_screen->leave();