forked from teamnwah/openmw-tes3coop
Simplify checking for near water sfx change
Rather than checking every frame you're near the water, only check when the current cell changed (the sfx will only change when moving between interior and exterior). It also doesn't need to look through all playing sounds, as it's a local one not attached to a Ptr.
This commit is contained in:
parent
617c05f557
commit
c5a3fb7ccd
1 changed files with 20 additions and 16 deletions
|
@ -72,8 +72,8 @@ namespace MWSound
|
||||||
mNearWaterPoints = mFallback.getFallbackInt("Water_NearWaterPoints");
|
mNearWaterPoints = mFallback.getFallbackInt("Water_NearWaterPoints");
|
||||||
mNearWaterIndoorTolerance = mFallback.getFallbackFloat("Water_NearWaterIndoorTolerance");
|
mNearWaterIndoorTolerance = mFallback.getFallbackFloat("Water_NearWaterIndoorTolerance");
|
||||||
mNearWaterOutdoorTolerance = mFallback.getFallbackFloat("Water_NearWaterOutdoorTolerance");
|
mNearWaterOutdoorTolerance = mFallback.getFallbackFloat("Water_NearWaterOutdoorTolerance");
|
||||||
mNearWaterIndoorID = mFallback.getFallbackString("Water_NearWaterIndoorID");
|
mNearWaterIndoorID = Misc::StringUtils::lowerCase(mFallback.getFallbackString("Water_NearWaterIndoorID"));
|
||||||
mNearWaterOutdoorID = mFallback.getFallbackString("Water_NearWaterOutdoorID");
|
mNearWaterOutdoorID = Misc::StringUtils::lowerCase(mFallback.getFallbackString("Water_NearWaterOutdoorID"));
|
||||||
|
|
||||||
mBufferCacheMin = std::max(Settings::Manager::getInt("buffer cache min", "Sound"), 1);
|
mBufferCacheMin = std::max(Settings::Manager::getInt("buffer cache min", "Sound"), 1);
|
||||||
mBufferCacheMax = std::max(Settings::Manager::getInt("buffer cache max", "Sound"), 1);
|
mBufferCacheMax = std::max(Settings::Manager::getInt("buffer cache max", "Sound"), 1);
|
||||||
|
@ -873,16 +873,18 @@ namespace MWSound
|
||||||
|
|
||||||
void SoundManager::updateWaterSound(float /*duration*/)
|
void SoundManager::updateWaterSound(float /*duration*/)
|
||||||
{
|
{
|
||||||
|
static const ESM::Cell *LastCell;
|
||||||
MWBase::World* world = MWBase::Environment::get().getWorld();
|
MWBase::World* world = MWBase::Environment::get().getWorld();
|
||||||
const MWWorld::ConstPtr player = world->getPlayerPtr();
|
const MWWorld::ConstPtr player = world->getPlayerPtr();
|
||||||
osg::Vec3f pos = player.getRefData().getPosition().asVec3();
|
osg::Vec3f pos = player.getRefData().getPosition().asVec3();
|
||||||
|
const ESM::Cell *curcell = player.getCell()->getCell();
|
||||||
|
|
||||||
float volume = 0.0f;
|
float volume = 0.0f;
|
||||||
const std::string& soundId = player.getCell()->isExterior() ? mNearWaterOutdoorID : mNearWaterIndoorID;
|
const std::string& soundId = player.getCell()->isExterior() ? mNearWaterOutdoorID : mNearWaterIndoorID;
|
||||||
|
|
||||||
if (!mListenerUnderwater)
|
if (!mListenerUnderwater)
|
||||||
{
|
{
|
||||||
if (player.getCell()->getCell()->hasWater())
|
if (curcell->hasWater())
|
||||||
{
|
{
|
||||||
float dist = std::abs(player.getCell()->getWaterLevel() - pos.z());
|
float dist = std::abs(player.getCell()->getWaterLevel() - pos.z());
|
||||||
|
|
||||||
|
@ -929,25 +931,24 @@ namespace MWSound
|
||||||
mOutput->finishSound(mNearWaterSound);
|
mOutput->finishSound(mNearWaterSound);
|
||||||
mNearWaterSound = nullptr;
|
mNearWaterSound = nullptr;
|
||||||
}
|
}
|
||||||
else
|
else if(LastCell != curcell)
|
||||||
{
|
{
|
||||||
bool soundIdChanged = false;
|
bool soundIdChanged = false;
|
||||||
|
|
||||||
Sound_Buffer* sfx = lookupSound(Misc::StringUtils::lowerCase(soundId));
|
Sound_Buffer* sfx = lookupSound(soundId);
|
||||||
|
SoundMap::const_iterator snditer = mActiveSounds.find(MWWorld::Ptr());
|
||||||
for (SoundMap::const_iterator snditer = mActiveSounds.begin(); snditer != mActiveSounds.end(); ++snditer)
|
if(snditer != mActiveSounds.end())
|
||||||
{
|
{
|
||||||
for (SoundBufferRefPairList::const_iterator pairiter = snditer->second.begin(); pairiter != snditer->second.end(); ++pairiter)
|
SoundBufferRefPairList::const_iterator pairiter = std::find_if(
|
||||||
{
|
snditer->second.begin(), snditer->second.end(),
|
||||||
if (pairiter->first == mNearWaterSound)
|
[this](const SoundBufferRefPairList::value_type &item) -> bool
|
||||||
{
|
{ return mNearWaterSound == item.first; }
|
||||||
if (pairiter->second != sfx)
|
);
|
||||||
soundIdChanged = true;
|
if (pairiter != snditer->second.end() && pairiter->second != sfx)
|
||||||
break;
|
soundIdChanged = true;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LastCell = curcell;
|
||||||
if (soundIdChanged)
|
if (soundIdChanged)
|
||||||
{
|
{
|
||||||
mOutput->finishSound(mNearWaterSound);
|
mOutput->finishSound(mNearWaterSound);
|
||||||
|
@ -958,7 +959,10 @@ namespace MWSound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (volume > 0.0f)
|
else if (volume > 0.0f)
|
||||||
|
{
|
||||||
|
LastCell = curcell;
|
||||||
mNearWaterSound = playSound(soundId, volume, 1.0f, Play_TypeSfx, Play_Loop);
|
mNearWaterSound = playSound(soundId, volume, 1.0f, Play_TypeSfx, Play_Loop);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::updateSounds(float duration)
|
void SoundManager::updateSounds(float duration)
|
||||||
|
|
Loading…
Reference in a new issue