SoundManager: add the ability to play non-3d looping sounds

actorid
Michael Papageorgiou 13 years ago
parent a309ef7b55
commit 6f46f2b7a0

@ -386,18 +386,28 @@ namespace MWSound
}
void SoundManager::playSound(const std::string& soundId, float volume, float pitch)
void SoundManager::playSound(const std::string& soundId, float volume, float pitch, bool loop)
{
// Play and forget
float min, max;
const std::string &file = lookup(soundId, volume, min, max);
if (file != "")
{
SoundPtr snd = mgr->load(file);
snd->setRepeat(loop);
snd->setVolume(volume);
snd->setRange(min,max);
snd->setPitch(pitch);
snd->play();
if (loop)
{
// Only add the looping sound once
IDMap::iterator it = mLoopedSounds.find(soundId);
if(it == mLoopedSounds.end())
{
mLoopedSounds[soundId] = WSoundPtr(snd);
}
}
}
}
@ -421,6 +431,17 @@ namespace MWSound
removeCell(cell);
}
void SoundManager::stopSound(const std::string& soundId)
{
IDMap::iterator it = mLoopedSounds.find(soundId);
if(it != mLoopedSounds.end())
{
SoundPtr snd = it->second.lock();
if(snd) snd->stop();
mLoopedSounds.erase(it);
}
}
bool SoundManager::getSoundPlaying (MWWorld::Ptr ptr, const std::string& soundId) const
{
// Mark all sounds as playing, otherwise the scripts will just

@ -80,6 +80,8 @@ namespace MWSound
// Points to the current playlist of music files stored in the music library
const Files::PathContainer* mCurrentPlaylist;
IDMap mLoopedSounds;
std::string lookup(const std::string &soundId,
float &volume, float &min, float &max);
void add(const std::string &file,
@ -130,7 +132,7 @@ namespace MWSound
bool sayDone (MWWorld::Ptr reference) const;
///< Is actor not speaking?
void playSound (const std::string& soundId, float volume, float pitch);
void playSound (const std::string& soundId, float volume, float pitch, bool loop=false);
///< Play a sound, independently of 3D-position
void playSound3D (MWWorld::Ptr reference, const std::string& soundId,
@ -144,6 +146,9 @@ namespace MWSound
void stopSound (MWWorld::Ptr::CellStore *cell);
///< Stop all sounds for the given cell.
void stopSound(const std::string& soundId);
///< Stop a non-3d looping sound
bool getSoundPlaying (MWWorld::Ptr reference, const std::string& soundId) const;
///< Is the given sound currently playing on the given object?

Loading…
Cancel
Save