From faefebf18ff3e34eb7fa7765b3b55317e6a6983e Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 13 May 2024 14:53:09 +0200 Subject: [PATCH 01/13] clang tidy: - add naming conventions checks --- .clang-tidy | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 127 insertions(+), 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index dc6c70d9..fd4de4a0 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -6,6 +6,133 @@ HeaderFilterRegex: "oopetris/src/.*" AnalyzeTemporaryDtors: false FormatStyle: "file" CheckOptions: + ## NAMING CONVENTION SECTION + - key: readability-identifier-naming.AbstractClassCase + value: "CamelCase" + - key: readability-identifier-naming.AggressiveDependentMemberLookup + value: true + - key: readability-identifier-naming.CheckAnonFieldInParent + value: false + - key: readability-identifier-naming.ClassCase + value: "CamelCase" + - key: readability-identifier-naming.ClassConstantCase + value: "lower_case" + - key: readability-identifier-naming.ClassConstantPrefix + value: "c_" + - key: readability-identifier-naming.ClassMemberCase + value: "lower_case" + - key: readability-identifier-naming.ClassMemberPrefix + value: "m_" + - key: readability-identifier-naming.ClassMethodCase + value: "lower_case" + - key: readability-identifier-naming.ConceptCase + value: "CamelCase" + - key: readability-identifier-naming.ConstantCase + value: "lower_case" + - key: readability-identifier-naming.ConstantMemberCase + value: "lower_case" + - key: readability-identifier-naming.ConstantParameterCase + value: "lower_case" + - key: readability-identifier-naming.ConstantPointerParameterCase + value: "lower_case" + - key: readability-identifier-naming.ConstexprFunctionCase + value: "lower_case" + - key: readability-identifier-naming.ConstexprMethodCase + value: "lower_case" + - key: readability-identifier-naming.ConstexprVariableCase + value: "lower_case" + - key: readability-identifier-naming.EnumCase + value: "CamelCase" + - key: readability-identifier-naming.EnumConstantCase + value: "CamelCase" + - key: readability-identifier-naming.FunctionCase + value: "lower_case" + - key: readability-identifier-naming.GlobalConstantCase + value: "lower_case" + - key: readability-identifier-naming.GlobalConstantPointerCase + value: "lower_case" + - key: readability-identifier-naming.GlobalFunctionCase + value: "lower_case" + - key: readability-identifier-naming.GlobalPointerCase + value: "lower_case" + - key: readability-identifier-naming.GlobalVariableCase + value: "lower_case" + - key: readability-identifier-naming.GlobalVariablePrefix + value: "g_" + - key: readability-identifier-naming.LocalConstantCase + value: "lower_case" + - key: readability-identifier-naming.LocalConstantPointerCase + value: "lower_case" + - key: readability-identifier-naming.LocalPointerCase + value: "lower_case" + - key: readability-identifier-naming.LocalVariableCase + value: "lower_case" + - key: readability-identifier-naming.MacroDefinitionCase + value: "UPPER_CASE" + - key: readability-identifier-naming.MemberCase + value: "lower_case" + - key: readability-identifier-naming.MemberPrefix + value: "m_" + - key: readability-identifier-naming.MethodCase + value: "lower_case" + - key: readability-identifier-naming.NamespaceCase + value: "lower_case" + - key: readability-identifier-naming.ParameterCase + value: "lower_case" + - key: readability-identifier-naming.ParameterPackCase + value: "lower_case" + - key: readability-identifier-naming.PointerParameterCase + value: "lower_case" + - key: readability-identifier-naming.PrivateMemberCase + value: "lower_case" + - key: readability-identifier-naming.PrivateMemberPrefix + value: "m_" + - key: readability-identifier-naming.PrivateMethodCase + value: "lower_case" + - key: readability-identifier-naming.ProtectedMemberCase + value: "lower_case" + - key: readability-identifier-naming.ProtectedMemberPrefix + value: "m_" + - key: readability-identifier-naming.ProtectedMethodCase + value: "lower_case" + - key: readability-identifier-naming.PublicMemberCase + value: "lower_case" + - key: readability-identifier-naming.PublicMemberPrefix + value: "" # NO PREFIX + - key: readability-identifier-naming.PublicMethodCase + value: "lower_case" + - key: readability-identifier-naming.ScopedEnumConstantCase + value: "CamelCase" + - key: readability-identifier-naming.StaticConstantCase + value: "lower_case" + - key: readability-identifier-naming.StaticConstantPrefix + value: "s_" + - key: readability-identifier-naming.StaticVariableCase + value: "lower_case" + - key: readability-identifier-naming.StaticVariablePrefix + value: "s_" + - key: readability-identifier-naming.StructCase + value: "CamelCase" + - key: readability-identifier-naming.TemplateParameterCase + value: "CamelCase" + - key: readability-identifier-naming.TemplateTemplateParameterCase + value: "CamelCase" + - key: readability-identifier-naming.TypeAliasCase + value: "CamelCase" + - key: readability-identifier-naming.TypedefCase + value: "CamelCase" + - key: readability-identifier-naming.TypeTemplateParameterCase + value: "CamelCase" + - key: readability-identifier-naming.UnionCase + value: "CamelCase" + - key: readability-identifier-naming.ValueTemplateParameterCase + value: "lower_case" + - key: readability-identifier-naming.VariableCase + value: "lower_case" + - key: readability-identifier-naming.VirtualMethodCase + value: "lower_case" + + - key: bugprone-argument-comment.CommentBoolLiterals value: "0" - key: bugprone-argument-comment.CommentCharacterLiterals @@ -154,8 +281,6 @@ CheckOptions: value: "800" - key: readability-function-size.VariableThreshold value: "4294967295" - - key: readability-identifier-naming.IgnoreFailedSplit - value: "0" - key: readability-implicit-bool-conversion.AllowIntegerConditions value: "0" - key: readability-implicit-bool-conversion.AllowPointerConditions From 81af69bf479e05f0a69e34f54ab9e75173efa91d Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 13 May 2024 15:33:31 +0200 Subject: [PATCH 02/13] run clang-format --- src/input/input.cpp | 6 +++--- src/input/touch_input.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/input/input.cpp b/src/input/input.cpp index d424930b..4bcb20d7 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -33,9 +33,9 @@ input::PointerEventHelper::PointerEventHelper(shapes::IPoint pos, PointerEvent e using Type = decltype(m_pos)::Type; assert(rect.top_left.x <= static_cast(std::numeric_limits::max())); - assert(rect.top_left.y <= static_cast(std::numeric_limits::max())); - assert(rect.bottom_right.x <= static_cast(std::numeric_limits::max())); - assert(rect.bottom_right.y <= static_cast(std::numeric_limits::max())); + assert(rect.top_left.y <= static_cast(std::numeric_limits::max())); + assert(rect.bottom_right.x <= static_cast(std::numeric_limits::max())); + assert(rect.bottom_right.y <= static_cast(std::numeric_limits::max())); return is_in(rect.cast()); } diff --git a/src/input/touch_input.cpp b/src/input/touch_input.cpp index 35050466..279be197 100644 --- a/src/input/touch_input.cpp +++ b/src/input/touch_input.cpp @@ -258,7 +258,7 @@ input::TouchInput::get_by_device_index(const std::shared_ptr& window, in throw std::runtime_error("Tried to offset event, that is no pointer event: in Touch Input"); } - using FloatType = decltype(event.tfinger.x); + using FloatType = decltype(event.tfinger.x); const FloatType x_percent = event.tfinger.x; const FloatType y_percent = event.tfinger.y; From 7f0bae09c31c1ffdb71896de2dd647d13a0a3deb Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 13 May 2024 15:34:31 +0200 Subject: [PATCH 03/13] clang tidy: - remove deprecated setting "AnalyzeTemporaryDtors" (deprecated in clang-tidy 16 and removed in clang-tidy 18) --- .clang-tidy | 1 - 1 file changed, 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index fd4de4a0..3f67ebc7 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -3,7 +3,6 @@ Checks: "clang-diagnostic-*,clang-analyzer-*,bugprone-*,misc-*,performance-*,readability-*,portability-*,modernize-*,cppcoreguidelines-*,-modernize-use-trailing-return-type,-readability-named-parameter,-readability-identifier-length,-misc-include-cleaner,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-misc-non-private-member-variables-in-classes,-cppcoreguidelines-non-private-member-variables-in-classes" WarningsAsErrors: "" HeaderFilterRegex: "oopetris/src/.*" -AnalyzeTemporaryDtors: false FormatStyle: "file" CheckOptions: ## NAMING CONVENTION SECTION From 8a4ad7f047bac9f4dc7670713626917d5482c10a Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 13 May 2024 15:43:44 +0200 Subject: [PATCH 04/13] clang tidy: refactor settings - remove defaults - add some more global checks - add back some checks, that where ignored before --- .clang-tidy | 460 ++++++++++++++++++---------------------------------- 1 file changed, 155 insertions(+), 305 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 3f67ebc7..22c1bb1e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,312 +1,162 @@ # taken from https://github.com/cpp-linter/cpp-linter-action/blob/main/demo/.clang-tidy --- -Checks: "clang-diagnostic-*,clang-analyzer-*,bugprone-*,misc-*,performance-*,readability-*,portability-*,modernize-*,cppcoreguidelines-*,-modernize-use-trailing-return-type,-readability-named-parameter,-readability-identifier-length,-misc-include-cleaner,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-misc-non-private-member-variables-in-classes,-cppcoreguidelines-non-private-member-variables-in-classes" +Checks: "clang-diagnostic-*,clang-analyzer-*,bugprone-*,misc-*,performance-*,readability-*,portability-*,modernize-*,cppcoreguidelines-*,google-*,llvm-*,cert-*,-modernize-use-trailing-return-type,-bugprone-argument-comment,-misc-include-cleaner,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers" WarningsAsErrors: "" HeaderFilterRegex: "oopetris/src/.*" FormatStyle: "file" CheckOptions: - ## NAMING CONVENTION SECTION - - key: readability-identifier-naming.AbstractClassCase - value: "CamelCase" - - key: readability-identifier-naming.AggressiveDependentMemberLookup - value: true - - key: readability-identifier-naming.CheckAnonFieldInParent - value: false - - key: readability-identifier-naming.ClassCase - value: "CamelCase" - - key: readability-identifier-naming.ClassConstantCase - value: "lower_case" - - key: readability-identifier-naming.ClassConstantPrefix - value: "c_" - - key: readability-identifier-naming.ClassMemberCase - value: "lower_case" - - key: readability-identifier-naming.ClassMemberPrefix - value: "m_" - - key: readability-identifier-naming.ClassMethodCase - value: "lower_case" - - key: readability-identifier-naming.ConceptCase - value: "CamelCase" - - key: readability-identifier-naming.ConstantCase - value: "lower_case" - - key: readability-identifier-naming.ConstantMemberCase - value: "lower_case" - - key: readability-identifier-naming.ConstantParameterCase - value: "lower_case" - - key: readability-identifier-naming.ConstantPointerParameterCase - value: "lower_case" - - key: readability-identifier-naming.ConstexprFunctionCase - value: "lower_case" - - key: readability-identifier-naming.ConstexprMethodCase - value: "lower_case" - - key: readability-identifier-naming.ConstexprVariableCase - value: "lower_case" - - key: readability-identifier-naming.EnumCase - value: "CamelCase" - - key: readability-identifier-naming.EnumConstantCase - value: "CamelCase" - - key: readability-identifier-naming.FunctionCase - value: "lower_case" - - key: readability-identifier-naming.GlobalConstantCase - value: "lower_case" - - key: readability-identifier-naming.GlobalConstantPointerCase - value: "lower_case" - - key: readability-identifier-naming.GlobalFunctionCase - value: "lower_case" - - key: readability-identifier-naming.GlobalPointerCase - value: "lower_case" - - key: readability-identifier-naming.GlobalVariableCase - value: "lower_case" - - key: readability-identifier-naming.GlobalVariablePrefix - value: "g_" - - key: readability-identifier-naming.LocalConstantCase - value: "lower_case" - - key: readability-identifier-naming.LocalConstantPointerCase - value: "lower_case" - - key: readability-identifier-naming.LocalPointerCase - value: "lower_case" - - key: readability-identifier-naming.LocalVariableCase - value: "lower_case" - - key: readability-identifier-naming.MacroDefinitionCase - value: "UPPER_CASE" - - key: readability-identifier-naming.MemberCase - value: "lower_case" - - key: readability-identifier-naming.MemberPrefix - value: "m_" - - key: readability-identifier-naming.MethodCase - value: "lower_case" - - key: readability-identifier-naming.NamespaceCase - value: "lower_case" - - key: readability-identifier-naming.ParameterCase - value: "lower_case" - - key: readability-identifier-naming.ParameterPackCase - value: "lower_case" - - key: readability-identifier-naming.PointerParameterCase - value: "lower_case" - - key: readability-identifier-naming.PrivateMemberCase - value: "lower_case" - - key: readability-identifier-naming.PrivateMemberPrefix - value: "m_" - - key: readability-identifier-naming.PrivateMethodCase - value: "lower_case" - - key: readability-identifier-naming.ProtectedMemberCase - value: "lower_case" - - key: readability-identifier-naming.ProtectedMemberPrefix - value: "m_" - - key: readability-identifier-naming.ProtectedMethodCase - value: "lower_case" - - key: readability-identifier-naming.PublicMemberCase - value: "lower_case" - - key: readability-identifier-naming.PublicMemberPrefix - value: "" # NO PREFIX - - key: readability-identifier-naming.PublicMethodCase - value: "lower_case" - - key: readability-identifier-naming.ScopedEnumConstantCase - value: "CamelCase" - - key: readability-identifier-naming.StaticConstantCase - value: "lower_case" - - key: readability-identifier-naming.StaticConstantPrefix - value: "s_" - - key: readability-identifier-naming.StaticVariableCase - value: "lower_case" - - key: readability-identifier-naming.StaticVariablePrefix - value: "s_" - - key: readability-identifier-naming.StructCase - value: "CamelCase" - - key: readability-identifier-naming.TemplateParameterCase - value: "CamelCase" - - key: readability-identifier-naming.TemplateTemplateParameterCase - value: "CamelCase" - - key: readability-identifier-naming.TypeAliasCase - value: "CamelCase" - - key: readability-identifier-naming.TypedefCase - value: "CamelCase" - - key: readability-identifier-naming.TypeTemplateParameterCase - value: "CamelCase" - - key: readability-identifier-naming.UnionCase - value: "CamelCase" - - key: readability-identifier-naming.ValueTemplateParameterCase - value: "lower_case" - - key: readability-identifier-naming.VariableCase - value: "lower_case" - - key: readability-identifier-naming.VirtualMethodCase - value: "lower_case" - + ## NAMING CONVENTION SECTION + - key: readability-identifier-naming.AbstractClassCase + value: "CamelCase" + - key: readability-identifier-naming.AggressiveDependentMemberLookup + value: true + - key: readability-identifier-naming.CheckAnonFieldInParent + value: false + - key: readability-identifier-naming.ClassCase + value: "CamelCase" + - key: readability-identifier-naming.ClassConstantCase + value: "lower_case" + - key: readability-identifier-naming.ClassConstantPrefix + value: "c_" + - key: readability-identifier-naming.ClassMemberCase + value: "lower_case" + - key: readability-identifier-naming.ClassMemberPrefix + value: "m_" + - key: readability-identifier-naming.ClassMethodCase + value: "lower_case" + - key: readability-identifier-naming.ConceptCase + value: "CamelCase" + - key: readability-identifier-naming.ConstantCase + value: "lower_case" + - key: readability-identifier-naming.ConstantMemberCase + value: "lower_case" + - key: readability-identifier-naming.ConstantParameterCase + value: "lower_case" + - key: readability-identifier-naming.ConstantPointerParameterCase + value: "lower_case" + - key: readability-identifier-naming.ConstexprFunctionCase + value: "lower_case" + - key: readability-identifier-naming.ConstexprMethodCase + value: "lower_case" + - key: readability-identifier-naming.ConstexprVariableCase + value: "lower_case" + - key: readability-identifier-naming.EnumCase + value: "CamelCase" + - key: readability-identifier-naming.EnumConstantCase + value: "CamelCase" + - key: readability-identifier-naming.FunctionCase + value: "lower_case" + - key: readability-identifier-naming.GlobalConstantCase + value: "lower_case" + - key: readability-identifier-naming.GlobalConstantPointerCase + value: "lower_case" + - key: readability-identifier-naming.GlobalFunctionCase + value: "lower_case" + - key: readability-identifier-naming.GlobalPointerCase + value: "lower_case" + - key: readability-identifier-naming.GlobalVariableCase + value: "lower_case" + - key: readability-identifier-naming.GlobalVariablePrefix + value: "g_" + - key: readability-identifier-naming.LocalConstantCase + value: "lower_case" + - key: readability-identifier-naming.LocalConstantPointerCase + value: "lower_case" + - key: readability-identifier-naming.LocalPointerCase + value: "lower_case" + - key: readability-identifier-naming.LocalVariableCase + value: "lower_case" + - key: readability-identifier-naming.MacroDefinitionCase + value: "UPPER_CASE" + - key: readability-identifier-naming.MemberCase + value: "lower_case" + - key: readability-identifier-naming.MemberPrefix + value: "m_" + - key: readability-identifier-naming.MethodCase + value: "lower_case" + - key: readability-identifier-naming.NamespaceCase + value: "lower_case" + - key: readability-identifier-naming.ParameterCase + value: "lower_case" + - key: readability-identifier-naming.ParameterPackCase + value: "lower_case" + - key: readability-identifier-naming.PointerParameterCase + value: "lower_case" + - key: readability-identifier-naming.PrivateMemberCase + value: "lower_case" + - key: readability-identifier-naming.PrivateMemberPrefix + value: "m_" + - key: readability-identifier-naming.PrivateMethodCase + value: "lower_case" + - key: readability-identifier-naming.ProtectedMemberCase + value: "lower_case" + - key: readability-identifier-naming.ProtectedMemberPrefix + value: "m_" + - key: readability-identifier-naming.ProtectedMethodCase + value: "lower_case" + - key: readability-identifier-naming.PublicMemberCase + value: "lower_case" + - key: readability-identifier-naming.PublicMemberPrefix + value: "" # NO PREFIX + - key: readability-identifier-naming.PublicMethodCase + value: "lower_case" + - key: readability-identifier-naming.ScopedEnumConstantCase + value: "CamelCase" + - key: readability-identifier-naming.StaticConstantCase + value: "lower_case" + - key: readability-identifier-naming.StaticConstantPrefix + value: "s_" + - key: readability-identifier-naming.StaticVariableCase + value: "lower_case" + - key: readability-identifier-naming.StaticVariablePrefix + value: "s_" + - key: readability-identifier-naming.StructCase + value: "CamelCase" + - key: readability-identifier-naming.TemplateParameterCase + value: "CamelCase" + - key: readability-identifier-naming.TemplateTemplateParameterCase + value: "CamelCase" + - key: readability-identifier-naming.TypeAliasCase + value: "CamelCase" + - key: readability-identifier-naming.TypedefCase + value: "CamelCase" + - key: readability-identifier-naming.TypeTemplateParameterCase + value: "CamelCase" + - key: readability-identifier-naming.UnionCase + value: "CamelCase" + - key: readability-identifier-naming.ValueTemplateParameterCase + value: "lower_case" + - key: readability-identifier-naming.VariableCase + value: "lower_case" + - key: readability-identifier-naming.VirtualMethodCase + value: "lower_case" - - key: bugprone-argument-comment.CommentBoolLiterals - value: "0" - - key: bugprone-argument-comment.CommentCharacterLiterals - value: "0" - - key: bugprone-argument-comment.CommentFloatLiterals - value: "0" - - key: bugprone-argument-comment.CommentIntegerLiterals - value: "0" - - key: bugprone-argument-comment.CommentNullPtrs - value: "0" - - key: bugprone-argument-comment.CommentStringLiterals - value: "0" - - key: bugprone-argument-comment.CommentUserDefinedLiterals - value: "0" - - key: bugprone-argument-comment.IgnoreSingleArgument - value: "0" - - key: bugprone-argument-comment.StrictMode - value: "0" - - key: bugprone-assert-side-effect.AssertMacros - value: assert - - key: bugprone-assert-side-effect.CheckFunctionCalls - value: "0" - - key: bugprone-dangling-handle.HandleClasses - value: "std::basic_string_view;std::experimental::basic_string_view" - - key: bugprone-dynamic-static-initializers.HeaderFileExtensions - value: ",h,hh,hpp,hxx" - - key: bugprone-exception-escape.FunctionsThatShouldNotThrow - value: "" - - key: bugprone-exception-escape.IgnoredExceptions - value: "" - - key: bugprone-misplaced-widening-cast.CheckImplicitCasts - value: "0" - - key: bugprone-not-null-terminated-result.WantToUseSafeFunctions - value: "1" - - key: bugprone-signed-char-misuse.CharTypdefsToIgnore - value: "" - - key: bugprone-sizeof-expression.WarnOnSizeOfCompareToConstant - value: "1" - - key: bugprone-sizeof-expression.WarnOnSizeOfConstant - value: "1" - - key: bugprone-sizeof-expression.WarnOnSizeOfIntegerExpression - value: "0" - - key: bugprone-sizeof-expression.WarnOnSizeOfThis - value: "1" - - key: bugprone-string-constructor.LargeLengthThreshold - value: "8388608" - - key: bugprone-string-constructor.WarnOnLargeLength - value: "1" - - key: bugprone-suspicious-enum-usage.StrictMode - value: "0" - - key: bugprone-suspicious-missing-comma.MaxConcatenatedTokens - value: "5" - - key: bugprone-suspicious-missing-comma.RatioThreshold - value: "0.200000" - - key: bugprone-suspicious-missing-comma.SizeThreshold - value: "5" - - key: bugprone-suspicious-string-compare.StringCompareLikeFunctions - value: "" - - key: bugprone-suspicious-string-compare.WarnOnImplicitComparison - value: "1" - - key: bugprone-suspicious-string-compare.WarnOnLogicalNotComparison - value: "0" - - key: bugprone-too-small-loop-variable.MagnitudeBitsUpperLimit - value: "16" - - key: bugprone-unhandled-self-assignment.WarnOnlyIfThisHasSuspiciousField - value: "1" - - key: bugprone-unused-return-value.CheckedFunctions - value: "::std::async;::std::launder;::std::remove;::std::remove_if;::std::unique;::std::unique_ptr::release;::std::basic_string::empty;::std::vector::empty" - - key: cert-dcl16-c.NewSuffixes - value: "L;LL;LU;LLU" - - key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField - value: "0" - - key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors - value: "1" - - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic - value: "1" - - key: google-readability-braces-around-statements.ShortStatementLines - value: "1" - - key: google-readability-function-size.StatementThreshold - value: "800" - - key: google-readability-namespace-comments.ShortNamespaceLines - value: "10" - - key: google-readability-namespace-comments.SpacesBeforeComments - value: "2" - - key: misc-definitions-in-headers.HeaderFileExtensions - value: ",h,hh,hpp,hxx" - - key: misc-definitions-in-headers.UseHeaderFileExtension - value: "1" - - key: misc-throw-by-value-catch-by-reference.CheckThrowTemporaries - value: "1" - - key: misc-unused-parameters.StrictMode - value: "0" - - key: modernize-loop-convert.MaxCopySize - value: "16" - - key: modernize-loop-convert.MinConfidence - value: reasonable - - key: modernize-use-trailing-return-type - value: "false" - - key: modernize-loop-convert.NamingStyle - value: CamelCase - - key: modernize-pass-by-value.IncludeStyle - value: llvm - - key: modernize-replace-auto-ptr.IncludeStyle - value: llvm - - key: modernize-use-nullptr.NullMacros - value: "NULL" - - key: performance-faster-string-find.StringLikeClasses - value: "std::basic_string" - - key: performance-for-range-copy.AllowedTypes - value: "" - - key: performance-for-range-copy.WarnOnAllAutoCopies - value: "0" - - key: performance-inefficient-string-concatenation.StrictMode - value: "0" - - key: performance-inefficient-vector-operation.EnableProto - value: "0" - - key: performance-inefficient-vector-operation.VectorLikeClasses - value: "::std::vector" - - key: performance-move-const-arg.CheckTriviallyCopyableMove - value: "1" - - key: performance-move-constructor-init.IncludeStyle - value: llvm - - key: performance-no-automatic-move.AllowedTypes - value: "" - - key: performance-type-promotion-in-math-fn.IncludeStyle - value: llvm - - key: performance-unnecessary-copy-initialization.AllowedTypes - value: "" - - key: performance-unnecessary-value-param.AllowedTypes - value: "" - - key: performance-unnecessary-value-param.IncludeStyle - value: llvm - - key: readability-braces-around-statements.ShortStatementLines - value: "0" - - key: readability-else-after-return.WarnOnUnfixable - value: "1" - - key: readability-function-size.BranchThreshold - value: "4294967295" - - key: readability-function-size.LineThreshold - value: "4294967295" - - key: readability-function-size.NestingThreshold - value: "4294967295" - - key: readability-function-size.ParameterThreshold - value: "4294967295" - - key: readability-function-size.StatementThreshold - value: "800" - - key: readability-function-size.VariableThreshold - value: "4294967295" - - key: readability-implicit-bool-conversion.AllowIntegerConditions - value: "0" - - key: readability-implicit-bool-conversion.AllowPointerConditions - value: "0" - - key: readability-inconsistent-declaration-parameter-name.IgnoreMacros - value: "1" - - key: readability-inconsistent-declaration-parameter-name.Strict - value: "0" - - key: readability-magic-numbers.IgnoredFloatingPointValues - value: "1.0;100.0;" - - key: readability-magic-numbers.IgnoredIntegerValues - value: "1;2;3;4;" - - key: readability-redundant-member-init.IgnoreBaseInCopyConstructors - value: "0" - - key: readability-redundant-smartptr-get.IgnoreMacros - value: "1" - - key: readability-redundant-string-init.StringNames - value: "::std::basic_string" - - key: readability-simplify-boolean-expr.ChainedConditionalAssignment - value: "0" - - key: readability-simplify-boolean-expr.ChainedConditionalReturn - value: "0" - - key: readability-simplify-subscript-expr.Types - value: "::std::basic_string;::std::basic_string_view;::std::vector;::std::array" - - key: readability-static-accessed-through-instance.NameSpecifierNestingThreshold - value: "3" - - key: readability-uppercase-literal-suffix.IgnoreMacros - value: "1" - - key: readability-uppercase-literal-suffix.NewSuffixes - value: "" + # some needed settings, that are non default + - key: bugprone-assert-side-effect.AssertMacros + value: "assert" + - key: bugprone-misplaced-widening-cast.CheckImplicitCasts + value: true + - key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic + value: true + - key: bugprone-suspicious-enum-usage.StrictMode + value: true + - key: bugprone-suspicious-string-compare.WarnOnLogicalNotComparison + value: true + - key: bugprone-unhandled-self-assignment.WarnOnlyIfThisHasSuspiciousField + value: true + - key: misc-unused-parameters.StrictMode + value: true + - key: performance-inefficient-string-concatenation.StrictMode + value: true + - key: readability-inconsistent-declaration-parameter-name.Strict + value: true + + ## special things, that have special values + - key: readability-identifier-length.IgnoredVariableNames + value: "" + - key: readability-identifier-length.IgnoredParameterNames + value: "^[n]$" + - key: readability-identifier-length.MinimumLoopCounterNameLength + value: 1 + - key: readability-identifier-length.MinimumExceptionNameLength + value: 5 From b8fffa7e42f2349fd4bd24436acf646c366df75a Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 13 May 2024 15:55:24 +0200 Subject: [PATCH 05/13] clang-tidy: fix some things --- src/application.cpp | 25 +++++++++++++++++-------- src/helper/errors.cpp | 26 ++++++++++++++++++-------- src/helper/errors.hpp | 18 +++++++++--------- 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/application.cpp b/src/application.cpp index c1d78364..f5ab5ce0 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -22,9 +22,15 @@ namespace { [[nodiscard]] helper::MessageBox::Type get_notification_level(helper::error::Severity severity) { - return severity == helper::error::Severity::Fatal ? helper::MessageBox::Type::Error - : severity == helper::error::Severity::Major ? helper::MessageBox::Type::Warning - : helper::MessageBox::Type::Information; + switch (severity) { + case helper::error::Severity::Minor: + return helper::MessageBox::Type::Information; + case helper::error::Severity::Major: + return helper::MessageBox::Type::Warning; + case helper::error::Severity::Fatal: + default: + return helper::MessageBox::Type::Error; + } } } // namespace @@ -88,7 +94,7 @@ void Application::run() { const Uint64 current_time = SDL_GetPerformanceCounter(); if (current_time - start_time >= update_time) { - double elapsed = static_cast(current_time - start_time) / count_per_s; + const double elapsed = static_cast(current_time - start_time) / count_per_s; m_fps_text->set_text(*this, fmt::format("FPS: {:.2f}", static_cast(frame_counter) / elapsed)); start_time = current_time; frame_counter = 0; @@ -100,7 +106,7 @@ void Application::run() { const auto now = std::chrono::steady_clock::now(); const auto runtime = (now - start_execution_time); if (runtime < sleep_time) { - //TODO: use SDL_DelayNS in sdl >= 3.0 + //TODO(totto): use SDL_DelayNS in sdl >= 3.0 helper::sleep_nanoseconds(sleep_time - runtime); start_execution_time = std::chrono::steady_clock::now(); } else { @@ -190,9 +196,12 @@ void Application::update() { spdlog::info("pushing back scene {}", raw_push.name); m_scene_stack.push_back(std::move(raw_push.scene)); }, - [this](const scenes::Scene::Switch& switch_) { - spdlog::info("switching to scene {}", magic_enum::enum_name(switch_.target_scene)); - auto scene = scenes::create_scene(*this, switch_.target_scene, switch_.layout); + [this](const scenes::Scene::Switch& scene_switch) { + spdlog::info( + "switching to scene {}", magic_enum::enum_name(scene_switch.target_scene) + ); + auto scene = + scenes::create_scene(*this, scene_switch.target_scene, scene_switch.layout); // only clear, after the construction was successful m_scene_stack.clear(); diff --git a/src/helper/errors.cpp b/src/helper/errors.cpp index 88ec58e8..a21f9a65 100644 --- a/src/helper/errors.cpp +++ b/src/helper/errors.cpp @@ -1,13 +1,17 @@ #include "errors.hpp" -helper::GeneralError::GeneralError(const std::string& message, error::Severity severity) +helper::GeneralError::GeneralError(const std::string& message, error::Severity severity) noexcept : m_message{ message }, m_severity{ severity } { } -helper::GeneralError::GeneralError(std::string&& message, error::Severity severity) +helper::GeneralError::GeneralError(std::string&& message, error::Severity severity) noexcept : m_message{ std::move(message) }, m_severity{ severity } { } +helper::GeneralError::GeneralError(const GeneralError& error) noexcept + : m_message{ error.message() }, + m_severity{ error.severity() } { } + [[nodiscard]] const std::string& helper::GeneralError::message() const { return m_message; } @@ -16,14 +20,20 @@ helper::GeneralError::GeneralError(std::string&& message, error::Severity severi return m_severity; } -helper::FatalError::FatalError(const std::string& message) : GeneralError{ message, error::Severity::Fatal } { } +helper::FatalError::FatalError(const std::string& message) noexcept + : GeneralError{ message, error::Severity::Fatal } { } -helper::FatalError::FatalError(std::string&& message) : GeneralError{ std::move(message), error::Severity::Fatal } { } +helper::FatalError::FatalError(std::string&& message) noexcept + : GeneralError{ std::move(message), error::Severity::Fatal } { } -helper::MajorError::MajorError(const std::string& message) : GeneralError{ message, error::Severity::Major } { } +helper::MajorError::MajorError(const std::string& message) noexcept + : GeneralError{ message, error::Severity::Major } { } -helper::MajorError::MajorError(std::string&& message) : GeneralError{ std::move(message), error::Severity::Major } { } +helper::MajorError::MajorError(std::string&& message) noexcept + : GeneralError{ std::move(message), error::Severity::Major } { } -helper::MinorError::MinorError(const std::string& message) : GeneralError{ message, error::Severity::Minor } { } +helper::MinorError::MinorError(const std::string& message) noexcept + : GeneralError{ message, error::Severity::Minor } { } -helper::MinorError::MinorError(std::string&& message) : GeneralError{ std::move(message), error::Severity::Minor } { } +helper::MinorError::MinorError(std::string&& message) noexcept + : GeneralError{ std::move(message), error::Severity::Minor } { } diff --git a/src/helper/errors.hpp b/src/helper/errors.hpp index e6388be3..056ef145 100644 --- a/src/helper/errors.hpp +++ b/src/helper/errors.hpp @@ -17,30 +17,30 @@ namespace helper { error::Severity m_severity; public: - GeneralError(const std::string& message, error::Severity severity); - - GeneralError(std::string&& message, error::Severity severity); + GeneralError(const std::string& message, error::Severity severity) noexcept; + GeneralError(std::string&& message, error::Severity severity) noexcept; + GeneralError(const GeneralError& error) noexcept; [[nodiscard]] const std::string& message() const; [[nodiscard]] error::Severity severity() const; }; struct FatalError : public GeneralError { - FatalError(const std::string& message); + FatalError(const std::string& message) noexcept; - FatalError(std::string&& message); + FatalError(std::string&& message) noexcept; }; struct MajorError : public GeneralError { - MajorError(const std::string& message); + MajorError(const std::string& message) noexcept; - MajorError(std::string&& message); + MajorError(std::string&& message) noexcept; }; struct MinorError : public GeneralError { - MinorError(const std::string& message); + MinorError(const std::string& message) noexcept ; - MinorError(std::string&& message); + MinorError(std::string&& message) noexcept; }; using InitializationError = FatalError; From a0bf1afd501fa747d54d970298604affcf317e94 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 13 May 2024 16:02:29 +0200 Subject: [PATCH 06/13] remove NOLINT's for readability-use-anyofallof and use std::ranges --- src/game/mino_stack.cpp | 11 ++++------- src/game/tetrion.cpp | 18 ++++++------------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/game/mino_stack.cpp b/src/game/mino_stack.cpp index 5d8eab4a..f05fde93 100644 --- a/src/game/mino_stack.cpp +++ b/src/game/mino_stack.cpp @@ -1,7 +1,7 @@ #include "mino_stack.hpp" - #include "grid_properties.hpp" #include "helper/magic_enum_wrapper.hpp" + #include void MinoStack::clear_row_and_let_sink(u8 row) { @@ -17,12 +17,9 @@ void MinoStack::clear_row_and_let_sink(u8 row) { } [[nodiscard]] bool MinoStack::is_empty(GridPoint coordinates) const { - for (const Mino& mino : m_minos) { // NOLINT(readability-use-anyofallof) - if (mino.position() == coordinates) { - return false; - } - } - return true; + return not std::ranges::any_of(m_minos, [&coordinates](const Mino& mino) { + return mino.position() == coordinates; + }); } void MinoStack::set(GridPoint coordinates, helper::TetrominoType type) { diff --git a/src/game/tetrion.cpp b/src/game/tetrion.cpp index 7b3efb70..0d9b0964 100644 --- a/src/game/tetrion.cpp +++ b/src/game/tetrion.cpp @@ -522,12 +522,9 @@ helper::TetrominoType Tetrion::get_next_tetromino_type() { } bool Tetrion::tetromino_can_move_down(const Tetromino& tetromino) const { - for (const Mino& mino : tetromino.minos()) { // NOLINT(readability-use-anyofallof) - if (not mino_can_move_down(mino.position())) { - return false; - } - } - return true; + return not std::ranges::any_of(tetromino.minos(), [this](const Mino& mino) { + return not mino_can_move_down(mino.position()); + }); } @@ -568,12 +565,9 @@ u8 Tetrion::rotation_to_index(const Rotation from, const Rotation to) { } bool Tetrion::is_tetromino_position_valid(const Tetromino& tetromino) const { - for (const Mino& mino : tetromino.minos()) { // NOLINT(readability-use-anyofallof) - if (not is_valid_mino_position(mino.position())) { - return false; - } - } - return true; + return not std::ranges::any_of(tetromino.minos(), [this](const Mino& mino) { + return not is_valid_mino_position(mino.position()); + }); } bool Tetrion::rotate(Tetrion::RotationDirection rotation_direction) { From 583b52c3bffa14fb138b6f7214a291a15e29de12 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 13 May 2024 16:23:46 +0200 Subject: [PATCH 07/13] modernize: - use std::ranges where possible --- src/game/mino_stack.cpp | 20 +++++++++----------- src/helper/parse_json.cpp | 2 +- src/helper/static_string.hpp | 4 ++-- src/input/input.hpp | 2 +- src/input/joystick_input.cpp | 2 +- src/manager/event_dispatcher.hpp | 6 ++---- src/manager/sdl_key.cpp | 29 ++++++++++++++++++----------- src/ui/layouts/focus_layout.cpp | 18 ++++++++++-------- 8 files changed, 44 insertions(+), 39 deletions(-) diff --git a/src/game/mino_stack.cpp b/src/game/mino_stack.cpp index f05fde93..770774d6 100644 --- a/src/game/mino_stack.cpp +++ b/src/game/mino_stack.cpp @@ -6,7 +6,7 @@ void MinoStack::clear_row_and_let_sink(u8 row) { m_minos.erase( - std::remove_if(m_minos.begin(), m_minos.end(), [&](const Mino& mino) { return mino.position().y == row; }), + std::ranges::remove_if(m_minos, [&](const Mino& mino) { return mino.position().y == row; }).begin(), m_minos.end() ); for (Mino& mino : m_minos) { @@ -45,18 +45,17 @@ void MinoStack::set(GridPoint coordinates, helper::TetrominoType type) { return false; } - const auto all_of_this_in_other = std::all_of(m_minos.cbegin(), m_minos.cend(), [&](const auto& mino) { - return std::find(other.m_minos.cbegin(), other.m_minos.cend(), mino) != end(other.m_minos); + const auto all_of_this_in_other = std::ranges::all_of(m_minos, [&](const auto& mino) { + return std::ranges::find(other.m_minos, mino) != end(other.m_minos); }); if (not all_of_this_in_other) { return false; } - const auto all_of_other_in_this = - std::all_of(other.m_minos.cbegin(), other.m_minos.cend(), [this](const auto& mino) { - return std::find(m_minos.cbegin(), m_minos.cend(), mino) != end(m_minos); - }); + const auto all_of_other_in_this = std::ranges::all_of(other.m_minos, [this](const auto& mino) { + return std::ranges::find(m_minos, mino) != end(m_minos); + }); return all_of_other_in_this; } @@ -70,10 +69,9 @@ std::ostream& operator<<(std::ostream& ostream, const MinoStack& mino_stack) { ostream << "MinoStack(\n"; for (u8 y = 0; y < grid::height_in_tiles; ++y) { for (u8 x = 0; x < grid::width_in_tiles; ++x) { - const auto find_iterator = - std::find_if(mino_stack.minos().cbegin(), mino_stack.minos().cend(), [&](const auto& mino) { - return mino.position() == shapes::AbstractPoint{ x, y }; - }); + const auto find_iterator = std::ranges::find_if(mino_stack.minos(), [&](const auto& mino) { + return mino.position() == shapes::AbstractPoint{ x, y }; + }); const auto found = (find_iterator != mino_stack.minos().cend()); if (found) { ostream << magic_enum::enum_name(find_iterator->type()); diff --git a/src/helper/parse_json.cpp b/src/helper/parse_json.cpp index a7434863..96b827e6 100644 --- a/src/helper/parse_json.cpp +++ b/src/helper/parse_json.cpp @@ -46,7 +46,7 @@ void json::check_for_no_additional_keys(const nlohmann::json& j, const std::vect for (const auto& [key, _] : object) { - if (std::find(keys.cbegin(), keys.cend(), key) == keys.cend()) { + if (std::ranges::find(keys, key) == keys.cend()) { throw nlohmann::json::type_error::create( 302, fmt::format("object may only contain expected keys, but contained '{}'", key), &j ); diff --git a/src/helper/static_string.hpp b/src/helper/static_string.hpp index 878a8cc4..5b4a96e0 100644 --- a/src/helper/static_string.hpp +++ b/src/helper/static_string.hpp @@ -72,8 +72,8 @@ struct StaticString { template> [[nodiscard]] constexpr Result operator+(const StaticString& other) const { auto concatenated = Result{}; - std::copy(cbegin(), cend(), concatenated.begin()); - std::copy(other.cbegin(), other.cend(), concatenated.begin() + size()); + std::ranges::copy(*this, concatenated.begin()); + std::ranges::copy(other, concatenated.begin() + size()); concatenated.back() = '\0'; return concatenated; } diff --git a/src/input/input.hpp b/src/input/input.hpp index 57c097cb..ddaa54a6 100644 --- a/src/input/input.hpp +++ b/src/input/input.hpp @@ -114,7 +114,7 @@ namespace input { for (const auto& single_check : to_check) { - if (std::find(already_bound.cbegin(), already_bound.cend(), single_check) != already_bound.cend()) { + if (std::ranges::find(already_bound, single_check) != already_bound.cend()) { return helper::unexpected{ fmt::format("KeyCode already bound: '{}'", single_check) }; } diff --git a/src/input/joystick_input.cpp b/src/input/joystick_input.cpp index 5c19eb55..240b572c 100644 --- a/src/input/joystick_input.cpp +++ b/src/input/joystick_input.cpp @@ -167,7 +167,7 @@ void input::JoyStickInputManager::discover_devices(std::vector(*it); joystick_input.has_value()) { diff --git a/src/manager/event_dispatcher.hpp b/src/manager/event_dispatcher.hpp index 5d546a19..1ce3954a 100644 --- a/src/manager/event_dispatcher.hpp +++ b/src/manager/event_dispatcher.hpp @@ -38,7 +38,7 @@ struct EventDispatcher final { } void unregister_listener(const EventListener* listener) { - const auto end = std::remove(m_listeners.begin(), m_listeners.end(), listener); + const auto end = std::ranges::remove(m_listeners, listener).begin(); assert(end != m_listeners.end() and "listener to delete could not be found"); m_listeners.erase(end, m_listeners.end()); } @@ -54,9 +54,7 @@ struct EventDispatcher final { switch (event.type) { case SDL_KEYDOWN: case SDL_KEYUP: { - if (std::find( - allowed_input_keys.cbegin(), allowed_input_keys.cend(), SDL::Key{ event.key.keysym } - ) + if (std::ranges::find(allowed_input_keys, SDL::Key{ event.key.keysym }) == allowed_input_keys.cend()) { return; } diff --git a/src/manager/sdl_key.cpp b/src/manager/sdl_key.cpp index 78f88f72..b061b3ca 100644 --- a/src/manager/sdl_key.cpp +++ b/src/manager/sdl_key.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include #include @@ -160,15 +162,15 @@ namespace { [[maybe_unused]] SDL::ModifierType typeof_modifier(SDL::Modifier modifier) { const auto& [normal, special, multiple] = get_modifier_type_array(); - if (std::find(normal.cbegin(), normal.cend(), modifier) != normal.cend()) { + if (std::ranges::find(normal, modifier) != normal.cend()) { return SDL::ModifierType::Normal; } - if (std::find(special.cbegin(), special.cend(), modifier) != special.cend()) { + if (std::ranges::find(special, modifier) != special.cend()) { return SDL::ModifierType::Special; } - if (std::find(multiple.cbegin(), multiple.cend(), modifier) != multiple.cend()) { + if (std::ranges::find(multiple, modifier) != multiple.cend()) { return SDL::ModifierType::Multiple; } @@ -249,21 +251,26 @@ namespace { } // trim from start (in place) - inline void ltrim(std::string& s) { - s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !std::isspace(ch); })); + inline void ltrim(std::string& str) { + str.erase(str.begin(), std::ranges::find_if(str, [](unsigned char ch) { return !std::isspace(ch); })); } // trim from end (in place) - inline void rtrim(std::string& s) { - s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), s.end()); + inline void rtrim(std::string& str) { + str.erase( + std::ranges::find_if( + std::ranges::reverse_view(str), [](unsigned char ch) { return !std::isspace(ch); } + ).base(), + str.end() + ); } - void trim(std::string& s) { - ltrim(s); - rtrim(s); + void trim(std::string& str) { + ltrim(str); + rtrim(str); } - helper::optional modifier_from_string(std::string modifier) { + helper::optional modifier_from_string(const std::string& modifier) { if (modifier.empty()) { return helper::nullopt; diff --git a/src/ui/layouts/focus_layout.cpp b/src/ui/layouts/focus_layout.cpp index c2aca12f..a61faf1e 100644 --- a/src/ui/layouts/focus_layout.cpp +++ b/src/ui/layouts/focus_layout.cpp @@ -4,6 +4,8 @@ #include "input/input.hpp" #include "ui/widget.hpp" +#include + ui::FocusLayout::FocusLayout(const Layout& layout, u32 focus_id, FocusOptions options, bool is_top_level) : Widget{ layout, WidgetType::Container, is_top_level }, @@ -179,11 +181,10 @@ ui::FocusLayout::handle_event_result( // NOLINT(readability-function-cognitive-c } [[nodiscard]] u32 ui::FocusLayout::focusable_index_by_id(const u32 id) const { - const auto find_iterator = - std::find_if(m_widgets.begin(), m_widgets.end(), [id](const std::unique_ptr& widget) { - const auto focusable = as_focusable(widget.get()); - return focusable.has_value() and focusable.value()->focus_id() == id; - }); + const auto find_iterator = std::ranges::find_if(m_widgets, [id](const std::unique_ptr& widget) { + const auto focusable = as_focusable(widget.get()); + return focusable.has_value() and focusable.value()->focus_id() == id; + }); assert(find_iterator != m_widgets.end()); const auto index = static_cast(std::distance(m_widgets.begin(), find_iterator)); return index; @@ -199,17 +200,18 @@ ui::FocusLayout::handle_event_result( // NOLINT(readability-function-cognitive-c } #ifdef DEBUG_BUILD - const auto duplicates = std::adjacent_find(result.cbegin(), result.cend()); + // this works, since result is sorted already + const auto duplicates = std::ranges::adjacent_find(result); if (duplicates != result.cend()) { throw std::runtime_error("Focusables have duplicates: " + std::to_string(*duplicates)); } #endif - std::sort(result.begin(), result.end()); + std::ranges::sort(result); return result; } [[nodiscard]] u32 ui::FocusLayout::index_of(const std::vector& ids, const u32 needle) { - return static_cast(std::distance(ids.cbegin(), std::find(ids.cbegin(), ids.cend(), needle))); + return static_cast(std::distance(ids.cbegin(), std::ranges::find(ids, needle))); } [[nodiscard]] bool ui::FocusLayout::try_set_next_focus(const FocusChangeDirection focus_direction) { From ae4644ce8a7efddfb6c2cc0422f73977c116ef7c Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 13 May 2024 16:43:04 +0200 Subject: [PATCH 08/13] c++ std version: remove c++20 and only use c++23 and c++26 (preview) --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 09c8aea7..cb73f7dc 100644 --- a/meson.build +++ b/meson.build @@ -7,7 +7,7 @@ project( 'buildtype': 'debug', 'optimization': '3', 'strip': true, - 'cpp_std': ['c++23', 'c++latest', 'vc++latest', 'c++20'], + 'cpp_std': ['c++26', 'c++23', 'c++latest', 'vc++latest'], 'b_ndebug': 'if-release', }, From 462bfa9e86ac3df0676803951695030a33730eda Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 13 May 2024 18:18:43 +0200 Subject: [PATCH 09/13] c++26: try to use newer features --- src/helper/const_utils.hpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/helper/const_utils.hpp b/src/helper/const_utils.hpp index 5176e715..232399e9 100644 --- a/src/helper/const_utils.hpp +++ b/src/helper/const_utils.hpp @@ -6,14 +6,28 @@ #include #include -// define a consteval assert, it isn't a pretty error message, but there's nothing we can do against that atm :( -// this https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2758r2.html tries to fix it +// use C++26 feature, if available: +#if __cpp_static_assert >= 202306L #define CONSTEVAL_ONLY_STATIC_ASSERT(CHECK, MSG) /*NOLINT(cppcoreguidelines-macro-usage)*/ \ ((CHECK) ? void(0) : [] { \ /* If you see this really bad c++ error message, follow the origin of MSG, to see the real error message, c++ error messages suck xD */ \ throw(MSG); \ }()) +//This doesn't work, since CHECK is in most cases not a constant expression so not constant evaluatable inside the if constexpr, and therefore static_assert(false,..) would trigger always +/* +#define CONSTEVAL_ONLY_STATIC_ASSERT(CHECK, MSG) +(if constexpr (!(CHECK)) { static_assert(false, MSG); }()) +s*/ + +#else +#define CONSTEVAL_ONLY_STATIC_ASSERT(CHECK, MSG) /*NOLINT(cppcoreguidelines-macro-usage)*/ \ + ((CHECK) ? void(0) : [] { \ + /* If you see this really bad c++ error message, follow the origin of MSG, to see the real error message, c++ error messages suck xD */ \ + throw(MSG); \ + }()) +#endif + #define CONSTEVAL_STATIC_ASSERT(CHECK, MSG) \ do { /*NOLINT(cppcoreguidelines-avoid-do-while)*/ \ if (utils::is_constant_evaluated()) { \ From 513a499d367a984c4ab3d472cf4b452210738d49 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Mon, 13 May 2024 21:28:34 +0200 Subject: [PATCH 10/13] clang-format files --- src/helper/errors.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helper/errors.hpp b/src/helper/errors.hpp index 056ef145..7b65e486 100644 --- a/src/helper/errors.hpp +++ b/src/helper/errors.hpp @@ -38,7 +38,7 @@ namespace helper { }; struct MinorError : public GeneralError { - MinorError(const std::string& message) noexcept ; + MinorError(const std::string& message) noexcept; MinorError(std::string&& message) noexcept; }; From da4bf159d83544ec717d5fed77df7fbca7caee86 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Tue, 14 May 2024 02:53:20 +0200 Subject: [PATCH 11/13] fix a few more clang-tidy things --- .clang-tidy | 12 ++++-- src/application.cpp | 12 ++---- src/game/game.cpp | 2 +- src/game/tetrion.cpp | 36 ++++++++--------- src/helper/color_literals.hpp | 6 +-- src/helper/errors.cpp | 12 ++++-- src/helper/errors.hpp | 20 +++++++--- src/input/keyboard_input.cpp | 5 +-- src/input/touch_input.cpp | 5 +-- src/manager/sdl_key.cpp | 1 - src/recordings/additional_information.cpp | 26 ++++++------- src/recordings/recording_reader.cpp | 3 +- src/recordings/tetrion_snapshot.cpp | 16 ++++---- src/ui/components/abstract_slider.hpp | 7 +--- src/ui/components/color_picker.cpp | 27 ++++++------- src/ui/components/textinput.cpp | 17 ++++---- src/ui/components/textinput.hpp | 7 +--- src/ui/layouts/focus_layout.cpp | 5 +-- src/ui/layouts/scroll_layout.cpp | 8 ++-- src/ui/layouts/tile_layout.cpp | 19 ++++----- src/ui/layouts/tile_layout.hpp | 7 +--- tests/core/color.cpp | 47 ++++++++++++----------- tests/graphics/sdl_key.cpp | 1 - 23 files changed, 140 insertions(+), 161 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 22c1bb1e..816282d7 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,6 +1,6 @@ # taken from https://github.com/cpp-linter/cpp-linter-action/blob/main/demo/.clang-tidy --- -Checks: "clang-diagnostic-*,clang-analyzer-*,bugprone-*,misc-*,performance-*,readability-*,portability-*,modernize-*,cppcoreguidelines-*,google-*,llvm-*,cert-*,-modernize-use-trailing-return-type,-bugprone-argument-comment,-misc-include-cleaner,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers" +Checks: "clang-diagnostic-*,clang-analyzer-*,bugprone-*,misc-*,performance-*,readability-*,portability-*,modernize-*,cppcoreguidelines-*,google-*,llvm-*,cert-*,-modernize-use-trailing-return-type,-bugprone-argument-comment,-misc-include-cleaner,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-readability-avoid-nested-conditional-operator,-llvm-namespace-comment" WarningsAsErrors: "" HeaderFilterRegex: "oopetris/src/.*" FormatStyle: "file" @@ -52,6 +52,8 @@ CheckOptions: value: "lower_case" - key: readability-identifier-naming.GlobalFunctionCase value: "lower_case" + - key: readability-identifier-naming.GlobalFunctionIgnoredRegexp + value: "(PrintTo)" ## for gtest - key: readability-identifier-naming.GlobalPointerCase value: "lower_case" - key: readability-identifier-naming.GlobalVariableCase @@ -132,8 +134,6 @@ CheckOptions: value: "lower_case" # some needed settings, that are non default - - key: bugprone-assert-side-effect.AssertMacros - value: "assert" - key: bugprone-misplaced-widening-cast.CheckImplicitCasts value: true - key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic @@ -153,10 +153,14 @@ CheckOptions: ## special things, that have special values - key: readability-identifier-length.IgnoredVariableNames - value: "" + value: "(os)" # ostream - key: readability-identifier-length.IgnoredParameterNames value: "^[n]$" - key: readability-identifier-length.MinimumLoopCounterNameLength value: 1 - key: readability-identifier-length.MinimumExceptionNameLength value: 5 + - key: readability-function-cognitive-complexity.Threshold + value: 50 + - key: bugprone-assert-side-effect.AssertMacros + value: "assert" diff --git a/src/application.cpp b/src/application.cpp index f5ab5ce0..c962c607 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -22,15 +22,9 @@ namespace { [[nodiscard]] helper::MessageBox::Type get_notification_level(helper::error::Severity severity) { - switch (severity) { - case helper::error::Severity::Minor: - return helper::MessageBox::Type::Information; - case helper::error::Severity::Major: - return helper::MessageBox::Type::Warning; - case helper::error::Severity::Fatal: - default: - return helper::MessageBox::Type::Error; - } + return severity == helper::error::Severity::Fatal ? helper::MessageBox::Type::Error + : severity == helper::error::Severity::Major ? helper::MessageBox::Type::Warning + : helper::MessageBox::Type::Information; } } // namespace diff --git a/src/game/game.cpp b/src/game/game.cpp index 81ca264c..66ab282c 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -13,7 +13,7 @@ Game::Game( ) : ui::Widget{ layout, ui::WidgetType::Component, is_top_level }, m_clock_source{ std::make_unique(starting_parameters.target_fps) }, - m_input{ std::move(input) } { + m_input{ input } { spdlog::info("starting level for tetrion {}", starting_parameters.starting_level); diff --git a/src/game/tetrion.cpp b/src/game/tetrion.cpp index 0d9b0964..e0f8168e 100644 --- a/src/game/tetrion.cpp +++ b/src/game/tetrion.cpp @@ -42,9 +42,9 @@ Tetrion::Tetrion( layout } { - main_layout.add(); + m_main_layout.add(); - main_layout.add( + m_main_layout.add( 1, 3, ui::Direction::Vertical, ui::AbsolutMargin{ 0 }, std::pair{ 0.0, 0.1 } ); @@ -105,7 +105,7 @@ void Tetrion::update_step(const SimulationStep simulation_step_index) { void Tetrion::render(const ServiceProvider& service_provider) const { - main_layout.render(service_provider); + m_main_layout.render(service_provider); const auto* grid = get_grid(); const double original_scale = grid->scale_to_original(); @@ -148,7 +148,7 @@ void Tetrion::render(const ServiceProvider& service_provider) const { } [[nodiscard]] helper::BoolWrapper> -Tetrion::handle_event(const std::shared_ptr&, const SDL_Event&) { +Tetrion::handle_event(const std::shared_ptr& /*input_manager*/, const SDL_Event& /*event*/) { return false; } @@ -179,7 +179,7 @@ bool Tetrion::handle_input_command(const input::GameInputCommand command, const } return false; case input::GameInputCommand::MoveDown: - //TODO: use input_type() != InputType:Touch + //TODO(Totto): use input_type() != InputType:Touch #if not defined(__ANDROID__) m_down_key_pressed = true; m_is_accelerated_down_movement = true; @@ -334,19 +334,19 @@ void Tetrion::hold_tetromino(const SimulationStep simulation_step_index) { } [[nodiscard]] Grid* Tetrion::get_grid() { - return main_layout.get(0); + return m_main_layout.get(0); } [[nodiscard]] const Grid* Tetrion::get_grid() const { - return main_layout.get(0); + return m_main_layout.get(0); } [[nodiscard]] ui::GridLayout* Tetrion::get_text_layout() { - return main_layout.get(1); + return m_main_layout.get(1); } [[nodiscard]] const ui::GridLayout* Tetrion::get_text_layout() const { - return main_layout.get(1); + return m_main_layout.get(1); } [[nodiscard]] u8 Tetrion::tetrion_index() const { @@ -536,29 +536,29 @@ bool Tetrion::tetromino_can_move_down(const Tetromino& tetromino) const { return frames; } -u8 Tetrion::rotation_to_index(const Rotation from, const Rotation to) { - if (from == Rotation::North and to == Rotation::East) { +u8 Tetrion::rotation_to_index(const Rotation from, const Rotation rotation_to) { + if (from == Rotation::North and rotation_to == Rotation::East) { return 0; } - if (from == Rotation::East and to == Rotation::North) { + if (from == Rotation::East and rotation_to == Rotation::North) { return 1; } - if (from == Rotation::East and to == Rotation::South) { + if (from == Rotation::East and rotation_to == Rotation::South) { return 2; } - if (from == Rotation::South and to == Rotation::East) { + if (from == Rotation::South and rotation_to == Rotation::East) { return 3; } - if (from == Rotation::South and to == Rotation::West) { + if (from == Rotation::South and rotation_to == Rotation::West) { return 4; } - if (from == Rotation::West and to == Rotation::South) { + if (from == Rotation::West and rotation_to == Rotation::South) { return 5; } - if (from == Rotation::West and to == Rotation::North) { + if (from == Rotation::West and rotation_to == Rotation::North) { return 6; } - if (from == Rotation::North and to == Rotation::West) { + if (from == Rotation::North and rotation_to == Rotation::West) { return 7; } utils::unreachable(); diff --git a/src/helper/color_literals.hpp b/src/helper/color_literals.hpp index 90b72a25..bc1b5411 100644 --- a/src/helper/color_literals.hpp +++ b/src/helper/color_literals.hpp @@ -200,7 +200,7 @@ namespace { using ColorFromHexStringReturnType = std::pair; [[nodiscard]] constexpr const_utils::expected - get_color_from_hex_string(const char* input, std::size_t size) { //NOLINT(readability-function-cognitive-complexity + get_color_from_hex_string(const char* input, std::size_t size) { if (size == const_constants::hex_rgb_size) { @@ -247,7 +247,7 @@ namespace { using ColorFromRGBStringReturnType = std::pair; [[nodiscard]] constexpr const_utils::expected - get_color_from_rgb_string(const char* input, std::size_t) { //NOLINT(readability-function-cognitive-complexity + get_color_from_rgb_string(const char* input, std::size_t) { if (input[0] == 'r' && input[1] == 'g' && input[2] == 'b') { if (input[3] == '(') { @@ -415,7 +415,7 @@ namespace { using ColorFromHSVStringReturnType = std::pair; [[nodiscard]] constexpr const_utils::expected - get_color_from_hsv_string(const char* input, std::size_t) { //NOLINT(readability-function-cognitive-complexity + get_color_from_hsv_string(const char* input, std::size_t) { if (input[0] == 'h' && input[1] == 's' && input[2] == 'v') { if (input[3] == '(') { diff --git a/src/helper/errors.cpp b/src/helper/errors.cpp index a21f9a65..f0221703 100644 --- a/src/helper/errors.cpp +++ b/src/helper/errors.cpp @@ -8,9 +8,15 @@ helper::GeneralError::GeneralError(std::string&& message, error::Severity severi : m_message{ std::move(message) }, m_severity{ severity } { } -helper::GeneralError::GeneralError(const GeneralError& error) noexcept - : m_message{ error.message() }, - m_severity{ error.severity() } { } +helper::GeneralError::~GeneralError() = default; + +helper::GeneralError::GeneralError(const GeneralError& error) noexcept = default; +[[nodiscard]] helper::GeneralError& helper::GeneralError::operator=(const GeneralError& error) noexcept = default; + +helper::GeneralError::GeneralError(GeneralError&& error) noexcept = default; + +[[nodiscard]] helper::GeneralError& helper::GeneralError::operator=(GeneralError&& error) noexcept = default; + [[nodiscard]] const std::string& helper::GeneralError::message() const { return m_message; diff --git a/src/helper/errors.hpp b/src/helper/errors.hpp index 7b65e486..f1c6550f 100644 --- a/src/helper/errors.hpp +++ b/src/helper/errors.hpp @@ -18,29 +18,37 @@ namespace helper { public: GeneralError(const std::string& message, error::Severity severity) noexcept; + GeneralError(std::string&& message, error::Severity severity) noexcept; + + ~GeneralError(); + GeneralError(const GeneralError& error) noexcept; + [[nodiscard]] GeneralError& operator=(const GeneralError& error) noexcept; + + GeneralError(GeneralError&& error) noexcept; + [[nodiscard]] GeneralError& operator=(GeneralError&& error) noexcept; [[nodiscard]] const std::string& message() const; [[nodiscard]] error::Severity severity() const; }; struct FatalError : public GeneralError { - FatalError(const std::string& message) noexcept; + explicit FatalError(const std::string& message) noexcept; - FatalError(std::string&& message) noexcept; + explicit FatalError(std::string&& message) noexcept; }; struct MajorError : public GeneralError { - MajorError(const std::string& message) noexcept; + explicit MajorError(const std::string& message) noexcept; - MajorError(std::string&& message) noexcept; + explicit MajorError(std::string&& message) noexcept; }; struct MinorError : public GeneralError { - MinorError(const std::string& message) noexcept; + explicit MinorError(const std::string& message) noexcept; - MinorError(std::string&& message) noexcept; + explicit MinorError(std::string&& message) noexcept; }; using InitializationError = FatalError; diff --git a/src/input/keyboard_input.cpp b/src/input/keyboard_input.cpp index 72c1dc14..b4f4e88e 100644 --- a/src/input/keyboard_input.cpp +++ b/src/input/keyboard_input.cpp @@ -95,10 +95,7 @@ void input::KeyboardGameInput::update(SimulationStep simulation_step_index) { GameInput::update(simulation_step_index); } -helper::optional -input::KeyboardGameInput::sdl_event_to_input_event( // NOLINT(readability-function-cognitive-complexity) - const SDL_Event& event -) const { +helper::optional input::KeyboardGameInput::sdl_event_to_input_event(const SDL_Event& event) const { if (event.type == SDL_KEYDOWN and event.key.repeat == 0) { const auto key = SDL::Key{ event.key.keysym }; if (key == m_settings.rotate_left) { diff --git a/src/input/touch_input.cpp b/src/input/touch_input.cpp index 279be197..5db6f16b 100644 --- a/src/input/touch_input.cpp +++ b/src/input/touch_input.cpp @@ -26,10 +26,7 @@ void input::TouchGameInput::update(SimulationStep simulation_step_index) { GameInput::update(simulation_step_index); } -helper::optional -input::TouchGameInput::sdl_event_to_input_event( // NOLINT(readability-function-cognitive-complexity) - const SDL_Event& event -) { +helper::optional input::TouchGameInput::sdl_event_to_input_event(const SDL_Event& event) { //TODO: /* if (event.tfinger.touchId != m_id) { diff --git a/src/manager/sdl_key.cpp b/src/manager/sdl_key.cpp index b061b3ca..3322b56a 100644 --- a/src/manager/sdl_key.cpp +++ b/src/manager/sdl_key.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include diff --git a/src/recordings/additional_information.cpp b/src/recordings/additional_information.cpp index e4c62984..0d753a05 100644 --- a/src/recordings/additional_information.cpp +++ b/src/recordings/additional_information.cpp @@ -77,9 +77,9 @@ recorder::InformationValue::to_bytes( // NOLINT(misc-no-recursion) typedef union { u32 original_value; float value; - } float_conversion; + } FloatConversion; - const float_conversion conversion_value{ .value = as() }; + const FloatConversion conversion_value{ .value = as() }; helper::writer::append_value(bytes, conversion_value.original_value); return bytes; } @@ -91,9 +91,9 @@ recorder::InformationValue::to_bytes( // NOLINT(misc-no-recursion) typedef union { u64 original_value; double value; - } double_conversion; + } DoubleConversion; - const double_conversion conversion_value{ .value = as() }; + const DoubleConversion conversion_value{ .value = as() }; helper::writer::append_value(bytes, conversion_value.original_value); return bytes; } @@ -232,11 +232,11 @@ helper::expected recorder::InformationValue::read_stri } -helper::expected recorder::InformationValue:: - read_value_from_istream( // NOLINT(readability-function-cognitive-complexity,misc-no-recursion) - std::istream& istream, - u32 recursion_depth - ) { +helper::expected +recorder::InformationValue::read_value_from_istream( // NOLINT(misc-no-recursion) + std::istream& istream, + u32 recursion_depth +) { const auto magic_byte = helper::reader::read_from_istream>(istream); if (not magic_byte.has_value()) { return helper::unexpected{ "unable to read magic byte" }; @@ -262,9 +262,9 @@ helper::expected recorder::InformationV typedef union { u32 original_value; float value; - } float_conversion; + } FloatConversion; - const float_conversion raw_float_value{ .original_value = raw_float.value() }; + const FloatConversion raw_float_value{ .original_value = raw_float.value() }; return recorder::InformationValue{ raw_float_value.value }; } @@ -278,9 +278,9 @@ helper::expected recorder::InformationV typedef union { u64 original_value; double value; - } double_conversion; + } DoubleConversion; - const double_conversion raw_double_value{ .original_value = raw_double.value() }; + const DoubleConversion raw_double_value{ .original_value = raw_double.value() }; return recorder::InformationValue{ raw_double_value.value }; } diff --git a/src/recordings/recording_reader.cpp b/src/recordings/recording_reader.cpp index 052d0ead..6ed6596b 100644 --- a/src/recordings/recording_reader.cpp +++ b/src/recordings/recording_reader.cpp @@ -101,8 +101,7 @@ recorder::RecordingReader::get_header_from_path(const std::filesystem::path& pat ); } -helper::expected -recorder::RecordingReader::from_path( // NOLINT(readability-function-cognitive-complexity) +helper::expected recorder::RecordingReader::from_path( const std::filesystem::path& path ) { diff --git a/src/recordings/tetrion_snapshot.cpp b/src/recordings/tetrion_snapshot.cpp index 869f7804..0dff1256 100644 --- a/src/recordings/tetrion_snapshot.cpp +++ b/src/recordings/tetrion_snapshot.cpp @@ -59,13 +59,13 @@ helper::expected TetrionSnapshot::from_istream(std MinoStack mino_stack{}; for (MinoCount i = 0; i < num_minos.value(); ++i) { - const auto x = helper::reader::read_from_istream(istream); - if (not x.has_value()) { + const auto x_coord = helper::reader::read_from_istream(istream); + if (not x_coord.has_value()) { return helper::unexpected{ "unable to read x coordinate of mino from snapshot" }; } - const auto y = helper::reader::read_from_istream(istream); - if (not y.has_value()) { + const auto y_coord = helper::reader::read_from_istream(istream); + if (not y_coord.has_value()) { return helper::unexpected{ "unable to read y coordinate of mino from snapshot" }; } @@ -81,7 +81,7 @@ helper::expected TetrionSnapshot::from_istream(std }; } - mino_stack.set(shapes::AbstractPoint(x.value(), y.value()), maybe_type.value()); + mino_stack.set(shapes::AbstractPoint(x_coord.value(), y_coord.value()), maybe_type.value()); } @@ -191,10 +191,10 @@ helper::expected TetrionSnapshot::compare_to(const TetrionSna } if (m_mino_stack != other.m_mino_stack) { - std::stringstream ss; - ss << m_mino_stack << " vs. " << other.m_mino_stack; + std::stringstream string_stream{}; + string_stream << m_mino_stack << " vs. " << other.m_mino_stack; - return helper::unexpected{ fmt::format("mino stacks do not match:\n {}", ss.str()) }; + return helper::unexpected{ fmt::format("mino stacks do not match:\n {}", string_stream.str()) }; } return true; diff --git a/src/ui/components/abstract_slider.hpp b/src/ui/components/abstract_slider.hpp index 25557daf..428d296e 100644 --- a/src/ui/components/abstract_slider.hpp +++ b/src/ui/components/abstract_slider.hpp @@ -91,11 +91,8 @@ namespace ui { } - Widget::EventHandleResult handle_event( - const std::shared_ptr& input_manager, - const SDL_Event& event - ) // NOLINT(readability-function-cognitive-complexity) - override { + Widget::EventHandleResult + handle_event(const std::shared_ptr& input_manager, const SDL_Event& event) override { Widget::EventHandleResult handled = false; const auto navigation_event = input_manager->get_navigation_event(event); diff --git a/src/ui/components/color_picker.cpp b/src/ui/components/color_picker.cpp index 91a28b2e..b487b736 100644 --- a/src/ui/components/color_picker.cpp +++ b/src/ui/components/color_picker.cpp @@ -149,10 +149,7 @@ void detail::ColorCanvas::draw_pseudo_circle(const ServiceProvider& service_prov } helper::BoolWrapper> -detail::ColorCanvas::handle_event( //NOLINT(readability-function-cognitive-complexity) - const std::shared_ptr& input_manager, - const SDL_Event& event -) { +detail::ColorCanvas::handle_event(const std::shared_ptr& input_manager, const SDL_Event& event) { Widget::EventHandleResult handled = false; const auto fill_rect = layout().get_rect(); @@ -261,16 +258,17 @@ void detail::ColorCanvas::redraw_texture() { m_service_provider->renderer().set_render_target(*m_texture); - const auto w = fill_rect.width(); - const auto h = fill_rect.height(); + const auto width = fill_rect.width(); + const auto height = fill_rect.height(); const auto hue = m_current_color.h; - //TODO: try to speed this up, since it is a performance bottle neck, if hovering like a madman (xD) over the color slider - for (u32 y = 0; y < h; y++) { - const auto v = 1.0 - (static_cast(y) / static_cast(h)); - for (u32 x = 0; x < w; x++) { - const Color color = HSVColor(hue, static_cast(x) / static_cast(w), v).to_rgb_color(); + //TODO(Totto): try to speed this up, since it is a performance bottle neck, if hovering like a madman (xD) over the color slider + for (u32 y = 0; y < height; y++) { + const auto value = 1.0 - (static_cast(y) / static_cast(height)); + for (u32 x = 0; x < width; x++) { + const Color color = + HSVColor(hue, static_cast(x) / static_cast(width), value).to_rgb_color(); m_service_provider->renderer().draw_pixel(shapes::UPoint{ x, y }, color); } @@ -293,7 +291,7 @@ ui::ColorPicker::ColorPicker( m_mode{ ColorMode::RGB }, m_callback{ std::move(callback) } { - //TODO: add alpha slider at the side + //TODO(Totto): add alpha slider at the side constexpr double main_rect_height = 0.8; @@ -459,10 +457,7 @@ void ui::ColorPicker::render(const ServiceProvider& service_provider) const { } helper::BoolWrapper> -ui::ColorPicker::handle_event( //NOLINT(readability-function-cognitive-complexity) - const std::shared_ptr& input_manager, - const SDL_Event& event -) { +ui::ColorPicker::handle_event(const std::shared_ptr& input_manager, const SDL_Event& event) { auto handled = m_color_slider->handle_event(input_manager, event); diff --git a/src/ui/components/textinput.cpp b/src/ui/components/textinput.cpp index 34da52fa..ede08679 100644 --- a/src/ui/components/textinput.cpp +++ b/src/ui/components/textinput.cpp @@ -102,10 +102,7 @@ void ui::TextInput::render(const ServiceProvider& service_provider) const { } helper::BoolWrapper> -ui::TextInput::handle_event( // NOLINT(readability-function-cognitive-complexity) - const std::shared_ptr& input_manager, - const SDL_Event& event -) { +ui::TextInput::handle_event(const std::shared_ptr& input_manager, const SDL_Event& event) { //TODO: if already has focus, position cursor there, where we clicked if (const auto hover_result = detect_hover(input_manager, event); hover_result) { @@ -246,7 +243,7 @@ void ui::TextInput::set_text(const std::string& text) { return m_text; } -void ui::TextInput::recalculate_textures(bool text_changed) { //NOLINT(readability-function-cognitive-complexity) +void ui::TextInput::recalculate_textures(bool text_changed) { const auto& renderer = m_service_provider->renderer(); @@ -308,17 +305,17 @@ void ui::TextInput::recalculate_textures(bool text_changed) { //NOLINT(readabili utf8::append(utf8::next(current_iterator, m_text.end()), sub_string); } - int w = 0; - int h = 0; - const int result = TTF_SizeUTF8(m_font.get(), sub_string.c_str(), &w, &h); + int width = 0; + int height = 0; + const int result = TTF_SizeUTF8(m_font.get(), sub_string.c_str(), &width, &height); if (result < 0) { throw helper::FatalError{ fmt::format("Error during SDL_TTF_SizeUTF8: {}", SDL_GetError()) }; } - const double ratio_sub_string = static_cast(h) / static_cast(fill_rect().height()); + const double ratio_sub_string = static_cast(height) / static_cast(fill_rect().height()); - cursor_offset = static_cast(static_cast(w) / ratio_sub_string); + cursor_offset = static_cast(static_cast(width) / ratio_sub_string); } m_cursor_rect = (unmoved_cursor >> fill_rect().top_left) >> shapes::UPoint{ cursor_offset, 0 }; diff --git a/src/ui/components/textinput.hpp b/src/ui/components/textinput.hpp index 850b6559..74300a5a 100644 --- a/src/ui/components/textinput.hpp +++ b/src/ui/components/textinput.hpp @@ -62,11 +62,8 @@ namespace ui { //TODO: how to handle text limits (since texture for texts on the gpu can't get unlimitedly big, maybe use software texture?) void render(const ServiceProvider& service_provider) const override; - Widget::EventHandleResult handle_event( - const std::shared_ptr& input_manager, - const SDL_Event& event - ) // NOLINT(readability-function-cognitive-complexity) - override; + Widget::EventHandleResult + handle_event(const std::shared_ptr& input_manager, const SDL_Event& event) override; void set_text(const std::string& text); diff --git a/src/ui/layouts/focus_layout.cpp b/src/ui/layouts/focus_layout.cpp index a61faf1e..ecc5b214 100644 --- a/src/ui/layouts/focus_layout.cpp +++ b/src/ui/layouts/focus_layout.cpp @@ -93,10 +93,7 @@ ui::Widget::EventHandleResult ui::FocusLayout::handle_focus_change_events( } [[nodiscard]] helper::optional -ui::FocusLayout::handle_event_result( // NOLINT(readability-function-cognitive-complexity) - const helper::optional& result, - Widget* widget -) { +ui::FocusLayout::handle_event_result(const helper::optional& result, Widget* widget) { if (not result.has_value()) { return helper::nullopt; diff --git a/src/ui/layouts/scroll_layout.cpp b/src/ui/layouts/scroll_layout.cpp index 5c5cfba7..a769deaa 100644 --- a/src/ui/layouts/scroll_layout.cpp +++ b/src/ui/layouts/scroll_layout.cpp @@ -107,10 +107,8 @@ void ui::ScrollLayout::render(const ServiceProvider& service_provider) const { } } -ui::Widget::EventHandleResult ui::ScrollLayout::handle_event( // NOLINT(readability-function-cognitive-complexity) - const std::shared_ptr& input_manager, - const SDL_Event& event -) { +ui::Widget::EventHandleResult +ui::ScrollLayout::handle_event(const std::shared_ptr& input_manager, const SDL_Event& event) { Widget::EventHandleResult handled = handle_focus_change_events(input_manager, event); @@ -173,7 +171,7 @@ ui::Widget::EventHandleResult ui::ScrollLayout::handle_event( // NOLINT(readabil handled = true; } - //TODO: support touch screen scrolling too, factor this out into the input manager + //TODO(Totto): support touch screen scrolling too, factor this out into the input manager } else if (event.type == SDL_MOUSEWHEEL) { // attention the mouse direction changes (it's called natural scrolling on macos/ windows / linux) are not detected by sdl until restart, and here we use the correct scroll behaviour, as the user configured the mouse in it's OS diff --git a/src/ui/layouts/tile_layout.cpp b/src/ui/layouts/tile_layout.cpp index 4b8c4ba3..dcfa4142 100644 --- a/src/ui/layouts/tile_layout.cpp +++ b/src/ui/layouts/tile_layout.cpp @@ -8,11 +8,8 @@ void ui::TileLayout::render(const ServiceProvider& service_provider) const { } } -ui::Widget::EventHandleResult ui::TileLayout::handle_event( - const std::shared_ptr& input_manager, - const SDL_Event& event -) // NOLINT(readability-function-cognitive-complexity) -{ +ui::Widget::EventHandleResult +ui::TileLayout::handle_event(const std::shared_ptr& input_manager, const SDL_Event& event) { Widget::EventHandleResult handled = handle_focus_change_events(input_manager, event); if (handled) { @@ -54,8 +51,8 @@ ui::Widget::EventHandleResult ui::TileLayout::handle_event( const auto start_point = layout().get_rect().top_left; - u32 x = start_point.x + margin.first; - u32 y = start_point.y + margin.second; + u32 x_pos = start_point.x + margin.first; + u32 y_pos = start_point.y + margin.second; u32 width = layout().get_rect().width() - (margin.first * 2); u32 height = layout().get_rect().height() - (margin.second * 2); @@ -70,7 +67,7 @@ ui::Widget::EventHandleResult ui::TileLayout::handle_event( : static_cast(width * steps.at(index)) - gap.get_margin() / 2); width = current_end - previous_start; - x += previous_start; + x_pos += previous_start; } else { const auto previous_start = index == 0 ? 0 : static_cast(height * steps.at(index - 1)) + gap.get_margin() / 2; @@ -82,13 +79,13 @@ ui::Widget::EventHandleResult ui::TileLayout::handle_event( : static_cast(height * steps.at(index)) - gap.get_margin() / 2); height = current_end - previous_start; - y += previous_start; + y_pos += previous_start; } return AbsolutLayout{ - x, - y, + x_pos, + y_pos, width, height, }; diff --git a/src/ui/layouts/tile_layout.hpp b/src/ui/layouts/tile_layout.hpp index 7d75c8c3..89e103c0 100644 --- a/src/ui/layouts/tile_layout.hpp +++ b/src/ui/layouts/tile_layout.hpp @@ -51,11 +51,8 @@ namespace ui { void render(const ServiceProvider& service_provider) const override; - Widget::EventHandleResult handle_event( - const std::shared_ptr& input_manager, - const SDL_Event& event - ) // NOLINT(readability-function-cognitive-complexity) - override; + Widget::EventHandleResult + handle_event(const std::shared_ptr& input_manager, const SDL_Event& event) override; private: [[nodiscard]] Layout get_layout_for_index(u32 index) override; diff --git a/tests/core/color.cpp b/tests/core/color.cpp index a51cfc5a..1742c548 100644 --- a/tests/core/color.cpp +++ b/tests/core/color.cpp @@ -9,18 +9,18 @@ #include namespace { - using ForeachCallback = std::function; + using ForeachCallback = std::function; void foreach_loop(const ForeachCallback& callback) { - u8 r{ 0 }; - u8 g{ 0 }; - u8 b{ 0 }; + u8 red{ 0 }; + u8 green{ 0 }; + u8 blue{ 0 }; do { // NOLINT(cppcoreguidelines-avoid-do-while) do { // NOLINT(cppcoreguidelines-avoid-do-while) do { // NOLINT(cppcoreguidelines-avoid-do-while) - callback(r, g, b); - } while (r++ != 255); - } while (g++ != 255); - } while (b++ != 255); + callback(red, green, blue); + } while (red++ != 255); + } while (green++ != 255); + } while (blue++ != 255); } } // namespace @@ -45,20 +45,21 @@ namespace color { void PrintTo(const SerializeMode& value, std::ostream* os) { *os << magic_enum::enum_name(value); } + } TEST(Color, DefaultConstruction) { - const auto c1 = Color{}; - const auto c2 = Color{ 0, 0, 0, 0 }; - ASSERT_EQ(c1, c2); + const auto color1 = Color{}; + const auto color2 = Color{ 0, 0, 0, 0 }; + ASSERT_EQ(color1, color2); } TEST(Color, ConstructorProperties) { - foreach_loop([](u8 r, u8 g, u8 b) { - const auto c1 = Color{ r, g, b }; - const auto c2 = Color{ r, g, b, 0xFF }; - ASSERT_EQ(c1, c2); + foreach_loop([](u8 red, u8 green, u8 blue) { + const auto color1 = Color{ red, green, blue }; + const auto color2 = Color{ red, green, blue, 0xFF }; + ASSERT_EQ(color1, color2); }); } @@ -163,9 +164,9 @@ TEST(Color, FromStringInvalid) { TEST(HSVColor, DefaultConstruction) { - const auto c1 = HSVColor{}; - const auto c2 = HSVColor{ 0, 0, 0, 0 }; - ASSERT_EQ(c1, c2); + const auto color1 = HSVColor{}; + const auto color2 = HSVColor{ 0, 0, 0, 0 }; + ASSERT_EQ(color1, color2); } TEST(HSVColor, ConstructorProperties) { @@ -179,9 +180,9 @@ TEST(HSVColor, ConstructorProperties) { }; for (const auto& [h, s, v] : values) { - const auto c1 = HSVColor{ h, s, v }; - const auto c2 = HSVColor{ h, s, v, 0xFF }; - ASSERT_EQ(c1, c2); + const auto color1 = HSVColor{ h, s, v }; + const auto color2 = HSVColor{ h, s, v, 0xFF }; + ASSERT_EQ(color1, color2); } } @@ -209,7 +210,7 @@ TEST(HSVColor, InvalidConstructors) { #endif -TEST(ColorConversion, HSV_to_RGB_to_HSV) { //NOLINT(readability-function-cognitive-complexity) +TEST(ColorConversion, HSVtoRGBtoHSV) { #if COLOR_TEST_MODE == 0 const std::vector colors{ @@ -255,7 +256,7 @@ TEST(ColorConversion, HSV_to_RGB_to_HSV) { //NOLINT(readability-function-cogniti } -TEST(ColorConversion, RGG_to_HSV_to_RGB) { //NOLINT(readability-function-cognitive-complexity) +TEST(ColorConversion, RGG_to_HSV_to_RGB) { #if COLOR_TEST_MODE == 0 const std::vector colors{ diff --git a/tests/graphics/sdl_key.cpp b/tests/graphics/sdl_key.cpp index fdaea975..d15c6045 100644 --- a/tests/graphics/sdl_key.cpp +++ b/tests/graphics/sdl_key.cpp @@ -3,7 +3,6 @@ #include "helper/expected.hpp" #include "utils/helper.hpp" -#include "gtest/gtest.h" #include #include #include From 9bef844d629a7f05fc7e441fe5dafb06078979ed Mon Sep 17 00:00:00 2001 From: Totto16 Date: Wed, 15 May 2024 18:43:20 +0200 Subject: [PATCH 12/13] clang-tidy: fix more errors --- .clang-tidy | 2 +- src/game/tetrion.cpp | 2 +- src/game/tetrion.hpp | 2 +- .../settings_menu/color_setting_row.cpp | 4 +- src/ui/components/abstract_slider.hpp | 10 ++- src/ui/components/button.hpp | 9 ++- src/ui/components/color_picker.cpp | 4 +- src/ui/components/image_button.cpp | 2 +- src/ui/components/text_button.cpp | 2 +- src/ui/focusable.hpp | 6 +- src/ui/hoverable.hpp | 2 +- src/ui/layout.hpp | 68 +++++++++++-------- 12 files changed, 69 insertions(+), 44 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 816282d7..9a892891 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,6 +1,6 @@ # taken from https://github.com/cpp-linter/cpp-linter-action/blob/main/demo/.clang-tidy --- -Checks: "clang-diagnostic-*,clang-analyzer-*,bugprone-*,misc-*,performance-*,readability-*,portability-*,modernize-*,cppcoreguidelines-*,google-*,llvm-*,cert-*,-modernize-use-trailing-return-type,-bugprone-argument-comment,-misc-include-cleaner,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-readability-avoid-nested-conditional-operator,-llvm-namespace-comment" +Checks: "clang-diagnostic-*,clang-analyzer-*,bugprone-*,misc-*,performance-*,readability-*,portability-*,modernize-*,cppcoreguidelines-*,google-*,llvm-*,cert-*,-modernize-use-trailing-return-type,-bugprone-argument-comment,-misc-include-cleaner,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-readability-avoid-nested-conditional-operator,-llvm-namespace-comment,-llvm-header-guard" WarningsAsErrors: "" HeaderFilterRegex: "oopetris/src/.*" FormatStyle: "file" diff --git a/src/game/tetrion.cpp b/src/game/tetrion.cpp index e0f8168e..ec6dea8a 100644 --- a/src/game/tetrion.cpp +++ b/src/game/tetrion.cpp @@ -32,7 +32,7 @@ Tetrion::Tetrion( m_level{ starting_level }, m_tetrion_index{ tetrion_index }, m_next_gravity_simulation_step_index{ get_gravity_delay_frames() }, - main_layout{ + m_main_layout{ utils::size_t_identity<2>(), 0, ui::Direction::Vertical, diff --git a/src/game/tetrion.hpp b/src/game/tetrion.hpp index f6588599..83f8a3ae 100644 --- a/src/game/tetrion.hpp +++ b/src/game/tetrion.hpp @@ -76,7 +76,7 @@ struct Tetrion final : public ui::Widget { std::array, num_preview_tetrominos> m_preview_tetrominos{}; u8 m_tetrion_index; u64 m_next_gravity_simulation_step_index; - ui::TileLayout main_layout; + ui::TileLayout m_main_layout; public: diff --git a/src/scenes/settings_menu/color_setting_row.cpp b/src/scenes/settings_menu/color_setting_row.cpp index bad82373..88b3bdcf 100644 --- a/src/scenes/settings_menu/color_setting_row.cpp +++ b/src/scenes/settings_menu/color_setting_row.cpp @@ -19,7 +19,7 @@ detail::ColorSettingRectangle::ColorSettingRectangle( bool is_top_level ) : Widget{ layout, ui::WidgetType::Component, is_top_level }, - Focusable{ ui::FocusHelper::FocusIDUnused() }, + Focusable{ ui::FocusHelper::focus_id_unused() }, Hoverable{ fill_rect }, m_color{ start_color }, m_fill_rect{ fill_rect } { } @@ -144,7 +144,7 @@ custom_ui::ColorSettingRow::ColorSettingRow( ui::Hoverable{ layout.get_rect() }, m_service_provider{ service_provider }, m_main_layout{ utils::size_t_identity<2>(), - ui::FocusHelper::FocusIDUnused(), + ui::FocusHelper::focus_id_unused(), ui::Direction::Horizontal, std::array{ 0.7 }, ui::RelativeMargin{ layout.get_rect(), ui::Direction::Vertical, 0.05 }, diff --git a/src/ui/components/abstract_slider.hpp b/src/ui/components/abstract_slider.hpp index 428d296e..ff057965 100644 --- a/src/ui/components/abstract_slider.hpp +++ b/src/ui/components/abstract_slider.hpp @@ -85,12 +85,18 @@ namespace ui { } } - ~AbstractSlider() override { SDL_CaptureMouse(SDL_FALSE); } + AbstractSlider(const AbstractSlider&) = default; + AbstractSlider& operator=(const AbstractSlider&) = default; + + AbstractSlider(AbstractSlider&&) noexcept = default; + AbstractSlider& operator=(AbstractSlider&&) noexcept = default; + + Widget::EventHandleResult handle_event(const std::shared_ptr& input_manager, const SDL_Event& event) override { Widget::EventHandleResult handled = false; @@ -173,7 +179,7 @@ namespace ui { handled = true; } - //TODO: this is not working, since pointer_event.has_value() is wrong in this case + //TODO(Totto): this is not working, since pointer_event.has_value() is wrong in this case } else if (event.type == SDL_MOUSEWHEEL && has_focus()) { // here we use a reverse scroll behaviour, since moving the mouse up is always considered increasing the volume, regardless of you OS setting about natural scrolling or not diff --git a/src/ui/components/button.hpp b/src/ui/components/button.hpp index 944e3e12..8367fc43 100644 --- a/src/ui/components/button.hpp +++ b/src/ui/components/button.hpp @@ -19,12 +19,13 @@ namespace ui { public: using Callback = std::function; - protected: + private: Content m_content; Callback m_callback; shapes::URect m_fill_rect; bool m_enabled; + protected: explicit Button( Content&& content, u32 focus_id, @@ -47,6 +48,10 @@ namespace ui { } } + [[nodiscard]] const Callback& callback() const { + return m_callback; + }; + public: explicit Button( Content&& content, @@ -72,7 +77,7 @@ namespace ui { void render(const ServiceProvider& service_provider) const override { - //TODO: get as input a color palette and use that! + //TODO(Totto): get as input a color palette and use that! const auto color = not m_enabled ? (has_focus() ? "#A36A6A"_c : "#919191"_c) : (has_focus() ? is_hovered() ? "#FF6A00"_c : Color::red() : is_hovered() ? "#00BBFF"_c diff --git a/src/ui/components/color_picker.cpp b/src/ui/components/color_picker.cpp index b487b736..d564fbf0 100644 --- a/src/ui/components/color_picker.cpp +++ b/src/ui/components/color_picker.cpp @@ -23,7 +23,7 @@ detail::ColorSlider::ColorSlider( const ui::Layout& layout, bool is_top_level ) - : AbstractSlider{ ui::FocusHelper::FocusIDUnused(), + : AbstractSlider{ ui::FocusHelper::focus_id_unused(), std::move(range), std::move(getter), std::move(setter), @@ -373,7 +373,7 @@ ui::ColorPicker::ColorPicker( const auto toggle_button_layout = ui::RelativeLayout{ components_fill_layout, 0.0, 0.0, toggle_button_size, 1.0 }; - const auto focus_id_unused = FocusHelper::FocusIDUnused(); + const auto focus_id_unused = FocusHelper::focus_id_unused(); const auto rgb_image_path = utils::get_assets_folder() / "icons" / "rgb_color_selector.png"; diff --git a/src/ui/components/image_button.cpp b/src/ui/components/image_button.cpp index 1d2f439a..07e10a54 100644 --- a/src/ui/components/image_button.cpp +++ b/src/ui/components/image_button.cpp @@ -24,5 +24,5 @@ ui::ImageButton::ImageButton( } { } [[nodiscard]] bool ui::ImageButton::on_clicked() const { - return m_callback(*this); + return callback()(*this); } diff --git a/src/ui/components/text_button.cpp b/src/ui/components/text_button.cpp index 07583c42..be5b8e90 100644 --- a/src/ui/components/text_button.cpp +++ b/src/ui/components/text_button.cpp @@ -62,5 +62,5 @@ ui::TextButton::TextButton( } { } [[nodiscard]] bool ui::TextButton::on_clicked() const { - return m_callback(*this); + return callback()(*this); } diff --git a/src/ui/focusable.hpp b/src/ui/focusable.hpp index a3274ccd..e0c91e40 100644 --- a/src/ui/focusable.hpp +++ b/src/ui/focusable.hpp @@ -5,20 +5,20 @@ namespace ui { - //TODO: replace this by a focus helper per scene! + //TODO(Totto): replace this by a focus helper per scene! struct FocusHelper { private: u32 m_focus_id; public: - FocusHelper(u32 start_focus_id = 0) : m_focus_id{ start_focus_id } {}; + explicit FocusHelper(u32 start_focus_id = 0) : m_focus_id{ start_focus_id } {}; [[nodiscard]] u32 focus_id() { return m_focus_id++; } // return a placeholder, that signifies, this focus id is unused - [[nodiscard]] static u32 FocusIDUnused() { + [[nodiscard]] static u32 focus_id_unused() { return static_cast(-1); } }; diff --git a/src/ui/hoverable.hpp b/src/ui/hoverable.hpp index 0257528d..7d984aa0 100644 --- a/src/ui/hoverable.hpp +++ b/src/ui/hoverable.hpp @@ -72,7 +72,7 @@ namespace ui { m_is_hovered = true; } - //TODO: this has to be used correctly, a click or focus change isn't an event, where an unhover needs to happen! + //TODO(Totto): this has to be used correctly, a click or focus change isn't an event, where an unhover needs to happen! void on_unhover() { m_is_hovered = false; } diff --git a/src/ui/layout.hpp b/src/ui/layout.hpp index 6bb75b45..e5b8e9c0 100644 --- a/src/ui/layout.hpp +++ b/src/ui/layout.hpp @@ -14,67 +14,85 @@ namespace ui { struct Layout { private: shapes::URect m_rect; - LayoutType type; + LayoutType m_type; protected: - Layout(const shapes::URect& rect, LayoutType type) : m_rect{ rect }, type{ type } { } + Layout(const shapes::URect& rect, LayoutType type) : m_rect{ rect }, m_type{ type } { } public: - Layout(const shapes::URect& rect) : m_rect{ rect }, type{ LayoutType::Raw } { } + explicit Layout(const shapes::URect& rect) : m_rect{ rect }, m_type{ LayoutType::Raw } { } [[nodiscard]] const shapes::URect& get_rect() const { return m_rect; } [[nodiscard]] bool is_full_screen() const { - return type == LayoutType::FullScreen; + return m_type == LayoutType::FullScreen; } }; struct AbsolutLayout : public Layout { - AbsolutLayout(const u32 x, const u32 y, const u32 width, const u32 height) + AbsolutLayout(const u32 start_x, const u32 start_y, const u32 width, const u32 height) : Layout{ - shapes::URect{ x, y, width, height }, + shapes::URect{ start_x, start_y, width, height }, LayoutType::Absolut } { } }; struct FullScreenLayout : public Layout { - FullScreenLayout(const shapes::URect& rect) : Layout{ rect, LayoutType::FullScreen } { } - FullScreenLayout(const Window& window) : FullScreenLayout{ window.screen_rect() } { } - FullScreenLayout(const Window* window) : FullScreenLayout{ window->screen_rect() } { } + explicit FullScreenLayout(const shapes::URect& rect) : Layout{ rect, LayoutType::FullScreen } { } + explicit FullScreenLayout(const Window& window) : FullScreenLayout{ window.screen_rect() } { } + explicit FullScreenLayout(const Window* window) : FullScreenLayout{ window->screen_rect() } { } }; struct RelativeLayout : public Layout { RelativeLayout( const shapes::URect& rect, - const double x, - const double y, + const double start_x, + const double start_y, const double width, const double height ) : Layout{ shapes::URect( - static_cast(x * static_cast(rect.width())), - static_cast(y * static_cast(rect.height())), + static_cast(start_x * static_cast(rect.width())), + static_cast(start_y * static_cast(rect.height())), static_cast(width * static_cast(rect.width())), static_cast(height * static_cast(rect.height())) ) >> rect.top_left, LayoutType::Relative } { - assert(x >= 0.0 && x <= 1.0 && "x has to be in correct percentage range!"); - assert(y >= 0.0 && y <= 1.0 && "y has to be in correct percentage range!"); + assert(start_x >= 0.0 && start_x <= 1.0 && "x has to be in correct percentage range!"); + assert(start_y >= 0.0 && start_y <= 1.0 && "y has to be in correct percentage range!"); assert(width >= 0.0 && width <= 1.0 && "width has to be in correct percentage range!"); assert(height >= 0.0 && height <= 1.0 && "height has to be in correct percentage range!"); } - RelativeLayout(const Window* window, const double x, const double y, const double width, const double height) - : RelativeLayout{ window->screen_rect(), x, y, width, height } { } - RelativeLayout(const Window& window, const double x, const double y, const double width, const double height) - : RelativeLayout{ window.screen_rect(), x, y, width, height } { } - RelativeLayout(const Layout& layout, const double x, const double y, const double width, const double height) - : RelativeLayout{ layout.get_rect(), x, y, width, height } { } + RelativeLayout( + const Window* window, + const double start_x, + const double start_y, + const double width, + const double height + ) + : RelativeLayout{ window->screen_rect(), start_x, start_y, width, height } { } + RelativeLayout( + const Window& window, + const double start_x, + const double start_y, + const double width, + const double height + ) + : RelativeLayout{ window.screen_rect(), start_x, start_y, width, height } { } + RelativeLayout( + const Layout& layout, + const double start_x, + const double start_y, + const double width, + const double height + ) + : RelativeLayout{ layout.get_rect(), start_x, start_y, width, height } { } }; @@ -83,10 +101,8 @@ namespace ui { using Alignment = std::pair; - [[nodiscard]] u32 get_horizontal_alignment_offset(const Layout& layout, AlignmentHorizontal alignment, u32 width); - [[nodiscard]] u32 get_vertical_alignment_offset(const Layout& layout, AlignmentVertical alignment, u32 height); [[nodiscard]] shapes::URect @@ -95,7 +111,6 @@ namespace ui { [[nodiscard]] std::pair ratio_helper(const std::pair& size, bool respect_ratio, const shapes::UPoint& original_ratio); - enum class Direction : u8 { Horizontal, Vertical }; struct Margin { @@ -103,8 +118,7 @@ namespace ui { u32 m_margin; public: - Margin(u32 margin) : m_margin{ margin } { } - + explicit Margin(u32 margin) : m_margin{ margin } { } [[nodiscard]] u32 get_margin() const { return m_margin; @@ -112,7 +126,7 @@ namespace ui { }; struct AbsolutMargin : public Margin { - AbsolutMargin(const u32 margin) : Margin{ margin } { } + explicit AbsolutMargin(const u32 margin) : Margin{ margin } { } }; struct RelativeMargin : public Margin { From 011b4f942276ace69f1c9d8b2d24a0af7ef8a813 Mon Sep 17 00:00:00 2001 From: Totto16 Date: Wed, 15 May 2024 23:44:49 +0200 Subject: [PATCH 13/13] clang-tidy: fix more things --- src/helper/nfd.cpp | 54 +++++++++--------- src/input/input.cpp | 13 ++--- src/input/input.hpp | 5 +- src/input/joystick_input.cpp | 11 ++-- src/input/joystick_input.hpp | 2 +- src/input/mouse_input.cpp | 7 ++- src/input/replay_input.cpp | 5 +- src/input/touch_input.cpp | 57 +++++++++++-------- src/input/touch_input.hpp | 2 +- src/manager/sdl_key.cpp | 9 ++- src/scenes/replay_game/replay_game.cpp | 2 +- src/scenes/scene.cpp | 2 +- .../settings_menu/color_setting_row.cpp | 2 +- src/scenes/settings_menu/settings_menu.cpp | 2 +- src/ui/components/color_picker.cpp | 3 +- 15 files changed, 90 insertions(+), 86 deletions(-) diff --git a/src/helper/nfd.cpp b/src/helper/nfd.cpp index b5f703dc..d31aa19c 100644 --- a/src/helper/nfd.cpp +++ b/src/helper/nfd.cpp @@ -20,22 +20,22 @@ namespace { [[nodiscard]] FilterItemType get_filter_items(const std::vector& allowed_files) { const auto size = static_cast(allowed_files.size()); - FilterItemType filterItem{ allowed_files.empty() ? nullptr : new nfdu8filteritem_t[size], - [size](const nfdu8filteritem_t* const value) { - if (value == nullptr) { - return; - } + FilterItemType filter_item{ allowed_files.empty() ? nullptr : new nfdu8filteritem_t[size], + [size](const nfdu8filteritem_t* const value) { + if (value == nullptr) { + return; + } - for (usize i = 0; i < size; ++i) { - const auto& item = - value[i]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + for (usize i = 0; i < size; ++i) { + const auto& item = + value[i]; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - delete item.name; // NOLINT(cppcoreguidelines-owning-memory) - delete item.spec; // NOLINT(cppcoreguidelines-owning-memory) - } + delete item.name; // NOLINT(cppcoreguidelines-owning-memory) + delete item.spec; // NOLINT(cppcoreguidelines-owning-memory) + } - delete[] value; // NOLINT(cppcoreguidelines-owning-memory) - } }; + delete[] value; // NOLINT(cppcoreguidelines-owning-memory) + } }; if (not allowed_files.empty()) { @@ -55,11 +55,11 @@ namespace { auto* extensions = new nfdu8char_t[extension_list_size]; // NOLINT(cppcoreguidelines-owning-memory) std::memcpy(extensions, extension_list.c_str(), extension_list_size * sizeof(nfdu8char_t)); - filterItem.get()[i] = { name, extensions }; + filter_item.get()[i] = { name, extensions }; } } - return filterItem; + return filter_item; } // namespace @@ -72,7 +72,7 @@ helper::expected helper::openFileDialog( helper::optional default_path ) { - NFD::UniquePathU8 outPath{}; + NFD::UniquePathU8 out_path{}; auto filterItem = get_filter_items(allowed_files); const auto path_deallocator = [](const nfdu8char_t* const char_value) { @@ -93,10 +93,10 @@ helper::expected helper::openFileDialog( } const nfdresult_t result = NFD::OpenDialog( - outPath, filterItem.get(), static_cast(allowed_files.size()), default_path_value.get() + out_path, filterItem.get(), static_cast(allowed_files.size()), default_path_value.get() ); if (result == NFD_OKAY) { - return std::filesystem::path{ outPath.get() }; + return std::filesystem::path{ out_path.get() }; } if (result == NFD_CANCEL) { @@ -112,7 +112,7 @@ helper::expected helper::openFileDialog( helper::optional default_path ) { - NFD::UniquePathSet outPaths{}; + NFD::UniquePathSet out_paths{}; auto filterItem = get_filter_items(allowed_files); const auto path_deallocator = [](const nfdu8char_t* const char_value) { @@ -133,20 +133,20 @@ helper::expected helper::openFileDialog( } const nfdresult_t result = NFD::OpenDialogMultiple( - outPaths, filterItem.get(), static_cast(allowed_files.size()), default_path_value.get() + out_paths, filterItem.get(), static_cast(allowed_files.size()), default_path_value.get() ); if (result == NFD_OKAY) { std::vector result_vector{}; nfdpathsetsize_t count_paths{}; - const auto temp_result = NFD::PathSet::Count(outPaths, count_paths); + const auto temp_result = NFD::PathSet::Count(out_paths, count_paths); ASSERT(temp_result == NFD_OKAY && "PathSet get count is successful"); for (nfdpathsetsize_t i = 0; i < count_paths; ++i) { - NFD::UniquePathSetPathU8 outPath{}; - const auto temp_result2 = NFD::PathSet::GetPath(outPaths, i, outPath); + NFD::UniquePathSetPathU8 out_path{}; + const auto temp_result2 = NFD::PathSet::GetPath(out_paths, i, out_path); ASSERT(temp_result2 == NFD_OKAY && "PathSet get path is successful"); - result_vector.emplace_back(outPath.get()); + result_vector.emplace_back(out_path.get()); } return result_vector; @@ -163,7 +163,7 @@ helper::expected helper::openFileDialog( helper::optional default_path ) { - NFD::UniquePathU8 outPath{}; + NFD::UniquePathU8 out_path{}; const auto path_deallocator = [](const nfdu8char_t* const char_value) { if (char_value == nullptr) { @@ -183,9 +183,9 @@ helper::expected helper::openFileDialog( std::memcpy(default_path_value.get(), str.c_str(), str_size * sizeof(nfdu8char_t)); } - const nfdresult_t result = NFD::PickFolder(outPath, default_path_value.get()); + const nfdresult_t result = NFD::PickFolder(out_path, default_path_value.get()); if (result == NFD_OKAY) { - return std::filesystem::path{ outPath.get() }; + return std::filesystem::path{ out_path.get() }; } if (result == NFD_CANCEL) { diff --git a/src/input/input.cpp b/src/input/input.cpp index 4bcb20d7..14da069c 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -13,7 +13,7 @@ #include -input::Input::Input(const std::string& name, InputType type) : m_name{ name }, m_type{ type } { } +input::Input::Input(std::string name, InputType type) : m_name{ std::move(name) }, m_type{ type } { } input::Input::~Input() = default; @@ -72,9 +72,6 @@ input::InputManager::InputManager(const std::shared_ptr& window) { input::JoyStickInputManager::discover_devices(m_inputs); } -input::InputManager::~InputManager() = default; - - [[nodiscard]] const std::vector>& input::InputManager::inputs() const { return m_inputs; } @@ -149,13 +146,13 @@ input::InputManager::~InputManager() = default; return false; } -//TODO: improve this API, to correctly use settings to determine the input to use. +//TODO(Totto): improve this API, to correctly use settings to determine the input to use. [[nodiscard]] std::shared_ptr input::InputManager::get_game_input(ServiceProvider* service_provider) { - //TODO: use smart pointer for the event dispatcher + //TODO(TODO): use smart pointer for the event dispatcher - //TODO: select the first suitable, by using the primary input method or some other settings! + //TODO(Totto): select the first suitable, by using the primary input method or some other settings! for (const auto& control : service_provider->settings_manager().settings().controls) { return std::visit( @@ -174,7 +171,7 @@ input::InputManager::~InputManager() = default; service_provider->input_manager(), event_dispatcher, joystick_settings ); - //TODO: better error handling, if this fails look forward in the + //TODO(Totto): better error handling, if this fails look forward in the if (not input.has_value()) { throw std::runtime_error("Not possible to get joystick by settings"); } diff --git a/src/input/input.hpp b/src/input/input.hpp index ddaa54a6..bab08ca2 100644 --- a/src/input/input.hpp +++ b/src/input/input.hpp @@ -32,7 +32,7 @@ namespace input { InputType m_type; public: - Input(const std::string& name, InputType type); + Input(std::string name, InputType type); virtual ~Input(); [[nodiscard]] const std::string& name() const; @@ -66,7 +66,7 @@ namespace input { struct PointerInput : Input { - PointerInput(const std::string& name); + explicit PointerInput(const std::string& name); [[nodiscard]] virtual helper::optional get_pointer_event(const SDL_Event& event) const = 0; @@ -80,7 +80,6 @@ namespace input { public: explicit InputManager(const std::shared_ptr& window); - ~InputManager(); [[nodiscard]] const std::vector>& inputs() const; diff --git a/src/input/joystick_input.cpp b/src/input/joystick_input.cpp index 240b572c..dee91229 100644 --- a/src/input/joystick_input.cpp +++ b/src/input/joystick_input.cpp @@ -62,7 +62,7 @@ input::JoystickInput::get_by_device_index(int device_index) { }; } - //TODO: add support for gamecontrollers (SDL_IsGameController) + //TODO(Totto): add support for gamecontrollers (SDL_IsGameController) const auto instance_id = SDL_JoystickInstanceID(joystick); @@ -186,7 +186,6 @@ void input::JoyStickInputManager::discover_devices(std::vector input::_3DSJoystickGameInput_Type1::sdl_event_to_in #endif -std::string json_helper::get_key_from_object(const nlohmann::json& j, const std::string& name) { +std::string json_helper::get_key_from_object(const nlohmann::json& obj, const std::string& name) { - const auto& context = j.at(name); + const auto& context = obj.at(name); std::string input; context.get_to(input); diff --git a/src/input/joystick_input.hpp b/src/input/joystick_input.hpp index 4a588d64..385081d0 100644 --- a/src/input/joystick_input.hpp +++ b/src/input/joystick_input.hpp @@ -206,7 +206,7 @@ namespace input { namespace json_helper { - [[nodiscard]] std::string get_key_from_object(const nlohmann::json& j, const std::string& name); + [[nodiscard]] std::string get_key_from_object(const nlohmann::json& obj, const std::string& name); } // namespace json_helper diff --git a/src/input/mouse_input.cpp b/src/input/mouse_input.cpp index 96a23994..b6059abb 100644 --- a/src/input/mouse_input.cpp +++ b/src/input/mouse_input.cpp @@ -31,11 +31,12 @@ input::MouseInput::MouseInput() : PointerInput("mouse") { } } -[[nodiscard]] helper::optional input::MouseInput::get_navigation_event(const SDL_Event&) const { +[[nodiscard]] helper::optional +input::MouseInput::get_navigation_event(const SDL_Event& /*event*/) const { return helper::nullopt; } -[[nodiscard]] std::string input::MouseInput::describe_navigation_event(NavigationEvent) const { +[[nodiscard]] std::string input::MouseInput::describe_navigation_event(NavigationEvent /*event*/) const { throw std::runtime_error("not supported"); } @@ -63,7 +64,7 @@ input::MouseInput::MouseInput() : PointerInput("mouse") { } return helper::nullopt; } - shapes::IPoint pos{ event.button.x, event.button.y }; + const shapes::IPoint pos{ event.button.x, event.button.y }; return input::PointerEventHelper{ pos, pointer_event }; } diff --git a/src/input/replay_input.cpp b/src/input/replay_input.cpp index da1c1501..bc05d31b 100644 --- a/src/input/replay_input.cpp +++ b/src/input/replay_input.cpp @@ -77,11 +77,12 @@ void input::ReplayGameInput::late_update(const SimulationStep simulation_step_in } -[[nodiscard]] helper::optional input::ReplayGameInput::get_menu_event(const SDL_Event&) const { +[[nodiscard]] helper::optional input::ReplayGameInput::get_menu_event(const SDL_Event& /*event*/) + const { return helper::nullopt; } -[[nodiscard]] std::string input::ReplayGameInput::describe_menu_event(MenuEvent) const { +[[nodiscard]] std::string input::ReplayGameInput::describe_menu_event(MenuEvent /*event*/) const { throw std::runtime_error("not supported"); } diff --git a/src/input/touch_input.cpp b/src/input/touch_input.cpp index 5db6f16b..80e55890 100644 --- a/src/input/touch_input.cpp +++ b/src/input/touch_input.cpp @@ -28,12 +28,12 @@ void input::TouchGameInput::update(SimulationStep simulation_step_index) { helper::optional input::TouchGameInput::sdl_event_to_input_event(const SDL_Event& event) { - //TODO: + //TODO(Totto): fix this /* if (event.tfinger.touchId != m_id) { return helper::nullopt; } */ - //TODO to handle those things better, holding has to be supported + //TODO(Totto): to handle those things better, holding has to be supported if (event.type == SDL_FINGERDOWN) { @@ -47,14 +47,14 @@ helper::optional input::TouchGameInput::sdl_event_to_input_event(con return helper::nullopt; } - const auto x = event.tfinger.x; - const auto y = event.tfinger.y; + const auto x_pos = event.tfinger.x; + const auto y_pos = event.tfinger.y; const auto timestamp = event.tfinger.timestamp; m_finger_state.insert_or_assign( finger_id, helper::optional{ - PressedState{ timestamp, x, y } + PressedState{ timestamp, x_pos, y_pos } } ); } @@ -66,24 +66,31 @@ helper::optional input::TouchGameInput::sdl_event_to_input_event(con const SDL_FingerID finger_id = event.tfinger.fingerId; - if (!m_finger_state.contains(finger_id) or !m_finger_state.at(finger_id).has_value()) { + if (!m_finger_state.contains(finger_id)) { // there are some valid reasons, this can occur now return helper::nullopt; } - const auto pressed_state = m_finger_state.at(finger_id).value(); + const auto& finger_state = m_finger_state.at(finger_id); - const auto x = event.tfinger.x; - const auto y = event.tfinger.y; + if (!finger_state.has_value()) { + return helper::nullopt; + } + + const auto& pressed_state = finger_state.value(); + + + const auto x_pos = event.tfinger.x; + const auto y_pos = event.tfinger.y; const auto timestamp = event.tfinger.timestamp; - const auto dx = x - pressed_state.x; - const auto dy = y - pressed_state.y; + const auto delta_x = x_pos - pressed_state.x; + const auto delta_y = y_pos - pressed_state.y; const auto duration = timestamp - pressed_state.timestamp; - const auto dx_abs = std::fabs(dx); - const auto dy_abs = std::fabs(dy); + const auto dx_abs = std::fabs(delta_x); + const auto dy_abs = std::fabs(delta_y); const auto threshold_x = m_settings.move_x_threshold; const auto threshold_y = m_settings.move_y_threshold; @@ -92,26 +99,26 @@ helper::optional input::TouchGameInput::sdl_event_to_input_event(con if (duration < m_settings.rotation_duration_threshold) { if (dx_abs < threshold_x and dy_abs < threshold_y) { // tap on the right side of the screen - if (x > 0.5) { + if (x_pos > 0.5) { return InputEvent::RotateRightPressed; } // tap on the left side of the screen - if (x <= 0.5) { + if (x_pos <= 0.5) { return InputEvent::RotateLeftPressed; } } } // swipe right - if (dx > threshold_x and dy_abs < threshold_y) { + if (delta_x > threshold_x and dy_abs < threshold_y) { return InputEvent::MoveRightPressed; } // swipe left - if (dx < -threshold_x and dy_abs < threshold_y) { + if (delta_x < -threshold_x and dy_abs < threshold_y) { return InputEvent::MoveLeftPressed; } // swipe down - if (dy > threshold_y and dx_abs < threshold_x) { + if (delta_y > threshold_y and dx_abs < threshold_x) { // swipe down to drop if (duration < m_settings.drop_duration_threshold) { return InputEvent::DropPressed; @@ -120,14 +127,14 @@ helper::optional input::TouchGameInput::sdl_event_to_input_event(con } // swipe up - if (dy < -threshold_y and dx_abs < threshold_x) { + if (delta_y < -threshold_y and dx_abs < threshold_x) { return InputEvent::HoldPressed; } } if (event.type == SDL_FINGERMOTION) { - //TODO support hold + //TODO(Totto): support hold } @@ -155,10 +162,10 @@ helper::optional input::TouchGameInput::sdl_event_to_input_event(con } } -input::TouchInput::TouchInput(const std::shared_ptr& window, SDL_TouchID id, const std::string& name) +input::TouchInput::TouchInput(const std::shared_ptr& window, SDL_TouchID touch_id, const std::string& name) : PointerInput{ name }, m_window{ window }, - m_id{ id } { } + m_id{ touch_id } { } [[nodiscard]] helper::expected, std::string> input::TouchInput::get_by_device_index(const std::shared_ptr& window, int device_index) { @@ -234,12 +241,12 @@ input::TouchInput::get_by_device_index(const std::shared_ptr& window, in const double x_percent = event.tfinger.x; const double y_percent = event.tfinger.y; const auto window_size = m_window->size(); - const auto x = static_cast(std::round(x_percent * window_size.x)); - const auto y = static_cast(std::round(y_percent * window_size.y)); + const auto x_pos = static_cast(std::round(x_percent * window_size.x)); + const auto y_pos = static_cast(std::round(y_percent * window_size.y)); return input::PointerEventHelper{ - shapes::IPoint{ x, y }, + shapes::IPoint{ x_pos, y_pos }, pointer_event }; } diff --git a/src/input/touch_input.hpp b/src/input/touch_input.hpp index cdb9e5a8..86fcb0d6 100644 --- a/src/input/touch_input.hpp +++ b/src/input/touch_input.hpp @@ -15,7 +15,7 @@ namespace input { SDL_TouchID m_id; public: - TouchInput(const std::shared_ptr& window, SDL_TouchID id, const std::string& name); + TouchInput(const std::shared_ptr& window, SDL_TouchID touch_id, const std::string& name); [[nodiscard]] static helper::expected, std::string> get_by_device_index(const std::shared_ptr& window, int device_index); diff --git a/src/manager/sdl_key.cpp b/src/manager/sdl_key.cpp index 3322b56a..9cf4955b 100644 --- a/src/manager/sdl_key.cpp +++ b/src/manager/sdl_key.cpp @@ -223,8 +223,7 @@ namespace { std::string to_lower_case(const std::string& input) { auto result = input; - for (size_t i = 0; i < result.size(); ++i) { - auto& elem = result.at(i); + for (auto& elem : result) { elem = static_cast(std::tolower(elem)); } @@ -234,7 +233,7 @@ namespace { // for string delimiter std::vector split_string_by_char(const std::string& start, const std::string& delimiter) { size_t pos_start = 0; - size_t pos_end; + size_t pos_end = 0; const auto delim_len = delimiter.length(); std::vector res{}; @@ -251,14 +250,14 @@ namespace { // trim from start (in place) inline void ltrim(std::string& str) { - str.erase(str.begin(), std::ranges::find_if(str, [](unsigned char ch) { return !std::isspace(ch); })); + str.erase(str.begin(), std::ranges::find_if(str, [](unsigned char chr) { return std::isspace(chr) == 0; })); } // trim from end (in place) inline void rtrim(std::string& str) { str.erase( std::ranges::find_if( - std::ranges::reverse_view(str), [](unsigned char ch) { return !std::isspace(ch); } + std::ranges::reverse_view(str), [](unsigned char chr) { return std::isspace(chr) == 0; } ).base(), str.end() ); diff --git a/src/scenes/replay_game/replay_game.cpp b/src/scenes/replay_game/replay_game.cpp index c4515649..37a580f5 100644 --- a/src/scenes/replay_game/replay_game.cpp +++ b/src/scenes/replay_game/replay_game.cpp @@ -22,7 +22,7 @@ namespace scenes { if (parameters.empty()) { throw std::runtime_error("An empty recording file isn't supported"); - } else if (parameters.size() == 1) { // NOLINT(readability-else-after-return) + } else if (parameters.size() == 1) { // NOLINT(readability-else-after-return,llvm-else-after-return) layouts.push_back(ui::RelativeLayout{ layout, 0.02, 0.01, 0.96, 0.98 }); } else if (parameters.size() == 2) { layouts.push_back(ui::RelativeLayout{ layout, 0.02, 0.01, 0.46, 0.98 }); diff --git a/src/scenes/scene.cpp b/src/scenes/scene.cpp index 46b22a39..e573efa0 100644 --- a/src/scenes/scene.cpp +++ b/src/scenes/scene.cpp @@ -42,7 +42,7 @@ namespace scenes { case SceneId::OnlineLobby: return std::make_unique(&service_provider, layout); #endif - //TODO + //TODO(Totto): implement those /* case SceneId::LocalMultiPlayerGame: return std::make_unique(&service_provider, layout); diff --git a/src/scenes/settings_menu/color_setting_row.cpp b/src/scenes/settings_menu/color_setting_row.cpp index 88b3bdcf..c4cec4f9 100644 --- a/src/scenes/settings_menu/color_setting_row.cpp +++ b/src/scenes/settings_menu/color_setting_row.cpp @@ -50,7 +50,7 @@ detail::ColorSettingRectangle::ColorSettingRectangle( void detail::ColorSettingRectangle::render(const ServiceProvider& service_provider) const { service_provider.renderer().draw_rect_filled(m_fill_rect, m_color); - //TODO: maybe use a dynamic color, to have some contrast? + //TODO(Totto): maybe use a dynamic color, to have some contrast? service_provider.renderer().draw_rect_outline(m_fill_rect, Color::white()); } helper::BoolWrapper> detail::ColorSettingRectangle::handle_event( diff --git a/src/scenes/settings_menu/settings_menu.cpp b/src/scenes/settings_menu/settings_menu.cpp index 9300d83b..8ef5286b 100644 --- a/src/scenes/settings_menu/settings_menu.cpp +++ b/src/scenes/settings_menu/settings_menu.cpp @@ -71,7 +71,7 @@ namespace scenes { }, [service_provider](double amount) { const auto mapped_amount = amount <= 0.0F ? helper::nullopt : helper::optional{ amount }; - return service_provider->music_manager().set_volume(mapped_amount, false, false); + service_provider->music_manager().set_volume(mapped_amount, false, false); }, 0.05F, std::pair{ 0.6, 1.0 }, ui::Alignment{ ui::AlignmentHorizontal::Middle, ui::AlignmentVertical::Center } diff --git a/src/ui/components/color_picker.cpp b/src/ui/components/color_picker.cpp index d564fbf0..b8c1eb7a 100644 --- a/src/ui/components/color_picker.cpp +++ b/src/ui/components/color_picker.cpp @@ -264,6 +264,7 @@ void detail::ColorCanvas::redraw_texture() { const auto hue = m_current_color.h; //TODO(Totto): try to speed this up, since it is a performance bottle neck, if hovering like a madman (xD) over the color slider + // maybe use shaders? for (u32 y = 0; y < height; y++) { const auto value = 1.0 - (static_cast(y) / static_cast(height)); for (u32 x = 0; x < width; x++) { @@ -505,7 +506,7 @@ ui::ColorPicker::handle_event(const std::shared_ptr& input_ } if (not maybe_color.has_value()) { - //TODO: maybe inform the user, that the input is incorrect? + //TODO(Totto): maybe inform the user, that the input is incorrect? //m_color_text->display_error(); // reset the text