mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-21 20:11:34 +00:00
Only allow one instance of a given tracked soundid
The untracked flag should probably be broken up and combined with the loop boolean into a set of flags.
This commit is contained in:
parent
bfac946878
commit
e48d125a84
2 changed files with 41 additions and 4 deletions
|
@ -67,6 +67,7 @@ namespace MWSound
|
||||||
|
|
||||||
SoundManager::~SoundManager()
|
SoundManager::~SoundManager()
|
||||||
{
|
{
|
||||||
|
mSingleSounds.clear();
|
||||||
mActiveSounds.clear();
|
mActiveSounds.clear();
|
||||||
mMusic.reset();
|
mMusic.reset();
|
||||||
mOutput.reset();
|
mOutput.reset();
|
||||||
|
@ -231,15 +232,29 @@ namespace MWSound
|
||||||
float volume, float pitch, bool loop,
|
float volume, float pitch, bool loop,
|
||||||
bool untracked)
|
bool untracked)
|
||||||
{
|
{
|
||||||
|
const ESM::Position &pos = ptr.getCellRef().pos;
|
||||||
|
const Ogre::Vector3 objpos(pos.pos[0], pos.pos[1], pos.pos[2]);
|
||||||
SoundPtr sound;
|
SoundPtr sound;
|
||||||
|
|
||||||
|
if(!untracked)
|
||||||
|
{
|
||||||
|
IDSoundMap::iterator inviter = mSingleSounds.find(soundId);
|
||||||
|
if(inviter != mSingleSounds.end())
|
||||||
|
{
|
||||||
|
if(inviter->second->mPos.squaredDistance(mOutput->mPos) <
|
||||||
|
objpos.squaredDistance(mOutput->mPos))
|
||||||
|
return sound;
|
||||||
|
inviter->second->stop();
|
||||||
|
mSingleSounds.erase(inviter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Look up the sound in the ESM data
|
// Look up the sound in the ESM data
|
||||||
float basevol = 1.0f; /* TODO: volume settings */
|
float basevol = 1.0f; /* TODO: volume settings */
|
||||||
float min, max;
|
float min, max;
|
||||||
std::string file = lookup(soundId, basevol, min, max);
|
std::string file = lookup(soundId, basevol, min, max);
|
||||||
const ESM::Position &pos = ptr.getCellRef().pos;
|
|
||||||
const Ogre::Vector3 objpos(pos.pos[0], pos.pos[1], pos.pos[2]);
|
|
||||||
|
|
||||||
sound = mOutput->playSound3D(file, objpos, volume*basevol, pitch, min, max, loop);
|
sound = mOutput->playSound3D(file, objpos, volume*basevol, pitch, min, max, loop);
|
||||||
sound->mPos = objpos;
|
sound->mPos = objpos;
|
||||||
|
@ -248,8 +263,13 @@ namespace MWSound
|
||||||
sound->mMinDistance = min;
|
sound->mMinDistance = min;
|
||||||
sound->mMaxDistance = max;
|
sound->mMaxDistance = max;
|
||||||
|
|
||||||
mActiveSounds[sound] = (!untracked ? std::make_pair(ptr, soundId) :
|
if(untracked)
|
||||||
std::make_pair(MWWorld::Ptr(), soundId));
|
mActiveSounds[sound] = std::make_pair(MWWorld::Ptr(), soundId);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mActiveSounds[sound] = std::make_pair(ptr, soundId);
|
||||||
|
mSingleSounds[soundId] = sound;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch(std::exception &e)
|
catch(std::exception &e)
|
||||||
{
|
{
|
||||||
|
@ -265,6 +285,9 @@ namespace MWSound
|
||||||
{
|
{
|
||||||
if(snditer->second.first == ptr && snditer->second.second == soundId)
|
if(snditer->second.first == ptr && snditer->second.second == soundId)
|
||||||
{
|
{
|
||||||
|
IDSoundMap::iterator inviter = mSingleSounds.find(snditer->second.second);
|
||||||
|
if(inviter != mSingleSounds.end() && inviter->second == snditer->first)
|
||||||
|
mSingleSounds.erase(inviter);
|
||||||
snditer->first->stop();
|
snditer->first->stop();
|
||||||
mActiveSounds.erase(snditer++);
|
mActiveSounds.erase(snditer++);
|
||||||
}
|
}
|
||||||
|
@ -280,6 +303,9 @@ namespace MWSound
|
||||||
{
|
{
|
||||||
if(snditer->second.first == ptr)
|
if(snditer->second.first == ptr)
|
||||||
{
|
{
|
||||||
|
IDSoundMap::iterator inviter = mSingleSounds.find(snditer->second.second);
|
||||||
|
if(inviter != mSingleSounds.end() && inviter->second == snditer->first)
|
||||||
|
mSingleSounds.erase(inviter);
|
||||||
snditer->first->stop();
|
snditer->first->stop();
|
||||||
mActiveSounds.erase(snditer++);
|
mActiveSounds.erase(snditer++);
|
||||||
}
|
}
|
||||||
|
@ -296,6 +322,9 @@ namespace MWSound
|
||||||
if(snditer->second.first != MWWorld::Ptr() &&
|
if(snditer->second.first != MWWorld::Ptr() &&
|
||||||
snditer->second.first.getCell() == cell)
|
snditer->second.first.getCell() == cell)
|
||||||
{
|
{
|
||||||
|
IDSoundMap::iterator inviter = mSingleSounds.find(snditer->second.second);
|
||||||
|
if(inviter != mSingleSounds.end() && inviter->second == snditer->first)
|
||||||
|
mSingleSounds.erase(inviter);
|
||||||
snditer->first->stop();
|
snditer->first->stop();
|
||||||
mActiveSounds.erase(snditer++);
|
mActiveSounds.erase(snditer++);
|
||||||
}
|
}
|
||||||
|
@ -424,7 +453,12 @@ namespace MWSound
|
||||||
while(snditer != mActiveSounds.end())
|
while(snditer != mActiveSounds.end())
|
||||||
{
|
{
|
||||||
if(!snditer->first->isPlaying())
|
if(!snditer->first->isPlaying())
|
||||||
|
{
|
||||||
|
IDSoundMap::iterator inviter = mSingleSounds.find(snditer->second.second);
|
||||||
|
if(inviter != mSingleSounds.end() && inviter->second == snditer->first)
|
||||||
|
mSingleSounds.erase(inviter);
|
||||||
mActiveSounds.erase(snditer++);
|
mActiveSounds.erase(snditer++);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
snditer->first->update();
|
snditer->first->update();
|
||||||
|
|
|
@ -45,6 +45,9 @@ namespace MWSound
|
||||||
typedef std::map<SoundPtr,PtrIDPair> SoundMap;
|
typedef std::map<SoundPtr,PtrIDPair> SoundMap;
|
||||||
SoundMap mActiveSounds;
|
SoundMap mActiveSounds;
|
||||||
|
|
||||||
|
typedef std::map<std::string,SoundPtr> IDSoundMap;
|
||||||
|
IDSoundMap mSingleSounds;
|
||||||
|
|
||||||
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 streamMusicFull(const std::string& filename);
|
void streamMusicFull(const std::string& filename);
|
||||||
|
|
Loading…
Reference in a new issue