1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-04-17 02:42:45 +00:00

Avoid some explicit loops

This commit is contained in:
Chris Robinson 2017-09-14 16:56:46 -07:00
parent 3757571d46
commit 1e123a22e1

View File

@ -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)
{ {
playSound(soundIter->mSound.toString(), 1.0f, 1.0f); if(r - pos < sndref.mChance)
break; {
playSound(sndref.mSound.toString(), 1.0f, 1.0f);
// Played this sound, stop iterating
return false;
}
pos += sndref.mChance;
// Not this sound, keep iterating
return true;
} }
pos += soundIter->mChance; );
++soundIter;
}
} }
void SoundManager::updateWaterSound(float /*duration*/) void SoundManager::updateWaterSound(float /*duration*/)