From 949206424e77b38abc39531c81618237a46f3e9b Mon Sep 17 00:00:00 2001 From: Andrew James Date: Tue, 12 Oct 2021 11:32:57 +1100 Subject: [PATCH] Enable clang-tidy in Visual Studio projects (#3101) --- CMakeLists.txt | 2 +- CMakeSettings.json | 18 ++++++++++++------ Source/engine/animationinfo.cpp | 16 ++++++++-------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eb6b66ff0..19e9317a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1064,7 +1064,7 @@ if(VITA) ${VITA_TRANSLATIONS_LIST} ) endif() - + endif() if(NINTENDO_3DS) diff --git a/CMakeSettings.json b/CMakeSettings.json index 20a391028..cf8f7db24 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -7,7 +7,8 @@ "buildRoot": "${workspaceRoot}\\build\\${name}", "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", "inheritEnvironments": [ "msvc_x64" ], - "intelliSenseMode": "windows-msvc-x64" + "intelliSenseMode": "windows-msvc-x64", + "enableClangTidyCodeAnalysis": true }, { "name": "x64-Debug-UnitTests", @@ -17,7 +18,8 @@ "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", "inheritEnvironments": [ "msvc_x64" ], "intelliSenseMode": "windows-msvc-x64", - "cmakeCommandArgs": "-DRUN_TESTS=ON" + "cmakeCommandArgs": "-DRUN_TESTS=ON", + "enableClangTidyCodeAnalysis": true }, { "name": "x64-Release", @@ -27,7 +29,8 @@ "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", "cmakeCommandArgs": "-DBINARY_RELEASE=ON", "inheritEnvironments": [ "msvc_x64" ], - "intelliSenseMode": "windows-msvc-x64" + "intelliSenseMode": "windows-msvc-x64", + "enableClangTidyCodeAnalysis": true }, { "name": "x86-Debug", @@ -36,7 +39,8 @@ "buildRoot": "${workspaceRoot}\\build\\${name}", "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", "inheritEnvironments": [ "msvc_x86" ], - "intelliSenseMode": "windows-msvc-x86" + "intelliSenseMode": "windows-msvc-x86", + "enableClangTidyCodeAnalysis": true }, { "name": "x86-Debug-UnitTests", @@ -46,7 +50,8 @@ "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", "inheritEnvironments": [ "msvc_x86" ], "intelliSenseMode": "windows-msvc-x86", - "cmakeCommandArgs": "-DRUN_TESTS=ON" + "cmakeCommandArgs": "-DRUN_TESTS=ON", + "enableClangTidyCodeAnalysis": true }, { "name": "x86-Release", @@ -56,7 +61,8 @@ "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", "cmakeCommandArgs": "-DBINARY_RELEASE=ON", "inheritEnvironments": [ "msvc_x86" ], - "intelliSenseMode": "windows-msvc-x86" + "intelliSenseMode": "windows-msvc-x86", + "enableClangTidyCodeAnalysis": true } ] } diff --git a/Source/engine/animationinfo.cpp b/Source/engine/animationinfo.cpp index 9cfc3e59c..e14224ab6 100644 --- a/Source/engine/animationinfo.cpp +++ b/Source/engine/animationinfo.cpp @@ -24,7 +24,7 @@ int AnimationInfo::GetFrameToUseForRendering() const if (CurrentFrame > RelevantFramesForDistributing) return CurrentFrame; - auto ticksSinceSequenceStarted = (float)TicksSinceSequenceStarted; + float ticksSinceSequenceStarted = static_cast(TicksSinceSequenceStarted); if (TicksSinceSequenceStarted < 0) { ticksSinceSequenceStarted = 0.0F; Log("GetFrameToUseForRendering: Invalid TicksSinceSequenceStarted {}", TicksSinceSequenceStarted); @@ -34,7 +34,7 @@ int AnimationInfo::GetFrameToUseForRendering() const float totalTicksForCurrentAnimationSequence = GetProgressToNextGameTick() + ticksSinceSequenceStarted; // 1 added for rounding reasons. float to int cast always truncate. - int absoluteAnimationFrame = 1 + (int)(totalTicksForCurrentAnimationSequence * TickModifier); + int absoluteAnimationFrame = 1 + static_cast(totalTicksForCurrentAnimationSequence * TickModifier); if (SkippedFramesFromPreviousAnimation > 0) { // absoluteAnimationFrames contains also the Frames from the previous Animation, so if we want to get the current Frame we have to remove them absoluteAnimationFrame -= SkippedFramesFromPreviousAnimation; @@ -66,12 +66,12 @@ float AnimationInfo::GetAnimationProgress() const // This logic is used if animation distribution is not active (see GetFrameToUseForRendering). // In this case the variables calculated with animation distribution are not initialized and we have to calculate them on the fly with the given information. ticksSinceSequenceStarted = ((CurrentFrame - 1) * TicksPerFrame) + TickCounterOfCurrentFrame; - tickModifier = 1.f / TicksPerFrame; + tickModifier = 1.0F / static_cast(TicksPerFrame); } - float totalTicksForCurrentAnimationSequence = GetProgressToNextGameTick() + ticksSinceSequenceStarted; + float totalTicksForCurrentAnimationSequence = GetProgressToNextGameTick() + static_cast(ticksSinceSequenceStarted); float progressInAnimationFrames = totalTicksForCurrentAnimationSequence * tickModifier; - float animationFraction = progressInAnimationFrames / NumberOfFrames; + float animationFraction = progressInAnimationFrames / static_cast(NumberOfFrames); return animationFraction; } @@ -153,10 +153,10 @@ void AnimationInfo::SetNewAnimation(const CelSprite *celSprite, int numberOfFram relevantAnimationTicksForDistribution += (SkippedFramesFromPreviousAnimation * ticksPerFrame); // if we skipped Frames we need to expand the game ticks to make one game tick for this Animation "faster" - float tickModifier = (float)relevantAnimationTicksForDistribution / (float)relevantAnimationTicksWithSkipping; + float tickModifier = static_cast(relevantAnimationTicksForDistribution) / static_cast(relevantAnimationTicksWithSkipping); // tickModifier specifies the Animation fraction per game tick, so we have to remove the delay from the variable - tickModifier /= ticksPerFrame; + tickModifier /= static_cast(ticksPerFrame); RelevantFramesForDistributing = relevantAnimationFramesForDistributing; TickModifier = tickModifier; @@ -208,7 +208,7 @@ void AnimationInfo::ProcessAnimation(bool reverseAnimation /*= false*/, bool don float AnimationInfo::GetProgressToNextGameTick() const { if (IsPetrified) - return 0.0; + return 0.0F; return gfProgressToNextGameTick; }