[Scummvm-git-logs] scummvm master -> 379f6aae478571d0cae4873ee2a117f173f9a390
bluegr
noreply at scummvm.org
Sat Apr 5 23:02:10 UTC 2025
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
379f6aae47 BACKENDS: Use C++ 11 range-based for loops
Commit: 379f6aae478571d0cae4873ee2a117f173f9a390
https://github.com/scummvm/scummvm/commit/379f6aae478571d0cae4873ee2a117f173f9a390
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2025-04-06T02:01:28+03:00
Commit Message:
BACKENDS: Use C++ 11 range-based for loops
Changed paths:
backends/audiocd/default/default-audiocd.cpp
backends/graphics/opengl/pipelines/libretro.cpp
backends/networking/sdl_net/getclienthandler.cpp
backends/saves/default/default-saves.cpp
backends/timer/default/default-timer.cpp
diff --git a/backends/audiocd/default/default-audiocd.cpp b/backends/audiocd/default/default-audiocd.cpp
index 4150ea6be2f..8bc4dca86da 100644
--- a/backends/audiocd/default/default-audiocd.cpp
+++ b/backends/audiocd/default/default-audiocd.cpp
@@ -112,8 +112,10 @@ bool DefaultAudioCDManager::play(int track, int numLoops, int startFrame, int du
fillPotentialTrackNames(trackNames, track);
Audio::SeekableAudioStream *stream = nullptr;
- for (Common::Array<Common::String>::iterator i = trackNames.begin(); !stream && i != trackNames.end(); ++i) {
- stream = Audio::SeekableAudioStream::openStreamFile(Common::Path(*i, '/'));
+ for (auto &trackName : trackNames) {
+ stream = Audio::SeekableAudioStream::openStreamFile(Common::Path(trackName, '/'));
+ if (stream)
+ break;
}
if (stream != nullptr) {
diff --git a/backends/graphics/opengl/pipelines/libretro.cpp b/backends/graphics/opengl/pipelines/libretro.cpp
index 71aac01d36f..75860d1f876 100644
--- a/backends/graphics/opengl/pipelines/libretro.cpp
+++ b/backends/graphics/opengl/pipelines/libretro.cpp
@@ -270,8 +270,8 @@ void LibRetroPipeline::finishScaling() {
* we can do the render through all libretro passes */
// Now we can actually draw the texture with the setup passes.
- for (PassArray::const_iterator i = _passes.begin(), end = _passes.end(); i != end; ++i) {
- renderPass(*i);
+ for (const auto &pass : _passes) {
+ renderPass(pass);
}
// Prepare for the next frame
@@ -394,18 +394,16 @@ void LibRetroPipeline::close() {
}
bool LibRetroPipeline::loadTextures(Common::SearchSet &archSet) {
- for (LibRetro::ShaderPreset::TextureArray::const_iterator
- i = _shaderPreset->textures.begin(), end = _shaderPreset->textures.end();
- i != end; ++i) {
- LibRetroTexture texture = loadTexture(_shaderPreset->basePath.join(i->fileName).normalize(), _shaderPreset->container, archSet);
- texture.id = i->id;
+ for (const auto &curTexture : _shaderPreset->textures) {
+ LibRetroTexture texture = loadTexture(_shaderPreset->basePath.join(curTexture.fileName).normalize(), _shaderPreset->container, archSet);
+ texture.id = curTexture.id;
if (!texture.textureData || !texture.glTexture) {
return false;
}
- texture.glTexture->enableLinearFiltering(i->filteringMode == LibRetro::kFilteringModeLinear);
- texture.glTexture->setWrapMode(i->wrapMode);
+ texture.glTexture->enableLinearFiltering(curTexture.filteringMode == LibRetro::kFilteringModeLinear);
+ texture.glTexture->setWrapMode(curTexture.wrapMode);
_textures.push_back(texture);
}
return true;
@@ -443,12 +441,10 @@ bool LibRetroPipeline::loadPasses(Common::SearchSet &archSet) {
Common::StringArray aliases;
aliases.reserve(_shaderPreset->passes.size());
- for (LibRetro::ShaderPreset::PassArray::const_iterator
- i = _shaderPreset->passes.begin(), end = _shaderPreset->passes.end();
- i != end; ++i) {
- aliases.push_back(i->alias);
- if (!i->alias.empty()) {
- aliasesDefines += Common::String::format("#define %s_ALIAS\n", i->alias.c_str());
+ for (const auto &pass : _shaderPreset->passes) {
+ aliases.push_back(pass.alias);
+ if (!pass.alias.empty()) {
+ aliasesDefines += Common::String::format("#define %s_ALIAS\n", pass.alias.c_str());
}
}
@@ -457,10 +453,8 @@ bool LibRetroPipeline::loadPasses(Common::SearchSet &archSet) {
// parameters are shared among all passes so we load them first and apply them to all shaders
UniformsMap uniformParams;
- for (LibRetro::ShaderPreset::PassArray::const_iterator
- i = _shaderPreset->passes.begin(), end = _shaderPreset->passes.end();
- i != end; ++i) {
- Common::Path fileName(_shaderPreset->basePath.join(i->fileName).normalize());
+ for (const auto &curPass : _shaderPreset->passes) {
+ Common::Path fileName(_shaderPreset->basePath.join(curPass.fileName).normalize());
Common::SeekableReadStream *stream = nullptr;
if (_shaderPreset->container) {
@@ -566,7 +560,7 @@ bool LibRetroPipeline::loadPasses(Common::SearchSet &archSet) {
// TODO: float and sRGB FBO handling.
target = new TextureTarget();
- _passes.push_back(Pass(i, shader, target));
+ _passes.push_back(Pass(&curPass, shader, target));
Pass &pass = _passes[_passes.size() - 1];
const uint passId = _passes.size() - 1;
@@ -578,8 +572,8 @@ bool LibRetroPipeline::loadPasses(Common::SearchSet &archSet) {
pass.buildTexSamplers(passId, _textures, aliases);
if (passId > 0) {
Texture *const texture = _passes[passId - 1].target->getTexture();
- texture->enableLinearFiltering(i->filteringMode == LibRetro::kFilteringModeLinear);
- texture->setWrapMode(i->wrapMode);
+ texture->enableLinearFiltering(curPass.filteringMode == LibRetro::kFilteringModeLinear);
+ texture->setWrapMode(curPass.wrapMode);
pass.inputTexture = texture;
}
@@ -589,14 +583,14 @@ bool LibRetroPipeline::loadPasses(Common::SearchSet &archSet) {
}
// Apply preset parameters last to override all others
- for(UniformsMap::iterator it = _shaderPreset->parameters.begin(); it != _shaderPreset->parameters.end(); it++) {
- uniformParams[it->_key] = it->_value;
+ for (const auto ¶m : _shaderPreset->parameters) {
+ uniformParams[param._key] = param._value;
}
// Finally apply parameters to all shaders as uniforms
- for(PassArray::iterator i = _passes.begin(); i != _passes.end(); i++) {
- for(UniformsMap::iterator it = uniformParams.begin(); it != uniformParams.end(); it++) {
- i->shader->setUniform1f(it->_key, it->_value);
+ for (auto &pass : _passes) {
+ for (auto &uniformParam : uniformParams) {
+ pass.shader->setUniform1f(uniformParam._key, uniformParam._value);
}
}
@@ -852,9 +846,9 @@ bool LibRetroPipeline::Pass::addTexSampler(const Common::String &prefix, uint *u
const Common::String id = prefixIsId ? prefix : (prefix + "Texture");
/* Search in the samplers if we already have one for the texture */
- for(TextureSamplerArray::iterator it = texSamplers.begin(); it != texSamplers.end(); it++) {
- if (it->type == type && it->index == index) {
- return shader->setUniform(id, it->unit);
+ for (auto &texSampler : texSamplers) {
+ if (texSampler.type == type && texSampler.index == index) {
+ return shader->setUniform(id, texSampler.unit);
}
}
@@ -901,17 +895,16 @@ void LibRetroPipeline::renderPass(const Pass &pass) {
void LibRetroPipeline::renderPassSetupCoordinates(const Pass &pass) {
pass.shader->enableVertexAttribute("VertexCoord", 2, GL_FLOAT, GL_FALSE, 0, pass.vertexCoord);
- for (Pass::TexCoordAttributeArray::const_iterator i = pass.texCoords.begin(), end = pass.texCoords.end();
- i != end; ++i) {
+ for (const auto &texCoord : pass.texCoords) {
const GLfloat *texCoords = nullptr;
- switch (i->type) {
+ switch (texCoord.type) {
case Pass::TexCoordAttribute::kTypeTexture:
- texCoords = _textures[i->index].glTexture->getTexCoords();
+ texCoords = _textures[texCoord.index].glTexture->getTexCoords();
break;
case Pass::TexCoordAttribute::kTypePass:
- texCoords = _passes[i->index].inputTexture->getTexCoords();
+ texCoords = _passes[texCoord.index].inputTexture->getTexCoords();
break;
case Pass::TexCoordAttribute::kTypePrev:
@@ -924,7 +917,7 @@ void LibRetroPipeline::renderPassSetupCoordinates(const Pass &pass) {
continue;
}
- pass.shader->enableVertexAttribute(i->name.c_str(), 2, GL_FLOAT, GL_FALSE, 0, texCoords);
+ pass.shader->enableVertexAttribute(texCoord.name.c_str(), 2, GL_FLOAT, GL_FALSE, 0, texCoords);
}
}
@@ -938,22 +931,21 @@ void LibRetroPipeline::renderPassSetupTextures(const Pass &pass) {
GL_CALL(glGenerateMipmap(GL_TEXTURE_2D));
}
- for (Pass::TextureSamplerArray::const_iterator i = pass.texSamplers.begin(), end = pass.texSamplers.end();
- i != end; ++i) {
+ for (const auto &texSampler : pass.texSamplers) {
const Texture *texture = nullptr;
- switch (i->type) {
+ switch (texSampler.type) {
case Pass::TextureSampler::kTypeTexture:
- texture = _textures[i->index].glTexture;
+ texture = _textures[texSampler.index].glTexture;
break;
case Pass::TextureSampler::kTypePass:
- texture = _passes[i->index].inputTexture;
+ texture = _passes[texSampler.index].inputTexture;
break;
case Pass::TextureSampler::kTypePrev: {
- assert(i->index < _inputTargets.size() - 1);
- texture = _inputTargets[(_currentTarget - i->index - 1
+ assert(texSampler.index < _inputTargets.size() - 1);
+ texture = _inputTargets[(_currentTarget - texSampler.index - 1
+ _inputTargets.size()) % _inputTargets.size()].getTexture();
break;
}
@@ -963,7 +955,7 @@ void LibRetroPipeline::renderPassSetupTextures(const Pass &pass) {
continue;
}
- GL_CALL(glActiveTexture(GL_TEXTURE0 + i->unit));
+ GL_CALL(glActiveTexture(GL_TEXTURE0 + texSampler.unit));
texture->bind();
}
}
diff --git a/backends/networking/sdl_net/getclienthandler.cpp b/backends/networking/sdl_net/getclienthandler.cpp
index bb6175f4275..09e4afe289a 100644
--- a/backends/networking/sdl_net/getclienthandler.cpp
+++ b/backends/networking/sdl_net/getclienthandler.cpp
@@ -112,8 +112,8 @@ void GetClientHandler::prepareHeaders() {
setHeader("Content-Length", Common::String::format("%u", unsigned(_stream->size())));
_headers = Common::String::format("HTTP/1.1 %ld %s\r\n", _responseCode, responseMessage(_responseCode));
- for (Common::HashMap<Common::String, Common::String>::iterator i = _specialHeaders.begin(); i != _specialHeaders.end(); ++i)
- _headers += i->_key + ": " + i->_value + "\r\n";
+ for (auto &specialHeader : _specialHeaders)
+ _headers += specialHeader._key + ": " + specialHeader._value + "\r\n";
_headers += "\r\n";
_headersPrepared = true;
diff --git a/backends/saves/default/default-saves.cpp b/backends/saves/default/default-saves.cpp
index 957602a73e7..7546a3d2c9a 100644
--- a/backends/saves/default/default-saves.cpp
+++ b/backends/saves/default/default-saves.cpp
@@ -78,14 +78,14 @@ Common::StringArray DefaultSaveFileManager::listSavefiles(const Common::String &
return Common::StringArray();
Common::HashMap<Common::String, bool> locked;
- for (Common::StringArray::const_iterator i = _lockedFiles.begin(), end = _lockedFiles.end(); i != end; ++i) {
- locked[*i] = true;
+ for (const auto &lockedFile : _lockedFiles) {
+ locked[lockedFile] = true;
}
Common::StringArray results;
- for (SaveFileCache::const_iterator file = _saveFileCache.begin(), end = _saveFileCache.end(); file != end; ++file) {
- if (!locked.contains(file->_key) && file->_key.matchString(pattern, true)) {
- results.push_back(file->_key);
+ for (const auto &file : _saveFileCache) {
+ if (!locked.contains(file._key) && file._key.matchString(pattern, true)) {
+ results.push_back(file._key);
}
}
return results;
@@ -113,9 +113,9 @@ Common::InSaveFile *DefaultSaveFileManager::openForLoading(const Common::String
if (getError().getCode() != Common::kNoError)
return nullptr;
- for (Common::StringArray::const_iterator i = _lockedFiles.begin(), end = _lockedFiles.end(); i != end; ++i) {
- if (filename == *i) {
- return nullptr; //file is locked, no loading available
+ for (const auto &lockedFile : _lockedFiles) {
+ if (filename == lockedFile) {
+ return nullptr; // file is locked, no loading available
}
}
@@ -136,9 +136,9 @@ Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const Common::String
if (getError().getCode() != Common::kNoError)
return nullptr;
- for (Common::StringArray::const_iterator i = _lockedFiles.begin(), end = _lockedFiles.end(); i != end; ++i) {
- if (filename == *i) {
- return nullptr; //file is locked, no saving available
+ for (const auto &lockedFile : _lockedFiles) {
+ if (filename == lockedFile) {
+ return nullptr; // file is locked, no saving available
}
}
@@ -225,8 +225,8 @@ bool DefaultSaveFileManager::exists(const Common::String &filename) {
if (getError().getCode() != Common::kNoError)
return false;
- for (Common::StringArray::const_iterator i = _lockedFiles.begin(), end = _lockedFiles.end(); i != end; ++i) {
- if (filename == *i)
+ for (const auto &lockedFile : _lockedFiles) {
+ if (filename == lockedFile)
return true;
}
@@ -283,11 +283,11 @@ void DefaultSaveFileManager::assureCached(const Common::Path &savePathName) {
}
// Build the savefile name cache.
- for (Common::FSList::const_iterator file = children.begin(), end = children.end(); file != end; ++file) {
- if (_saveFileCache.contains(file->getName())) {
- warning("DefaultSaveFileManager::assureCached: Name clash when building cache, ignoring file '%s'", file->getName().c_str());
+ for (const auto &file : children) {
+ if (_saveFileCache.contains(file.getName())) {
+ warning("DefaultSaveFileManager::assureCached: Name clash when building cache, ignoring file '%s'", file.getName().c_str());
} else {
- _saveFileCache[file->getName()] = *file;
+ _saveFileCache[file.getName()] = file;
}
}
@@ -366,11 +366,11 @@ void DefaultSaveFileManager::saveTimestamps(Common::HashMap<Common::String, uint
return;
}
- for (Common::HashMap<Common::String, uint32>::iterator i = timestamps.begin(); i != timestamps.end(); ++i) {
- uint32 v = i->_value;
+ for (auto ×tamp : timestamps) {
+ uint32 v = timestamp._value;
if (v < 1) v = 1; // 0 timestamp is treated as EOF up there, so we should never save zeros
- Common::String data = i->_key + Common::String::format(" %u\n", v);
+ Common::String data = timestamp._key + Common::String::format(" %u\n", v);
if (f.write(data.c_str(), data.size()) != data.size()) {
warning("DefaultSaveFileManager: failed to write timestamps data into '%s'", filename.toString(Common::Path::kNativeSeparator).c_str());
return;
diff --git a/backends/timer/default/default-timer.cpp b/backends/timer/default/default-timer.cpp
index be93b65509c..84981106d41 100644
--- a/backends/timer/default/default-timer.cpp
+++ b/backends/timer/default/default-timer.cpp
@@ -133,11 +133,10 @@ bool DefaultTimerManager::installTimerProc(TimerProc callback, int32 interval, v
error("Different callbacks are referred by same name (%s)", id.c_str());
}
}
- TimerSlotMap::const_iterator i;
- for (i = _callbacks.begin(); i != _callbacks.end(); ++i) {
- if (i->_value == callback) {
- error("Same callback added twice (old name: %s, new name: %s)", i->_key.c_str(), id.c_str());
+ for (const auto &curCallback : _callbacks) {
+ if (curCallback._value == callback) {
+ error("Same callback added twice (old name: %s, new name: %s)", curCallback._key.c_str(), id.c_str());
}
}
_callbacks[id] = callback;
More information about the Scummvm-git-logs
mailing list