diff --git a/src/modules/audio/openal/Pool.cpp b/src/modules/audio/openal/Pool.cpp index efc71e603..03434fac8 100644 --- a/src/modules/audio/openal/Pool.cpp +++ b/src/modules/audio/openal/Pool.cpp @@ -76,7 +76,7 @@ bool Pool::isPlaying(Source *s) bool p = false; { thread::Lock lock(mutex); - for (std::map::iterator i = playing.begin(); i != playing.end(); i++) + for (auto i = playing.begin(); i != playing.end(); i++) { if (i->first == s) p = true; @@ -161,7 +161,7 @@ bool Pool::play(Source *source, ALuint &out) void Pool::stop() { thread::Lock lock(mutex); - for (std::map::iterator i = playing.begin(); i != playing.end(); i++) + for (auto i = playing.begin(); i != playing.end(); i++) { i->first->stopAtomic(); i->first->release(); @@ -180,7 +180,7 @@ void Pool::stop(Source *source) void Pool::pause() { thread::Lock lock(mutex); - for (std::map::iterator i = playing.begin(); i != playing.end(); i++) + for (auto i = playing.begin(); i != playing.end(); i++) i->first->pauseAtomic(); } @@ -195,7 +195,7 @@ void Pool::pause(Source *source) void Pool::resume() { thread::Lock lock(mutex); - for (std::map::iterator i = playing.begin(); i != playing.end(); i++) + for (auto i = playing.begin(); i != playing.end(); i++) i->first->resumeAtomic(); } @@ -210,7 +210,7 @@ void Pool::resume(Source *source) void Pool::rewind() { thread::Lock lock(mutex); - for (std::map::iterator i = playing.begin(); i != playing.end(); i++) + for (auto i = playing.begin(); i != playing.end(); i++) i->first->rewindAtomic(); } diff --git a/src/modules/graphics/opengl/Font.cpp b/src/modules/graphics/opengl/Font.cpp index 41eb34189..265bda8f1 100644 --- a/src/modules/graphics/opengl/Font.cpp +++ b/src/modules/graphics/opengl/Font.cpp @@ -245,7 +245,7 @@ Font::Glyph *Font::addGlyph(uint32 glyph) Font::Glyph *Font::findGlyph(uint32 glyph) { - std::map::const_iterator it = glyphs.find(glyph); + auto it = glyphs.find(glyph); if (it != glyphs.end()) return it->second; @@ -499,8 +499,7 @@ void Font::setFilter(const Image::Filter &f) { filter = f; - std::vector::const_iterator it; - for (it = textures.begin(); it != textures.end(); ++it) + for (auto it = textures.begin(); it != textures.end(); ++it) { gl.bindTexture(*it); filter.anisotropy = gl.setTextureFilter(f); diff --git a/src/modules/graphics/opengl/Shader.cpp b/src/modules/graphics/opengl/Shader.cpp index 16cfe1ada..cbf18ec4b 100644 --- a/src/modules/graphics/opengl/Shader.cpp +++ b/src/modules/graphics/opengl/Shader.cpp @@ -554,7 +554,7 @@ void Shader::sendTexture(const std::string &name, GLuint texture) if (activeTextureUnits[textureunit-1] == 0) ++textureCounters[textureunit-1]; - // store texture id so it can be re-bound to the proper texture unit when necessary + // store texture id so it can be re-bound to the proper texture unit later activeTextureUnits[textureunit-1] = texture; } @@ -570,7 +570,7 @@ void Shader::sendCanvas(const std::string &name, const Canvas &canvas) int Shader::getTextureUnit(const std::string &name) { - std::map::const_iterator it = textureUnitPool.find(name); + auto it = textureUnitPool.find(name); if (it != textureUnitPool.end()) return it->second; @@ -578,19 +578,23 @@ int Shader::getTextureUnit(const std::string &name) int textureunit = 1; // prefer texture units which are unused by all other shaders - std::vector::iterator nextfreeunit = std::find(textureCounters.begin(), textureCounters.end(), 0); + auto freeunit_it = std::find(textureCounters.begin(), textureCounters.end(), 0); - if (nextfreeunit != textureCounters.end()) - textureunit = std::distance(textureCounters.begin(), nextfreeunit) + 1; // we don't want to use unit 0 + if (freeunit_it != textureCounters.end()) + { + // we don't want to use unit 0 + textureunit = std::distance(textureCounters.begin(), freeunit_it) + 1; + } else { // no completely unused texture units exist, try to use next free slot in our own list - std::vector::iterator nexttexunit = std::find(activeTextureUnits.begin(), activeTextureUnits.end(), 0); + auto nextunit_it = std::find(activeTextureUnits.begin(), activeTextureUnits.end(), 0); - if (nexttexunit == activeTextureUnits.end()) + if (nextunit_it == activeTextureUnits.end()) throw love::Exception("No more texture units available for shader."); - textureunit = std::distance(activeTextureUnits.begin(), nexttexunit) + 1; // we don't want to use unit 0 + // we don't want to use unit 0 + textureunit = std::distance(activeTextureUnits.begin(), nextunit_it) + 1; } textureUnitPool[name] = textureunit; diff --git a/src/modules/joystick/sdl/JoystickModule.cpp b/src/modules/joystick/sdl/JoystickModule.cpp index 1c1fab0ba..a5e7a1ea8 100644 --- a/src/modules/joystick/sdl/JoystickModule.cpp +++ b/src/modules/joystick/sdl/JoystickModule.cpp @@ -57,8 +57,7 @@ JoystickModule::JoystickModule() JoystickModule::~JoystickModule() { // Close any open Joysticks. - std::list::iterator it; - for (it = joysticks.begin(); it != joysticks.end(); ++it) + for (auto it = joysticks.begin(); it != joysticks.end(); ++it) { (*it)->close(); (*it)->release(); @@ -117,8 +116,7 @@ love::joystick::Joystick *JoystickModule::addJoystick(int deviceindex) joystick::Joystick *joystick = 0; bool reused = false; - std::list::iterator it; - for (it = joysticks.begin(); it != joysticks.end(); ++it) + for (auto it = joysticks.begin(); it != joysticks.end(); ++it) { // Try to re-use a disconnected Joystick with the same GUID. if (!(*it)->isConnected() && (*it)->getGUID() == guidstr) @@ -143,19 +141,20 @@ love::joystick::Joystick *JoystickModule::addJoystick(int deviceindex) // Make sure multiple instances of the same physical joystick aren't added // to the active list. - for (size_t i = 0; i < activeSticks.size(); i++) + for (auto it = activeSticks.begin(); it != activeSticks.end(); ++it) { - if (joystick->getHandle() == activeSticks[i]->getHandle()) + if (joystick->getHandle() == (*it)->getHandle()) { joystick->close(); + // If we just created the stick, remove it since it's a duplicate. if (!reused) { joysticks.remove(joystick); joystick->release(); } - return activeSticks[i]; + return *it; } } @@ -169,7 +168,7 @@ void JoystickModule::removeJoystick(love::joystick::Joystick *joystick) return; // Close the Joystick and remove it from the active joystick list. - std::vector::iterator it = std::find(activeSticks.begin(), activeSticks.end(), joystick); + auto it = std::find(activeSticks.begin(), activeSticks.end(), joystick); if (it != activeSticks.end()) { (*it)->close(); @@ -425,8 +424,7 @@ void JoystickModule::checkGamepads(const std::string &guid) const if (guid.compare(getDeviceGUID(d_index)) != 0) continue; - std::vector::const_iterator it; - for (it = activeSticks.begin(); it != activeSticks.end(); ++it) + for (auto it = activeSticks.begin(); it != activeSticks.end(); ++it) { if ((*it)->isGamepad() || guid.compare((*it)->getGUID()) != 0) continue; diff --git a/src/modules/physics/box2d/World.cpp b/src/modules/physics/box2d/World.cpp index 957fc8b20..f70893fe8 100644 --- a/src/modules/physics/box2d/World.cpp +++ b/src/modules/physics/box2d/World.cpp @@ -257,21 +257,21 @@ void World::update(float dt) world->Step(dt, 8, 6); // Destroy all objects marked during the time step. - for (std::vector::iterator i = destructBodies.begin(); i < destructBodies.end(); i++) + for (auto i = destructBodies.begin(); i < destructBodies.end(); i++) { Body *b = *i; if (b->body != 0) b->destroy(); // Release for reference in vector. b->release(); } - for (std::vector::iterator i = destructFixtures.begin(); i < destructFixtures.end(); i++) + for (auto i = destructFixtures.begin(); i < destructFixtures.end(); i++) { Fixture *f = *i; if (f->isValid()) f->destroy(); // Release for reference in vector. f->release(); } - for (std::vector::iterator i = destructJoints.begin(); i < destructJoints.end(); i++) + for (auto i = destructJoints.begin(); i < destructJoints.end(); i++) { Joint *j = *i; if (j->isValid()) j->destroyJoint();