Răsfoiți Sursa

Rinse and repeat using Clang-Tidy 4.0 and Clion.

Yao Wei Tjong 姚伟忠 8 ani în urmă
părinte
comite
c277e7fd01

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

@@ -131,7 +131,7 @@ void Run(const Vector<String>& arguments)
             {
                 float x = ((float)i) / ((float)(width - 1));
 
-                data[i] = (unsigned char)((1.0f - pow(x, power)) * 255.0f);
+                data[i] = (unsigned char)((1.0f - Pow(x, power)) * 255.0f);
             }
 
             // Ensure start is full bright & end is completely black
@@ -158,7 +158,7 @@ void Run(const Vector<String>& arguments)
                     if (dist > 1.0f)
                         dist = 1.0f;
 
-                    data[i] = (unsigned char)((1.0f - pow(dist, power)) * 255.0f);
+                    data[i] = (unsigned char)((1.0f - Pow(dist, power)) * 255.0f);
                 }
             }
 

+ 2 - 2
Source/Urho3D/AngelScript/APITemplates.h

@@ -407,7 +407,7 @@ template <class T> void RegisterNamedObjectConstructor(asIScriptEngine* engine,
     engine->RegisterObjectBehaviour(className, asBEHAVE_FACTORY, declFactoryWithName.CString(), asFUNCTION(ConstructNamedObject<T>), asCALL_CDECL);
 }
 
-static const AttributeInfo noAttributeInfo;
+static const AttributeInfo noAttributeInfo{};
 
 // To keep Xcode LLVM/Clang happy - it erroneously warns on unused functions defined below which are actually being referenced in the code
 #if __clang__
@@ -653,7 +653,7 @@ static CScriptArray* NodeGetChildrenWithClassName(const String& className, bool
         const Vector<SharedPtr<Component> >& components = node->GetComponents();
         for (Vector<SharedPtr<Component> >::ConstIterator j = components.Begin(); j != components.End(); ++j)
         {
-            if (ScriptInstance* instance = (*j)->Cast<ScriptInstance>())
+            if (auto* instance = (*j)->Cast<ScriptInstance>())
             {
                 if (instance->IsA(className))
                     result.Push(node);

+ 1 - 1
Source/Urho3D/AngelScript/Script.cpp

@@ -259,7 +259,7 @@ void Script::ExceptionCallback(asIScriptContext* context)
     message.AppendWithFormat("- Exception '%s' in '%s'\n%s", context->GetExceptionString(),
         context->GetExceptionFunction()->GetDeclaration(), GetCallStack(context).CString());
 
-    asSMessageInfo msg;
+    asSMessageInfo msg{};
     msg.row = context->GetExceptionLineNumber(&msg.col, &msg.section);
     msg.type = asMSGTYPE_ERROR;
     msg.message = message.CString();

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

@@ -123,7 +123,7 @@ void ScriptInstance::OnSetAttribute(const AttributeInfo& attr, const Variant& sr
     }
     else if (attr.type_ == VAR_VARIANTVECTOR && attr.ptr_)
     {
-        CScriptArray* arr = reinterpret_cast<CScriptArray*>(attr.ptr_);
+        auto* arr = reinterpret_cast<CScriptArray*>(attr.ptr_);
         if (arr)
         {
             const Vector<Variant>& vector = src.GetVariantVector();
@@ -135,7 +135,7 @@ void ScriptInstance::OnSetAttribute(const AttributeInfo& attr, const Variant& sr
     }
     else if (attr.type_ == VAR_STRINGVECTOR && attr.ptr_)
     {
-        CScriptArray* arr = reinterpret_cast<CScriptArray*>(attr.ptr_);
+        auto* arr = reinterpret_cast<CScriptArray*>(attr.ptr_);
         if (arr)
         {
             const Vector<String>& vector = src.GetStringVector();
@@ -182,13 +182,13 @@ void ScriptInstance::OnGetAttribute(const AttributeInfo& attr, Variant& dest) co
     }
     else if (attr.type_ == VAR_VARIANTVECTOR && attr.ptr_)
     {
-        CScriptArray* arr = reinterpret_cast<CScriptArray*>(attr.ptr_);
+        auto* arr = reinterpret_cast<CScriptArray*>(attr.ptr_);
         if (arr)
             dest = ArrayToVector<Variant>(arr);
     }
     else if (attr.type_ == VAR_STRINGVECTOR && attr.ptr_)
     {
-        CScriptArray* arr = reinterpret_cast<CScriptArray*>(attr.ptr_);
+        auto* arr = reinterpret_cast<CScriptArray*>(attr.ptr_);
         if (arr)
             dest = ArrayToVector<String>(arr);
     } else

+ 1 - 1
Source/Urho3D/Audio/Sound.cpp

@@ -133,7 +133,7 @@ bool Sound::LoadOggVorbis(Deserializer& source)
 
 bool Sound::LoadWav(Deserializer& source)
 {
-    WavHeader header;
+    WavHeader header{};
 
     // Try to open
     memset(&header, 0, sizeof header);

+ 3 - 2
Source/Urho3D/Container/Ptr.h

@@ -544,10 +544,11 @@ public:
     UniquePtr(std::nullptr_t) { }   // NOLINT(google-explicit-constructor)
 
     /// Move-construct from UniquePtr.
-    UniquePtr(UniquePtr && up) : ptr_(up.Detach()) { }
+    UniquePtr(UniquePtr&& up) noexcept :
+        ptr_(up.Detach()) {}
 
     /// Move-assign from UniquePtr.
-    UniquePtr& operator = (UniquePtr && up)
+    UniquePtr& operator =(UniquePtr&& up) noexcept
     {
         Reset(up.Detach());
         return *this;

+ 2 - 2
Source/Urho3D/Core/Attribute.h

@@ -65,10 +65,10 @@ public:
 struct AttributeInfo
 {
     /// Construct empty.
-    AttributeInfo() { }
+    AttributeInfo() = default;
 
     /// Construct attribute.
-    AttributeInfo(VariantType type, const char* name, SharedPtr<AttributeAccessor> accessor, const char** enumNames, const Variant& defaultValue, unsigned mode) :
+    AttributeInfo(VariantType type, const char* name, const SharedPtr<AttributeAccessor>& accessor, const char** enumNames, const Variant& defaultValue, unsigned mode) :
         type_(type),
         name_(name),
         enumNames_(enumNames),

+ 0 - 2
Source/Urho3D/Core/Spline.cpp

@@ -53,8 +53,6 @@ Spline::Spline(const Vector<Variant>& knots, InterpolationMode mode) :
 {
 }
 
-Spline::Spline(const Spline& rhs) = default;
-
 Variant Spline::GetPoint(float f) const
 {
     if (knots_.Size() < 2)

+ 2 - 6
Source/Urho3D/Core/Spline.h

@@ -54,14 +54,10 @@ public:
     /// Constructor setting knots and interpolation mode.
     explicit Spline(const Vector<Variant>& knots, InterpolationMode mode = BEZIER_CURVE);
     /// Copy constructor.
-    Spline(const Spline& rhs);
+    Spline(const Spline& rhs) = default;
 
     /// Copy operator.
-    void operator =(const Spline& rhs)
-    {
-        knots_ = rhs.knots_;
-        interpolationMode_ = rhs.interpolationMode_;
-    }
+    Spline& operator =(const Spline& rhs) = default;
 
     /// Equality operator.
     bool operator ==(const Spline& rhs) const

+ 5 - 1
Source/Urho3D/Graphics/OpenGL/OGLTexture2D.cpp

@@ -444,10 +444,14 @@ bool Texture2D::Create()
         glGetError();
 #ifndef GL_ES_VERSION_2_0
         if (multiSample_ > 1 && !autoResolve_)
+        {
             glTexImage2DMultisample(target_, multiSample_, format, width_, height_, GL_TRUE);
+        }
         else
 #endif
-        glTexImage2D(target_, 0, format, width_, height_, 0, externalFormat, dataType, nullptr);
+        {
+            glTexImage2D(target_, 0, format, width_, height_, 0, externalFormat, dataType, nullptr);
+        }
         if (glGetError())
         {
             URHO3D_LOGERROR("Failed to create texture");

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

@@ -421,7 +421,7 @@ bool View::Define(RenderSurface* renderTarget, Viewport* viewport)
         {
             hasScenePasses_ = true;
 
-            ScenePassInfo info;
+            ScenePassInfo info{};
             info.passIndex_ = command.passIndex_ = Technique::GetPassIndex(command.pass_);
             info.allowInstancing_ = command.sortMode_ != SORT_BACKTOFRONT;
             info.markToStencil_ = !noStencil_ && command.markToStencil_;

+ 1 - 1
Source/Urho3D/LuaScript/ToluaUtils.h

@@ -35,7 +35,7 @@ using namespace Urho3D;
 /// Check is String.
 #define tolua_isurho3dstring tolua_isstring
 /// Push String.
-#define tolua_pushurho3dstring(L, s) tolua_pushstring(L, s.CString())
+#define tolua_pushurho3dstring(L, s) tolua_pushstring(L, s.CString())       // NOLINT(misc-macro-parentheses)
 /// Convert to String.
 const char* tolua_tourho3dstring(lua_State* L, int narg, const char* str);
 /// Convert to String.

+ 1 - 1
Source/Urho3D/Math/Quaternion.cpp

@@ -223,7 +223,7 @@ float Quaternion::RollAngle() const
 
 Urho3D::Vector3 Quaternion::Axis() const
 {
-    return Vector3(x_, y_, z_) / sqrt(1 - w_ * w_);
+    return Vector3(x_, y_, z_) / sqrt(1. - w_ * w_);
 }
 
 float Quaternion::Angle() const

+ 8 - 8
Source/Urho3D/Math/Rect.h

@@ -363,37 +363,37 @@ public:
     /// Divide by scalar.
     IntRect operator /(float value) const
     {
-        return IntRect(
+        return {
             static_cast<int>(left_ / value), static_cast<int>(top_ / value),
             static_cast<int>(right_ / value), static_cast<int>(bottom_ / value)
-        );
+        };
     }
 
     /// Multiply by scalar.
     IntRect operator *(float value) const
     {
-        return IntRect(
+        return {
             static_cast<int>(left_ * value), static_cast<int>(top_ * value),
             static_cast<int>(right_ * value), static_cast<int>(bottom_ * value)
-        );
+        };
     }
 
     /// Add another rect.
     IntRect operator +(const IntRect& rhs) const
     {
-        return IntRect(
+        return {
             left_ + rhs.left_, top_ + rhs.top_,
             right_ + rhs.right_, bottom_ + rhs.bottom_
-        );
+        };
     }
 
     /// Subtract another rect.
     IntRect operator -(const IntRect& rhs) const
     {
-        return IntRect(
+        return {
             left_ - rhs.left_, top_ - rhs.top_,
             right_ - rhs.right_, bottom_ - rhs.bottom_
-        );
+        };
     }
 
     /// Return size.

+ 1 - 1
Source/Urho3D/Network/Connection.cpp

@@ -60,7 +60,7 @@ PackageUpload::PackageUpload() :
 {
 }
 
-Connection::Connection(Context* context, bool isClient, kNet::SharedPtr<kNet::MessageConnection> connection) :
+Connection::Connection(Context* context, bool isClient, const kNet::SharedPtr<kNet::MessageConnection>& connection) :
     Object(context),
     timeStamp_(0),
     connection_(connection),

+ 1 - 1
Source/Urho3D/Network/Connection.h

@@ -108,7 +108,7 @@ class URHO3D_API Connection : public Object
 
 public:
     /// Construct with context and kNet message connection pointers.
-    Connection(Context* context, bool isClient, kNet::SharedPtr<kNet::MessageConnection> connection);
+    Connection(Context* context, bool isClient, const kNet::SharedPtr<kNet::MessageConnection>& connection);
     /// Destruct.
     ~Connection() override;
 

+ 3 - 6
Source/Urho3D/Physics/RaycastVehicle.cpp

@@ -45,10 +45,8 @@ struct RaycastVehicleData
 
     ~RaycastVehicleData()
     {
-        if (vehicleRayCaster_)
-        {
-            delete vehicleRayCaster_;
-        }
+        delete vehicleRayCaster_;
+
         vehicleRayCaster_ = nullptr;
         if (vehicle_)
         {
@@ -80,8 +78,7 @@ struct RaycastVehicleData
             return;
 
         // Delete old vehicle & action first
-        if (vehicleRayCaster_)
-            delete vehicleRayCaster_;
+        delete vehicleRayCaster_;
         if (vehicle_)
         {
             if (added_)

+ 2 - 2
Source/Urho3D/Resource/Decompress.cpp

@@ -948,7 +948,7 @@ void DecompressImagePVRTC(unsigned char* rgba, const void* blocks, int width, in
     }
 }
 
-void FlipBlockVertical(unsigned char* dest, unsigned char* src, CompressedFormat format)
+void FlipBlockVertical(unsigned char* dest, const unsigned char* src, CompressedFormat format)
 {
     switch (format)
     {
@@ -1018,7 +1018,7 @@ static unsigned FlipDXT5AlphaHorizontal(unsigned src)
            ((src & 0x7000) << 9) | ((src & 0x38000) << 3) | ((src & 0x1c0000) >> 3) | ((src & 0xe00000) >> 9);
 }
 
-void FlipBlockHorizontal(unsigned char* dest, unsigned char* src, CompressedFormat format)
+void FlipBlockHorizontal(unsigned char* dest, const unsigned char* src, CompressedFormat format)
 {
     switch (format)
     {

+ 2 - 2
Source/Urho3D/Resource/Decompress.h

@@ -35,8 +35,8 @@ URHO3D_API void DecompressImageETC(unsigned char* rgba, const void* blocks, int
 /// Decompress a PVRTC compressed image to RGBA.
 URHO3D_API void DecompressImagePVRTC(unsigned char* rgba, const void* blocks, int width, int height, CompressedFormat format);
 /// Flip a compressed block vertically.
-URHO3D_API void FlipBlockVertical(unsigned char* dest, unsigned char* src, CompressedFormat format);
+URHO3D_API void FlipBlockVertical(unsigned char* dest, const unsigned char* src, CompressedFormat format);
 /// Flip a compressed block horizontally.
-URHO3D_API void FlipBlockHorizontal(unsigned char* dest, unsigned char* src, CompressedFormat format);
+URHO3D_API void FlipBlockHorizontal(unsigned char* dest, const unsigned char* src, CompressedFormat format);
 
 }

+ 6 - 6
Source/Urho3D/UI/UIComponent.cpp

@@ -74,16 +74,16 @@ public:
             return result;
 
         Scene* scene = node_->GetScene();
-        StaticModel* model = node_->GetComponent<StaticModel>();
+        auto* model = node_->GetComponent<StaticModel>();
         if (scene == nullptr || model == nullptr)
             return result;
 
-        Renderer* renderer = GetSubsystem<Renderer>();
+        auto* renderer = GetSubsystem<Renderer>();
         if (renderer == nullptr)
             return result;
 
         // \todo Always uses the first viewport, in case there are multiple
-        Octree* octree = scene->GetComponent<Octree>();
+        auto* octree = scene->GetComponent<Octree>();
         if (viewport_ == nullptr)
             viewport_ = renderer->GetViewportForScene(scene, 0);
 
@@ -104,7 +104,7 @@ public:
         IntRect rect = viewport_->GetRect();
         if (rect == IntRect::ZERO)
         {
-            Graphics* graphics = GetSubsystem<Graphics>();
+            auto* graphics = GetSubsystem<Graphics>();
             rect.right_ = graphics->GetWidth();
             rect.bottom_ = graphics->GetHeight();
         }
@@ -197,8 +197,8 @@ void UIComponent::OnNodeSet(Node* node)
     rootElement_->SetNode(node);
     if (node)
     {
-        Renderer* renderer = GetSubsystem<Renderer>();
-        StaticModel* model = node->GetComponent<StaticModel>();
+        auto* renderer = GetSubsystem<Renderer>();
+        auto* model = node->GetComponent<StaticModel>();
         rootElement_->SetViewport(renderer->GetViewportForScene(GetScene(), viewportIndex_));
         if (model == nullptr)
             model_ = model = node->CreateComponent<StaticModel>();

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

@@ -2282,7 +2282,7 @@ void UIElement::HandlePostUpdate(StringHash eventType, VariantMap& eventData)
 
 void UIElement::SetRenderTexture(Texture2D* texture)
 {
-    if (UI* ui = GetSubsystem<UI>())
+    if (auto* ui = GetSubsystem<UI>())
         ui->SetElementRenderTexture(this, texture);
 }
 

+ 1 - 1
Source/Urho3D/Urho2D/SpriterInstance2D.cpp

@@ -139,7 +139,7 @@ void SpriterInstance::Update(float deltaTime)
 
         if (looping_)
         {
-            currentTime_ = fmod(currentTime_, animation_->length_);
+            currentTime_ = Mod(currentTime_, animation_->length_);
             sendFinishEvent = true;
         }
         else