X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fmainloop.cpp;h=d0b6236931a82bbeb49d5adea006c5cd41ba9514;hb=339968d0eb222f5cad1397580631ab44acf40b10;hp=95104c6ded29bfeafa320ab157094833cec9b03e;hpb=082ae24f45d72add668572bbc9e57bdfc8cdd106;p=supertux.git diff --git a/src/mainloop.cpp b/src/mainloop.cpp index 95104c6de..d0b623693 100644 --- a/src/mainloop.cpp +++ b/src/mainloop.cpp @@ -35,6 +35,7 @@ #include "screen_fade.hpp" #include "timer.hpp" #include "player_status.hpp" +#include "random_generator.hpp" // the engine will be run with a logical framerate of 64fps. // We chose 64fps here because it is a power of 2, so 1/64 gives an "even" @@ -67,10 +68,7 @@ MainLoop::push_screen(Screen* screen, ScreenFade* screen_fade) { this->next_screen.reset(screen); this->screen_fade.reset(screen_fade); - if(nextpop) - nextpush = false; - else - nextpush = true; + nextpush = !nextpop; nextpop = false; speed = 1.0; } @@ -113,25 +111,25 @@ MainLoop::draw_fps(DrawingContext& context, float fps_fps) 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_FOREGROUND1); - context.draw_text(gold_text, str, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y + 20), RIGHT_ALLIGN, LAYER_FOREGROUND1); + 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::run() { - DrawingContext context; - + DrawingContext context; + unsigned int frame_count = 0; float fps_fps = 0; Uint32 fps_ticks = SDL_GetTicks(); Uint32 fps_nextframe_ticks = SDL_GetTicks(); Uint32 ticks; bool skipdraw = false; - + running = true; while(running) { - while( (next_screen.get() != NULL || nextpop == true) && + while( (next_screen.get() != NULL || nextpop) && (screen_fade.get() == NULL || screen_fade->done())) { if(current_screen.get() != NULL) { current_screen->leave(); @@ -148,7 +146,7 @@ MainLoop::run() if(nextpush && current_screen.get() != NULL) { screen_stack.push_back(current_screen.release()); } - + nextpush = false; nextpop = false; speed = 1.0; @@ -162,11 +160,11 @@ MainLoop::run() if(!running || current_screen.get() == NULL) break; - + float elapsed_time = 1.0 / LOGICAL_FPS; ticks = SDL_GetTicks(); if(ticks > fps_nextframe_ticks) { - if(skipdraw == true) { + if(skipdraw) { // already skipped last frame? we have to slow down the game then... skipdraw = false; fps_nextframe_ticks -= (Uint32) (1000.0 / LOGICAL_FPS); @@ -205,7 +203,7 @@ MainLoop::run() if(config->show_fps) { ++frame_count; - + if(SDL_GetTicks() - fps_ticks >= 500) { fps_fps = (float) frame_count / .5; @@ -218,14 +216,14 @@ MainLoop::run() real_time += elapsed_time; elapsed_time *= speed; game_time += 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); - + main_controller->update(); SDL_Event event; while(SDL_PollEvent(&event)) { @@ -237,6 +235,7 @@ MainLoop::run() } sound_manager->update(); + + //log_info << "== periodic rand() = " << systemRandom.rand() << std::endl; } } -