mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 06:53:53 +00:00
Add methods to pause and stop all playing sounds (and music)
This commit is contained in:
parent
973b5faf25
commit
2c1eceb9f0
7 changed files with 61 additions and 0 deletions
|
@ -112,6 +112,12 @@ namespace MWBase
|
|||
virtual bool getSoundPlaying(MWWorld::Ptr reference, const std::string& soundId) const = 0;
|
||||
///< Is the given sound currently playing on the given object?
|
||||
|
||||
virtual void pauseAllSounds() = 0;
|
||||
///< Pauses all currently playing sounds, including music.
|
||||
|
||||
virtual void resumeAllSounds() = 0;
|
||||
///< Resumes all previously paused sounds.
|
||||
|
||||
virtual void update(float duration) = 0;
|
||||
|
||||
virtual void setListenerPosDir(const Ogre::Vector3 &pos, const Ogre::Vector3 &dir, const Ogre::Vector3 &up) = 0;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/soundmanager.hpp"
|
||||
|
||||
|
||||
|
||||
|
@ -821,6 +822,7 @@ namespace MWRender
|
|||
// Register all formats and codecs
|
||||
av_register_all();
|
||||
|
||||
MWBase::Environment::get().getSoundManager()->pauseAllSounds();
|
||||
if(SDL_Init(SDL_INIT_AUDIO)) {
|
||||
throw std::runtime_error("Failed to initialize SDL");
|
||||
}
|
||||
|
@ -860,6 +862,7 @@ namespace MWRender
|
|||
mState = NULL;
|
||||
|
||||
SDL_CloseAudio();
|
||||
MWBase::Environment::get().getSoundManager()->resumeAllSounds();
|
||||
|
||||
mRectangle->setVisible (false);
|
||||
MWBase::Environment::get().getWindowManager ()->removeGuiMode (MWGui::GM_Video);
|
||||
|
|
|
@ -814,6 +814,33 @@ void OpenAL_Output::updateListener(const Ogre::Vector3 &pos, const Ogre::Vector3
|
|||
}
|
||||
|
||||
|
||||
void OpenAL_Output::pauseAllSounds()
|
||||
{
|
||||
IDVec sources = mSources;
|
||||
IDDq::const_iterator iter = mFreeSources.begin();
|
||||
while(iter != mFreeSources.end())
|
||||
{
|
||||
sources.erase(std::find(sources.begin(), sources.end(), *iter));
|
||||
iter++;
|
||||
}
|
||||
if(sources.size() > 0)
|
||||
alSourcePausev(sources.size(), &sources[0]);
|
||||
}
|
||||
|
||||
void OpenAL_Output::resumeAllSounds()
|
||||
{
|
||||
IDVec sources = mSources;
|
||||
IDDq::const_iterator iter = mFreeSources.begin();
|
||||
while(iter != mFreeSources.end())
|
||||
{
|
||||
sources.erase(std::find(sources.begin(), sources.end(), *iter));
|
||||
iter++;
|
||||
}
|
||||
if(sources.size() > 0)
|
||||
alSourcePlayv(sources.size(), &sources[0]);
|
||||
}
|
||||
|
||||
|
||||
OpenAL_Output::OpenAL_Output(SoundManager &mgr)
|
||||
: Sound_Output(mgr), mDevice(0), mContext(0), mBufferCacheMemSize(0),
|
||||
mLastEnvironment(Env_Normal), mStreamThread(new StreamThread)
|
||||
|
|
|
@ -52,6 +52,9 @@ namespace MWSound
|
|||
|
||||
virtual void updateListener(const Ogre::Vector3 &pos, const Ogre::Vector3 &atdir, const Ogre::Vector3 &updir, Environment env);
|
||||
|
||||
virtual void pauseAllSounds();
|
||||
virtual void resumeAllSounds();
|
||||
|
||||
OpenAL_Output& operator=(const OpenAL_Output &rhs);
|
||||
OpenAL_Output(const OpenAL_Output &rhs);
|
||||
|
||||
|
|
|
@ -31,6 +31,9 @@ namespace MWSound
|
|||
|
||||
virtual void updateListener(const Ogre::Vector3 &pos, const Ogre::Vector3 &atdir, const Ogre::Vector3 &updir, Environment env) = 0;
|
||||
|
||||
virtual void pauseAllSounds() = 0;
|
||||
virtual void resumeAllSounds() = 0;
|
||||
|
||||
Sound_Output& operator=(const Sound_Output &rhs);
|
||||
Sound_Output(const Sound_Output &rhs);
|
||||
|
||||
|
|
|
@ -404,6 +404,19 @@ namespace MWSound
|
|||
}
|
||||
|
||||
|
||||
void SoundManager::pauseAllSounds()
|
||||
{
|
||||
if(mOutput->isInitialized())
|
||||
mOutput->pauseAllSounds();
|
||||
}
|
||||
|
||||
void SoundManager::resumeAllSounds()
|
||||
{
|
||||
if(mOutput->isInitialized())
|
||||
mOutput->resumeAllSounds();
|
||||
}
|
||||
|
||||
|
||||
void SoundManager::updateRegionSound(float duration)
|
||||
{
|
||||
MWWorld::Ptr::CellStore *current = MWBase::Environment::get().getWorld()->getPlayer().getPlayer().getCell();
|
||||
|
|
|
@ -127,6 +127,12 @@ namespace MWSound
|
|||
virtual bool getSoundPlaying(MWWorld::Ptr reference, const std::string& soundId) const;
|
||||
///< Is the given sound currently playing on the given object?
|
||||
|
||||
virtual void pauseAllSounds();
|
||||
///< Pauses all currently playing sounds, including music.
|
||||
|
||||
virtual void resumeAllSounds();
|
||||
///< Resumes all previously paused sounds.
|
||||
|
||||
virtual void update(float duration);
|
||||
|
||||
virtual void setListenerPosDir(const Ogre::Vector3 &pos, const Ogre::Vector3 &dir, const Ogre::Vector3 &up);
|
||||
|
|
Loading…
Reference in a new issue