hopefully fixed the crash on exit, keep sectors script bundled in the sector and...
[supertux.git] / src / mainloop.cpp
index 1c98cd4..575005b 100644 (file)
@@ -29,6 +29,7 @@
 #include "gameconfig.hpp"
 #include "main.hpp"
 #include "resources.hpp"
+#include "script_manager.hpp"
 #include "screen.hpp"
 #include "timer.hpp"
 
@@ -97,10 +98,13 @@ MainLoop::run()
   running = true;
   while(running) {
     if(next_screen.get() != NULL) {
-      if(nextpush)
+      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;
@@ -159,8 +163,9 @@ MainLoop::run()
     elapsed_time *= speed;
 
     game_time += elapsed_time;
+    ScriptManager::instance->update();
     current_screen->update(elapsed_time);
-
     main_controller->update();
     SDL_Event event;
     while(SDL_PollEvent(&event)) {