mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-10 21:40:15 +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
@ -67,6 +67,7 @@ namespace MWSound
|
||||
|
||||
SoundManager::~SoundManager()
|
||||
{
|
||||
mSingleSounds.clear();
|
||||
mActiveSounds.clear();
|
||||
mMusic.reset();
|
||||
mOutput.reset();
|
||||
@ -231,15 +232,29 @@ namespace MWSound
|
||||
float volume, float pitch, bool loop,
|
||||
bool untracked)
|
||||
{
|
||||
const ESM::Position &pos = ptr.getCellRef().pos;
|
||||
const Ogre::Vector3 objpos(pos.pos[0], pos.pos[1], pos.pos[2]);
|
||||
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
|
||||
{
|
||||
// Look up the sound in the ESM data
|
||||
float basevol = 1.0f; /* TODO: volume settings */
|
||||
float 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->mPos = objpos;
|
||||
@ -248,8 +263,13 @@ namespace MWSound
|
||||
sound->mMinDistance = min;
|
||||
sound->mMaxDistance = max;
|
||||
|
||||
mActiveSounds[sound] = (!untracked ? std::make_pair(ptr, soundId) :
|
||||
std::make_pair(MWWorld::Ptr(), soundId));
|
||||
if(untracked)
|
||||
mActiveSounds[sound] = std::make_pair(MWWorld::Ptr(), soundId);
|
||||
else
|
||||
{
|
||||
mActiveSounds[sound] = std::make_pair(ptr, soundId);
|
||||
mSingleSounds[soundId] = sound;
|
||||
}
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
@ -265,6 +285,9 @@ namespace MWSound
|
||||
{
|
||||
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();
|
||||
mActiveSounds.erase(snditer++);
|
||||
}
|
||||
@ -280,6 +303,9 @@ namespace MWSound
|
||||
{
|
||||
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();
|
||||
mActiveSounds.erase(snditer++);
|
||||
}
|
||||
@ -296,6 +322,9 @@ namespace MWSound
|
||||
if(snditer->second.first != MWWorld::Ptr() &&
|
||||
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();
|
||||
mActiveSounds.erase(snditer++);
|
||||
}
|
||||
@ -424,7 +453,12 @@ namespace MWSound
|
||||
while(snditer != mActiveSounds.end())
|
||||
{
|
||||
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++);
|
||||
}
|
||||
else
|
||||
{
|
||||
snditer->first->update();
|
||||
|
@ -45,6 +45,9 @@ namespace MWSound
|
||||
typedef std::map<SoundPtr,PtrIDPair> SoundMap;
|
||||
SoundMap mActiveSounds;
|
||||
|
||||
typedef std::map<std::string,SoundPtr> IDSoundMap;
|
||||
IDSoundMap mSingleSounds;
|
||||
|
||||
std::string lookup(const std::string &soundId,
|
||||
float &volume, float &min, float &max);
|
||||
void streamMusicFull(const std::string& filename);
|
||||
|
Loading…
x
Reference in New Issue
Block a user