Ver código fonte

Clang-Tidy - modernize-loop-convert.

Yao Wei Tjong 姚伟忠 8 anos atrás
pai
commit
446247fa8c

+ 2 - 2
Source/Samples/46_RaycastVehicle/Vehicle.cpp

@@ -138,9 +138,9 @@ void Vehicle::ApplyAttributes()
     auto* vehicle = node_->GetOrCreateComponent<RaycastVehicle>();
     if (emittersCreated)
         return;
-    for (int i = 0; i < 4; i++)
+    for (const auto& connectionPoint : connectionPoints_)
     {
-        CreateEmitter(connectionPoints_[i]);
+        CreateEmitter(connectionPoint);
     }
     emittersCreated = true;
 }

+ 2 - 2
Source/Tools/AssetImporter/AssetImporter.cpp

@@ -2774,8 +2774,8 @@ void CreatePivotlessFbxBoneStruct(OutModel &model)
 
         // Calculate chained transform
         aiMatrix4x4 finalTransform;
-        for (unsigned j = 0; j < TransformationComp_MAXIMUM; ++j)
-            finalTransform = finalTransform * chain[j];
+        for (const auto& j : chain)
+            finalTransform = finalTransform * j;
 
         // New bone node
         auto*pnode = new aiNode;

+ 2 - 2
Source/Urho3D/AngelScript/ScriptInstance.cpp

@@ -615,8 +615,8 @@ void ScriptInstance::ReleaseObject()
 
 void ScriptInstance::ClearScriptMethods()
 {
-    for (unsigned i = 0; i < MAX_SCRIPT_METHODS; ++i)
-        methods_[i] = nullptr;
+    for (auto& method : methods_)
+        method = nullptr;
 
     delayedCalls_.Clear();
 }

+ 10 - 10
Source/Urho3D/Graphics/DecalSet.cpp

@@ -400,7 +400,7 @@ bool DecalSet::AddDecal(Drawable* target, const Vector3& worldPosition, const Qu
     }
 
     // Clip the acquired faces against all frustum planes
-    for (unsigned i = 0; i < NUM_FRUSTUM_PLANES; ++i)
+    for (const auto& plane : decalFrustum.planes_)
     {
         for (unsigned j = 0; j < faces.Size(); ++j)
         {
@@ -408,7 +408,7 @@ bool DecalSet::AddDecal(Drawable* target, const Vector3& worldPosition, const Qu
             if (face.Empty())
                 continue;
 
-            ClipPolygon(tempFace, face, decalFrustum.planes_[i], skinned_);
+            ClipPolygon(tempFace, face, plane, skinned_);
             face = tempFace;
         }
     }
@@ -553,10 +553,10 @@ void DecalSet::SetDecalsAttr(const PODVector<unsigned char>& value)
             i->tangent_ = buffer.ReadVector4();
             if (skinned_)
             {
-                for (unsigned j = 0; j < 4; ++j)
-                    i->blendWeights_[j] = buffer.ReadFloat();
-                for (unsigned j = 0; j < 4; ++j)
-                    i->blendIndices_[j] = buffer.ReadUByte();
+                for (float& blendWeight : i->blendWeights_)
+                    blendWeight = buffer.ReadFloat();
+                for (unsigned char& blendIndice : i->blendIndices_)
+                    blendIndice = buffer.ReadUByte();
             }
         }
 
@@ -623,10 +623,10 @@ PODVector<unsigned char> DecalSet::GetDecalsAttr() const
             ret.WriteVector4(j->tangent_);
             if (skinned_)
             {
-                for (unsigned k = 0; k < 4; ++k)
-                    ret.WriteFloat(j->blendWeights_[k]);
-                for (unsigned k = 0; k < 4; ++k)
-                    ret.WriteUByte(j->blendIndices_[k]);
+                for (float blendWeight : j->blendWeights_)
+                    ret.WriteFloat(blendWeight);
+                for (unsigned char blendIndice : j->blendIndices_)
+                    ret.WriteUByte(blendIndice);
             }
         }
 

+ 2 - 2
Source/Urho3D/Graphics/OcclusionBuffer.cpp

@@ -357,8 +357,8 @@ bool OcclusionBuffer::IsVisible(const BoundingBox& worldSpaceBox) const
     vertices[7] = ModelTransform(viewProj_, worldSpaceBox.max_);
 
     // Apply a far clip relative bias
-    for (unsigned i = 0; i < 8; ++i)
-        vertices[i].z_ -= OCCLUSION_RELATIVE_BIAS;
+    for (auto& vertice : vertices)
+        vertice.z_ -= OCCLUSION_RELATIVE_BIAS;
 
     // Transform to screen space. If any of the corners cross the near plane, assume visible
     float minX, maxX, minY, maxY, minZ;

+ 17 - 17
Source/Urho3D/Graphics/Octree.cpp

@@ -77,8 +77,8 @@ Octant::Octant(const BoundingBox& box, unsigned level, Octant* parent, Octree* r
 {
     Initialize(box);
 
-    for (unsigned i = 0; i < NUM_OCTANTS; ++i)
-        children_[i] = nullptr;
+    for (auto& i : children_)
+        i = nullptr;
 }
 
 Octant::~Octant()
@@ -201,10 +201,10 @@ void Octant::ResetRoot()
     for (PODVector<Drawable*>::Iterator i = drawables_.Begin(); i != drawables_.End(); ++i)
         (*i)->SetOctant(nullptr);
 
-    for (unsigned i = 0; i < NUM_OCTANTS; ++i)
+    for (auto& i : children_)
     {
-        if (children_[i])
-            children_[i]->ResetRoot();
+        if (i)
+            i->ResetRoot();
     }
 }
 
@@ -214,10 +214,10 @@ void Octant::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
     {
         debug->AddBoundingBox(worldBoundingBox_, Color(0.25f, 0.25f, 0.25f), depthTest);
 
-        for (unsigned i = 0; i < NUM_OCTANTS; ++i)
+        for (auto& i : children_)
         {
-            if (children_[i])
-                children_[i]->DrawDebugGeometry(debug, depthTest);
+            if (i)
+                i->DrawDebugGeometry(debug, depthTest);
         }
     }
 }
@@ -251,10 +251,10 @@ void Octant::GetDrawablesInternal(OctreeQuery& query, bool inside) const
         query.TestDrawables(start, end, inside);
     }
 
-    for (unsigned i = 0; i < NUM_OCTANTS; ++i)
+    for (auto i : children_)
     {
-        if (children_[i])
-            children_[i]->GetDrawablesInternal(query, inside);
+        if (i)
+            i->GetDrawablesInternal(query, inside);
     }
 }
 
@@ -278,10 +278,10 @@ void Octant::GetDrawablesInternal(RayOctreeQuery& query) const
         }
     }
 
-    for (unsigned i = 0; i < NUM_OCTANTS; ++i)
+    for (auto i : children_)
     {
-        if (children_[i])
-            children_[i]->GetDrawablesInternal(query);
+        if (i)
+            i->GetDrawablesInternal(query);
     }
 }
 
@@ -305,10 +305,10 @@ void Octant::GetDrawablesOnlyInternal(RayOctreeQuery& query, PODVector<Drawable*
         }
     }
 
-    for (unsigned i = 0; i < NUM_OCTANTS; ++i)
+    for (auto i : children_)
     {
-        if (children_[i])
-            children_[i]->GetDrawablesOnlyInternal(query, drawables);
+        if (i)
+            i->GetDrawablesOnlyInternal(query, drawables);
     }
 }
 

+ 8 - 8
Source/Urho3D/Graphics/OpenGL/OGLGraphics.cpp

@@ -2881,9 +2881,9 @@ void Graphics::PrepareDraw()
         bool noFbo = !depthStencil_;
         if (noFbo)
         {
-            for (unsigned i = 0; i < MAX_RENDERTARGETS; ++i)
+            for (auto& renderTarget : renderTargets_)
             {
-                if (renderTargets_[i])
+                if (renderTarget)
                 {
                     noFbo = false;
                     break;
@@ -3204,8 +3204,8 @@ void Graphics::CleanupFramebuffers()
 
 void Graphics::ResetCachedState()
 {
-    for (unsigned i = 0; i < MAX_VERTEX_STREAMS; ++i)
-        vertexBuffers_[i] = nullptr;
+    for (auto& vertexBuffer : vertexBuffers_)
+        vertexBuffer = nullptr;
 
     for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
     {
@@ -3213,8 +3213,8 @@ void Graphics::ResetCachedState()
         impl_->textureTypes_[i] = 0;
     }
 
-    for (unsigned i = 0; i < MAX_RENDERTARGETS; ++i)
-        renderTargets_[i] = nullptr;
+    for (auto& renderTarget : renderTargets_)
+        renderTarget = nullptr;
 
     depthStencil_ = nullptr;
     viewport_ = IntRect(0, 0, 0, 0);
@@ -3262,8 +3262,8 @@ void Graphics::ResetCachedState()
         SetDepthWrite(true);
     }
 
-    for (unsigned i = 0; i < MAX_SHADER_PARAMETER_GROUPS * 2; ++i)
-        impl_->constantBuffers_[i] = nullptr;
+    for (auto& constantBuffer : impl_->constantBuffers_)
+        constantBuffer = nullptr;
     impl_->dirtyConstantBuffers_.Clear();
 }
 

+ 2 - 2
Source/Urho3D/Graphics/OpenGL/OGLGraphicsImpl.h

@@ -83,8 +83,8 @@ struct FrameBufferObject
         readBuffers_(M_MAX_UNSIGNED),
         drawBuffers_(M_MAX_UNSIGNED)
     {
-        for (unsigned i = 0; i < MAX_RENDERTARGETS; ++i)
-            colorAttachments_[i] = nullptr;
+        for (auto& colorAttachment : colorAttachments_)
+            colorAttachment = nullptr;
     }
 
     /// Frame buffer handle.

+ 11 - 11
Source/Urho3D/Graphics/OpenGL/OGLShaderProgram.cpp

@@ -65,10 +65,10 @@ ShaderProgram::ShaderProgram(Graphics* graphics, ShaderVariation* vertexShader,
     usedVertexAttributes_(0),
     frameNumber_(0)
 {
-    for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
-        useTextureUnit_[i] = false;
-    for (unsigned i = 0; i < MAX_SHADER_PARAMETER_GROUPS; ++i)
-        parameterSources_[i] = (const void*)M_MAX_UNSIGNED;
+    for (bool& i : useTextureUnit_)
+        i = false;
+    for (auto& parameterSource : parameterSources_)
+        parameterSource = (const void*)M_MAX_UNSIGNED;
 }
 
 ShaderProgram::~ShaderProgram()
@@ -107,8 +107,8 @@ void ShaderProgram::Release()
         vertexAttributes_.Clear();
         usedVertexAttributes_ = 0;
 
-        for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
-            useTextureUnit_[i] = false;
+        for (bool& i : useTextureUnit_)
+            i = false;
         for (unsigned i = 0; i < MAX_SHADER_PARAMETER_GROUPS; ++i)
             constantBuffers_[i].Reset();
     }
@@ -181,7 +181,7 @@ bool ShaderProgram::Link()
 
         if (semantic == MAX_VERTEX_ELEMENT_SEMANTICS)
         {
-            URHO3D_LOGWARNING("Found vertex attribute " + name + " with no known semantic in shader program " + 
+            URHO3D_LOGWARNING("Found vertex attribute " + name + " with no known semantic in shader program " +
                 vertexShader_->GetFullName() + " " + pixelShader_->GetFullName());
             continue;
         }
@@ -353,8 +353,8 @@ bool ShaderProgram::NeedParameterUpdate(ShaderParameterGroup group, const void*
     // If global framenumber has changed, invalidate all per-program parameter sources now
     if (globalFrameNumber != frameNumber_)
     {
-        for (unsigned i = 0; i < MAX_SHADER_PARAMETER_GROUPS; ++i)
-            parameterSources_[i] = (const void*)M_MAX_UNSIGNED;
+        for (auto& parameterSource : parameterSources_)
+            parameterSource = (const void*)M_MAX_UNSIGNED;
         frameNumber_ = globalFrameNumber;
     }
 
@@ -411,8 +411,8 @@ void ShaderProgram::ClearParameterSources()
         ++globalFrameNumber;
 
 #ifndef GL_ES_VERSION_2_0
-    for (unsigned i = 0; i < MAX_SHADER_PARAMETER_GROUPS; ++i)
-        globalParameterSources[i] = (const void*)M_MAX_UNSIGNED;
+    for (auto& globalParameterSource : globalParameterSources)
+        globalParameterSource = (const void*)M_MAX_UNSIGNED;
 #endif
 }
 

+ 10 - 10
Source/Urho3D/Graphics/OpenGL/OGLTextureCube.cpp

@@ -47,10 +47,10 @@ void TextureCube::OnDeviceLost()
 {
     GPUObject::OnDeviceLost();
 
-    for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
+    for (auto& renderSurface : renderSurfaces_)
     {
-        if (renderSurfaces_[i])
-            renderSurfaces_[i]->OnDeviceLost();
+        if (renderSurface)
+            renderSurface->OnDeviceLost();
     }
 }
 
@@ -91,10 +91,10 @@ void TextureCube::Release()
             glDeleteTextures(1, &object_.name_);
         }
 
-        for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
+        for (auto& renderSurface : renderSurfaces_)
         {
-            if (renderSurfaces_[i])
-                renderSurfaces_[i]->Release();
+            if (renderSurface)
+                renderSurface->Release();
         }
 
         object_.name_ = 0;
@@ -360,8 +360,8 @@ bool TextureCube::SetData(CubeMapFace face, Image* image, bool useAlpha)
 
     faceMemoryUse_[face] = memoryUse;
     unsigned totalMemoryUse = sizeof(TextureCube);
-    for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
-        totalMemoryUse += faceMemoryUse_[i];
+    for (unsigned int i : faceMemoryUse_)
+        totalMemoryUse += i;
     SetMemoryUse(totalMemoryUse);
     return true;
 }
@@ -462,8 +462,8 @@ bool TextureCube::Create()
     // If multisample, create renderbuffers for each face
     if (multiSample_ > 1)
     {
-        for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
-            renderSurfaces_[i]->CreateRenderBuffer(width_, height_, format, multiSample_);
+        for (auto& renderSurface : renderSurfaces_)
+            renderSurface->CreateRenderBuffer(width_, height_, format, multiSample_);
     }
 
     bool success = true;

+ 4 - 4
Source/Urho3D/Graphics/ShaderVariation.cpp

@@ -37,10 +37,10 @@ ShaderVariation::ShaderVariation(Shader* owner, ShaderType type) :
     type_(type),
     elementHash_(0)
 {
-    for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
-        useTextureUnit_[i] = false;
-    for (unsigned i = 0; i < MAX_SHADER_PARAMETER_GROUPS; ++i)
-        constantBufferSizes_[i] = 0;
+    for (bool& i : useTextureUnit_)
+        i = false;
+    for (unsigned int& constantBufferSize : constantBufferSizes_)
+        constantBufferSize = 0;
 }
 
 ShaderVariation::~ShaderVariation()

+ 2 - 2
Source/Urho3D/Graphics/Texture.cpp

@@ -78,8 +78,8 @@ Texture::Texture(Context* context) :
     resolveDirty_(false),
     levelsDirty_(false)
 {
-    for (int i = 0; i < MAX_COORDS; ++i)
-        addressMode_[i] = ADDRESS_WRAP;
+    for (auto& i : addressMode_)
+        i = ADDRESS_WRAP;
     for (int i = 0; i < MAX_TEXTURE_QUALITY_LEVELS; ++i)
         mipsToSkip_[i] = (unsigned)(MAX_TEXTURE_QUALITY_LEVELS - 1 - i);
 }

+ 6 - 6
Source/Urho3D/Graphics/TextureCube.cpp

@@ -70,8 +70,8 @@ TextureCube::TextureCube(Context* context) :
     addressMode_[COORD_V] = ADDRESS_CLAMP;
     addressMode_[COORD_W] = ADDRESS_CLAMP;
 
-    for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
-        faceMemoryUse_[i] = 0;
+    for (unsigned int& i : faceMemoryUse_)
+        i = 0;
 }
 
 TextureCube::~TextureCube()
@@ -340,13 +340,13 @@ void TextureCube::HandleRenderSurfaceUpdate(StringHash eventType, VariantMap& ev
 {
     auto* renderer = GetSubsystem<Renderer>();
 
-    for (unsigned i = 0; i < MAX_CUBEMAP_FACES; ++i)
+    for (auto& renderSurface : renderSurfaces_)
     {
-        if (renderSurfaces_[i] && (renderSurfaces_[i]->GetUpdateMode() == SURFACE_UPDATEALWAYS || renderSurfaces_[i]->IsUpdateQueued()))
+        if (renderSurface && (renderSurface->GetUpdateMode() == SURFACE_UPDATEALWAYS || renderSurface->IsUpdateQueued()))
         {
             if (renderer)
-                renderer->QueueRenderSurface(renderSurfaces_[i]);
-            renderSurfaces_[i]->ResetUpdateQueued();
+                renderer->QueueRenderSurface(renderSurface);
+            renderSurface->ResetUpdateQueued();
         }
     }
 }

+ 2 - 2
Source/Urho3D/Graphics/View.cpp

@@ -1921,9 +1921,9 @@ bool View::IsNecessary(const RenderPathCommand& command)
 
 bool View::CheckViewportRead(const RenderPathCommand& command)
 {
-    for (unsigned i = 0; i < MAX_TEXTURE_UNITS; ++i)
+    for (const auto& textureName : command.textureNames_)
     {
-        if (!command.textureNames_[i].Empty() && !command.textureNames_[i].Compare("viewport", false))
+        if (!textureName.Empty() && !textureName.Compare("viewport", false))
             return true;
     }
 

+ 4 - 4
Source/Urho3D/LuaScript/LuaScriptInstance.cpp

@@ -73,8 +73,8 @@ LuaScriptInstance::LuaScriptInstance(Context* context) :
 
     eventInvoker_ = new LuaScriptEventInvoker(this);
 
-    for (int i = 0; i < MAX_LUA_SCRIPT_OBJECT_METHODS; ++i)
-        scriptObjectMethods_[i] = nullptr;
+    for (auto& scriptObjectMethod : scriptObjectMethods_)
+        scriptObjectMethod = nullptr;
 }
 
 LuaScriptInstance::~LuaScriptInstance()
@@ -750,8 +750,8 @@ void LuaScriptInstance::ReleaseObject()
         function->EndCall();
     }
 
-    for (int i = 0; i < MAX_LUA_SCRIPT_OBJECT_METHODS; ++i)
-        scriptObjectMethods_[i] = nullptr;
+    for (auto& scriptObjectMethod : scriptObjectMethods_)
+        scriptObjectMethod = nullptr;
 }
 
 LuaFunction* LuaScriptInstance::GetScriptObjectFunction(const String& functionName) const

+ 2 - 2
Source/Urho3D/Math/BoundingBox.cpp

@@ -187,9 +187,9 @@ Rect BoundingBox::Projected(const Matrix4& projection) const
     vertices[7] = projMax;
 
     Rect rect;
-    for (unsigned i = 0; i < 8; ++i)
+    for (const auto& vertice : vertices)
     {
-        Vector3 projected = projection * vertices[i];
+        Vector3 projected = projection * vertice;
         rect.Merge(Vector2(projected.x_, projected.y_));
     }
 

+ 7 - 7
Source/Urho3D/Math/Frustum.cpp

@@ -176,16 +176,16 @@ void Frustum::DefineSplit(const Matrix4& projection, float near, float far)
 
 void Frustum::Transform(const Matrix3& transform)
 {
-    for (unsigned i = 0; i < NUM_FRUSTUM_VERTICES; ++i)
-        vertices_[i] = transform * vertices_[i];
+    for (auto& vertice : vertices_)
+        vertice = transform * vertice;
 
     UpdatePlanes();
 }
 
 void Frustum::Transform(const Matrix3x4& transform)
 {
-    for (unsigned i = 0; i < NUM_FRUSTUM_VERTICES; ++i)
-        vertices_[i] = transform * vertices_[i];
+    for (auto& vertice : vertices_)
+        vertice = transform * vertice;
 
     UpdatePlanes();
 }
@@ -238,10 +238,10 @@ void Frustum::UpdatePlanes()
     // Check if we ended up with inverted planes (reflected transform) and flip in that case
     if (planes_[PLANE_NEAR].Distance(vertices_[5]) < 0.0f)
     {
-        for (unsigned i = 0; i < NUM_FRUSTUM_PLANES; ++i)
+        for (auto& plane : planes_)
         {
-            planes_[i].normal_ = -planes_[i].normal_;
-            planes_[i].d_ = -planes_[i].d_;
+            plane.normal_ = -plane.normal_;
+            plane.d_ = -plane.d_;
         }
     }
 

+ 10 - 12
Source/Urho3D/Math/Frustum.h

@@ -79,9 +79,9 @@ public:
     /// Test if a point is inside or outside.
     Intersection IsInside(const Vector3& point) const
     {
-        for (unsigned i = 0; i < NUM_FRUSTUM_PLANES; ++i)
+        for (const auto& plane : planes_)
         {
-            if (planes_[i].Distance(point) < 0.0f)
+            if (plane.Distance(point) < 0.0f)
                 return OUTSIDE;
         }
 
@@ -92,9 +92,9 @@ public:
     Intersection IsInside(const Sphere& sphere) const
     {
         bool allInside = true;
-        for (unsigned i = 0; i < NUM_FRUSTUM_PLANES; ++i)
+        for (const auto& plane : planes_)
         {
-            float dist = planes_[i].Distance(sphere.center_);
+            float dist = plane.Distance(sphere.center_);
             if (dist < -sphere.radius_)
                 return OUTSIDE;
             else if (dist < sphere.radius_)
@@ -107,9 +107,9 @@ public:
     /// Test if a sphere if (partially) inside or outside.
     Intersection IsInsideFast(const Sphere& sphere) const
     {
-        for (unsigned i = 0; i < NUM_FRUSTUM_PLANES; ++i)
+        for (const auto& plane : planes_)
         {
-            if (planes_[i].Distance(sphere.center_) < -sphere.radius_)
+            if (plane.Distance(sphere.center_) < -sphere.radius_)
                 return OUTSIDE;
         }
 
@@ -123,9 +123,8 @@ public:
         Vector3 edge = center - box.min_;
         bool allInside = true;
 
-        for (unsigned i = 0; i < NUM_FRUSTUM_PLANES; ++i)
+        for (const auto& plane : planes_)
         {
-            const Plane& plane = planes_[i];
             float dist = plane.normal_.DotProduct(center) + plane.d_;
             float absDist = plane.absNormal_.DotProduct(edge);
 
@@ -144,9 +143,8 @@ public:
         Vector3 center = box.Center();
         Vector3 edge = center - box.min_;
 
-        for (unsigned i = 0; i < NUM_FRUSTUM_PLANES; ++i)
+        for (const auto& plane : planes_)
         {
-            const Plane& plane = planes_[i];
             float dist = plane.normal_.DotProduct(center) + plane.d_;
             float absDist = plane.absNormal_.DotProduct(edge);
 
@@ -161,8 +159,8 @@ public:
     float Distance(const Vector3& point) const
     {
         float distance = 0.0f;
-        for (unsigned i = 0; i < NUM_FRUSTUM_PLANES; ++i)
-            distance = Max(-planes_[i].Distance(point), distance);
+        for (const auto& plane : planes_)
+            distance = Max(-plane.Distance(point), distance);
 
         return distance;
     }

+ 2 - 2
Source/Urho3D/Math/Polyhedron.cpp

@@ -209,8 +209,8 @@ void Polyhedron::Clip(const Plane& plane)
 
 void Polyhedron::Clip(const Frustum& frustum)
 {
-    for (unsigned i = 0; i < NUM_FRUSTUM_PLANES; ++i)
-        Clip(frustum.planes_[i]);
+    for (const auto& plane : frustum.planes_)
+        Clip(plane);
 }
 
 void Polyhedron::Clip(const BoundingBox& box)

+ 3 - 3
Source/Urho3D/Math/Ray.cpp

@@ -153,10 +153,10 @@ float Ray::HitDistance(const Frustum& frustum, bool solidInside) const
     float minInside = M_INFINITY;
     bool allInside = true;
 
-    for (unsigned i = 0; i < NUM_FRUSTUM_PLANES; ++i)
+    for (const auto& i : frustum.planes_)
     {
-        const Plane& plane = frustum.planes_[i];
-        float distance = HitDistance(frustum.planes_[i]);
+        const Plane& plane = i;
+        float distance = HitDistance(i);
 
         if (plane.Distance(origin_) < 0.0f)
         {

+ 2 - 2
Source/Urho3D/Navigation/NavigationMesh.cpp

@@ -1170,8 +1170,8 @@ void NavigationMesh::GetTileGeometry(NavBuildData* build, Vector<NavigationGeome
                             4, 0, 3, 4, 3, 7, 1, 0, 4, 1, 4, 5
                         };
 
-                        for (unsigned j = 0; j < 36; ++j)
-                            build->indices_.Push(indices[j] + destVertexStart);
+                        for (unsigned int indice : indices)
+                            build->indices_.Push(indice + destVertexStart);
                     }
                     break;
 

+ 7 - 7
Source/Urho3D/Resource/XMLFile.cpp

@@ -199,9 +199,9 @@ void XMLFile::Patch(XMLElement patchElement)
 {
     pugi::xml_node root = pugi::xml_node(patchElement.GetNode());
 
-    for (pugi::xml_node::iterator patch = root.begin(); patch != root.end(); patch++)
+    for (auto& patch : root)
     {
-        pugi::xml_attribute sel = patch->attribute("sel");
+        pugi::xml_attribute sel = patch.attribute("sel");
         if (sel.empty())
         {
             URHO3D_LOGERROR("XML Patch failed due to node not having a sel attribute.");
@@ -216,11 +216,11 @@ void XMLFile::Patch(XMLElement patchElement)
             continue;
         }
 
-        if (strcmp(patch->name(), "add") == 0)
-            PatchAdd(*patch, original);
-        else if (strcmp(patch->name(), "replace") == 0)
-            PatchReplace(*patch, original);
-        else if (strcmp(patch->name(), "remove") == 0)
+        if (strcmp(patch.name(), "add") == 0)
+            PatchAdd(patch, original);
+        else if (strcmp(patch.name(), "replace") == 0)
+            PatchReplace(patch, original);
+        else if (strcmp(patch.name(), "remove") == 0)
             PatchRemove(original);
         else
             URHO3D_LOGERROR("XMLFiles used for patching should only use 'add', 'replace' or 'remove' elements.");

+ 2 - 2
Source/Urho3D/UI/UIElement.cpp

@@ -866,8 +866,8 @@ void UIElement::SetClipBorder(const IntRect& rect)
 
 void UIElement::SetColor(const Color& color)
 {
-    for (unsigned i = 0; i < MAX_UIELEMENT_CORNERS; ++i)
-        color_[i] = color;
+    for (auto& i : color_)
+        i = color;
     colorGradient_ = false;
     derivedColorDirty_ = true;
 }