mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 22:15:32 +00:00
Use range-for loops instead of for_each
This commit is contained in:
parent
1e729e8da9
commit
4b448c74d2
1 changed files with 66 additions and 86 deletions
|
@ -192,12 +192,11 @@ static ALenum getALFormat(ChannelConfig chans, SampleType type)
|
||||||
{ AL_FORMAT_STEREO8, ChannelConfig_Stereo, SampleType_UInt8 },
|
{ AL_FORMAT_STEREO8, ChannelConfig_Stereo, SampleType_UInt8 },
|
||||||
}};
|
}};
|
||||||
|
|
||||||
auto fmt = std::find_if(fmtlist.cbegin(), fmtlist.cend(),
|
for(auto &fmt : fmtlist)
|
||||||
[chans,type](const FormatEntry &fmt) -> bool
|
{
|
||||||
{ return fmt.chans == chans && fmt.type == type; }
|
if(fmt.chans == chans && fmt.type == type)
|
||||||
);
|
return fmt.format;
|
||||||
if(fmt != fmtlist.cend())
|
}
|
||||||
return fmt->format;
|
|
||||||
|
|
||||||
if(alIsExtensionPresent("AL_EXT_MCFORMATS"))
|
if(alIsExtensionPresent("AL_EXT_MCFORMATS"))
|
||||||
{
|
{
|
||||||
|
@ -209,37 +208,33 @@ static ALenum getALFormat(ChannelConfig chans, SampleType type)
|
||||||
{ "AL_FORMAT_71CHN16", ChannelConfig_7point1, SampleType_Int16 },
|
{ "AL_FORMAT_71CHN16", ChannelConfig_7point1, SampleType_Int16 },
|
||||||
{ "AL_FORMAT_71CHN8", ChannelConfig_7point1, SampleType_UInt8 },
|
{ "AL_FORMAT_71CHN8", ChannelConfig_7point1, SampleType_UInt8 },
|
||||||
}};
|
}};
|
||||||
ALenum format = AL_NONE;
|
|
||||||
|
|
||||||
std::find_if(mcfmtlist.cbegin(), mcfmtlist.cend(),
|
for(auto &fmt : mcfmtlist)
|
||||||
[&format,chans,type](const FormatEntryExt &fmt) -> bool
|
|
||||||
{
|
{
|
||||||
if(fmt.chans == chans && fmt.type == type)
|
if(fmt.chans == chans && fmt.type == type)
|
||||||
format = alGetEnumValue(fmt.name);
|
{
|
||||||
return format != 0 && format != -1;
|
ALenum format = alGetEnumValue(fmt.name);
|
||||||
}
|
|
||||||
);
|
|
||||||
if(format != 0 && format != -1)
|
if(format != 0 && format != -1)
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if(alIsExtensionPresent("AL_EXT_FLOAT32"))
|
if(alIsExtensionPresent("AL_EXT_FLOAT32"))
|
||||||
{
|
{
|
||||||
static const std::array<FormatEntryExt,2> fltfmtlist{{
|
static const std::array<FormatEntryExt,2> fltfmtlist{{
|
||||||
{ "AL_FORMAT_MONO_FLOAT32", ChannelConfig_Mono, SampleType_Float32 },
|
{ "AL_FORMAT_MONO_FLOAT32", ChannelConfig_Mono, SampleType_Float32 },
|
||||||
{ "AL_FORMAT_STEREO_FLOAT32", ChannelConfig_Stereo, SampleType_Float32 },
|
{ "AL_FORMAT_STEREO_FLOAT32", ChannelConfig_Stereo, SampleType_Float32 },
|
||||||
}};
|
}};
|
||||||
ALenum format = AL_NONE;
|
|
||||||
|
|
||||||
std::find_if(fltfmtlist.cbegin(), fltfmtlist.cend(),
|
for(auto &fmt : fltfmtlist)
|
||||||
[&format,chans,type](const FormatEntryExt &fmt) -> bool
|
|
||||||
{
|
{
|
||||||
if(fmt.chans == chans && fmt.type == type)
|
if(fmt.chans == chans && fmt.type == type)
|
||||||
format = alGetEnumValue(fmt.name);
|
{
|
||||||
return format != 0 && format != -1;
|
ALenum format = alGetEnumValue(fmt.name);
|
||||||
}
|
|
||||||
);
|
|
||||||
if(format != 0 && format != -1)
|
if(format != 0 && format != -1)
|
||||||
return format;
|
return format;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(alIsExtensionPresent("AL_EXT_MCFORMATS"))
|
if(alIsExtensionPresent("AL_EXT_MCFORMATS"))
|
||||||
{
|
{
|
||||||
|
@ -249,18 +244,17 @@ static ALenum getALFormat(ChannelConfig chans, SampleType type)
|
||||||
{ "AL_FORMAT_71CHN32", ChannelConfig_7point1, SampleType_Float32 },
|
{ "AL_FORMAT_71CHN32", ChannelConfig_7point1, SampleType_Float32 },
|
||||||
}};
|
}};
|
||||||
|
|
||||||
std::find_if(fltmcfmtlist.cbegin(), fltmcfmtlist.cend(),
|
for(auto &fmt : fltmcfmtlist)
|
||||||
[&format,chans,type](const FormatEntryExt &fmt) -> bool
|
|
||||||
{
|
{
|
||||||
if(fmt.chans == chans && fmt.type == type)
|
if(fmt.chans == chans && fmt.type == type)
|
||||||
format = alGetEnumValue(fmt.name);
|
{
|
||||||
return format != 0 && format != -1;
|
ALenum format = alGetEnumValue(fmt.name);
|
||||||
}
|
|
||||||
);
|
|
||||||
if(format != 0 && format != -1)
|
if(format != 0 && format != -1)
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::cerr<< "Unsupported sound format ("<<getChannelConfigName(chans)<<", "<<
|
std::cerr<< "Unsupported sound format ("<<getChannelConfigName(chans)<<", "<<
|
||||||
getSampleTypeName(type)<<")" <<std::endl;
|
getSampleTypeName(type)<<")" <<std::endl;
|
||||||
|
@ -547,11 +541,11 @@ ALint OpenAL_SoundStream::refillQueue()
|
||||||
std::vector<char> data(mBufferSize);
|
std::vector<char> data(mBufferSize);
|
||||||
for(;!mIsFinished && (ALuint)queued < mBuffers.size();++queued)
|
for(;!mIsFinished && (ALuint)queued < mBuffers.size();++queued)
|
||||||
{
|
{
|
||||||
size_t got = mDecoder->read(&data[0], data.size());
|
size_t got = mDecoder->read(data.data(), data.size());
|
||||||
if(got < data.size())
|
if(got < data.size())
|
||||||
{
|
{
|
||||||
mIsFinished = true;
|
mIsFinished = true;
|
||||||
std::memset(&data[got], mSilence, data.size()-got);
|
std::fill(data.begin()+got, data.end(), mSilence);
|
||||||
}
|
}
|
||||||
if(got > 0)
|
if(got > 0)
|
||||||
{
|
{
|
||||||
|
@ -559,7 +553,7 @@ ALint OpenAL_SoundStream::refillQueue()
|
||||||
mLoudnessAnalyzer->analyzeLoudness(data);
|
mLoudnessAnalyzer->analyzeLoudness(data);
|
||||||
|
|
||||||
ALuint bufid = mBuffers[mCurrentBufIdx];
|
ALuint bufid = mBuffers[mCurrentBufIdx];
|
||||||
alBufferData(bufid, mFormat, &data[0], data.size(), mSampleRate);
|
alBufferData(bufid, mFormat, data.data(), data.size(), mSampleRate);
|
||||||
alSourceQueueBuffers(mSource, 1, &bufid);
|
alSourceQueueBuffers(mSource, 1, &bufid);
|
||||||
mCurrentBufIdx = (mCurrentBufIdx+1) % mBuffers.size();
|
mCurrentBufIdx = (mCurrentBufIdx+1) % mBuffers.size();
|
||||||
}
|
}
|
||||||
|
@ -837,10 +831,8 @@ void OpenAL_Output::deinit()
|
||||||
{
|
{
|
||||||
mStreamThread->removeAll();
|
mStreamThread->removeAll();
|
||||||
|
|
||||||
std::for_each(mFreeSources.cbegin(), mFreeSources.cend(),
|
for(ALuint source : mFreeSources)
|
||||||
[](ALuint source) -> void
|
alDeleteSources(1, &source);
|
||||||
{ alDeleteSources(1, &source); }
|
|
||||||
);
|
|
||||||
mFreeSources.clear();
|
mFreeSources.clear();
|
||||||
|
|
||||||
if(mEffectSlot)
|
if(mEffectSlot)
|
||||||
|
@ -1383,23 +1375,19 @@ void OpenAL_Output::updateListener(const osg::Vec3f &pos, const osg::Vec3f &atdi
|
||||||
if(mWaterFilter)
|
if(mWaterFilter)
|
||||||
{
|
{
|
||||||
ALuint filter = (env == Env_Underwater) ? mWaterFilter : AL_FILTER_NULL;
|
ALuint filter = (env == Env_Underwater) ? mWaterFilter : AL_FILTER_NULL;
|
||||||
std::for_each(mActiveSounds.cbegin(), mActiveSounds.cend(),
|
for(Sound *sound : mActiveSounds)
|
||||||
[filter](const SoundVec::value_type &item) -> void
|
|
||||||
{
|
{
|
||||||
if(item->getUseEnv())
|
if(sound->getUseEnv())
|
||||||
alSourcei(GET_PTRID(item->mHandle), AL_DIRECT_FILTER, filter);
|
alSourcei(GET_PTRID(sound->mHandle), AL_DIRECT_FILTER, filter);
|
||||||
}
|
}
|
||||||
);
|
for(Stream *sound : mActiveStreams)
|
||||||
std::for_each(mActiveStreams.cbegin(), mActiveStreams.cend(),
|
|
||||||
[filter](const StreamVec::value_type &item) -> void
|
|
||||||
{
|
{
|
||||||
if(item->getUseEnv())
|
if(sound->getUseEnv())
|
||||||
alSourcei(
|
alSourcei(
|
||||||
reinterpret_cast<OpenAL_SoundStream*>(item->mHandle)->mSource,
|
reinterpret_cast<OpenAL_SoundStream*>(sound->mHandle)->mSource,
|
||||||
AL_DIRECT_FILTER, filter
|
AL_DIRECT_FILTER, filter
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
// Update the environment effect
|
// Update the environment effect
|
||||||
if(mEffectSlot)
|
if(mEffectSlot)
|
||||||
|
@ -1418,23 +1406,19 @@ void OpenAL_Output::updateListener(const osg::Vec3f &pos, const osg::Vec3f &atdi
|
||||||
void OpenAL_Output::pauseSounds(int types)
|
void OpenAL_Output::pauseSounds(int types)
|
||||||
{
|
{
|
||||||
std::vector<ALuint> sources;
|
std::vector<ALuint> sources;
|
||||||
std::for_each(mActiveSounds.cbegin(), mActiveSounds.cend(),
|
for(Sound *sound : mActiveSounds)
|
||||||
[types,&sources](const SoundVec::value_type &sound) -> void
|
|
||||||
{
|
{
|
||||||
if(sound && sound->mHandle && (types&sound->getPlayType()))
|
if((types&sound->getPlayType()))
|
||||||
sources.push_back(GET_PTRID(sound->mHandle));
|
sources.push_back(GET_PTRID(sound->mHandle));
|
||||||
}
|
}
|
||||||
);
|
for(Stream *sound : mActiveStreams)
|
||||||
std::for_each(mActiveStreams.cbegin(), mActiveStreams.cend(),
|
|
||||||
[types,&sources](const StreamVec::value_type &stream) -> void
|
|
||||||
{
|
{
|
||||||
if(stream && stream->mHandle && (types&stream->getPlayType()))
|
if((types&sound->getPlayType()))
|
||||||
{
|
{
|
||||||
OpenAL_SoundStream *strm = reinterpret_cast<OpenAL_SoundStream*>(stream->mHandle);
|
OpenAL_SoundStream *stream = reinterpret_cast<OpenAL_SoundStream*>(sound->mHandle);
|
||||||
sources.push_back(strm->mSource);
|
sources.push_back(stream->mSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
|
||||||
if(!sources.empty())
|
if(!sources.empty())
|
||||||
{
|
{
|
||||||
alSourcePausev(sources.size(), sources.data());
|
alSourcePausev(sources.size(), sources.data());
|
||||||
|
@ -1445,23 +1429,19 @@ void OpenAL_Output::pauseSounds(int types)
|
||||||
void OpenAL_Output::resumeSounds(int types)
|
void OpenAL_Output::resumeSounds(int types)
|
||||||
{
|
{
|
||||||
std::vector<ALuint> sources;
|
std::vector<ALuint> sources;
|
||||||
std::for_each(mActiveSounds.cbegin(), mActiveSounds.cend(),
|
for(Sound *sound : mActiveSounds)
|
||||||
[types,&sources](const SoundVec::value_type &sound) -> void
|
|
||||||
{
|
{
|
||||||
if(sound && sound->mHandle && (types&sound->getPlayType()))
|
if((types&sound->getPlayType()))
|
||||||
sources.push_back(GET_PTRID(sound->mHandle));
|
sources.push_back(GET_PTRID(sound->mHandle));
|
||||||
}
|
}
|
||||||
);
|
for(Stream *sound : mActiveStreams)
|
||||||
std::for_each(mActiveStreams.cbegin(), mActiveStreams.cend(),
|
|
||||||
[types,&sources](const StreamVec::value_type &stream) -> void
|
|
||||||
{
|
{
|
||||||
if(stream && stream->mHandle && (types&stream->getPlayType()))
|
if((types&sound->getPlayType()))
|
||||||
{
|
{
|
||||||
OpenAL_SoundStream *strm = reinterpret_cast<OpenAL_SoundStream*>(stream->mHandle);
|
OpenAL_SoundStream *stream = reinterpret_cast<OpenAL_SoundStream*>(sound->mHandle);
|
||||||
sources.push_back(strm->mSource);
|
sources.push_back(stream->mSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
|
||||||
if(!sources.empty())
|
if(!sources.empty())
|
||||||
{
|
{
|
||||||
alSourcePlayv(sources.size(), sources.data());
|
alSourcePlayv(sources.size(), sources.data());
|
||||||
|
|
Loading…
Reference in a new issue