mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 10:53:51 +00:00
Combine some duplicate code
This commit is contained in:
parent
febc7b510a
commit
e362896817
2 changed files with 47 additions and 72 deletions
|
@ -722,12 +722,7 @@ namespace MWSound
|
||||||
|
|
||||||
Environment env = Env_Normal;
|
Environment env = Env_Normal;
|
||||||
if (mListenerUnderwater)
|
if (mListenerUnderwater)
|
||||||
{
|
|
||||||
env = Env_Underwater;
|
env = Env_Underwater;
|
||||||
//play underwater sound
|
|
||||||
if(!(mUnderwaterSound && mUnderwaterSound->isPlaying()))
|
|
||||||
mUnderwaterSound = playSound("Underwater", 1.0f, 1.0f, Play_TypeSfx, Play_LoopNoEnv);
|
|
||||||
}
|
|
||||||
else if(mUnderwaterSound)
|
else if(mUnderwaterSound)
|
||||||
{
|
{
|
||||||
mUnderwaterSound->stop();
|
mUnderwaterSound->stop();
|
||||||
|
@ -741,47 +736,23 @@ namespace MWSound
|
||||||
env
|
env
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if(mListenerUnderwater)
|
||||||
|
{
|
||||||
|
// Play underwater sound (after updating listener)
|
||||||
|
if(!(mUnderwaterSound && mUnderwaterSound->isPlaying()))
|
||||||
|
mUnderwaterSound = playSound("Underwater", 1.0f, 1.0f, Play_TypeSfx, Play_LoopNoEnv);
|
||||||
|
}
|
||||||
|
|
||||||
// Check if any sounds are finished playing, and trash them
|
// Check if any sounds are finished playing, and trash them
|
||||||
// Lower volume on fading out sounds
|
|
||||||
SoundMap::iterator snditer = mActiveSounds.begin();
|
SoundMap::iterator snditer = mActiveSounds.begin();
|
||||||
while(snditer != mActiveSounds.end())
|
while(snditer != mActiveSounds.end())
|
||||||
{
|
{
|
||||||
SoundNamePairList::iterator sndname = snditer->second.begin();
|
SoundNamePairList::iterator sndname = snditer->second.begin();
|
||||||
while(sndname != snditer->second.end())
|
while(sndname != snditer->second.end())
|
||||||
{
|
{
|
||||||
MWBase::SoundPtr sound = sndname->first;
|
if(!updateSound(sndname->first, snditer->first, duration))
|
||||||
if(!sound->isPlaying())
|
|
||||||
{
|
|
||||||
sndname = snditer->second.erase(sndname);
|
sndname = snditer->second.erase(sndname);
|
||||||
continue;
|
else
|
||||||
}
|
|
||||||
|
|
||||||
const MWWorld::Ptr &ptr = snditer->first;
|
|
||||||
if(!ptr.isEmpty())
|
|
||||||
{
|
|
||||||
const ESM::Position &pos = ptr.getRefData().getPosition();
|
|
||||||
const osg::Vec3f objpos(pos.asVec3());
|
|
||||||
sound->setPosition(objpos);
|
|
||||||
|
|
||||||
if ((sound->mFlags & Play_RemoveAtDistance)
|
|
||||||
&& (mListenerPos - ptr.getRefData().getPosition().asVec3()).length2() > 2000*2000)
|
|
||||||
{
|
|
||||||
sndname = snditer->second.erase(sndname);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//update fade out
|
|
||||||
if(sound->mFadeOutTime > 0.0f)
|
|
||||||
{
|
|
||||||
float soundDuration = duration;
|
|
||||||
if(soundDuration > sound->mFadeOutTime)
|
|
||||||
soundDuration = sound->mFadeOutTime;
|
|
||||||
sound->setVolume(sound->mVolume - soundDuration/sound->mFadeOutTime*sound->mVolume);
|
|
||||||
sound->mFadeOutTime -= soundDuration;
|
|
||||||
}
|
|
||||||
sound->update();
|
|
||||||
|
|
||||||
++sndname;
|
++sndname;
|
||||||
}
|
}
|
||||||
if(snditer->second.empty())
|
if(snditer->second.empty())
|
||||||
|
@ -793,29 +764,33 @@ namespace MWSound
|
||||||
SaySoundMap::iterator sayiter = mActiveSaySounds.begin();
|
SaySoundMap::iterator sayiter = mActiveSaySounds.begin();
|
||||||
while(sayiter != mActiveSaySounds.end())
|
while(sayiter != mActiveSaySounds.end())
|
||||||
{
|
{
|
||||||
MWBase::SoundPtr sound = sayiter->second.first;
|
if(!updateSound(sayiter->second.first, sayiter->first, duration))
|
||||||
if(!sound->isPlaying())
|
|
||||||
{
|
|
||||||
mActiveSaySounds.erase(sayiter++);
|
mActiveSaySounds.erase(sayiter++);
|
||||||
continue;
|
else
|
||||||
|
++sayiter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const MWWorld::Ptr &ptr = sayiter->first;
|
bool SoundManager::updateSound(MWBase::SoundPtr sound, const MWWorld::Ptr& ptr, float duration)
|
||||||
|
{
|
||||||
if(!ptr.isEmpty())
|
if(!ptr.isEmpty())
|
||||||
{
|
{
|
||||||
const ESM::Position &pos = ptr.getRefData().getPosition();
|
const ESM::Position &pos = ptr.getRefData().getPosition();
|
||||||
const osg::Vec3f objpos(pos.asVec3());
|
const osg::Vec3f objpos(pos.asVec3());
|
||||||
sound->setPosition(objpos);
|
sound->setPosition(objpos);
|
||||||
|
|
||||||
if ((sound->mFlags & Play_RemoveAtDistance)
|
if((sound->mFlags&Play_RemoveAtDistance))
|
||||||
&& (mListenerPos - ptr.getRefData().getPosition().asVec3()).length2() > 2000*2000)
|
|
||||||
{
|
{
|
||||||
mActiveSaySounds.erase(sayiter++);
|
osg::Vec3f diff = mListenerPos - ptr.getRefData().getPosition().asVec3();
|
||||||
continue;
|
if(diff.length2() > 2000*2000)
|
||||||
|
sound->stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//update fade out
|
if(!sound->isPlaying())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Update fade out
|
||||||
if(sound->mFadeOutTime > 0.0f)
|
if(sound->mFadeOutTime > 0.0f)
|
||||||
{
|
{
|
||||||
float soundDuration = duration;
|
float soundDuration = duration;
|
||||||
|
@ -825,10 +800,9 @@ namespace MWSound
|
||||||
sound->mFadeOutTime -= soundDuration;
|
sound->mFadeOutTime -= soundDuration;
|
||||||
}
|
}
|
||||||
sound->update();
|
sound->update();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
++sayiter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SoundManager::update(float duration)
|
void SoundManager::update(float duration)
|
||||||
{
|
{
|
||||||
|
|
|
@ -74,6 +74,7 @@ namespace MWSound
|
||||||
const Sound_Buffer *lookupVoice(const std::string &voicefile);
|
const Sound_Buffer *lookupVoice(const std::string &voicefile);
|
||||||
|
|
||||||
void streamMusicFull(const std::string& filename);
|
void streamMusicFull(const std::string& filename);
|
||||||
|
bool updateSound(MWBase::SoundPtr sound, const MWWorld::Ptr &ptr, float duration);
|
||||||
void updateSounds(float duration);
|
void updateSounds(float duration);
|
||||||
void updateRegionSound(float duration);
|
void updateRegionSound(float duration);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue