From 140fbbc4a152887722567268e0dd7759abc1796f Mon Sep 17 00:00:00 2001 From: Krzysztof Rudnicki Date: Sun, 2 Jul 2023 16:02:11 +0200 Subject: [PATCH] feat: set up the most restrictive clang tidy settings --- .clang-tidy | 48 +++++---- breakout/breakout.cpp | 6 +- breakout/game.hpp | 41 ++++---- breakout/shader.cpp | 222 +++++++++++++++++++----------------------- breakout/texture.hpp | 59 ++++++----- clang_script.sh | 4 +- 6 files changed, 182 insertions(+), 198 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 017ba2f..f3948d0 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,28 +1,38 @@ --- -Checks: 'clang-diagnostic-*,clang-analyzer-*' +Checks: '*' WarningsAsErrors: '' HeaderFilterRegex: '' AnalyzeTemporaryDtors: false FormatStyle: none User: kuchy CheckOptions: - llvm-else-after-return.WarnOnConditionVariables: 'false' - modernize-loop-convert.MinConfidence: reasonable - modernize-replace-auto-ptr.IncludeStyle: llvm - modernize-pass-by-value.IncludeStyle: llvm - google-readability-namespace-comments.ShortNamespaceLines: '10' - google-readability-namespace-comments.SpacesBeforeComments: '2' - cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: 'true' - google-readability-braces-around-statements.ShortStatementLines: '1' - cert-err33-c.CheckedFunctions: '::aligned_alloc;::asctime_s;::at_quick_exit;::atexit;::bsearch;::bsearch_s;::btowc;::c16rtomb;::c32rtomb;::calloc;::clock;::cnd_broadcast;::cnd_init;::cnd_signal;::cnd_timedwait;::cnd_wait;::ctime_s;::fclose;::fflush;::fgetc;::fgetpos;::fgets;::fgetwc;::fopen;::fopen_s;::fprintf;::fprintf_s;::fputc;::fputs;::fputwc;::fputws;::fread;::freopen;::freopen_s;::fscanf;::fscanf_s;::fseek;::fsetpos;::ftell;::fwprintf;::fwprintf_s;::fwrite;::fwscanf;::fwscanf_s;::getc;::getchar;::getenv;::getenv_s;::gets_s;::getwc;::getwchar;::gmtime;::gmtime_s;::localtime;::localtime_s;::malloc;::mbrtoc16;::mbrtoc32;::mbsrtowcs;::mbsrtowcs_s;::mbstowcs;::mbstowcs_s;::memchr;::mktime;::mtx_init;::mtx_lock;::mtx_timedlock;::mtx_trylock;::mtx_unlock;::printf_s;::putc;::putwc;::raise;::realloc;::remove;::rename;::scanf;::scanf_s;::setlocale;::setvbuf;::signal;::snprintf;::snprintf_s;::sprintf;::sprintf_s;::sscanf;::sscanf_s;::strchr;::strerror_s;::strftime;::strpbrk;::strrchr;::strstr;::strtod;::strtof;::strtoimax;::strtok;::strtok_s;::strtol;::strtold;::strtoll;::strtoul;::strtoull;::strtoumax;::strxfrm;::swprintf;::swprintf_s;::swscanf;::swscanf_s;::thrd_create;::thrd_detach;::thrd_join;::thrd_sleep;::time;::timespec_get;::tmpfile;::tmpfile_s;::tmpnam;::tmpnam_s;::tss_create;::tss_get;::tss_set;::ungetc;::ungetwc;::vfprintf;::vfprintf_s;::vfscanf;::vfscanf_s;::vfwprintf;::vfwprintf_s;::vfwscanf;::vfwscanf_s;::vprintf_s;::vscanf;::vscanf_s;::vsnprintf;::vsnprintf_s;::vsprintf;::vsprintf_s;::vsscanf;::vsscanf_s;::vswprintf;::vswprintf_s;::vswscanf;::vswscanf_s;::vwprintf_s;::vwscanf;::vwscanf_s;::wcrtomb;::wcschr;::wcsftime;::wcspbrk;::wcsrchr;::wcsrtombs;::wcsrtombs_s;::wcsstr;::wcstod;::wcstof;::wcstoimax;::wcstok;::wcstok_s;::wcstol;::wcstold;::wcstoll;::wcstombs;::wcstombs_s;::wcstoul;::wcstoull;::wcstoumax;::wcsxfrm;::wctob;::wctrans;::wctype;::wmemchr;::wprintf_s;::wscanf;::wscanf_s;' - modernize-loop-convert.MaxCopySize: '16' - cert-dcl16-c.NewSuffixes: 'L;LL;LU;LLU' - cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField: 'false' - cert-str34-c.DiagnoseSignedUnsignedCharComparisons: 'false' - modernize-use-nullptr.NullMacros: 'NULL' - llvm-qualified-auto.AddConstToQualified: 'false' - modernize-loop-convert.NamingStyle: CamelCase - llvm-else-after-return.WarnOnUnfixable: 'false' - google-readability-function-size.StatementThreshold: '800' + - 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.LineThreshold + value: '16' + - key: google-readability-namespace-comments.ShortNamespaceLines + value: '10' + - key: google-readability-namespace-comments.SpacesBeforeComments + value: '2' + - key: modernize-loop-convert.MaxCopySize + value: '16' + - key: modernize-loop-convert.MinConfidence + value: reasonable + - 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' ... diff --git a/breakout/breakout.cpp b/breakout/breakout.cpp index dc61315..a6572f7 100644 --- a/breakout/breakout.cpp +++ b/breakout/breakout.cpp @@ -23,8 +23,7 @@ const unsigned int SCREEN_HEIGHT = 600; Game Breakout(SCREEN_WIDTH, SCREEN_HEIGHT); -int main(int argc, char *argv[]) -{ +int main(int argc, char *argv[]) { glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); @@ -110,8 +109,7 @@ int scancode, int action, int mode) { } } -void framebuffer_size_callback(GLFWwindow* window, int width, int height) -{ +void framebuffer_size_callback(GLFWwindow* window, int width, int height) { // make sure the viewport matches the new window dimensions; // note that width and // height will be significantly larger than specified on retina displays. diff --git a/breakout/game.hpp b/breakout/game.hpp index d1f3b08..62ab650 100644 --- a/breakout/game.hpp +++ b/breakout/game.hpp @@ -7,28 +7,23 @@ #include "../dependencies/include/glad/glad.h" // Represents the current state of the game -enum GameState { - GAME_ACTIVE, - GAME_MENU, - GAME_WIN +enum GameState { GAME_ACTIVE, GAME_MENU, GAME_WIN }; + +class Game { +public: + // game state + GameState State; + bool Keys[1024]; + unsigned int Width, Height; + // constructor/destructor + Game(unsigned int width, unsigned int height); + ~Game(); + // initialize game state (load all shaders/textures/levels) + void Init(); + // game loop + void ProcessInput(float dt); + void Update(float dt); + void Render(); }; -class Game -{ - public: - // game state - GameState State; - bool Keys[1024]; - unsigned int Width, Height; - // constructor/destructor - Game(unsigned int width, unsigned int height); - ~Game(); - // initialize game state (load all shaders/textures/levels) - void Init(); - // game loop - void ProcessInput(float dt); - void Update(float dt); - void Render(); -}; - -#endif // BREAKOUT_GAME_HPP_ +#endif // BREAKOUT_GAME_HPP_ diff --git a/breakout/shader.cpp b/breakout/shader.cpp index 2f48801..7098cba 100644 --- a/breakout/shader.cpp +++ b/breakout/shader.cpp @@ -5,145 +5,125 @@ #include -Shader &Shader::Use() -{ - glUseProgram(this->ID); - return *this; +Shader &Shader::Use() { + glUseProgram(this->ID); + return *this; } -void Shader::Compile(const char* vertexSource, -const char* fragmentSource, -const char* geometrySource) { - unsigned int sVertex, sFragment, gShader; - // vertex Shader - sVertex = glCreateShader(GL_VERTEX_SHADER); - glShaderSource(sVertex, 1, &vertexSource, NULL); - glCompileShader(sVertex); - checkCompileErrors(sVertex, "VERTEX"); - // fragment Shader - sFragment = glCreateShader(GL_FRAGMENT_SHADER); - glShaderSource(sFragment, 1, &fragmentSource, NULL); - glCompileShader(sFragment); - checkCompileErrors(sFragment, "FRAGMENT"); - // if geometry shader source code is given, also compile geometry shader - if (geometrySource != nullptr) { - gShader = glCreateShader(GL_GEOMETRY_SHADER); - glShaderSource(gShader, 1, &geometrySource, NULL); - glCompileShader(gShader); - checkCompileErrors(gShader, "GEOMETRY"); - } - // shader program - this->ID = glCreateProgram(); - glAttachShader(this->ID, sVertex); - glAttachShader(this->ID, sFragment); - if (geometrySource != nullptr) - glAttachShader(this->ID, gShader); - glLinkProgram(this->ID); - checkCompileErrors(this->ID, "PROGRAM"); - // delete the shaders as they're linked into our - // program now and no longer necessary - glDeleteShader(sVertex); - glDeleteShader(sFragment); - if (geometrySource != nullptr) - glDeleteShader(gShader); +void Shader::Compile(const char *vertexSource, const char *fragmentSource, + const char *geometrySource) { + unsigned int sVertex, sFragment, gShader; + // vertex Shader + sVertex = glCreateShader(GL_VERTEX_SHADER); + glShaderSource(sVertex, 1, &vertexSource, NULL); + glCompileShader(sVertex); + checkCompileErrors(sVertex, "VERTEX"); + // fragment Shader + sFragment = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(sFragment, 1, &fragmentSource, NULL); + glCompileShader(sFragment); + checkCompileErrors(sFragment, "FRAGMENT"); + // if geometry shader source code is given, also compile geometry shader + if (geometrySource != nullptr) { + gShader = glCreateShader(GL_GEOMETRY_SHADER); + glShaderSource(gShader, 1, &geometrySource, NULL); + glCompileShader(gShader); + checkCompileErrors(gShader, "GEOMETRY"); + } + // shader program + this->ID = glCreateProgram(); + glAttachShader(this->ID, sVertex); + glAttachShader(this->ID, sFragment); + if (geometrySource != nullptr) + glAttachShader(this->ID, gShader); + glLinkProgram(this->ID); + checkCompileErrors(this->ID, "PROGRAM"); + // delete the shaders as they're linked into our + // program now and no longer necessary + glDeleteShader(sVertex); + glDeleteShader(sFragment); + if (geometrySource != nullptr) + glDeleteShader(gShader); } void Shader::SetFloat(const char *name, float value, bool useShader) { - if (useShader) - this->Use(); - glUniform1f(glGetUniformLocation(this->ID, name), value); + if (useShader) + this->Use(); + glUniform1f(glGetUniformLocation(this->ID, name), value); } void Shader::SetInteger(const char *name, int value, bool useShader) { - if (useShader) - this->Use(); - glUniform1i(glGetUniformLocation(this->ID, name), value); + if (useShader) + this->Use(); + glUniform1i(glGetUniformLocation(this->ID, name), value); } void Shader::SetVector2f(const char *name, float x, float y, bool useShader) { - if (useShader) - this->Use(); - glUniform2f(glGetUniformLocation(this->ID, name), x, y); + if (useShader) + this->Use(); + glUniform2f(glGetUniformLocation(this->ID, name), x, y); } -void Shader::SetVector2f( - const char *name, - const glm::vec2 &value, - bool useShader) { - if (useShader) - this->Use(); - glUniform2f(glGetUniformLocation(this->ID, name), value.x, value.y); +void Shader::SetVector2f(const char *name, const glm::vec2 &value, + bool useShader) { + if (useShader) + this->Use(); + glUniform2f(glGetUniformLocation(this->ID, name), value.x, value.y); } -void Shader::SetVector3f( - const char *name, - float x, - float y, - float z, - bool useShader) { - if (useShader) - this->Use(); - glUniform3f(glGetUniformLocation(this->ID, name), x, y, z); +void Shader::SetVector3f(const char *name, float x, float y, float z, + bool useShader) { + if (useShader) + this->Use(); + glUniform3f(glGetUniformLocation(this->ID, name), x, y, z); } -void Shader::SetVector3f( - const char *name, - const glm::vec3 &value, - bool useShader) { - if (useShader) - this->Use(); - glUniform3f - (glGetUniformLocation(this->ID, name), - value.x, value.y, value.z); +void Shader::SetVector3f(const char *name, const glm::vec3 &value, + bool useShader) { + if (useShader) + this->Use(); + glUniform3f(glGetUniformLocation(this->ID, name), value.x, value.y, value.z); } -void Shader::SetVector4f( - const char *name, - float x, float y, float z, float w, bool useShader) { - if (useShader) - this->Use(); - glUniform4f(glGetUniformLocation(this->ID, name), x, y, z, w); +void Shader::SetVector4f(const char *name, float x, float y, float z, float w, + bool useShader) { + if (useShader) + this->Use(); + glUniform4f(glGetUniformLocation(this->ID, name), x, y, z, w); } -void Shader::SetVector4f( - const char *name, - const glm::vec4 &value, - bool useShader) { - if (useShader) - this->Use(); - glUniform4f( - glGetUniformLocation(this->ID, name), - value.x, value.y, value.z, value.w); +void Shader::SetVector4f(const char *name, const glm::vec4 &value, + bool useShader) { + if (useShader) + this->Use(); + glUniform4f(glGetUniformLocation(this->ID, name), value.x, value.y, value.z, + value.w); } -void Shader::SetMatrix4( - const char *name, - const glm::mat4 &matrix, - bool useShader) { - if (useShader) - this->Use(); - glUniformMatrix4fv( - glGetUniformLocation(this->ID, name), - 1, false, glm::value_ptr(matrix)); +void Shader::SetMatrix4(const char *name, const glm::mat4 &matrix, + bool useShader) { + if (useShader) + this->Use(); + glUniformMatrix4fv(glGetUniformLocation(this->ID, name), 1, false, + glm::value_ptr(matrix)); } - void Shader::checkCompileErrors(unsigned int object, std::string type) { - int success; - char infoLog[1024]; - if (type != "PROGRAM") { - glGetShaderiv(object, GL_COMPILE_STATUS, &success); - if (!success) { - glGetShaderInfoLog(object, 1024, NULL, infoLog); - std::cout << "| ERROR::SHADER: Compile-time error: Type: " - << type << "\n" - << infoLog - << "\n -- --------------------------------------------------- -- " - << std::endl; - } - } else { - glGetProgramiv(object, GL_LINK_STATUS, &success); - if (!success) { - glGetProgramInfoLog(object, 1024, NULL, infoLog); - std::cout << "| ERROR::Shader: Link-time error: Type: " - << type << "\n" - << infoLog - << "\n -- --------------------------------------------------- -- " - << std::endl; - } + int success; + char infoLog[1024]; + if (type != "PROGRAM") { + glGetShaderiv(object, GL_COMPILE_STATUS, &success); + if (!success) { + glGetShaderInfoLog(object, 1024, NULL, infoLog); + std::cout + << "| ERROR::SHADER: Compile-time error: Type: " << type << "\n" + << infoLog + << "\n -- --------------------------------------------------- -- " + << std::endl; } + } else { + glGetProgramiv(object, GL_LINK_STATUS, &success); + if (!success) { + glGetProgramInfoLog(object, 1024, NULL, infoLog); + std::cout + << "| ERROR::Shader: Link-time error: Type: " << type << "\n" + << infoLog + << "\n -- --------------------------------------------------- -- " + << std::endl; + } + } } -#endif // BREAKOUT_SHADER_CPP +#endif // BREAKOUT_SHADER_CPP diff --git a/breakout/texture.hpp b/breakout/texture.hpp index 423bb6a..9d665b0 100644 --- a/breakout/texture.hpp +++ b/breakout/texture.hpp @@ -6,35 +6,34 @@ // Texture2D is able to store and configure a texture in OpenGL. // It also hosts utility functions for easy management. -class Texture2D -{ - public: - // holds the ID of the texture object, - // used for all texture operations to reference to this particular texture - unsigned int ID; - // texture image dimensions - unsigned int Width, Height; - // width and height of loaded image in pixels - // texture Format - unsigned int Internal_Format; - // format of texture object - unsigned int Image_Format; - // format of loaded image - // texture configuration - unsigned int Wrap_S; - // wrapping mode on S axis - unsigned int Wrap_T; - // wrapping mode on T axis - unsigned int Filter_Min; - // filtering mode if texture pixels < screen pixels - unsigned int Filter_Max; - // filtering mode if texture pixels > screen pixels - // constructor (sets default texture modes) - Texture2D(); - // generates texture from image data - void Generate(unsigned int width, unsigned int height, unsigned char* data); - // binds the texture as the current active GL_TEXTURE_2D texture object - void Bind() const; +class Texture2D { +public: + // holds the ID of the texture object, + // used for all texture operations to reference to this particular texture + unsigned int ID; + // texture image dimensions + unsigned int Width, Height; + // width and height of loaded image in pixels + // texture Format + unsigned int Internal_Format; + // format of texture object + unsigned int Image_Format; + // format of loaded image + // texture configuration + unsigned int Wrap_S; + // wrapping mode on S axis + unsigned int Wrap_T; + // wrapping mode on T axis + unsigned int Filter_Min; + // filtering mode if texture pixels < screen pixels + unsigned int Filter_Max; + // filtering mode if texture pixels > screen pixels + // constructor (sets default texture modes) + Texture2D(); + // generates texture from image data + void Generate(unsigned int width, unsigned int height, unsigned char *data); + // binds the texture as the current active GL_TEXTURE_2D texture object + void Bind() const; }; -#endif // BREAKOUT_TEXTURE_HPP_ +#endif // BREAKOUT_TEXTURE_HPP_ diff --git a/clang_script.sh b/clang_script.sh index 6976332..cdc1a82 100755 --- a/clang_script.sh +++ b/clang_script.sh @@ -1,2 +1,4 @@ #!/bin/sh -clang-tidy --config-file=.clang-tidy --fix-errors --fix-notes -p ./build/compile_commands.json ./breakout/breakout.cpp ./breakout/game.cpp ./breakout/game.hpp ./breakout/resourceManager.cpp ./breakout/resourceManager.hpp ./breakout/shader.cpp ./breakout/shader.hpp ./breakout/texture.cpp ./breakout/texture.hpp \ No newline at end of file +clang-tidy --config-file=./.clang-tidy --fix-errors --fix-notes -p ./build/compile_commands.json ./breakout/breakout.cpp ./breakout/game.cpp ./breakout/game.hpp ./breakout/resourceManager.cpp ./breakout/resourceManager.hpp ./breakout/shader.cpp ./breakout/shader.hpp ./breakout/texture.cpp ./breakout/texture.hpp + +cpplint ./breakout/breakout.cpp ./breakout/game.cpp ./breakout/game.hpp ./breakout/resourceManager.cpp ./breakout/resourceManager.hpp ./breakout/shader.cpp ./breakout/shader.hpp ./breakout/texture.cpp ./breakout/texture.hpp \ No newline at end of file