From 86020ad94dac4c963c92c25e90e1e01ba99ed914 Mon Sep 17 00:00:00 2001 From: PLkolek Date: Thu, 8 Aug 2013 19:16:05 +0200 Subject: [PATCH] Added underwater and drowning sounds. --- apps/openmw/mwbase/soundmanager.hpp | 1 + apps/openmw/mwmechanics/mechanicsmanagerimp.cpp | 17 ++++++++++++++++- apps/openmw/mwsound/soundmanagerimp.cpp | 12 ++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwbase/soundmanager.hpp b/apps/openmw/mwbase/soundmanager.hpp index e1ca8e745..b75f6753d 100644 --- a/apps/openmw/mwbase/soundmanager.hpp +++ b/apps/openmw/mwbase/soundmanager.hpp @@ -134,6 +134,7 @@ namespace MWBase virtual bool getSoundPlaying(const MWWorld::Ptr &reference, const std::string& soundId) const = 0; ///< Is the given sound currently playing on the given object? + /// If you want to check if sound played with playSound is playing, use empty Ptr virtual void pauseSounds(int types=Play_TypeMask) = 0; ///< Pauses all currently playing sounds, including music. diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index cdcede507..2627a01b0 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -8,6 +8,7 @@ #include "../mwbase/world.hpp" #include "../mwbase/windowmanager.hpp" #include "../mwbase/dialoguemanager.hpp" +#include "../mwbase/soundmanager.hpp" #include "../mwworld/class.hpp" #include "../mwworld/player.hpp" @@ -287,13 +288,27 @@ namespace MWMechanics MWBase::Environment::get().getWindowManager()->setValue ("level", stats.getLevel()); } + //update drowning sound + MWBase::World *world = MWBase::Environment::get().getWorld(); + MWBase::SoundManager * sndmgr = MWBase::Environment::get().getSoundManager(); + MWWorld::Ptr playerPtr = world->getPlayer().getPlayer(); + NpcStats& playerStats = MWWorld::Class::get(playerPtr).getNpcStats(playerPtr); + if(!sndmgr->getSoundPlaying(MWWorld::Ptr(), "drown") && playerStats.getTimeToStartDrowning()==0.0) + { + sndmgr->playSound("drown",1.0,1.0,MWBase::SoundManager::Play_TypeSfx,MWBase::SoundManager::Play_Loop); + } + if(playerStats.getTimeToStartDrowning()>0.0) + { + //no need to check if it's playing, stop sound does nothing in that case + sndmgr->stopSound("drown"); + } + if (mUpdatePlayer) { // basic player profile; should not change anymore after the creation phase is finished. MWBase::WindowManager *winMgr = MWBase::Environment::get().getWindowManager(); - MWBase::World *world = MWBase::Environment::get().getWorld(); const ESM::NPC *player = world->getPlayer().getPlayer().get()->mBase; diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index 226b5ec3b..03e2ce623 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -547,7 +547,19 @@ namespace MWSound Environment env = Env_Normal; if((cell->mData.mFlags&cell->HasWater) && mListenerPos.z < cell->mWater) + { env = Env_Underwater; + //play underwater sound + //HACK: this sound is always played underwater, so set volume and pitch higher (it's then lowered) + //Currently not possible to play looping sound with no environment + if(!getSoundPlaying(MWWorld::Ptr(), "Underwater")) + playSound("Underwater", 1.11, 1.42 ,Play_TypeSfx, Play_Loop ); + } + else + { + //no need to check if it's playing, stop sound does nothing in that case + stopSound("Underwater"); + } mOutput->updateListener( mListenerPos,