Browse Source

Fix portion of warnings

1vanK 3 years ago
parent
commit
feb0d90190

+ 3 - 2
Source/Tools/RampGenerator/RampGenerator.cpp

@@ -239,8 +239,9 @@ bool ReadIES(File* data, Vector<float>& vertical, Vector<float>& horizontal, Vec
     while (!data->IsEof())
         lines.Push(data->ReadLine());
     Vector<String> words;
-    for (unsigned i = 0; i < lines.Size(); ++i)
-        words.Push(lines[i].Split(' '));
+    
+    for (const String& line : lines)
+        words.Push(line.Split(' '));
 
     // Prune any 'junk' collected
     for (unsigned i = 0; i < words.Size(); ++i)

+ 2 - 2
Source/Urho3D/Core/ProcessUtils.cpp

@@ -277,8 +277,8 @@ const Vector<String>& ParseArguments(const String& cmdLine, bool skipFirstArgume
     }
 
     // Strip double quotes from the arguments
-    for (unsigned i = 0; i < arguments.Size(); ++i)
-        arguments[i].Replace("\"", "");
+    for (String& argument : arguments)
+        argument.Replace("\"", "");
 
     return arguments;
 }

+ 2 - 2
Source/Urho3D/Core/WorkQueue.cpp

@@ -65,8 +65,8 @@ WorkQueue::~WorkQueue()
     shutDown_ = true;
     Resume();
 
-    for (unsigned i = 0; i < threads_.Size(); ++i)
-        threads_[i]->Stop();
+    for (const SharedPtr<WorkerThread>& thread : threads_)
+        thread->Stop();
 }
 
 void WorkQueue::CreateThreads(unsigned numThreads)

+ 3 - 1
Source/Urho3D/Graphics/AnimatedModel.cpp

@@ -246,10 +246,12 @@ void AnimatedModel::UpdateBatches(const FrameInfo& frame)
     // Note: per-geometry distances do not take skinning into account. Especially in case of a ragdoll they may be
     // much off base if the node's own transform is not updated
     if (batches_.Size() == 1)
+    {
         batches_[0].distance_ = distance_;
+    }
     else
     {
-        for (unsigned i = 0; i < batches_.Size(); ++i)
+        for (i32 i = 0; i < batches_.Size(); ++i)
             batches_[i].distance_ = frame.camera_->GetDistance(worldTransform * geometryData_[i].center_);
     }
 

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

@@ -1342,8 +1342,8 @@ void Material::HandleAttributeAnimationUpdate(StringHash eventType, VariantMap&
     }
 
     // Remove finished animations
-    for (unsigned i = 0; i < finishedNames.Size(); ++i)
-        SetShaderParameterAnimation(finishedNames[i], nullptr);
+    for (const String& finishedName : finishedNames)
+        SetShaderParameterAnimation(finishedName, nullptr);
 }
 
 void Material::ApplyShaderDefines(unsigned index)

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

@@ -136,8 +136,8 @@ void OcclusionBuffer::Clear()
 
     // Only clear the main thread buffer. Rest are cleared on-demand when drawing the first batch
     ClearBuffer(0);
-    for (unsigned i = 1; i < buffers_.Size(); ++i)
-        buffers_[i].used_ = false;
+    for (OcclusionBufferData& buffer : buffers_)
+        buffer.used_ = false;
 
     depthHierarchyDirty_ = true;
 }

+ 23 - 18
Source/Urho3D/Graphics/Renderer.cpp

@@ -682,14 +682,16 @@ void Renderer::Render()
 
     // If no views that render to the backbuffer, clear the screen so that e.g. the UI is not rendered on top of previous frame
     bool hasBackbufferViews = false;
-    for (unsigned i = 0; i < views_.Size(); ++i)
+    
+    for (const WeakPtr<View>& view : views_)
     {
-        if (!views_[i]->GetRenderTarget())
+        if (!view->GetRenderTarget())
         {
             hasBackbufferViews = true;
             break;
         }
     }
+    
     if (!hasBackbufferViews)
     {
         graphics_->SetBlendMode(BLEND_REPLACE);
@@ -739,7 +741,7 @@ void Renderer::DrawDebugGeometry(bool depthTest)
         Octree* octree = view->GetOctree();
         if (!octree)
             continue;
-        auto* debug = octree->GetComponent<DebugRenderer>();
+        DebugRenderer* debug = octree->GetComponent<DebugRenderer>();
         if (!debug || !debug->IsEnabledEffective())
             continue;
 
@@ -747,20 +749,21 @@ void Renderer::DrawDebugGeometry(bool depthTest)
         const Vector<Drawable*>& geometries = view->GetGeometries();
         const Vector<Light*>& lights = view->GetLights();
 
-        for (unsigned i = 0; i < geometries.Size(); ++i)
+        for (Drawable* geometry : geometries)
         {
-            if (!processedGeometries.Contains(geometries[i]))
+            if (!processedGeometries.Contains(geometry))
             {
-                geometries[i]->DrawDebugGeometry(debug, depthTest);
-                processedGeometries.Insert(geometries[i]);
+                geometry->DrawDebugGeometry(debug, depthTest);
+                processedGeometries.Insert(geometry);
             }
         }
-        for (unsigned i = 0; i < lights.Size(); ++i)
+        
+        for (Light* light : lights)
         {
-            if (!processedLights.Contains(lights[i]))
+            if (!processedLights.Contains(light))
             {
-                lights[i]->DrawDebugGeometry(debug, depthTest);
-                processedLights.Insert(lights[i]);
+                light->DrawDebugGeometry(debug, depthTest);
+                processedLights.Insert(light);
             }
         }
     }
@@ -1725,22 +1728,24 @@ void Renderer::ReleaseMaterialShaders()
 
     cache->GetResources<Material>(materials);
 
-    for (unsigned i = 0; i < materials.Size(); ++i)
-        materials[i]->ReleaseShaders();
+    for (Material* material : materials)
+        material->ReleaseShaders();
 }
 
 void Renderer::ReloadTextures()
 {
-    auto* cache = GetSubsystem<ResourceCache>();
+    ResourceCache* cache = GetSubsystem<ResourceCache>();
     Vector<Resource*> textures;
 
     cache->GetResources(textures, Texture2D::GetTypeStatic());
-    for (unsigned i = 0; i < textures.Size(); ++i)
-        cache->ReloadResource(textures[i]);
+    
+    for (Resource* texture : textures)
+        cache->ReloadResource(texture);
 
     cache->GetResources(textures, TextureCube::GetTypeStatic());
-    for (unsigned i = 0; i < textures.Size(); ++i)
-        cache->ReloadResource(textures[i]);
+    
+    for (Resource* texture : textures)
+        cache->ReloadResource(texture);
 }
 
 void Renderer::CreateGeometries()

+ 26 - 22
Source/Urho3D/Graphics/View.cpp

@@ -940,9 +940,8 @@ void View::GetDrawables()
         minZ_ = 0.0f;
 
     // Sort the lights to brightest/closest first, and per-vertex lights first so that per-vertex base pass can be evaluated first
-    for (unsigned i = 0; i < lights_.Size(); ++i)
+    for (Light* light : lights_)
     {
-        Light* light = lights_[i];
         light->SetIntensitySortValue(cullCamera_->GetDistance(light->GetNode()->GetWorldPosition()));
         light->SetLightQueue(nullptr);
     }
@@ -1166,11 +1165,11 @@ void View::GetLightBatches()
             drawable->LimitLights();
             const Vector<Light*>& lights = drawable->GetLights();
 
-            for (unsigned i = 0; i < lights.Size(); ++i)
+            for (const Light* light : lights)
             {
-                Light* light = lights[i];
                 // Find the correct light queue again
                 LightBatchQueue* queue = light->GetLightQueue();
+
                 if (queue)
                     GetLitBatches(drawable, *queue, alphaQueue);
             }
@@ -1677,10 +1676,10 @@ void View::ExecuteRenderPathCommands()
                             passCommand_ = &command;
                         }
 
-                        for (unsigned j = 0; j < i->volumeBatches_.Size(); ++j)
+                        for (Batch& volumeBatch : i->volumeBatches_)
                         {
-                            SetupLightVolumeBatch(i->volumeBatches_[j]);
-                            i->volumeBatches_[j].Draw(this, camera_, false);
+                            SetupLightVolumeBatch(volumeBatch);
+                            volumeBatch.Draw(this, camera_, false);
                         }
 
                         passCommand_ = nullptr;
@@ -2255,11 +2254,12 @@ void View::DrawOccluders(OcclusionBuffer* buffer, const Vector<Drawable*>& occlu
     else
     {
         // In threaded mode submit all triangles first, then render (cannot test in this case)
-        for (unsigned i = 0; i < occluders.Size(); ++i)
+        for (Drawable* occluder : occluders)
         {
             // Check for running out of triangles
             ++activeOccluders_;
-            if (!occluders[i]->DrawOcclusion(buffer))
+            
+            if (!occluder->DrawOcclusion(buffer))
                 break;
         }
 
@@ -2294,10 +2294,10 @@ void View::ProcessLight(LightQueryResult& query, unsigned threadIndex)
     switch (type)
     {
     case LIGHT_DIRECTIONAL:
-        for (unsigned i = 0; i < geometries_.Size(); ++i)
+        for (Drawable* geometry : geometries_)
         {
-            if (GetLightMask(geometries_[i]) & lightMask)
-                query.litGeometries_.Push(geometries_[i]);
+            if (GetLightMask(geometry) & lightMask)
+                query.litGeometries_.Push(geometry);
         }
         break;
 
@@ -2306,10 +2306,11 @@ void View::ProcessLight(LightQueryResult& query, unsigned threadIndex)
             FrustumOctreeQuery octreeQuery(tempDrawables, light->GetFrustum(), DRAWABLE_GEOMETRY,
                 cullCamera_->GetViewMask());
             octree_->GetDrawables(octreeQuery);
-            for (unsigned i = 0; i < tempDrawables.Size(); ++i)
+            
+            for (Drawable* tempDrawable : tempDrawables)
             {
-                if (tempDrawables[i]->IsInView(frame_) && (GetLightMask(tempDrawables[i]) & lightMask))
-                    query.litGeometries_.Push(tempDrawables[i]);
+                if (tempDrawable->IsInView(frame_) && (GetLightMask(tempDrawable) & lightMask))
+                    query.litGeometries_.Push(tempDrawable);
             }
         }
         break;
@@ -2319,10 +2320,11 @@ void View::ProcessLight(LightQueryResult& query, unsigned threadIndex)
             SphereOctreeQuery octreeQuery(tempDrawables, Sphere(light->GetNode()->GetWorldPosition(), light->GetRange()),
                 DRAWABLE_GEOMETRY, cullCamera_->GetViewMask());
             octree_->GetDrawables(octreeQuery);
-            for (unsigned i = 0; i < tempDrawables.Size(); ++i)
+            
+            for (Drawable* tempDrawable : tempDrawables)
             {
-                if (tempDrawables[i]->IsInView(frame_) && (GetLightMask(tempDrawables[i]) & lightMask))
-                    query.litGeometries_.Push(tempDrawables[i]);
+                if (tempDrawable->IsInView(frame_) && (GetLightMask(tempDrawable) & lightMask))
+                    query.litGeometries_.Push(tempDrawable);
             }
         }
         break;
@@ -2966,8 +2968,9 @@ void View::PrepareInstancingBuffer()
 
     for (Vector<LightBatchQueue>::Iterator i = lightQueues_.Begin(); i != lightQueues_.End(); ++i)
     {
-        for (unsigned j = 0; j < i->shadowSplits_.Size(); ++j)
-            totalInstances += i->shadowSplits_[j].shadowBatches_.GetNumInstances();
+        for (const ShadowBatchQueue& shadowSplit : i->shadowSplits_)
+            totalInstances += shadowSplit.shadowBatches_.GetNumInstances();
+        
         totalInstances += i->litBaseBatches_.GetNumInstances();
         totalInstances += i->litBatches_.GetNumInstances();
     }
@@ -2987,8 +2990,9 @@ void View::PrepareInstancingBuffer()
 
     for (Vector<LightBatchQueue>::Iterator i = lightQueues_.Begin(); i != lightQueues_.End(); ++i)
     {
-        for (unsigned j = 0; j < i->shadowSplits_.Size(); ++j)
-            i->shadowSplits_[j].shadowBatches_.SetInstancingData(dest, stride, freeIndex);
+        for (ShadowBatchQueue& shadowSplit : i->shadowSplits_)
+            shadowSplit.shadowBatches_.SetInstancingData(dest, stride, freeIndex);
+
         i->litBaseBatches_.SetInstancingData(dest, stride, freeIndex);
         i->litBatches_.SetInstancingData(dest, stride, freeIndex);
     }

+ 40 - 29
Source/Urho3D/Resource/ResourceCache.cpp

@@ -91,9 +91,9 @@ bool ResourceCache::AddResourceDir(const String& pathName, unsigned priority)
     String fixedPath = SanitateResourceDirName(pathName);
 
     // Check that the same path does not already exist
-    for (unsigned i = 0; i < resourceDirs_.Size(); ++i)
+    for (const String& resourceDir : resourceDirs_)
     {
-        if (!resourceDirs_[i].Compare(fixedPath, false))
+        if (!resourceDir.Compare(fixedPath, false))
             return true;
     }
 
@@ -405,10 +405,10 @@ void ResourceCache::ReloadResourceWithDependencies(const String& fileName)
                     dependents.Push(dependent);
             }
 
-            for (unsigned k = 0; k < dependents.Size(); ++k)
+            for (const SharedPtr<Resource>& dependent : dependents)
             {
-                URHO3D_LOGDEBUG("Reloading resource " + dependents[k]->GetName() + " depending on " + fileName);
-                ReloadResource(dependents[k]);
+                URHO3D_LOGDEBUG("Reloading resource " + dependent->GetName() + " depending on " + fileName);
+                ReloadResource(dependent);
             }
         }
     }
@@ -425,15 +425,17 @@ void ResourceCache::SetAutoReloadResources(bool enable)
     {
         if (enable)
         {
-            for (unsigned i = 0; i < resourceDirs_.Size(); ++i)
+            for (const String& resourceDir : resourceDirs_)
             {
                 SharedPtr<FileWatcher> watcher(new FileWatcher(context_));
-                watcher->StartWatching(resourceDirs_[i], true);
+                watcher->StartWatching(resourceDir, true);
                 fileWatchers_.Push(watcher);
             }
         }
         else
+        {
             fileWatchers_.Clear();
+        }
 
         autoReloadResources_ = enable;
     }
@@ -442,9 +444,9 @@ void ResourceCache::SetAutoReloadResources(bool enable)
 void ResourceCache::AddResourceRouter(ResourceRouter* router, bool addAsFirst)
 {
     // Check for duplicate
-    for (unsigned i = 0; i < resourceRouters_.Size(); ++i)
+    for (const SharedPtr<ResourceRouter>& resourceRouter : resourceRouters_)
     {
-        if (resourceRouters_[i] == router)
+        if (resourceRouter == router)
             return;
     }
 
@@ -471,11 +473,14 @@ SharedPtr<File> ResourceCache::GetFile(const String& name, bool sendEventOnFailu
     MutexLock lock(resourceMutex_);
 
     String sanitatedName = SanitateResourceName(name);
+    
     if (!isRouting_)
     {
         isRouting_ = true;
-        for (unsigned i = 0; i < resourceRouters_.Size(); ++i)
-            resourceRouters_[i]->Route(sanitatedName, RESOURCE_GETFILE);
+        
+        for (const SharedPtr<ResourceRouter>& resourceRouter : resourceRouters_)
+            resourceRouter->Route(sanitatedName, RESOURCE_GETFILE);
+        
         isRouting_ = false;
     }
 
@@ -715,27 +720,31 @@ bool ResourceCache::Exists(const String& name) const
     MutexLock lock(resourceMutex_);
 
     String sanitatedName = SanitateResourceName(name);
+    
     if (!isRouting_)
     {
         isRouting_ = true;
-        for (unsigned i = 0; i < resourceRouters_.Size(); ++i)
-            resourceRouters_[i]->Route(sanitatedName, RESOURCE_CHECKEXISTS);
+        
+        for (const SharedPtr<ResourceRouter>& resourceRouter : resourceRouters_)
+            resourceRouter->Route(sanitatedName, RESOURCE_CHECKEXISTS);
+        
         isRouting_ = false;
     }
 
     if (sanitatedName.Empty())
         return false;
 
-    for (unsigned i = 0; i < packages_.Size(); ++i)
+    for (const SharedPtr<PackageFile>& package : packages_)
     {
-        if (packages_[i]->Exists(sanitatedName))
+        if (package->Exists(sanitatedName))
             return true;
     }
 
-    auto* fileSystem = GetSubsystem<FileSystem>();
-    for (unsigned i = 0; i < resourceDirs_.Size(); ++i)
+    FileSystem* fileSystem = GetSubsystem<FileSystem>();
+    
+    for (const String& resourceDir : resourceDirs_)
     {
-        if (fileSystem->FileExists(resourceDirs_[i] + sanitatedName))
+        if (fileSystem->FileExists(resourceDir + sanitatedName))
             return true;
     }
 
@@ -765,11 +774,12 @@ unsigned long long ResourceCache::GetTotalMemoryUse() const
 
 String ResourceCache::GetResourceFileName(const String& name) const
 {
-    auto* fileSystem = GetSubsystem<FileSystem>();
-    for (unsigned i = 0; i < resourceDirs_.Size(); ++i)
+    FileSystem* fileSystem = GetSubsystem<FileSystem>();
+    
+    for (const String& resourceDir : resourceDirs_)
     {
-        if (fileSystem->FileExists(resourceDirs_[i] + name))
-            return resourceDirs_[i] + name;
+        if (fileSystem->FileExists(resourceDir + name))
+            return resourceDir + name;
     }
 
     if (IsAbsolutePath(name) && fileSystem->FileExists(name))
@@ -1081,14 +1091,15 @@ void ResourceCache::HandleBeginFrame(StringHash eventType, VariantMap& eventData
 
 File* ResourceCache::SearchResourceDirs(const String& name)
 {
-    auto* fileSystem = GetSubsystem<FileSystem>();
-    for (unsigned i = 0; i < resourceDirs_.Size(); ++i)
+    FileSystem* fileSystem = GetSubsystem<FileSystem>();
+    
+    for (const String& resourceDir : resourceDirs_)
     {
-        if (fileSystem->FileExists(resourceDirs_[i] + name))
+        if (fileSystem->FileExists(resourceDir + name))
         {
             // Construct the file first with full path, then rename it to not contain the resource path,
             // so that the file's sanitatedName can be used in further GetFile() calls (for example over the network)
-            File* file(new File(context_, resourceDirs_[i] + name));
+            File* file(new File(context_, resourceDir + name));
             file->SetName(name);
             return file;
         }
@@ -1103,10 +1114,10 @@ File* ResourceCache::SearchResourceDirs(const String& name)
 
 File* ResourceCache::SearchPackages(const String& name)
 {
-    for (unsigned i = 0; i < packages_.Size(); ++i)
+    for (const SharedPtr<PackageFile>& package : packages_)
     {
-        if (packages_[i]->Exists(name))
-            return new File(context_, packages_[i], name);
+        if (package->Exists(name))
+            return new File(context_, package, name);
     }
 
     return nullptr;

+ 2 - 2
Source/Urho3D/Scene/Animatable.cpp

@@ -507,8 +507,8 @@ void Animatable::UpdateAttributeAnimations(float timeStep)
             finishedNames.Push(i->second_->GetAttributeInfo().name_);
     }
 
-    for (unsigned i = 0; i < finishedNames.Size(); ++i)
-        SetAttributeAnimation(finishedNames[i], nullptr);
+    for (const String& finishedName : finishedNames)
+        SetAttributeAnimation(finishedName, nullptr);
 }
 
 bool Animatable::IsAnimatedNetworkAttribute(const AttributeInfo& attrInfo) const

+ 6 - 6
Source/Urho3D/Scene/Node.cpp

@@ -253,11 +253,11 @@ bool Node::SaveJSON(JSONValue& dest) const
 
 void Node::ApplyAttributes()
 {
-    for (unsigned i = 0; i < components_.Size(); ++i)
-        components_[i]->ApplyAttributes();
+    for (const SharedPtr<Component>& component : components_)
+        component->ApplyAttributes();
 
-    for (unsigned i = 0; i < children_.Size(); ++i)
-        children_[i]->ApplyAttributes();
+    for (const SharedPtr<Node>& child : children_)
+        child->ApplyAttributes();
 }
 
 void Node::MarkNetworkUpdate()
@@ -363,8 +363,8 @@ void Node::AddTags(const String& tags, char separator)
 void Node::AddTags(const StringVector& tags)
 {
     // This is OK, as MarkNetworkUpdate() early-outs when called multiple times
-    for (unsigned i = 0; i < tags.Size(); ++i)
-        AddTag(tags[i]);
+    for (const String& tag : tags)
+        AddTag(tag);
 }
 
 bool Node::RemoveTag(const String& tag)

+ 5 - 5
Source/Urho3D/Urho2D/Renderer2D.cpp

@@ -411,16 +411,16 @@ void Renderer2D::UpdateViewBatchInfo(ViewBatchInfo2D& viewBatchInfo, Camera* cam
             continue;
 
         const Vector<SourceBatch2D>& batches = drawables_[d]->GetSourceBatches();
-        for (unsigned b = 0; b < batches.Size(); ++b)
+        
+        for (const SourceBatch2D& batch : batches)
         {
-            if (batches[b].material_ && !batches[b].vertices_.Empty())
-                sourceBatches.Push(&batches[b]);
+            if (batch.material_ && !batch.vertices_.Empty())
+                sourceBatches.Push(&batch);
         }
     }
 
-    for (unsigned i = 0; i < sourceBatches.Size(); ++i)
+    for (const SourceBatch2D* sourceBatch : sourceBatches)
     {
-        const SourceBatch2D* sourceBatch = sourceBatches[i];
         Vector3 worldPos = sourceBatch->owner_->GetNode()->GetWorldPosition();
         sourceBatch->distance_ = camera->GetDistance(worldPos);
     }