[Super-tux-commit] supertux/src gameloop.cpp,1.91,1.92 level.cpp,1.44,1.45 level.h,1.34,1.35 player.
Brought to you by:
wkendrick
From: Ingo R. <gr...@us...> - 2004-04-21 23:42:05
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9831 Modified Files: gameloop.cpp level.cpp level.h player.cpp scene.cpp setup.cpp sound.cpp sound.h special.cpp world.cpp world.h worldmap.cpp Log Message: - music patch from MatzeB, should fix crash on level exit too worldmap Index: scene.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/scene.cpp,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- scene.cpp 20 Apr 2004 11:09:34 -0000 1.22 +++ scene.cpp 21 Apr 2004 23:38:03 -0000 1.23 @@ -25,7 +25,8 @@ PlayerStatus::PlayerStatus() : score(0), distros(0), - lives(3) + lives(3), + score_multiplier(1) { } Index: world.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/world.h,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- world.h 20 Apr 2004 20:10:53 -0000 1.27 +++ world.h 21 Apr 2004 23:38:13 -0000 1.28 @@ -55,6 +55,8 @@ int distro_counter; bool counting_distros; + int currentmusic; + static World* current_; public: static World* current() { return current_; } @@ -73,6 +75,10 @@ void draw(); void action(double frame_ratio); + void play_music(int musictype); + int get_music_type(); + + /** Checks for all possible collisions. And calls the collision_handlers, which the collision_objects provide for this case (or not). */ Index: special.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/special.cpp,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- special.cpp 20 Apr 2004 19:55:10 -0000 1.23 +++ special.cpp 21 Apr 2004 23:38:07 -0000 1.24 @@ -311,12 +311,7 @@ { play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER); pplayer->invincible_timer.start(TUX_INVINCIBLE_TIME); - /* play the herring song ^^ */ - if (get_current_music() != HURRYUP_MUSIC) - { - set_current_music(HERRING_MUSIC); - play_current_music(); - } + World::current()->play_music(HERRING_MUSIC); } else if (kind == UPGRADE_1UP) { Index: sound.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/sound.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- sound.cpp 20 Apr 2004 11:09:34 -0000 1.9 +++ sound.cpp 21 Apr 2004 23:38:04 -0000 1.10 @@ -54,7 +54,8 @@ #include <SDL_mixer.h> Mix_Chunk * sounds[NUM_SOUNDS]; -Mix_Music * level_song, * level_song_fast, * herring_song; +Mix_Music * herring_song = 0; +Mix_Music * current_song = 0; /* --- OPEN THE AUDIO DEVICE --- */ @@ -113,13 +114,17 @@ Mix_Music * load_song(const std::string& file) { + if(!audio_device) + return 0; + Mix_Music * sng; sng = Mix_LoadMUS(file.c_str()); /* printf message and abort if there is an initialized audio device */ - if ((sng == NULL) && audio_device) + if (sng == NULL) st_abort("Can't load", file); + return (sng); } @@ -161,88 +166,42 @@ } } - -int playing_music(void) +void halt_music(void) { - if (use_music) - { - return Mix_PlayingMusic(); - } - else - { - /* we are in --disable-music we can't be playing music */ - return 0; - } + if (!use_music || !audio_device) + return; + + Mix_HaltMusic(); + current_song = 0; } -int halt_music(void) +void play_music(Mix_Music *music) { - if (use_music && audio_device) - { - return Mix_HaltMusic(); - } - else - { - return 0; - } -} + if (!audio_device) + return; + if (use_music && Mix_PlayMusic(music, -1) < 0) + st_abort("Couldn't play music: ", Mix_GetError()); -int play_music(Mix_Music *music, int loops) -{ - if (use_music && audio_device) - { - DEBUG_MSG(__PRETTY_FUNCTION__); - return Mix_PlayMusic(music, loops); - } - else - { - /* return error since you're trying to play music in --disable-sound mode */ - return -1; - } + current_song = music; } void free_music(Mix_Music *music) { - if ( music != NULL ) - { - DEBUG_MSG(__PRETTY_FUNCTION__); - Mix_FreeMusic( music ); - music = NULL; - } + Mix_FreeMusic( music ); } - int get_current_music() - { - return current_music; - } - - void set_current_music(int music) - { - current_music = music; - } - - void play_current_music() - { - if(playing_music()) - halt_music(); - - switch(current_music) - { - case LEVEL_MUSIC: - play_music(level_song, -1); // -1 to play forever - break; - case HERRING_MUSIC: - play_music(herring_song, -1); - break; - case HURRYUP_MUSIC: - play_music(level_song_fast, -1); - break; - case NO_MUSIC: // keep the compiler happy for the moment :-) - {} - /*default:*/ - } - /* use halt_music whenever you want to stop it */ + +void enable_music(bool enable) +{ + if(!audio_device) + return; + + use_music = enable; + if(!use_music) + Mix_HaltMusic(); + else + Mix_PlayMusic(current_song, -1); } Index: worldmap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.cpp,v retrieving revision 1.41 retrieving revision 1.42 diff -u -d -r1.41 -r1.42 --- worldmap.cpp 21 Apr 2004 11:17:31 -0000 1.41 +++ worldmap.cpp 21 Apr 2004 23:38:14 -0000 1.42 @@ -582,7 +582,7 @@ break; } - play_music(song, 1); + play_music(song); Menu::set_current(0); if (!savegame_file.empty()) savegame(savegame_file); @@ -726,7 +726,7 @@ quit = false; song = load_song(datadir + "/music/" + music); - play_music(song, 1); + play_music(song); while(!quit) { Point tux_pos = tux->get_pos(); Index: sound.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/sound.h,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- sound.h 20 Apr 2004 11:09:34 -0000 1.23 +++ sound.h 21 Apr 2004 23:38:05 -0000 1.24 @@ -77,8 +77,6 @@ /* variables for stocking the sound and music */ extern Mix_Chunk* sounds[NUM_SOUNDS]; -extern Mix_Music* level_song; -extern Mix_Music* level_song_fast; extern Mix_Music* herring_song; /* functions handling the sound and music */ @@ -86,17 +84,13 @@ void close_audio( void ); Mix_Chunk * load_sound(const std::string& file); -void play_sound(Mix_Chunk * snd, enum Sound_Speaker whichSpeaker); -Mix_Music * load_song(const std::string& file); - -int playing_music(void); -int halt_music(void); -int play_music(Mix_Music*music, int loops); -void free_music(Mix_Music*music); void free_chunk(Mix_Chunk*chunk); +void play_sound(Mix_Chunk * snd, enum Sound_Speaker whichSpeaker); -int get_current_music(); -void set_current_music(int music); -void play_current_music(); +Mix_Music* load_song(const std::string& file); +void free_music(Mix_Music* music); +void halt_music(void); +void enable_music(bool enable); +void play_music(Mix_Music* music); #endif /*SUPERTUX_SOUND_H*/ Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.91 retrieving revision 1.92 diff -u -d -r1.91 -r1.92 --- gameloop.cpp 21 Apr 2004 13:40:44 -0000 1.91 +++ gameloop.cpp 21 Apr 2004 23:36:39 -0000 1.92 @@ -122,7 +122,8 @@ } time_left.init(true); - start_timers(); + start_timers(); + world->play_music(LEVEL_MUSIC); } GameSession::~GameSession() @@ -484,9 +485,6 @@ clearscreen(0, 0, 0); updatescreen(); - /* Play music: */ - play_current_music(); - // Eat unneeded events SDL_Event event; while (SDL_PollEvent(&event)) {} @@ -557,19 +555,25 @@ } /* Handle time: */ - if (time_left.check()) + if (!time_left.check() && tux->dying == DYING_NOT) + tux->kill(KILL); + + /* Handle music: */ + if(tux->invincible_timer.check()) { - /* are we low on time ? */ - if (time_left.get_left() < TIME_WARNING - && (get_current_music() != HURRYUP_MUSIC)) /* play the fast music */ - { - set_current_music(HURRYUP_MUSIC); - play_current_music(); - } + if(world->get_music_type() != HERRING_MUSIC) + world->play_music(HERRING_MUSIC); } - else if(tux->dying == DYING_NOT) + /* are we low on time ? */ + else if (time_left.get_left() < TIME_WARNING + && (world->get_music_type() == LEVEL_MUSIC)) { - tux->kill(KILL); + world->play_music(HURRYUP_MUSIC); + } + /* or just normal music? */ + else if(world->get_music_type() != LEVEL_MUSIC) + { + world->play_music(LEVEL_MUSIC); } /* Calculate frames per second */ @@ -586,11 +590,8 @@ } } - halt_music(); - - world->get_level()->free_gfx(); - world->get_level()->cleanup(); - world->get_level()->free_song(); + delete world; + world = 0; return exit_status; } Index: setup.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/setup.cpp,v retrieving revision 1.46 retrieving revision 1.47 diff -u -d -r1.46 -r1.47 --- setup.cpp 21 Apr 2004 15:15:28 -0000 1.46 +++ setup.cpp 21 Apr 2004 23:38:03 -0000 1.47 @@ -520,22 +520,7 @@ case 5: if(use_music != options_menu->item[5].toggled) { - if(use_music) - { - if(playing_music()) - { - halt_music(); - } - use_music = false; - } - else - { - use_music = true; - if (!playing_music()) - { - play_current_music(); - } - } + enable_music(options_menu->item[5].toggled); } break; case 6: @@ -1000,6 +985,7 @@ /* Disable the compiled in sound feature */ printf("Sounds disabled \n"); use_sound = false; + audio_device = false; } else if (strcmp(argv[i], "--disable-music") == 0) { Index: level.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.h,v retrieving revision 1.34 retrieving revision 1.35 diff -u -d -r1.34 -r1.35 --- level.h 20 Apr 2004 11:09:33 -0000 1.34 +++ level.h 21 Apr 2004 23:37:40 -0000 1.35 @@ -68,6 +68,8 @@ { public: Surface* img_bkgd; + Mix_Music* level_song; + Mix_Music* level_song_fast; std::string name; std::string author; @@ -95,6 +97,7 @@ Level(); Level(const std::string& subset, int level); Level(const std::string& filename); + ~Level(); /** Will the Level structure with default values */ void init_defaults(); @@ -115,6 +118,8 @@ void load_song(); void free_song(); + Mix_Music* get_level_music(); + Mix_Music* get_level_music_fast(); void save(const char* subset, int level); Index: player.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/player.cpp,v retrieving revision 1.50 retrieving revision 1.51 diff -u -d -r1.50 -r1.51 --- player.cpp 20 Apr 2004 19:55:09 -0000 1.50 +++ player.cpp 21 Apr 2004 23:37:50 -0000 1.51 @@ -276,36 +276,8 @@ } } - /* ---- DONE HANDLING TUX! --- */ - /* Handle invincibility timer: */ - if (get_current_music() == HERRING_MUSIC && !invincible_timer.check()) - { - /* - no, we are no more invincible - or we were not in invincible mode - but are we in hurry ? - */ - - // FIXME: Move this to gamesession - if (GameSession::current()->time_left.get_left() < TIME_WARNING) - { - /* yes, we are in hurry - stop the herring_song, prepare to play the correct - fast level_song ! - */ - set_current_music(HURRYUP_MUSIC); - } - else - { - set_current_music(LEVEL_MUSIC); - } - - /* start playing it */ - play_current_music(); - } - // check some timers skidding_timer.check(); invincible_timer.check(); Index: level.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.cpp,v retrieving revision 1.44 retrieving revision 1.45 diff -u -d -r1.44 -r1.45 --- level.cpp 21 Apr 2004 12:45:06 -0000 1.44 +++ level.cpp 21 Apr 2004 23:37:39 -0000 1.45 @@ -199,19 +199,28 @@ } Level::Level() + : level_song(0), level_song_fast(0) { } Level::Level(const std::string& subset, int level) + : level_song(0), level_song_fast(0) { load(subset, level); } Level::Level(const std::string& filename) + : level_song(0), level_song_fast(0) { load(filename); } +Level::~Level() +{ + free_gfx(); + free_song(); +} + void Level::init_defaults() { @@ -688,12 +697,16 @@ Level::free_song(void) { free_music(level_song); + level_song = 0; free_music(level_song_fast); + level_song_fast = 0; } void Level::load_song() { + free_song(); + char* song_path; char* song_subtitle; @@ -710,6 +723,18 @@ free(song_path); } +Mix_Music* +Level::get_level_music() +{ + return level_song; +} + +Mix_Music* +Level::get_level_music_fast() +{ + return level_song_fast; +} + unsigned int Level::gettileid(float x, float y) { Index: world.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/world.cpp,v retrieving revision 1.34 retrieving revision 1.35 diff -u -d -r1.34 -r1.35 --- world.cpp 21 Apr 2004 22:48:43 -0000 1.34 +++ world.cpp 21 Apr 2004 23:38:08 -0000 1.35 @@ -68,10 +68,13 @@ activate_bad_guys(); activate_particle_systems(); get_level()->load_song(); + + play_music(LEVEL_MUSIC); } World::~World() { + halt_music(); // just to be sure (because levelmusic is freed now) delete level; } @@ -87,7 +90,7 @@ distro_counter = 0; /* set current song/music */ - set_current_music(LEVEL_MUSIC); + currentmusic = LEVEL_MUSIC; } void @@ -409,6 +412,32 @@ play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER); } +void +World::play_music(int musictype) +{ + currentmusic = musictype; + switch(currentmusic) { + case HURRYUP_MUSIC: + ::play_music(get_level()->get_level_music_fast()); + break; + case LEVEL_MUSIC: + ::play_music(get_level()->get_level_music()); + break; + case HERRING_MUSIC: + ::play_music(herring_song); + break; + default: + ::halt_music(); + break; + } +} + +int +World::get_music_type() +{ + return currentmusic; +} + /* Break a brick: */ void World::trybreakbrick(float x, float y, bool small) |