X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fmainloop.cpp;h=fb45247c7cfcc73c4633e743e35b07dbdea83059;hb=f53572ad2b744ddddd7cc4b6479489543d44f98d;hp=65da30ba4705a936109e2d9950ec905d85d196df;hpb=690ac9e5920c8d3dd0a8a14a7bd163eaf52ce689;p=supertux.git diff --git a/src/mainloop.cpp b/src/mainloop.cpp index 65da30ba4..fb45247c7 100644 --- a/src/mainloop.cpp +++ b/src/mainloop.cpp @@ -26,14 +26,16 @@ #include "control/joystickkeyboardcontroller.hpp" #include "gui/menu.hpp" #include "audio/sound_manager.hpp" +#include "scripting/time_scheduler.hpp" +#include "scripting/squirrel_util.hpp" #include "gameconfig.hpp" #include "main.hpp" #include "resources.hpp" -#include "script_manager.hpp" #include "screen.hpp" #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" @@ -43,12 +45,18 @@ static const float LOGICAL_FPS = 64.0; MainLoop* main_loop = NULL; MainLoop::MainLoop() - : speed(1.0) + : speed(1.0), nextpop(false), nextpush(false) { + using namespace Scripting; + TimeScheduler::instance = new TimeScheduler(); } MainLoop::~MainLoop() { + using namespace Scripting; + delete TimeScheduler::instance; + TimeScheduler::instance = NULL; + for(std::vector::iterator i = screen_stack.begin(); i != screen_stack.end(); ++i) { delete *i; @@ -115,7 +123,8 @@ MainLoop::run() { DrawingContext context; - unsigned int frame_count; + unsigned int frame_count = 0; + unsigned int rand_prints = 0; float fps_fps = 0; Uint32 fps_ticks = SDL_GetTicks(); Uint32 fps_nextframe_ticks = SDL_GetTicks(); @@ -124,7 +133,7 @@ MainLoop::run() running = true; while(running) { - if( (next_screen.get() != NULL || nextpop == true) && + while( (next_screen.get() != NULL || nextpop == true) && (screen_fade.get() == NULL || screen_fade->done())) { if(current_screen.get() != NULL) { current_screen->leave(); @@ -137,22 +146,24 @@ MainLoop::run() } next_screen.reset(screen_stack.back()); screen_stack.pop_back(); - nextpop = false; - speed = 1.0; } if(nextpush && current_screen.get() != NULL) { screen_stack.push_back(current_screen.release()); } - - next_screen->setup(); - ScriptManager::instance->fire_wakeup_event(ScriptManager::SCREEN_SWITCHED); + + nextpush = false; + nextpop = false; + speed = 1.0; + if(next_screen.get() != NULL) + next_screen->setup(); current_screen.reset(next_screen.release()); - next_screen.reset(NULL); screen_fade.reset(NULL); + + waiting_threads.wakeup(); } - if(current_screen.get() == NULL) - break; + if(!running || current_screen.get() == NULL) + break; float elapsed_time = 1.0 / LOGICAL_FPS; ticks = SDL_GetTicks(); @@ -206,10 +217,12 @@ MainLoop::run() } } + real_time += elapsed_time; elapsed_time *= speed; - game_time += elapsed_time; - ScriptManager::instance->update(); + + Scripting::update_debugger(); + Scripting::TimeScheduler::instance->update(game_time); current_screen->update(elapsed_time); if(screen_fade.get() != NULL) screen_fade->update(elapsed_time); @@ -226,6 +239,11 @@ MainLoop::run() } sound_manager->update(); + + // insert calls for debug (there are few rand calls otherwise) + if (0 && rand_prints++ % 20 == 0) + log_info << "== periodic rand() call " << systemRandom.rand() << + " at frame " << rand_prints << "==" <