Included supertux.h stuff into it.
[supertux.git] / src / gameloop.cpp
index 5016bae..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)
         {
@@ -249,11 +248,11 @@ GameSession::process_events()
                 break;
               case SDLK_END:
                 if(debug_mode)
-                  distros += 50;
+                  player_status.distros += 50;
                 break;
               case SDLK_SPACE:
                 if(debug_mode)
-                  next_level = 1;
+                  player_status.next_level = 1;
                 break;
               case SDLK_DELETE:
                 if(debug_mode)
@@ -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)
@@ -269,7 +268,7 @@ GameSession::process_events()
                 break;
               case SDLK_s:
                 if(debug_mode)
-                  score += 1000;
+                  player_status.score += 1000;
               case SDLK_f:
                 if(debug_fps)
                   debug_fps = false;
@@ -338,20 +337,20 @@ GameSession::process_events()
 }
 
 int
-GameSession::action()
+GameSession::action(double frame_ratio)
 {
   Player& tux = *world->get_tux();
 
-  if (tux.is_dead() || next_level)
+  if (tux.is_dead() || player_status.next_level)
     {
       /* Tux either died, or reached the end of a level! */
       halt_music();
       
-      if (next_level)
+      if (player_status.next_level)
         {
           /* End of a level! */
           levelnb++;
-          next_level = 0;
+          player_status.next_level = 0;
           if(st_gl_mode != ST_GL_TEST)
             {
               drawresultscreen();
@@ -363,7 +362,6 @@ GameSession::action()
               world->get_level()->free_song();
               world->arrays_free();
 
-              unloadshared();
               return(0);
             }
           tux.level_begin();
@@ -381,8 +379,8 @@ GameSession::action()
 
               if(st_gl_mode != ST_GL_TEST)
                 {
-                  if (score > hs_score)
-                    save_hs(score);
+                  if (player_status.score > hs_score)
+                    save_hs(player_status.score);
                 }
 
               world->get_level()->free_gfx();
@@ -390,7 +388,6 @@ GameSession::action()
               world->get_level()->free_song();
               world->arrays_free();
 
-              unloadshared();
               return(0);
             } /* if (lives < 0) */
         }
@@ -428,9 +425,9 @@ GameSession::action()
       play_current_music();
     }
 
-  tux.action();
+  tux.action(frame_ratio);
 
-  world->action();
+  world->action(frame_ratio);
 
   return -1;
 }
@@ -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;
 
@@ -496,13 +495,13 @@ GameSession::run()
   while (!done && !quit)
     {
       /* Calculate the movement-factor */
-      frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE);
+      double frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE);
       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;
         }
 
@@ -555,7 +554,7 @@ GameSession::run()
             frame_ratio = 1;
             while(z >= 1)
             {*/
-          if (action() == 0)
+          if (action(frame_ratio) == 0)
             {
               /* == 0: no more lives */
               /* == -1: continues */
@@ -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;
@@ -660,7 +658,7 @@ GameSession::drawstatus()
   Player& tux = *world->get_tux();
   char str[60];
 
-  sprintf(str, "%d", score);
+  sprintf(str, "%d", player_status.score);
   text_draw(&white_text, "SCORE", 0, 0, 1);
   text_draw(&gold_text, str, 96, 0, 1);
 
@@ -675,14 +673,14 @@ 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);
     }
 
-  sprintf(str, "%d", distros);
+  sprintf(str, "%d", player_status.distros);
   text_draw(&white_text, "DISTROS", screen->h, 0, 1);
   text_draw(&gold_text, str, 608, 0, 1);
 
@@ -710,10 +708,10 @@ GameSession::drawendscreen()
 
   text_drawf(&blue_text, "GAMEOVER", 0, 200, A_HMIDDLE, A_TOP, 1);
 
-  sprintf(str, "SCORE: %d", score);
+  sprintf(str, "SCORE: %d", player_status.score);
   text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1);
 
-  sprintf(str, "DISTROS: %d", distros);
+  sprintf(str, "DISTROS: %d", player_status.distros);
   text_drawf(&gold_text, str, 0, 256, A_HMIDDLE, A_TOP, 1);
 
   flipscreen();
@@ -731,10 +729,10 @@ GameSession::drawresultscreen(void)
 
   text_drawf(&blue_text, "Result:", 0, 200, A_HMIDDLE, A_TOP, 1);
 
-  sprintf(str, "SCORE: %d", score);
+  sprintf(str, "SCORE: %d", player_status.score);
   text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1);
 
-  sprintf(str, "DISTROS: %d", distros);
+  sprintf(str, "DISTROS: %d", player_status.distros);
   text_drawf(&gold_text, str, 0, 256, A_HMIDDLE, A_TOP, 1);
 
   flipscreen();