1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 23:53:52 +00:00

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

This commit is contained in:
Michael Papageorgiou 2012-03-09 18:10:23 +02:00
parent a309ef7b55
commit 6f46f2b7a0
2 changed files with 29 additions and 3 deletions

View file

@ -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; float min, max;
const std::string &file = lookup(soundId, volume, min, max); const std::string &file = lookup(soundId, volume, min, max);
if (file != "") if (file != "")
{ {
SoundPtr snd = mgr->load(file); SoundPtr snd = mgr->load(file);
snd->setRepeat(loop);
snd->setVolume(volume); snd->setVolume(volume);
snd->setRange(min,max); snd->setRange(min,max);
snd->setPitch(pitch); snd->setPitch(pitch);
snd->play(); 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); 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 bool SoundManager::getSoundPlaying (MWWorld::Ptr ptr, const std::string& soundId) const
{ {
// Mark all sounds as playing, otherwise the scripts will just // Mark all sounds as playing, otherwise the scripts will just

View file

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