From f3c436b67f6fcc24a80a9ff2b4ebf561f19568f6 Mon Sep 17 00:00:00 2001 From: titiger Date: Thu, 2 Feb 2017 02:54:29 +0100 Subject: [PATCH] force playing important sounds see issue #144 --- source/glest_game/game/chat_manager.cpp | 2 +- source/glest_game/game/game.cpp | 2 +- source/glest_game/sound/sound_renderer.cpp | 4 ++-- source/glest_game/sound/sound_renderer.h | 2 +- source/glest_game/world/unit_updater.cpp | 2 +- .../include/sound/openal/sound_player_openal.h | 2 +- source/shared_lib/include/sound/sound_player.h | 2 +- .../sources/sound/openal/sound_player_openal.cpp | 12 +++++++++--- 8 files changed, 17 insertions(+), 11 deletions(-) diff --git a/source/glest_game/game/chat_manager.cpp b/source/glest_game/game/chat_manager.cpp index 34ca6f4c..502c6f2e 100644 --- a/source/glest_game/game/chat_manager.cpp +++ b/source/glest_game/game/chat_manager.cpp @@ -490,7 +490,7 @@ void ChatManager::updateNetwork() { if(msg.chatText.find(playerName) != string::npos){ CoreData &coreData= CoreData::getInstance(); SoundRenderer &soundRenderer= SoundRenderer::getInstance(); - soundRenderer.playFx(coreData.getHighlightSound()); + soundRenderer.playFx(coreData.getHighlightSound(),true); } console->addLine(msg.chatText.substr(1,msg.chatText.size()), true, msg.chatPlayerIndex,Vec3f(1.f, 1.f, 1.f),teamMode); } diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 0b2608c0..bea2f999 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -3097,7 +3097,7 @@ void Game::addOrReplaceInHighlightedCells(MarkedCell mc){ //printf("faction [%p][%s]\n",faction,(faction != NULL ? faction->getType()->getName().c_str() : "")); if((faction == NULL) || (faction->getTeam() == getWorld()->getThisFaction()->getTeam())) { - soundRenderer.playFx(coreData.getMarkerSound()); + soundRenderer.playFx(coreData.getMarkerSound(),true); } } } diff --git a/source/glest_game/sound/sound_renderer.cpp b/source/glest_game/sound/sound_renderer.cpp index 96b9d16d..7d094809 100644 --- a/source/glest_game/sound/sound_renderer.cpp +++ b/source/glest_game/sound/sound_renderer.cpp @@ -203,7 +203,7 @@ void SoundRenderer::playFx(StaticSound *staticSound, Vec3f soundPos, Vec3f camPo } } -void SoundRenderer::playFx(StaticSound *staticSound) { +void SoundRenderer::playFx(StaticSound *staticSound, bool force) { if(staticSound!=NULL){ staticSound->setVolume(fxVolume); if(soundPlayer != NULL) { @@ -213,7 +213,7 @@ void SoundRenderer::playFx(StaticSound *staticSound) { } if(soundPlayer) { - soundPlayer->play(staticSound); + soundPlayer->play(staticSound, force); } } } diff --git a/source/glest_game/sound/sound_renderer.h b/source/glest_game/sound/sound_renderer.h index 8d35b935..0f17196b 100644 --- a/source/glest_game/sound/sound_renderer.h +++ b/source/glest_game/sound/sound_renderer.h @@ -75,7 +75,7 @@ public: //fx void playFx(StaticSound *staticSound, Vec3f soundPos, Vec3f camPos); - void playFx(StaticSound *staticSound); + void playFx(StaticSound *staticSound, bool force=false); //ambient void playAmbient(StrSound *strSound); diff --git a/source/glest_game/world/unit_updater.cpp b/source/glest_game/world/unit_updater.cpp index ed700383..e1d76754 100644 --- a/source/glest_game/world/unit_updater.cpp +++ b/source/glest_game/world/unit_updater.cpp @@ -3127,7 +3127,7 @@ bool UnitUpdater::unitOnRange(Unit *unit, int range, Unit **rangedPtr, if(world->getAttackWarningsEnabled() == true) { - SoundRenderer::getInstance().playFx(CoreData::getInstance().getAttentionSound()); + SoundRenderer::getInstance().playFx(CoreData::getInstance().getAttentionSound(),true); world->addAttackEffects(enemyUnit); } } diff --git a/source/shared_lib/include/sound/openal/sound_player_openal.h b/source/shared_lib/include/sound/openal/sound_player_openal.h index 7b712224..7d4e89ce 100644 --- a/source/shared_lib/include/sound/openal/sound_player_openal.h +++ b/source/shared_lib/include/sound/openal/sound_player_openal.h @@ -97,7 +97,7 @@ public: virtual ~SoundPlayerOpenAL(); virtual bool init(const SoundPlayerParams *params); virtual void end(); - virtual void play(StaticSound *staticSound); + virtual void play(StaticSound *staticSound, bool force=false); virtual void play(StrSound *strSound, int64 fadeOn=0); virtual void stop(StrSound *strSound, int64 fadeOff=0); virtual void stopAllSounds(int64 fadeOff=0); diff --git a/source/shared_lib/include/sound/sound_player.h b/source/shared_lib/include/sound/sound_player.h index 5b0ed4cc..66f3e739 100644 --- a/source/shared_lib/include/sound/sound_player.h +++ b/source/shared_lib/include/sound/sound_player.h @@ -51,7 +51,7 @@ public: }; virtual bool init(const SoundPlayerParams *params)= 0; virtual void end()= 0; - virtual void play(StaticSound *staticSound)= 0; + virtual void play(StaticSound *staticSound, bool force=false)= 0; virtual void play(StrSound *strSound, int64 fadeOn=0)= 0; //delay and fade in miliseconds virtual void stop(StrSound *strSound, int64 fadeOff=0)= 0; virtual void stopAllSounds(int64 fadeOff=0)= 0; diff --git a/source/shared_lib/sources/sound/openal/sound_player_openal.cpp b/source/shared_lib/sources/sound/openal/sound_player_openal.cpp index e7d65e49..b163b867 100644 --- a/source/shared_lib/sources/sound/openal/sound_player_openal.cpp +++ b/source/shared_lib/sources/sound/openal/sound_player_openal.cpp @@ -516,7 +516,7 @@ void SoundPlayerOpenAL::end() { if(SystemFlags::getSystemSettingType(SystemFlags::debugSound).enabled) SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__); } -void SoundPlayerOpenAL::play(StaticSound* staticSound) { +void SoundPlayerOpenAL::play(StaticSound* staticSound, bool force ) { assert(staticSound != 0); if(initOk == false) return; @@ -524,8 +524,14 @@ void SoundPlayerOpenAL::play(StaticSound* staticSound) { try { StaticSoundSource* source = findStaticSoundSource(); - if(source == 0) { - return; + if(source == 0 ) { + if( force == false ) + return; + else { + // force usage of first StaticSoundSource + source = staticSources.front(); + source->stop(); + } } source->play(staticSound); }