mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-31 14:36:39 +00:00
Avoid some explicit loops
This commit is contained in:
parent
3757571d46
commit
1e123a22e1
1 changed files with 16 additions and 17 deletions
|
@ -819,15 +819,12 @@ namespace MWSound
|
||||||
if(regn == NULL)
|
if(regn == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::vector<ESM::Region::SoundRef>::const_iterator soundIter;
|
|
||||||
if(total == 0)
|
if(total == 0)
|
||||||
{
|
{
|
||||||
soundIter = regn->mSoundList.begin();
|
std::for_each(regn->mSoundList.cbegin(), regn->mSoundList.cend(),
|
||||||
while(soundIter != regn->mSoundList.end())
|
[](const ESM::Region::SoundRef &sndref) -> void
|
||||||
{
|
{ total += (int)sndref.mChance; }
|
||||||
total += (int)soundIter->mChance;
|
);
|
||||||
++soundIter;
|
|
||||||
}
|
|
||||||
if(total == 0)
|
if(total == 0)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -835,18 +832,20 @@ namespace MWSound
|
||||||
int r = Misc::Rng::rollDice(total);
|
int r = Misc::Rng::rollDice(total);
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|
||||||
soundIter = regn->mSoundList.begin();
|
std::find_if_not(regn->mSoundList.cbegin(), regn->mSoundList.cend(),
|
||||||
while(soundIter != regn->mSoundList.end())
|
[&pos, r, this](const ESM::Region::SoundRef &sndref) -> bool
|
||||||
{
|
{
|
||||||
if(r - pos < soundIter->mChance)
|
if(r - pos < sndref.mChance)
|
||||||
{
|
{
|
||||||
playSound(soundIter->mSound.toString(), 1.0f, 1.0f);
|
playSound(sndref.mSound.toString(), 1.0f, 1.0f);
|
||||||
break;
|
// Played this sound, stop iterating
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
pos += soundIter->mChance;
|
pos += sndref.mChance;
|
||||||
|
// Not this sound, keep iterating
|
||||||
++soundIter;
|
return true;
|
||||||
}
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::updateWaterSound(float /*duration*/)
|
void SoundManager::updateWaterSound(float /*duration*/)
|
||||||
|
|
Loading…
Reference in a new issue