feat: set up the most restrictive clang tidy settings

This commit is contained in:
Krzysztof Rudnicki 2023-07-02 16:02:11 +02:00
parent b2e5e1a356
commit 140fbbc4a1
6 changed files with 182 additions and 198 deletions

View File

@ -1,28 +1,38 @@
--- ---
Checks: 'clang-diagnostic-*,clang-analyzer-*' Checks: '*'
WarningsAsErrors: '' WarningsAsErrors: ''
HeaderFilterRegex: '' HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false AnalyzeTemporaryDtors: false
FormatStyle: none FormatStyle: none
User: kuchy User: kuchy
CheckOptions: CheckOptions:
llvm-else-after-return.WarnOnConditionVariables: 'false' - key: cert-dcl16-c.NewSuffixes
modernize-loop-convert.MinConfidence: reasonable value: 'L;LL;LU;LLU'
modernize-replace-auto-ptr.IncludeStyle: llvm - key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
modernize-pass-by-value.IncludeStyle: llvm value: '0'
google-readability-namespace-comments.ShortNamespaceLines: '10' - key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
google-readability-namespace-comments.SpacesBeforeComments: '2' value: '1'
cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: 'true' - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
google-readability-braces-around-statements.ShortStatementLines: '1' value: '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;' - key: google-readability-braces-around-statements.ShortStatementLines
modernize-loop-convert.MaxCopySize: '16' value: '1'
cert-dcl16-c.NewSuffixes: 'L;LL;LU;LLU' - key: google-readability-function-size.LineThreshold
cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField: 'false' value: '16'
cert-str34-c.DiagnoseSignedUnsignedCharComparisons: 'false' - key: google-readability-namespace-comments.ShortNamespaceLines
modernize-use-nullptr.NullMacros: 'NULL' value: '10'
llvm-qualified-auto.AddConstToQualified: 'false' - key: google-readability-namespace-comments.SpacesBeforeComments
modernize-loop-convert.NamingStyle: CamelCase value: '2'
llvm-else-after-return.WarnOnUnfixable: 'false' - key: modernize-loop-convert.MaxCopySize
google-readability-function-size.StatementThreshold: '800' 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'
... ...

View File

@ -23,8 +23,7 @@ const unsigned int SCREEN_HEIGHT = 600;
Game Breakout(SCREEN_WIDTH, SCREEN_HEIGHT); Game Breakout(SCREEN_WIDTH, SCREEN_HEIGHT);
int main(int argc, char *argv[]) int main(int argc, char *argv[]) {
{
glfwInit(); glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 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; // make sure the viewport matches the new window dimensions;
// note that width and // note that width and
// height will be significantly larger than specified on retina displays. // height will be significantly larger than specified on retina displays.

View File

@ -7,28 +7,23 @@
#include "../dependencies/include/glad/glad.h" #include "../dependencies/include/glad/glad.h"
// Represents the current state of the game // Represents the current state of the game
enum GameState { enum GameState { GAME_ACTIVE, GAME_MENU, GAME_WIN };
GAME_ACTIVE,
GAME_MENU, class Game {
GAME_WIN 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 #endif // BREAKOUT_GAME_HPP_
{
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_

View File

@ -5,145 +5,125 @@
#include <iostream> #include <iostream>
Shader &Shader::Use() Shader &Shader::Use() {
{ glUseProgram(this->ID);
glUseProgram(this->ID); return *this;
return *this;
} }
void Shader::Compile(const char* vertexSource, void Shader::Compile(const char *vertexSource, const char *fragmentSource,
const char* fragmentSource, const char *geometrySource) {
const char* geometrySource) { unsigned int sVertex, sFragment, gShader;
unsigned int sVertex, sFragment, gShader; // vertex Shader
// vertex Shader sVertex = glCreateShader(GL_VERTEX_SHADER);
sVertex = glCreateShader(GL_VERTEX_SHADER); glShaderSource(sVertex, 1, &vertexSource, NULL);
glShaderSource(sVertex, 1, &vertexSource, NULL); glCompileShader(sVertex);
glCompileShader(sVertex); checkCompileErrors(sVertex, "VERTEX");
checkCompileErrors(sVertex, "VERTEX"); // fragment Shader
// fragment Shader sFragment = glCreateShader(GL_FRAGMENT_SHADER);
sFragment = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(sFragment, 1, &fragmentSource, NULL);
glShaderSource(sFragment, 1, &fragmentSource, NULL); glCompileShader(sFragment);
glCompileShader(sFragment); checkCompileErrors(sFragment, "FRAGMENT");
checkCompileErrors(sFragment, "FRAGMENT"); // if geometry shader source code is given, also compile geometry shader
// if geometry shader source code is given, also compile geometry shader if (geometrySource != nullptr) {
if (geometrySource != nullptr) { gShader = glCreateShader(GL_GEOMETRY_SHADER);
gShader = glCreateShader(GL_GEOMETRY_SHADER); glShaderSource(gShader, 1, &geometrySource, NULL);
glShaderSource(gShader, 1, &geometrySource, NULL); glCompileShader(gShader);
glCompileShader(gShader); checkCompileErrors(gShader, "GEOMETRY");
checkCompileErrors(gShader, "GEOMETRY"); }
} // shader program
// shader program this->ID = glCreateProgram();
this->ID = glCreateProgram(); glAttachShader(this->ID, sVertex);
glAttachShader(this->ID, sVertex); glAttachShader(this->ID, sFragment);
glAttachShader(this->ID, sFragment); if (geometrySource != nullptr)
if (geometrySource != nullptr) glAttachShader(this->ID, gShader);
glAttachShader(this->ID, gShader); glLinkProgram(this->ID);
glLinkProgram(this->ID); checkCompileErrors(this->ID, "PROGRAM");
checkCompileErrors(this->ID, "PROGRAM"); // delete the shaders as they're linked into our
// delete the shaders as they're linked into our // program now and no longer necessary
// program now and no longer necessary glDeleteShader(sVertex);
glDeleteShader(sVertex); glDeleteShader(sFragment);
glDeleteShader(sFragment); if (geometrySource != nullptr)
if (geometrySource != nullptr) glDeleteShader(gShader);
glDeleteShader(gShader);
} }
void Shader::SetFloat(const char *name, float value, bool useShader) { void Shader::SetFloat(const char *name, float value, bool useShader) {
if (useShader) if (useShader)
this->Use(); this->Use();
glUniform1f(glGetUniformLocation(this->ID, name), value); glUniform1f(glGetUniformLocation(this->ID, name), value);
} }
void Shader::SetInteger(const char *name, int value, bool useShader) { void Shader::SetInteger(const char *name, int value, bool useShader) {
if (useShader) if (useShader)
this->Use(); this->Use();
glUniform1i(glGetUniformLocation(this->ID, name), value); glUniform1i(glGetUniformLocation(this->ID, name), value);
} }
void Shader::SetVector2f(const char *name, float x, float y, bool useShader) { void Shader::SetVector2f(const char *name, float x, float y, bool useShader) {
if (useShader) if (useShader)
this->Use(); this->Use();
glUniform2f(glGetUniformLocation(this->ID, name), x, y); glUniform2f(glGetUniformLocation(this->ID, name), x, y);
} }
void Shader::SetVector2f( void Shader::SetVector2f(const char *name, const glm::vec2 &value,
const char *name, bool useShader) {
const glm::vec2 &value, if (useShader)
bool useShader) { this->Use();
if (useShader) glUniform2f(glGetUniformLocation(this->ID, name), value.x, value.y);
this->Use();
glUniform2f(glGetUniformLocation(this->ID, name), value.x, value.y);
} }
void Shader::SetVector3f( void Shader::SetVector3f(const char *name, float x, float y, float z,
const char *name, bool useShader) {
float x, if (useShader)
float y, this->Use();
float z, glUniform3f(glGetUniformLocation(this->ID, name), x, y, z);
bool useShader) {
if (useShader)
this->Use();
glUniform3f(glGetUniformLocation(this->ID, name), x, y, z);
} }
void Shader::SetVector3f( void Shader::SetVector3f(const char *name, const glm::vec3 &value,
const char *name, bool useShader) {
const glm::vec3 &value, if (useShader)
bool useShader) { this->Use();
if (useShader) glUniform3f(glGetUniformLocation(this->ID, name), value.x, value.y, value.z);
this->Use();
glUniform3f
(glGetUniformLocation(this->ID, name),
value.x, value.y, value.z);
} }
void Shader::SetVector4f( void Shader::SetVector4f(const char *name, float x, float y, float z, float w,
const char *name, bool useShader) {
float x, float y, float z, float w, bool useShader) { if (useShader)
if (useShader) this->Use();
this->Use(); glUniform4f(glGetUniformLocation(this->ID, name), x, y, z, w);
glUniform4f(glGetUniformLocation(this->ID, name), x, y, z, w);
} }
void Shader::SetVector4f( void Shader::SetVector4f(const char *name, const glm::vec4 &value,
const char *name, bool useShader) {
const glm::vec4 &value, if (useShader)
bool useShader) { this->Use();
if (useShader) glUniform4f(glGetUniformLocation(this->ID, name), value.x, value.y, value.z,
this->Use(); value.w);
glUniform4f(
glGetUniformLocation(this->ID, name),
value.x, value.y, value.z, value.w);
} }
void Shader::SetMatrix4( void Shader::SetMatrix4(const char *name, const glm::mat4 &matrix,
const char *name, bool useShader) {
const glm::mat4 &matrix, if (useShader)
bool useShader) { this->Use();
if (useShader) glUniformMatrix4fv(glGetUniformLocation(this->ID, name), 1, false,
this->Use(); glm::value_ptr(matrix));
glUniformMatrix4fv(
glGetUniformLocation(this->ID, name),
1, false, glm::value_ptr(matrix));
} }
void Shader::checkCompileErrors(unsigned int object, std::string type) { void Shader::checkCompileErrors(unsigned int object, std::string type) {
int success; int success;
char infoLog[1024]; char infoLog[1024];
if (type != "PROGRAM") { if (type != "PROGRAM") {
glGetShaderiv(object, GL_COMPILE_STATUS, &success); glGetShaderiv(object, GL_COMPILE_STATUS, &success);
if (!success) { if (!success) {
glGetShaderInfoLog(object, 1024, NULL, infoLog); glGetShaderInfoLog(object, 1024, NULL, infoLog);
std::cout << "| ERROR::SHADER: Compile-time error: Type: " std::cout
<< type << "\n" << "| ERROR::SHADER: Compile-time error: Type: " << type << "\n"
<< infoLog << infoLog
<< "\n -- --------------------------------------------------- -- " << "\n -- --------------------------------------------------- -- "
<< std::endl; << 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;
}
} }
} 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

View File

@ -6,35 +6,34 @@
// Texture2D is able to store and configure a texture in OpenGL. // Texture2D is able to store and configure a texture in OpenGL.
// It also hosts utility functions for easy management. // It also hosts utility functions for easy management.
class Texture2D class Texture2D {
{ public:
public: // holds the ID of the texture object,
// holds the ID of the texture object, // used for all texture operations to reference to this particular texture
// used for all texture operations to reference to this particular texture unsigned int ID;
unsigned int ID; // texture image dimensions
// texture image dimensions unsigned int Width, Height;
unsigned int Width, Height; // width and height of loaded image in pixels
// width and height of loaded image in pixels // texture Format
// texture Format unsigned int Internal_Format;
unsigned int Internal_Format; // format of texture object
// format of texture object unsigned int Image_Format;
unsigned int Image_Format; // format of loaded image
// format of loaded image // texture configuration
// texture configuration unsigned int Wrap_S;
unsigned int Wrap_S; // wrapping mode on S axis
// wrapping mode on S axis unsigned int Wrap_T;
unsigned int Wrap_T; // wrapping mode on T axis
// wrapping mode on T axis unsigned int Filter_Min;
unsigned int Filter_Min; // filtering mode if texture pixels < screen pixels
// filtering mode if texture pixels < screen pixels unsigned int Filter_Max;
unsigned int Filter_Max; // filtering mode if texture pixels > screen pixels
// filtering mode if texture pixels > screen pixels // constructor (sets default texture modes)
// constructor (sets default texture modes) Texture2D();
Texture2D(); // generates texture from image data
// generates texture from image data void Generate(unsigned int width, unsigned int height, unsigned char *data);
void Generate(unsigned int width, unsigned int height, unsigned char* data); // binds the texture as the current active GL_TEXTURE_2D texture object
// binds the texture as the current active GL_TEXTURE_2D texture object void Bind() const;
void Bind() const;
}; };
#endif // BREAKOUT_TEXTURE_HPP_ #endif // BREAKOUT_TEXTURE_HPP_

View File

@ -1,2 +1,4 @@
#!/bin/sh #!/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 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