mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-19 23:23:54 +00:00
Allow pausing only certain types of sounds
This commit is contained in:
parent
b4e36d4f31
commit
2f8daec379
7 changed files with 33 additions and 28 deletions
|
@ -44,10 +44,10 @@ namespace MWBase
|
||||||
* the object and will not stop when the object is deleted. */
|
* the object and will not stop when the object is deleted. */
|
||||||
};
|
};
|
||||||
enum PlayType {
|
enum PlayType {
|
||||||
Play_TypeSfx = 0, /* Normal SFX sound */
|
Play_TypeSfx = 1<<3, /* Normal SFX sound */
|
||||||
Play_TypeVoice = 1<<3, /* Voice sound */
|
Play_TypeVoice = 1<<4, /* Voice sound */
|
||||||
Play_TypeMusic = 1<<4, /* Music track */
|
Play_TypeMusic = 1<<5, /* Music track */
|
||||||
Play_TypeMovie = 1<<5, /* Movie audio track */
|
Play_TypeMovie = 1<<6, /* Movie audio track */
|
||||||
Play_TypeMask = Play_TypeSfx|Play_TypeVoice|Play_TypeMusic|Play_TypeMovie
|
Play_TypeMask = Play_TypeSfx|Play_TypeVoice|Play_TypeMusic|Play_TypeMovie
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -124,10 +124,10 @@ namespace MWBase
|
||||||
virtual bool getSoundPlaying(MWWorld::Ptr reference, const std::string& soundId) const = 0;
|
virtual bool getSoundPlaying(MWWorld::Ptr reference, const std::string& soundId) const = 0;
|
||||||
///< Is the given sound currently playing on the given object?
|
///< Is the given sound currently playing on the given object?
|
||||||
|
|
||||||
virtual void pauseAllSounds() = 0;
|
virtual void pauseSounds(int types=Play_TypeMask) = 0;
|
||||||
///< Pauses all currently playing sounds, including music.
|
///< Pauses all currently playing sounds, including music.
|
||||||
|
|
||||||
virtual void resumeAllSounds() = 0;
|
virtual void resumeSounds(int types=Play_TypeMask) = 0;
|
||||||
///< Resumes all previously paused sounds.
|
///< Resumes all previously paused sounds.
|
||||||
|
|
||||||
virtual void update(float duration) = 0;
|
virtual void update(float duration) = 0;
|
||||||
|
@ -139,6 +139,11 @@ namespace MWBase
|
||||||
{ return static_cast<int> (a) | static_cast<int> (b); }
|
{ return static_cast<int> (a) | static_cast<int> (b); }
|
||||||
inline int operator&(SoundManager::PlayMode a, SoundManager::PlayMode b)
|
inline int operator&(SoundManager::PlayMode a, SoundManager::PlayMode b)
|
||||||
{ return static_cast<int> (a) & static_cast<int> (b); }
|
{ return static_cast<int> (a) & static_cast<int> (b); }
|
||||||
|
|
||||||
|
inline int operator|(SoundManager::PlayType a, SoundManager::PlayType b)
|
||||||
|
{ return static_cast<int> (a) | static_cast<int> (b); }
|
||||||
|
inline int operator&(SoundManager::PlayType a, SoundManager::PlayType b)
|
||||||
|
{ return static_cast<int> (a) & static_cast<int> (b); }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1092,7 +1092,7 @@ void VideoPlayer::playVideo(const std::string &resourceName)
|
||||||
}
|
}
|
||||||
mSceneMgr->setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_EXCLUDE);
|
mSceneMgr->setSpecialCaseRenderQueueMode(Ogre::SceneManager::SCRQM_EXCLUDE);
|
||||||
|
|
||||||
MWBase::Environment::get().getSoundManager()->pauseAllSounds();
|
MWBase::Environment::get().getSoundManager()->pauseSounds();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
mState = new VideoState;
|
mState = new VideoState;
|
||||||
|
@ -1123,7 +1123,7 @@ void VideoPlayer::close()
|
||||||
mState = NULL;
|
mState = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
MWBase::Environment::get().getSoundManager()->resumeAllSounds();
|
MWBase::Environment::get().getSoundManager()->resumeSounds();
|
||||||
|
|
||||||
mRectangle->setVisible(false);
|
mRectangle->setVisible(false);
|
||||||
mBackgroundRectangle->setVisible(false);
|
mBackgroundRectangle->setVisible(false);
|
||||||
|
|
|
@ -891,7 +891,7 @@ void OpenAL_Output::updateListener(const Ogre::Vector3 &pos, const Ogre::Vector3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OpenAL_Output::pauseAllSounds()
|
void OpenAL_Output::pauseSounds(int types)
|
||||||
{
|
{
|
||||||
IDVec sources;
|
IDVec sources;
|
||||||
SoundVec::const_iterator iter = mActiveSounds.begin();
|
SoundVec::const_iterator iter = mActiveSounds.begin();
|
||||||
|
@ -900,13 +900,13 @@ void OpenAL_Output::pauseAllSounds()
|
||||||
const OpenAL_SoundStream *stream = dynamic_cast<OpenAL_SoundStream*>(*iter);
|
const OpenAL_SoundStream *stream = dynamic_cast<OpenAL_SoundStream*>(*iter);
|
||||||
if(stream)
|
if(stream)
|
||||||
{
|
{
|
||||||
if(stream->mSource)
|
if(stream->mSource && (stream->getPlayType()&types))
|
||||||
sources.push_back(stream->mSource);
|
sources.push_back(stream->mSource);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const OpenAL_Sound *sound = dynamic_cast<OpenAL_Sound*>(*iter);
|
const OpenAL_Sound *sound = dynamic_cast<OpenAL_Sound*>(*iter);
|
||||||
if(sound && sound->mSource)
|
if(sound && sound->mSource && (sound->getPlayType()&types))
|
||||||
sources.push_back(sound->mSource);
|
sources.push_back(sound->mSource);
|
||||||
}
|
}
|
||||||
iter++;
|
iter++;
|
||||||
|
@ -915,7 +915,7 @@ void OpenAL_Output::pauseAllSounds()
|
||||||
alSourcePausev(sources.size(), &sources[0]);
|
alSourcePausev(sources.size(), &sources[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenAL_Output::resumeAllSounds()
|
void OpenAL_Output::resumeSounds(int types)
|
||||||
{
|
{
|
||||||
IDVec sources;
|
IDVec sources;
|
||||||
SoundVec::const_iterator iter = mActiveSounds.begin();
|
SoundVec::const_iterator iter = mActiveSounds.begin();
|
||||||
|
@ -924,13 +924,13 @@ void OpenAL_Output::resumeAllSounds()
|
||||||
const OpenAL_SoundStream *stream = dynamic_cast<OpenAL_SoundStream*>(*iter);
|
const OpenAL_SoundStream *stream = dynamic_cast<OpenAL_SoundStream*>(*iter);
|
||||||
if(stream)
|
if(stream)
|
||||||
{
|
{
|
||||||
if(stream->mSource)
|
if(stream->mSource && (stream->getPlayType()&types))
|
||||||
sources.push_back(stream->mSource);
|
sources.push_back(stream->mSource);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const OpenAL_Sound *sound = dynamic_cast<OpenAL_Sound*>(*iter);
|
const OpenAL_Sound *sound = dynamic_cast<OpenAL_Sound*>(*iter);
|
||||||
if(sound && sound->mSource)
|
if(sound && sound->mSource && (sound->getPlayType()&types))
|
||||||
sources.push_back(sound->mSource);
|
sources.push_back(sound->mSource);
|
||||||
}
|
}
|
||||||
iter++;
|
iter++;
|
||||||
|
|
|
@ -55,8 +55,8 @@ namespace MWSound
|
||||||
|
|
||||||
virtual void updateListener(const Ogre::Vector3 &pos, const Ogre::Vector3 &atdir, const Ogre::Vector3 &updir, Environment env);
|
virtual void updateListener(const Ogre::Vector3 &pos, const Ogre::Vector3 &atdir, const Ogre::Vector3 &updir, Environment env);
|
||||||
|
|
||||||
virtual void pauseAllSounds();
|
virtual void pauseSounds(int types);
|
||||||
virtual void resumeAllSounds();
|
virtual void resumeSounds(int types);
|
||||||
|
|
||||||
OpenAL_Output& operator=(const OpenAL_Output &rhs);
|
OpenAL_Output& operator=(const OpenAL_Output &rhs);
|
||||||
OpenAL_Output(const OpenAL_Output &rhs);
|
OpenAL_Output(const OpenAL_Output &rhs);
|
||||||
|
|
|
@ -31,8 +31,8 @@ namespace MWSound
|
||||||
|
|
||||||
virtual void updateListener(const Ogre::Vector3 &pos, const Ogre::Vector3 &atdir, const Ogre::Vector3 &updir, Environment env) = 0;
|
virtual void updateListener(const Ogre::Vector3 &pos, const Ogre::Vector3 &atdir, const Ogre::Vector3 &updir, Environment env) = 0;
|
||||||
|
|
||||||
virtual void pauseAllSounds() = 0;
|
virtual void pauseSounds(int types) = 0;
|
||||||
virtual void resumeAllSounds() = 0;
|
virtual void resumeSounds(int types) = 0;
|
||||||
|
|
||||||
Sound_Output& operator=(const Sound_Output &rhs);
|
Sound_Output& operator=(const Sound_Output &rhs);
|
||||||
Sound_Output(const Sound_Output &rhs);
|
Sound_Output(const Sound_Output &rhs);
|
||||||
|
|
|
@ -313,11 +313,11 @@ namespace MWSound
|
||||||
return sound;
|
return sound;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
float basevol = volumeFromType((PlayType)(mode&Play_TypeMask));
|
float basevol = volumeFromType(Play_TypeSfx);
|
||||||
float min, max;
|
float min, max;
|
||||||
std::string file = lookup(soundId, volume, min, max);
|
std::string file = lookup(soundId, volume, min, max);
|
||||||
|
|
||||||
sound = mOutput->playSound(file, volume, basevol, pitch, mode);
|
sound = mOutput->playSound(file, volume, basevol, pitch, mode|Play_TypeSfx);
|
||||||
mActiveSounds[sound] = std::make_pair(MWWorld::Ptr(), soundId);
|
mActiveSounds[sound] = std::make_pair(MWWorld::Ptr(), soundId);
|
||||||
}
|
}
|
||||||
catch(std::exception &e)
|
catch(std::exception &e)
|
||||||
|
@ -336,13 +336,13 @@ namespace MWSound
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Look up the sound in the ESM data
|
// Look up the sound in the ESM data
|
||||||
float basevol = volumeFromType((PlayType)(mode&Play_TypeMask));
|
float basevol = volumeFromType(Play_TypeSfx);
|
||||||
float min, max;
|
float min, max;
|
||||||
std::string file = lookup(soundId, volume, min, max);
|
std::string file = lookup(soundId, volume, min, max);
|
||||||
const ESM::Position &pos = ptr.getRefData().getPosition();;
|
const ESM::Position &pos = ptr.getRefData().getPosition();;
|
||||||
const Ogre::Vector3 objpos(pos.pos[0], pos.pos[1], pos.pos[2]);
|
const Ogre::Vector3 objpos(pos.pos[0], pos.pos[1], pos.pos[2]);
|
||||||
|
|
||||||
sound = mOutput->playSound3D(file, objpos, volume, basevol, pitch, min, max, mode);
|
sound = mOutput->playSound3D(file, objpos, volume, basevol, pitch, min, max, mode|Play_TypeSfx);
|
||||||
if((mode&Play_NoTrack))
|
if((mode&Play_NoTrack))
|
||||||
mActiveSounds[sound] = std::make_pair(MWWorld::Ptr(), soundId);
|
mActiveSounds[sound] = std::make_pair(MWWorld::Ptr(), soundId);
|
||||||
else
|
else
|
||||||
|
@ -423,16 +423,16 @@ namespace MWSound
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SoundManager::pauseAllSounds()
|
void SoundManager::pauseSounds(int types)
|
||||||
{
|
{
|
||||||
if(mOutput->isInitialized())
|
if(mOutput->isInitialized())
|
||||||
mOutput->pauseAllSounds();
|
mOutput->pauseSounds(types);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::resumeAllSounds()
|
void SoundManager::resumeSounds(int types)
|
||||||
{
|
{
|
||||||
if(mOutput->isInitialized())
|
if(mOutput->isInitialized())
|
||||||
mOutput->resumeAllSounds();
|
mOutput->resumeSounds(types);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -130,10 +130,10 @@ namespace MWSound
|
||||||
virtual bool getSoundPlaying(MWWorld::Ptr reference, const std::string& soundId) const;
|
virtual bool getSoundPlaying(MWWorld::Ptr reference, const std::string& soundId) const;
|
||||||
///< Is the given sound currently playing on the given object?
|
///< Is the given sound currently playing on the given object?
|
||||||
|
|
||||||
virtual void pauseAllSounds();
|
virtual void pauseSounds(int types=Play_TypeMask);
|
||||||
///< Pauses all currently playing sounds, including music.
|
///< Pauses all currently playing sounds, including music.
|
||||||
|
|
||||||
virtual void resumeAllSounds();
|
virtual void resumeSounds(int types=Play_TypeMask);
|
||||||
///< Resumes all previously paused sounds.
|
///< Resumes all previously paused sounds.
|
||||||
|
|
||||||
virtual void update(float duration);
|
virtual void update(float duration);
|
||||||
|
|
Loading…
Reference in a new issue