From: Ricardo Cruz Date: Thu, 22 Apr 2004 11:17:34 +0000 (+0000) Subject: Applied MatzeB (Ryan?) patch that fixes crash and also improves music. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=7fa266cd1d7062e3451a7dda0ccf42571faac78c;p=supertux.git Applied MatzeB (Ryan?) patch that fixes crash and also improves music. Ingo, you seem to have forgotten to add two files to cvs: smalltux-gameover-0.png smalltux-gameover-1.png SVN-Revision: 625 --- diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 64d3ee839..b43a0a9f7 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -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); diff --git a/src/level.cpp b/src/level.cpp index f0700c91a..bbd09158a 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -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); } diff --git a/src/resources.cpp b/src/resources.cpp index fadd88c80..b986b8466 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -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"); } diff --git a/src/sound.cpp b/src/sound.cpp index 340d01934..984618a0e 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -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 ); } diff --git a/src/title.cpp b/src/title.cpp index 33a28e24f..83151af3e 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -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 diff --git a/src/world.cpp b/src/world.cpp index 4b6b62e57..287c8949a 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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() diff --git a/src/worldmap.cpp b/src/worldmap.cpp index 24bc53b5b..f595490b3 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -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) {