From 55a0cb0552f4e30a1ca2a013b85703d330d230e6 Mon Sep 17 00:00:00 2001 From: Allanis Date: Wed, 21 May 2014 21:30:28 +0100 Subject: [PATCH] [Add] Dirty hack to make sure engine sounds stop when toolkit is open. Proper fix will involve fixing SDL_mixer stuff. --- src/menu.c | 14 ++++++++++++-- src/player.c | 32 ++++++++++++++++++++++++++++++-- src/player.h | 3 +++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/menu.c b/src/menu.c index 5940610..06eb891 100644 --- a/src/menu.c +++ b/src/menu.c @@ -206,6 +206,9 @@ void menu_small(void) { menu_isOpen(MENU_DEATH))) return; + /* Pauses the players sounds. */ + player_soundPause(); + wid = window_create("Menu", -1, -1, MENU_WIDTH, MENU_HEIGHT); window_setCancel(wid, menu_small_close); @@ -232,6 +235,9 @@ static void menu_small_close(unsigned int wid, char* str) { (void)str; window_destroy(wid); menu_Close(MENU_SMALL); + + /* Resume player sounds. */ + player_soundResume(); } /** @@ -284,8 +290,6 @@ static void exit_game(void) { } /** - * @fn void menu_info(void) - * * @brief Open the information window. */ void menu_info(void) { @@ -296,6 +300,9 @@ void menu_info(void) { /* Can't open menu twise. */ if(menu_isOpen(MENU_INFO) || dialogue_isOpen()) return; + /* Pauses the players sounds. */ + player_soundPause(); + wid = window_create("Info", -1, -1, INFO_WIDTH, INFO_HEIGHT); /* Pilot generics. */ @@ -355,6 +362,9 @@ static void menu_info_close(unsigned int wid, char* str) { (void)str; window_destroy(wid); menu_Close(MENU_INFO); + + /* Resume player sounds. */ + player_soundResume(); } /** diff --git a/src/player.c b/src/player.c index 225e611..afd1ca2 100644 --- a/src/player.c +++ b/src/player.c @@ -5,6 +5,7 @@ */ #include +#include "SDL_mixer.h" /** @todo Remove dependency. */ #include "lephisto.h" #include "pilot.h" @@ -2007,12 +2008,13 @@ void player_land(void) { player_message("You are going too fast to land on %s.", planet->name); return; } - /* Stop acceleration / afterburning. */ - player_accelOver(); + /* Stop afterburning. */ player_afterburnOver(); /* Open land menu. */ + player_soundPause(); land(planet); + player_soundResume(); } else { /* Get nearest planet target. */ if(cur_system->nplanets == 0) { @@ -2171,6 +2173,8 @@ void player_afterburn(void) { sound_stopGroup(PLAYER_ENGINE_CHANNEL); sound_playGroup(PLAYER_ENGINE_CHANNEL, player->afterburner->outfit->u.afb.sound, 0); + if(toolkit) + player_soundPause(); } } @@ -2195,6 +2199,8 @@ void player_accel(double acc) { sound_stopGroup(PLAYER_ENGINE_CHANNEL); sound_playGroup(PLAYER_ENGINE_CHANNEL, player->ship->sound, 0); + if(toolkit) + player_soundPause(); } } @@ -2206,6 +2212,28 @@ void player_accelOver(void) { sound_stopGroup(PLAYER_ENGINE_CHANNEL); } +/** + * @brief Pause the ship's sounds. + * + * @todo Not use hardcoded PLAYER_ENGINE_CHANNEL sound... Ideally add support + * for pausing/resuming groups in SDL_Mixer. + */ +void player_soundPause(void) { + if(!Mix_Paused(0)) + Mix_Pause(0); +} + +/** + * @brief Resumes the ships sounds. + * + * @todo Not use hardcoded PLAYER_ENGINE_CHANNEL sound... Ideally add support + * for pausing/resuming groups in SDL_Mixer. + */ +void player_soundResume(void) { + if(Mix_Paused(0)) + Mix_Resume(0); +} + /** * @brief Target the nearest hostile enemy to the player. */ diff --git a/src/player.h b/src/player.h index bd348a7..f9ce8da 100644 --- a/src/player.h +++ b/src/player.h @@ -51,8 +51,11 @@ void player_message(const char* fmt, ...); void player_clear(void); void player_warp(const double x, const double y); const char* player_rating(void); +/* Sounds. */ void player_playSound(int sound, int once); void player_stopSound(void); +void player_soundPause(void); +void player_soundResume(void); /* Cargo. */ int player_outfitOwned(const char* outfitname); int player_cargoOwned(const char* commodityname);