- moved some more level_ stuff into the levelclass
authorIngo Ruhnke <grumbel@gmx.de>
Sun, 11 Apr 2004 01:24:58 +0000 (01:24 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Sun, 11 Apr 2004 01:24:58 +0000 (01:24 +0000)
- removed a quit, since it did the same as a done

SVN-Revision: 465

src/gameloop.cpp
src/gameloop.h
src/level.cpp
src/level.h
src/leveleditor.cpp
src/scene.cpp
src/scene.h
src/supertux.cpp
src/title.cpp
src/title.h
src/world.cpp

index e0cbe6a..838ccd7 100644 (file)
@@ -191,7 +191,7 @@ GameSession::process_events()
       switch(event.type)
         {
         case SDL_QUIT:        /* Quit event - quit: */
-          quit = 1;
+          quit = true;
           break;
         case SDL_KEYDOWN:     /* A keypress! */
           key = event.key.keysym.sym;
@@ -205,7 +205,7 @@ GameSession::process_events()
               if(!game_pause)
                 {
                   if(st_gl_mode == ST_GL_TEST)
-                    quit = 1;
+                    quit = true;
                   else if(show_menu)
                     {
                       Menu::set_current(game_menu);
@@ -367,9 +367,9 @@ GameSession::action()
             }
           else
             {
-              level_free_gfx();
+              world->get_level()->free_gfx();
               world->get_level()->cleanup();
-              level_free_song();
+              world->get_level()->free_song();
               unloadshared();
               world->arrays_free();
               return(0);
@@ -392,9 +392,9 @@ GameSession::action()
                   if (score > hs_score)
                     save_hs(score);
                 }
-              level_free_gfx();
+              world->get_level()->free_gfx();
               world->get_level()->cleanup();
-              level_free_song();
+              world->get_level()->free_song();
               unloadshared();
               world->arrays_free();
               return(0);
@@ -421,10 +421,12 @@ GameSession::action()
       world->arrays_free();
       activate_bad_guys(world->get_level());
       world->activate_particle_systems();
-      level_free_gfx();
+
+      world->get_level()->free_gfx();
       world->get_level()->load_gfx();
-      level_free_song();
+      world->get_level()->free_song();
       world->get_level()->load_song();
+
       if(st_gl_mode != ST_GL_TEST)
         levelintro();
       start_timers();
@@ -452,10 +454,7 @@ GameSession::action()
 void 
 GameSession::draw()
 {
-
-  
   world->draw();
-
   drawstatus();
 
   if(game_pause)
@@ -470,12 +469,11 @@ GameSession::draw()
     }
 
   if(show_menu)
-  {
-    menu_process_current();
-    mouse_cursor->draw();
-  }
+    {
+      menu_process_current();
+      mouse_cursor->draw();
+    }
 
-  /* (Update it all!) */
   updatescreen();
 }
 
@@ -486,13 +484,8 @@ GameSession::run()
   current_ = this;
   
   int  fps_cnt;
-  bool jump;
   bool done;
 
-  /* --- MAIN GAME LOOP!!! --- */
-  jump = false;
-  done = false;
-  quit = 0;
   global_frame_counter = 0;
   game_pause = 0;
   timer_init(&fps_timer,true);
@@ -511,10 +504,11 @@ GameSession::run()
   {}
 
   draw();
-  do
-    {
-      jump = false;
 
+  done = false;
+  quit = false;
+  while (!done && !quit)
+    {
       /* Calculate the movement-factor */
       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. */
@@ -617,17 +611,14 @@ GameSession::run()
       /* Pause till next frame, if the machine running the game is too fast: */
       /* FIXME: Works great for in OpenGl mode, where the CPU doesn't have to do that much. But
          the results in SDL mode aren't perfect (thought the 100 FPS are reached), even on an AMD2500+. */
-      if(last_update_time >= update_time - 12 && !jump) {
+      if(last_update_time >= update_time - 12) {
         SDL_Delay(10);
         update_time = st_get_ticks();
       }
       /*if((update_time - last_update_time) < 10)
         SDL_Delay((11 - (update_time - last_update_time))/2);*/
 
-
-
       /* Handle time: */
-
       if (timer_check(&time_left))
         {
           /* are we low on time ? */
@@ -642,7 +633,6 @@ GameSession::run()
       else
         tux.kill(KILL);
 
-
       /* Calculate frames per second */
       if(show_fps)
         {
@@ -655,15 +645,14 @@ GameSession::run()
               fps_cnt = 0;
             }
         }
-
     }
-  while (!done && !quit);
 
   halt_music();
 
-  level_free_gfx();
+  world->get_level()->free_gfx();
   world->get_level()->cleanup();
-  level_free_song();
+  world->get_level()->free_song();
+
   unloadshared();
   world->arrays_free();
 
@@ -860,10 +849,12 @@ GameSession::loadgame(int slot)
       world->arrays_free();
       activate_bad_guys(world->get_level());
       world->activate_particle_systems();
-      level_free_gfx();
+      
+      world->get_level()->free_gfx();
       world->get_level()->load_gfx();
-      level_free_song();
+      world->get_level()->free_song();
       world->get_level()->load_song();
+
       levelintro();
       update_time = st_get_ticks();
 
index 4806aeb..df0868d 100644 (file)
@@ -35,6 +35,7 @@ class World;
 class GameSession
 {
  private:
+  bool quit;
   timer_type fps_timer, frame_timer;
   World* world;
 
index e3e40c0..e316e47 100644 (file)
@@ -26,8 +26,6 @@
 
 using namespace std;
 
-texture_type img_bkgd;
-
 st_subset::st_subset()
 {
   levels = 0;
@@ -539,30 +537,9 @@ Level::cleanup()
   badguy_data.clear();
 }
 
-/* Load graphics: */
-
 void 
 Level::load_gfx()
 {
-  /*
-  level_load_image(&img_brick[0],theme,"brick0.png", IGNORE_ALPHA);
-  level_load_image(&img_brick[1],theme,"brick1.png", IGNORE_ALPHA);
-
-  level_load_image(&img_solid[0],theme,"solid0.png", USE_ALPHA);
-  level_load_image(&img_solid[1],theme,"solid1.png", USE_ALPHA);
-  level_load_image(&img_solid[2],theme,"solid2.png", USE_ALPHA);
-  level_load_image(&img_solid[3],theme,"solid3.png", USE_ALPHA);
-
-  level_load_image(&img_bkgd_tile[0][0],theme,"bkgd-00.png", USE_ALPHA);
-  level_load_image(&img_bkgd_tile[0][1],theme,"bkgd-01.png", USE_ALPHA);
-  level_load_image(&img_bkgd_tile[0][2],theme,"bkgd-02.png", USE_ALPHA);
-  level_load_image(&img_bkgd_tile[0][3],theme,"bkgd-03.png", USE_ALPHA);
-
-  level_load_image(&img_bkgd_tile[1][0],theme,"bkgd-10.png", USE_ALPHA);
-  level_load_image(&img_bkgd_tile[1][1],theme,"bkgd-11.png", USE_ALPHA);
-  level_load_image(&img_bkgd_tile[1][2],theme,"bkgd-12.png", USE_ALPHA);
-  level_load_image(&img_bkgd_tile[1][3],theme,"bkgd-13.png", USE_ALPHA);
-  */
   if(!bkgd_image.empty())
     {
       char fname[1024];
@@ -573,20 +550,20 @@ Level::load_gfx()
     }
   else
     {
-      /* Quick hack to make sure an image is loaded, when we are freeing it afterwards. */#
-      level_load_image(&img_bkgd, theme,"solid0.png", IGNORE_ALPHA);
+      /* Quick hack to make sure an image is loaded, when we are freeing it afterwards. */
+      load_image(&img_bkgd, theme,"solid0.png", IGNORE_ALPHA);
     }
 }
 
-/* Free graphics data for this level: */
-void level_free_gfx(void)
+void
+Level::free_gfx()
 {
   texture_free(&img_bkgd);
 }
 
 /* Load a level-specific graphic... */
-
-void level_load_image(texture_type* ptexture, string theme,const  char * file, int use_alpha)
+void
+Level::load_image(texture_type* ptexture, string theme,const  char * file, int use_alpha)
 {
   char fname[1024];
 
@@ -647,16 +624,13 @@ Level::change(float x, float y, int tm, unsigned int c)
     }
 }
 
-/* Free music data for this level: */
-
-void level_free_song(void)
+void 
+Level::free_song(void)
 {
   free_music(level_song);
   free_music(level_song_fast);
 }
 
-/* Load music: */
-
 void
 Level::load_song()
 {
@@ -669,7 +643,8 @@ Level::load_song()
                               strlen(song_title.c_str()) + 8 + 5);
   song_subtitle = strdup(song_title.c_str());
   strcpy(strstr(song_subtitle, "."), "\0");
-  sprintf(song_path, "%s/music/%s-fast%s", datadir.c_str(), song_subtitle, strstr(song_title.c_str(), "."));
+  sprintf(song_path, "%s/music/%s-fast%s", datadir.c_str(), 
+          song_subtitle, strstr(song_title.c_str(), "."));
   level_song_fast = ::load_song(song_path);
   free(song_subtitle);
   free(song_path);
index 2a4526d..dfb1c1e 100644 (file)
@@ -50,11 +50,11 @@ enum TileMapType {
  TM_FG
  };
 
-extern texture_type img_bkgd;
-
 class Level 
 {
  public:
+  texture_type img_bkgd;
+
   std::string name;
   std::string theme;
   std::string song_title;
@@ -87,7 +87,9 @@ class Level
   int  load(const std::string& filename);
 
   void load_gfx();
+  
   void load_song();
+  void free_song();
 
   void save(const char* subset, int level);
 
@@ -99,10 +101,11 @@ class Level
 
   /** Return the id of the tile at position x/y */
   unsigned int gettileid(float x, float y);
+
+  void free_gfx();
+
+  void load_image(texture_type* ptexture, std::string theme, const char * file, int use_alpha);
 };
 
-void level_load_image(texture_type* ptexture, std::string theme, const char * file, int use_alpha);
-void level_free_song();
-void level_free_gfx();
 
 #endif /*SUPERTUX_LEVEL_H*/
index 6bca703..a4c40fa 100644 (file)
@@ -519,7 +519,7 @@ void apply_level_settings_menu()
 
   if(i)
     {
-      level_free_gfx();
+      le_current_level->free_gfx();
       le_current_level->load_gfx();
     }
 
@@ -556,9 +556,9 @@ void le_goto_level(int levelnb)
 
   le_set_defaults();
 
-
-  level_free_gfx();
+  le_current_level->free_gfx();
   le_current_level->load_gfx();
+
   activate_bad_guys(le_current_level);
 }
 
@@ -593,7 +593,7 @@ void le_quit(void)
 
   if(le_current_level != NULL)
     {
-      level_free_gfx();
+      le_current_level->free_gfx();
       le_current_level->cleanup();
       unloadshared();
       world.arrays_free();
@@ -682,8 +682,10 @@ void le_drawlevel()
   if(le_current_level->bkgd_image[0] != '\0')
     {
       s = pos_x / 30;
-      texture_draw_part(&img_bkgd,s,0,0,0,img_bkgd.w - s - 32, img_bkgd.h);
-      texture_draw_part(&img_bkgd,0,0,screen->w - s - 32 ,0,s,img_bkgd.h);
+      texture_draw_part(&le_current_level->img_bkgd,s,0,0,0,
+                        le_current_level->img_bkgd.w - s - 32, le_current_level->img_bkgd.h);
+      texture_draw_part(&le_current_level->img_bkgd,0,0,screen->w - s - 32 ,0,s,
+                        le_current_level->img_bkgd.h);
     }
   else
     {
index b2a2421..c9c506a 100644 (file)
@@ -18,7 +18,6 @@ int distros;
 int level;
 int next_level;
 int game_pause;
-bool quit;
 int score_multiplier;
 int endpos;
 bool counting_distros;
index c3e6018..6d0203a 100644 (file)
@@ -29,7 +29,6 @@ extern int distros;
 extern int level; 
 extern int next_level;
 extern int game_pause;
-extern bool quit;
 extern int score_multiplier;
 extern int endpos;
 extern bool counting_distros;
index 5d90b61..73991fe 100644 (file)
@@ -17,7 +17,7 @@
 
 int main(int argc, char * argv[])
 {
-  int done;
+  bool done;
   
   st_directory_setup();
   parseargs(argc, argv);
@@ -39,8 +39,7 @@ int main(int argc, char * argv[])
     }
   else
     {  
-      done = 0;
-  
+      done = false;
       while (!done)
         {
           done = title();
@@ -52,5 +51,5 @@ int main(int argc, char * argv[])
 
   st_shutdown();
   
-  return(0);
+  return 0;
 }
index b90a631..38812ae 100644 (file)
@@ -129,9 +129,8 @@ void draw_demo(Level* plevel)
 
 /* --- TITLE SCREEN --- */
 
-int title(void)
+bool title(void)
 {
-  int done;
   string_list_type level_subsets;
   st_subset subset;
   level_subsets = dsubdirs("/levels", "info");
@@ -162,9 +161,7 @@ int title(void)
   texture_load(&img_choose_subset,datadir + "/images/status/choose-level-subset.png", USE_ALPHA);
 
   /* --- Main title loop: --- */
-
-  done = 0;
-  quit = 0;
+  bool done = 0;
   show_menu = 1;
   frame = 0;
 
@@ -175,9 +172,8 @@ int title(void)
   update_time = st_get_ticks();
   timer_start(&random_timer, rand() % 2000 + 2000);
 
-  while (!done && !quit)
+  while (!done)
     {
-
       /* Calculate the movement-factor */
       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. */
@@ -192,13 +188,11 @@ int title(void)
           menu_event(event);
           if (event.type == SDL_QUIT)
             {
-              /* Quit event - quit: */
-              quit = 1;
+              done = true;
             }
           else if (event.type == SDL_KEYDOWN)
             {
               /* Keypress... */
-
               key = event.key.keysym.sym;
 
               /* Check for menu events */
@@ -207,8 +201,7 @@ int title(void)
               if (key == SDLK_ESCAPE)
                 {
                   /* Escape: Quit: */
-
-                  quit = 1;
+                  done = true;
                 }
             }
         }
@@ -237,7 +230,7 @@ int title(void)
       */
 
       /* Don't draw menu, if quit is true */
-      if(show_menu && !quit)
+      if(show_menu && !done)
         menu_process_current();
 
       if(current_menu == main_menu)
@@ -276,8 +269,7 @@ int title(void)
                           switch(event.type)
                             {
                             case SDL_QUIT:
-                              done = 1;
-                              quit = 1;
+                              done = true;
                               break;
                             case SDL_KEYDOWN:          // key pressed
                               // Keypress...
@@ -333,13 +325,13 @@ int title(void)
               break;
             case 3:
               done = 1;
-              quit = leveleditor(1);
+              done = leveleditor(1);
               break;
             case 4:
               display_credits();
               break;
             case 5:
-              quit = 1;
+              done = true;
               break;
             }
         }
@@ -382,8 +374,7 @@ int title(void)
   string_list_free(&level_subsets);
 
   /* Return to main! */
-
-  return(quit);
+  return done;
 }
 
 #define MAX_VEL 10
index 4241a88..280e75c 100644 (file)
@@ -10,4 +10,4 @@
   April 11, 2000 - March 15, 2004
 */
 
-int title(void);
+bool title(void);
index 95ff32c..b4eca07 100644 (file)
@@ -18,6 +18,7 @@
 #include "screen.h"
 #include "defines.h"
 #include "world.h"
+#include "level.h"
 #include "tile.h"
 
 texture_type img_distro[4];
@@ -95,8 +96,8 @@ World::draw()
       if(get_level()->bkgd_image[0] != '\0')
         {
           int s = (int)scroll_x / 30;
-          texture_draw_part(&img_bkgd,s,0,0,0,img_bkgd.w - s, img_bkgd.h);
-          texture_draw_part(&img_bkgd,0,0,screen->w - s ,0,s,img_bkgd.h);
+          texture_draw_part(&level->img_bkgd, s, 0,0,0,level->img_bkgd.w - s, level->img_bkgd.h);
+          texture_draw_part(&level->img_bkgd, 0, 0,screen->w - s ,0,s,level->img_bkgd.h);
         }
       else
         {
@@ -399,7 +400,8 @@ void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick)
       else
         {
           s = (int)scroll_x / 30;
-          texture_draw_part(&img_bkgd,dest.x + s,dest.y,dest.x,dest.y,dest.w,dest.h);
+          texture_draw_part(&plevel->img_bkgd, dest.x + s, dest.y, 
+                            dest.x, dest.y,dest.w,dest.h);
         }
 
       drawshape(pbouncy_brick->base.x - scroll_x,