Included supertux.h stuff into it.
[supertux.git] / src / gameloop.cpp
index d2aadba..834f98f 100644 (file)
@@ -65,10 +65,10 @@ GameSession::GameSession(const std::string& filename)
   //assert(!"Don't call me");
   current_ = this;
 
-  world = new World; // &::global_world;
+  world = new World;
 
-  timer_init(&fps_timer, true);
-  timer_init(&frame_timer, true);
+  fps_timer.init(true);
+  frame_timer.init(true);
 
   world->load(filename);
 }
@@ -81,10 +81,10 @@ GameSession::GameSession(const std::string& subset_, int levelnb_, int mode)
 
   current_ = this;
 
-  world = new World; // &::global_world;
+  world = new World;
 
-  timer_init(&fps_timer, true);
-  timer_init(&frame_timer, true);
+  fps_timer.init(true);
+  frame_timer.init(true);
 
   st_gl_mode = mode;
   
@@ -104,7 +104,6 @@ GameSession::GameSession(const std::string& subset_, int levelnb_, int mode)
     }
 
   world->get_level()->load_gfx();
-  loadshared();
   
   world->activate_bad_guys();
   world->activate_particle_systems();
@@ -116,7 +115,7 @@ GameSession::GameSession(const std::string& subset_, int levelnb_, int mode)
   if(st_gl_mode == ST_GL_PLAY || st_gl_mode == ST_GL_LOAD_LEVEL_FILE)
     levelintro();
 
-  timer_init(&time_left,true);
+  time_left.init(true);
   start_timers();
 
   if(st_gl_mode == ST_GL_LOAD_GAME)
@@ -156,7 +155,7 @@ GameSession::levelintro(void)
 void
 GameSession::start_timers()
 {
-  timer_start(&time_left, world->get_level()->time_left*1000);
+  time_left.start(world->get_level()->time_left*1000);
   st_pause_ticks_init();
   update_time = st_get_ticks();
 }
@@ -171,7 +170,7 @@ GameSession::process_events()
     {
       /* Check for menu-events, if the menu is shown */
       if(show_menu)
-        menu_event(event);
+        current_menu->event(event);
 
       switch(event.type)
         {
@@ -261,7 +260,7 @@ GameSession::process_events()
                 break;
               case SDLK_INSERT:
                 if(debug_mode)
-                  timer_start(&tux.invincible_timer,TUX_INVINCIBLE_TIME);
+                  tux.invincible_timer.start(TUX_INVINCIBLE_TIME);
                 break;
               case SDLK_l:
                 if(debug_mode)
@@ -363,7 +362,6 @@ GameSession::action(double frame_ratio)
               world->get_level()->free_song();
               world->arrays_free();
 
-              unloadshared();
               return(0);
             }
           tux.level_begin();
@@ -390,7 +388,6 @@ GameSession::action(double frame_ratio)
               world->get_level()->free_song();
               world->arrays_free();
 
-              unloadshared();
               return(0);
             } /* if (lives < 0) */
         }
@@ -473,8 +470,10 @@ GameSession::run()
 
   global_frame_counter = 0;
   game_pause = false;
-  timer_init(&fps_timer,true);
-  timer_init(&frame_timer,true);
+
+  fps_timer.init(true);
+  frame_timer.init(true);
+
   last_update_time = st_get_ticks();
   fps_cnt = 0;
 
@@ -500,9 +499,9 @@ GameSession::run()
       if(frame_ratio > 1.5) /* Quick hack to correct the unprecise CPU clocks a little bit. */
         frame_ratio = 1.5 + (frame_ratio - 1.5) * 0.85;
 
-      if(!timer_check(&frame_timer))
+      if(!frame_timer.check())
         {
-          timer_start(&frame_timer,25);
+          frame_timer.start(25);
           ++global_frame_counter;
         }
 
@@ -604,10 +603,10 @@ GameSession::run()
         SDL_Delay((11 - (update_time - last_update_time))/2);*/
 
       /* Handle time: */
-      if (timer_check(&time_left))
+      if (time_left.check())
         {
           /* are we low on time ? */
-          if ((timer_get_left(&time_left) < TIME_WARNING)
+          if (time_left.get_left() < TIME_WARNING
               && (get_current_music() != HURRYUP_MUSIC))     /* play the fast music */
             {
               set_current_music(HURRYUP_MUSIC);
@@ -622,11 +621,11 @@ GameSession::run()
       if(show_fps)
         {
           ++fps_cnt;
-          fps_fps = (1000.0 / (float)timer_get_gone(&fps_timer)) * (float)fps_cnt;
+          fps_fps = (1000.0 / (float)fps_timer.get_gone()) * (float)fps_cnt;
 
-          if(!timer_check(&fps_timer))
+          if(!fps_timer.check())
             {
-              timer_start(&fps_timer,1000);
+              fps_timer.start(1000);
               fps_cnt = 0;
             }
         }
@@ -638,7 +637,6 @@ GameSession::run()
   world->get_level()->cleanup();
   world->get_level()->free_song();
 
-  unloadshared();
   world->arrays_free();
 
   return quit;
@@ -675,9 +673,9 @@ GameSession::drawstatus()
       text_draw(&white_text,"Press ESC To Return",0,20,1);
     }
 
-  if (timer_get_left(&time_left) > TIME_WARNING || (global_frame_counter % 10) < 5)
+  if (time_left.get_left() > TIME_WARNING || (global_frame_counter % 10) < 5)
     {
-      sprintf(str, "%d", timer_get_left(&time_left) / 1000 );
+      sprintf(str, "%d", time_left.get_left() / 1000 );
       text_draw(&white_text, "TIME", 224, 0, 1);
       text_draw(&gold_text, str, 304, 0, 1);
     }