Applied MatzeB (Ryan?) patch that fixes crash and also improves music.
authorRicardo Cruz <rick2@aeiou.pt>
Thu, 22 Apr 2004 11:17:34 +0000 (11:17 +0000)
committerRicardo Cruz <rick2@aeiou.pt>
Thu, 22 Apr 2004 11:17:34 +0000 (11:17 +0000)
Ingo, you seem to have forgotten to add two files to cvs:
smalltux-gameover-0.png
smalltux-gameover-1.png

SVN-Revision: 625

src/gameloop.cpp
src/level.cpp
src/resources.cpp
src/sound.cpp
src/title.cpp
src/world.cpp
src/worldmap.cpp

index 64d3ee8..b43a0a9 100644 (file)
@@ -474,7 +474,6 @@ GameSession::ExitStatus
 GameSession::run()
 {
   Menu::set_current(0);
-  Player* tux = world->get_tux();
   current_ = this;
   
   int fps_cnt = 0;
@@ -504,7 +503,7 @@ GameSession::run()
         }
 
       /* Handle events: */
-      tux->input.old_fire = tux->input.fire;
+      world->get_tux()->input.old_fire = world->get_tux()->input.fire;
 
       process_events();
       process_menu();
@@ -555,11 +554,11 @@ GameSession::run()
         }
 
       /* Handle time: */
-      if (!time_left.check() && tux->dying == DYING_NOT)
-        tux->kill(KILL);
+      if (!time_left.check() && world->get_tux()->dying == DYING_NOT)
+        world->get_tux()->kill(KILL);
 
       /* Handle music: */
-      if(tux->invincible_timer.check())
+      if(world->get_tux()->invincible_timer.check())
         {
           if(world->get_music_type() != HERRING_MUSIC)
             world->play_music(HERRING_MUSIC);
index f0700c9..bbd0915 100644 (file)
@@ -199,18 +199,18 @@ void st_subset::free()
 }
 
 Level::Level()
-  : level_song(0), level_song_fast(0)
+  : img_bkgd(0), level_song(0), level_song_fast(0)
 {
 }
 
 Level::Level(const std::string& subset, int level)
-  : level_song(0), level_song_fast(0)
+  : img_bkgd(0), level_song(0), level_song_fast(0)
 {
   load(subset, level);
 }
 
 Level::Level(const std::string& filename)
-  : level_song(0), level_song_fast(0)
+  : img_bkgd(0), level_song(0), level_song_fast(0)
 {
   load(filename);
 }
@@ -696,10 +696,13 @@ Level::change(float x, float y, int tm, unsigned int c)
 void 
 Level::free_song(void)
 {
+  if(level_song_fast != level_song) {
+    free_music(level_song_fast);
+    level_song_fast = 0;
+  }
+    
   free_music(level_song);
   level_song = 0;
-  free_music(level_song_fast);
-  level_song_fast = 0;
 }
 
 void
@@ -711,6 +714,8 @@ Level::load_song()
   char* song_subtitle;
 
   level_song = ::load_song(datadir + "/music/" + song_title);
+  if(!level_song)
+    st_abort("Couldn't load song: " , song_title.c_str());
 
   song_path = (char *) malloc(sizeof(char) * datadir.length() +
                               strlen(song_title.c_str()) + 8 + 5);
@@ -719,6 +724,9 @@ Level::load_song()
   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);
+  if(!level_song_fast) {
+    level_song_fast = level_song;
+  }
   free(song_subtitle);
   free(song_path);
 }
index fadd88c..b986b84 100644 (file)
@@ -25,6 +25,7 @@
 #include "special.h"
 #include "resources.h"
 #include "sprite_manager.h"
+#include "setup.h"
 
 Surface* img_waves[3]; 
 Surface* img_water;
@@ -289,6 +290,8 @@ void loadshared()
 
   /* Herring song */
   herring_song = load_song(datadir + "/music/SALCON.MOD");
+  if(!herring_song)
+    st_abort("Couldn't load song ", "/music/SALCON.MOD");
 }
 
 
index 340d019..984618a 100644 (file)
@@ -102,7 +102,6 @@ Mix_Chunk * load_sound(const std::string& file)
 
   snd = Mix_LoadWAV(file.c_str());
 
-  /* printf message and abort if there is an initialized audio device */
   if ((snd == NULL) && audio_device)
     st_abort("Can't load", file);
 
@@ -115,17 +114,10 @@ Mix_Chunk * load_sound(const std::string& file)
 Mix_Music * load_song(const std::string& file)
 {
   if(!audio_device)
-    return 0;
+    return (Mix_Music*) ~0;
   
-  Mix_Music * sng;
-
-  sng = Mix_LoadMUS(file.c_str());
-
-  /* printf message and abort if there is an initialized audio device */
-  if (sng == NULL)
-    st_abort("Can't load", file);
-  return (sng);
+  Mix_Music* song = Mix_LoadMUS(file.c_str());
+  return song;
 }
 
 
@@ -160,7 +152,6 @@ void free_chunk(Mix_Chunk *chunk)
 {
   if (chunk != NULL)
     {
-      DEBUG_MSG( __PRETTY_FUNCTION__ );
       Mix_FreeChunk( chunk );
       chunk = NULL;
     }
@@ -180,6 +171,8 @@ void play_music(Mix_Music *music)
 {
   if (!audio_device)
     return;
+  if(music == current_song)
+    return;
 
   if (use_music && Mix_PlayMusic(music, -1) < 0)
     st_abort("Couldn't play music: ", Mix_GetError());
@@ -190,6 +183,9 @@ void play_music(Mix_Music *music)
 
 void free_music(Mix_Music *music)
 {
+  if(!audio_device)
+    return;
+
   Mix_FreeMusic( music );
 }
 
index 33a28e2..83151af 100644 (file)
@@ -139,6 +139,7 @@ void check_contrib_subset_menu()
         {
           index -= 1; // FIXME: Hack
           std::cout << "Sarting level: " << index << std::endl;
+          halt_music();
           GameSession session(current_contrib_subset, index, ST_GL_PLAY);
           session.run();
           Menu::set_current(main_menu);
@@ -159,6 +160,8 @@ void draw_demo(GameSession* session, double frame_ratio)
   //World* world  = session->get_world();
   Level* plevel = session->get_level();
   Player* tux = session->get_world()->get_tux();
+
+  session->get_world()->play_music(LEVEL_MUSIC);
   
   /* FIXME:
   // update particle systems
@@ -248,9 +251,6 @@ void title(void)
   update_time = st_get_ticks();
   random_timer.start(rand() % 2000 + 2000);
 
-  Mix_Music* music = load_song(datadir + "/music/theme.mod");
-  play_music(music);
-
   Menu::set_current(main_menu);
   while (Menu::current())
     {
@@ -357,14 +357,11 @@ void title(void)
       /* Pause: */
       frame++;
       SDL_Delay(25);
-
-      play_music(music);
     }
   /* Free surfaces: */
 
   delete bkg_title;
   delete logo;
-  free_music(music);
 }
 
 #define MAX_VEL 10
index 4b6b62e..287c894 100644 (file)
@@ -68,8 +68,6 @@ World::World(const std::string& subset, int level_nr)
   activate_bad_guys();
   activate_particle_systems();
   get_level()->load_song();
-
-  play_music(LEVEL_MUSIC);
 }
 
 World::~World()
index 24bc53b..f595490 100644 (file)
@@ -726,6 +726,9 @@ WorldMap::display()
   quit = false;
 
   song = load_song(datadir +  "/music/" + music);
+  if(!song)
+    st_abort("Couldn't load song ", music.c_str());
+
   play_music(song);
 
   while(!quit) {