From 6c5af0ef42b16ac7a35b9ebb2369dde437a6d639 Mon Sep 17 00:00:00 2001 From: dekrain Date: Fri, 30 Dec 2022 01:12:25 +0100 Subject: [PATCH 1/6] Add formatting style --- .clang-format | 182 +++++++++++++++++++++++++++++++++++++ scripts/format.sh | 1 + src/graphics/mesh.cpp | 14 +-- src/graphics/mesh.hpp | 5 +- src/graphics/shader.cpp | 30 +++--- src/graphics/shader.hpp | 15 ++- src/graphics/texture.cpp | 63 +++++++------ src/graphics/texture.hpp | 31 +++---- src/main.cpp | 41 ++++----- src/shader/basic_vert.glsl | 5 +- 10 files changed, 276 insertions(+), 111 deletions(-) create mode 100644 .clang-format create mode 100755 scripts/format.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..e96a7ce --- /dev/null +++ b/.clang-format @@ -0,0 +1,182 @@ +# Generated based on style: LLVM +--- +Language: Cpp +AccessModifierOffset: -2 +AlignAfterOpenBracket: BlockIndent +AlignArrayOfStructures: None +AlignConsecutiveMacros: None +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: None +AlignConsecutiveDeclarations: None +AlignEscapedNewlines: Right +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Inline +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeConceptDeclarations: true +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakStringLiterals: true +ColumnLimit: 120 +CommentPragmas: '^ IWYU pragma:' +QualifierAlignment: Leave +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +PackConstructorInitializers: BinPack +BasedOnStyle: '' +ConstructorInitializerAllOnOneLineOrOnePerLine: false +AllowAllConstructorInitializersOnNextLine: true +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseLabels: false +IndentCaseBlocks: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentExternBlock: AfterExternBlock +IndentRequires: false +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +KeepEmptyLinesAtTheStartOfBlocks: true +LambdaBodyIndentation: Signature +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 5 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PenaltyIndentedWhitespace: 0 +PointerAlignment: Right +PPIndentWidth: -1 +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SortIncludes: CaseSensitive +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + BeforeNonEmptyParentheses: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +BitFieldColonSpacing: Both +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 4 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE + - NS_SWIFT_NAME + - CF_SWIFT_NAME +... diff --git a/scripts/format.sh b/scripts/format.sh new file mode 100755 index 0000000..02a9334 --- /dev/null +++ b/scripts/format.sh @@ -0,0 +1 @@ +clang-format -i src/main.cpp src/graphics/{mesh,shader,texture}.[ch]pp diff --git a/src/graphics/mesh.cpp b/src/graphics/mesh.cpp index 4e1b930..61169b9 100644 --- a/src/graphics/mesh.cpp +++ b/src/graphics/mesh.cpp @@ -3,7 +3,7 @@ #include Mesh::Mesh(std::vector vertices, std::vector indices, std::vector texcoords) { - + glGenVertexArrays(1, &vao); glBindVertexArray(vao); @@ -11,28 +11,31 @@ Mesh::Mesh(std::vector vertices, std::vector indices, std::vector vertices, std::vector indices, std::vector texcoords); void draw(); ~Mesh(); - }; diff --git a/src/graphics/shader.cpp b/src/graphics/shader.cpp index 4e5f7d3..8600e0c 100644 --- a/src/graphics/shader.cpp +++ b/src/graphics/shader.cpp @@ -9,13 +9,15 @@ namespace { // Load a whole file as a string. -const GLchar* load_file_as_string(const char* path) { +const GLchar *load_file_as_string(const char *path) { // TODO - do this with C++ classes. - FILE* fp = fopen(path, "r"); - if (!fp) return nullptr; + FILE *fp = fopen(path, "r"); + if (!fp) + return nullptr; + fseek(fp, 0, SEEK_END); int len = ftell(fp); - char* code = (char*) malloc(len + 1); + char *code = (char *)malloc(len + 1); rewind(fp); for (int pos = 0; pos < len; ++pos) { code[pos] = getc(fp); @@ -25,11 +27,11 @@ const GLchar* load_file_as_string(const char* path) { return code; } -} +} // namespace namespace gl { -Shader::Shader(const char* vertex_path, const char* fragment_path) { +Shader::Shader(const char *vertex_path, const char *fragment_path) { this->program_id = glCreateProgram(); // TODO - check for error @@ -40,12 +42,11 @@ Shader::Shader(const char* vertex_path, const char* fragment_path) { this->link(vert, frag); - free((void*) vertcode); - free((void*) fragcode); - + free((void *)vertcode); + free((void *)fragcode); } -int Shader::create_subshader(const GLchar* code, int type) { +int Shader::create_subshader(const GLchar *code, int type) { int id = glCreateShader(type); if (!id) { @@ -65,13 +66,12 @@ int Shader::create_subshader(const GLchar* code, int type) { } return id; - } void Shader::link(int vert, int frag) { glAttachShader(this->program_id, vert); glAttachShader(this->program_id, frag); - glLinkProgram (this->program_id); + glLinkProgram(this->program_id); // We no longer need these sub-shaders. glDetachShader(this->program_id, vert); glDetachShader(this->program_id, frag); @@ -114,13 +114,11 @@ void Shader::set_uniform_value(std::string name, float value) { } void load_all_shaders() { - GAME_SHADER = std::make_unique( - "src/shader/basic_vert.glsl", "src/shader/basic_frag.glsl" - ); + GAME_SHADER = std::make_unique("src/shader/basic_vert.glsl", "src/shader/basic_frag.glsl"); } void unload_all_shaders() { GAME_SHADER->destroy(); } -} +} // namespace gl diff --git a/src/graphics/shader.hpp b/src/graphics/shader.hpp index 998374d..c864886 100644 --- a/src/graphics/shader.hpp +++ b/src/graphics/shader.hpp @@ -14,21 +14,21 @@ namespace gl { class Shader { -private: + private: // The OpenGL ID of this shader. unsigned program_id; // Create a single vertex or fragment shader. - int create_subshader(const char* code, int type); + int create_subshader(const char *code, int type); // Finalize the shader. void link(int vert, int frag); // All uniforms. std::map uniforms; -public: + public: // Take in the file paths. - Shader(const char* vertex_path, const char* fragment_path); - ~Shader(); + Shader(const char *vertex_path, const char *fragment_path); + ~Shader(); void bind(); // set as active shader void unbind(); @@ -37,8 +37,7 @@ class Shader { void register_uniform(std::string name); void set_uniform_value(std::string name, float value); -friend void unload_all_shaders(); - + friend void unload_all_shaders(); }; extern std::unique_ptr GAME_SHADER; // the basic shader @@ -49,4 +48,4 @@ extern std::unique_ptr GAME_SHADER; // the basic shader void load_all_shaders(); void unload_all_shaders(); -} +} // namespace gl diff --git a/src/graphics/texture.cpp b/src/graphics/texture.cpp index 255d234..b4ac27e 100644 --- a/src/graphics/texture.cpp +++ b/src/graphics/texture.cpp @@ -1,7 +1,7 @@ #include "texture.hpp" -#include #include +#include namespace gl { @@ -18,10 +18,9 @@ TextureAtlas::TextureAtlas(std::string name) { this->id = load(data, w, h, GL_RGBA); stbi_image_free(data); - } -unsigned TextureAtlas::load(const unsigned char* buffer, int w, int h, int f) { +unsigned TextureAtlas::load(const unsigned char *buffer, int w, int h, int f) { unsigned ret; @@ -37,7 +36,6 @@ unsigned TextureAtlas::load(const unsigned char* buffer, int w, int h, int f) { glGenerateMipmap(GL_TEXTURE_2D); return ret; - } void TextureAtlas::destroy() { @@ -59,7 +57,7 @@ void TextureAtlas::unbind() { glBindTexture(GL_TEXTURE_2D, 0); } -} +} // namespace gl namespace tex { @@ -75,38 +73,38 @@ void unload_all_textures() { // Private -- render a texture atlas void render_texture( - double x, double y, double width, double height, - RenderBasis xbasis, RenderBasis ybasis, std::shared_ptr tex, - float x_start, float y_start, float w, float h + double x, double y, double width, double height, RenderBasis xbasis, RenderBasis ybasis, + std::shared_ptr tex, float x_start, float y_start, float w, float h ) { float x_off, y_off; switch (xbasis) { - case LOW: - x_off = 0; - break; - case MID: - x_off = - width / 2; - break; - case HI: - x_off = - width; - break; + case LOW: + x_off = 0; + break; + case MID: + x_off = -width / 2; + break; + case HI: + x_off = -width; + break; } switch (ybasis) { - case LOW: - y_off = 0; - break; - case MID: - y_off = - height / 2; - break; - case HI: - y_off = - height; - break; + case LOW: + y_off = 0; + break; + case MID: + y_off = -height / 2; + break; + case HI: + y_off = -height; + break; } - float - xb = (float) x + x_off, - yb = (float) y + y_off, - wb = (float) width, - hb = (float) height; + // Maybe we can handle it better in clang-format + float xb = (float)x + x_off; + float yb = (float)y + y_off; + float wb = (float)width; + float hb = (float)height; + // clang-format off Mesh mesh { std::vector{ xb, yb, @@ -122,6 +120,7 @@ void render_texture( x_start + w, y_start } }; + // clang-format on tex->bind(); mesh.draw(); } @@ -138,4 +137,4 @@ void Texture::render(double x, double y, double width, double height, RenderBasi render_texture(x, y, width, height, xbasis, ybasis, atlas, start_x, start_y, w, h); } -} \ No newline at end of file +} // namespace tex diff --git a/src/graphics/texture.hpp b/src/graphics/texture.hpp index 884748b..934ac78 100644 --- a/src/graphics/texture.hpp +++ b/src/graphics/texture.hpp @@ -17,22 +17,21 @@ class TextureAtlas { // The OpenGL ID assigned to this texture. unsigned id; -protected: + protected: // Load a buffer of width w and height h, of format f, into a GL texture and // return the ID. - static unsigned load(const unsigned char* buffer, int w, int h, int f); + static unsigned load(const unsigned char *buffer, int w, int h, int f); -public: + public: TextureAtlas(std::string filename); TextureAtlas() = default; - ~TextureAtlas(); - void bind(); // Make this the currently drawn texture + ~TextureAtlas(); + void bind(); // Make this the currently drawn texture void unbind(); // Shouldn't need to be used often, actually void destroy(); - }; -} +} // namespace gl namespace tex { @@ -41,34 +40,26 @@ namespace tex { * the x coordinate is the left of the figure and the y coordinate is the middle * of it. */ -enum RenderBasis { - LOW, - MID, - HI -}; +enum RenderBasis { LOW, MID, HI }; class Texture { -private: - + private: // The texture atlas that this texture is part of. std::shared_ptr atlas; double start_x, start_y, w, h; -public: - + public: Texture(std::shared_ptr a, double sx, double sy, double w, double h); void render(double x, double y, double width, double height, RenderBasis xbasis, RenderBasis ybasis); - }; // More textures here later? -extern std::shared_ptr - GAME_TEX; +extern std::shared_ptr GAME_TEX; void load_all_textures(); void unload_all_textures(); -} +} // namespace tex diff --git a/src/main.cpp b/src/main.cpp index e718225..b84b380 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,15 +4,15 @@ #include #include -#include #include +#include #include #include namespace sniper { -GLFWwindow * wn; +GLFWwindow *wn; void init() { @@ -24,41 +24,38 @@ void init() { glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); wn = glfwCreateWindow(500, 500, "Sniper", nullptr, nullptr); - glfwMakeContextCurrent(wn); - gladLoadGL(); - glfwShowWindow(wn); + glfwMakeContextCurrent(wn); + gladLoadGL(); + glfwShowWindow(wn); gl::load_all_shaders(); tex::load_all_textures(); - } void mainloop() { tex::Texture player_tex{tex::GAME_TEX, 0.0, 0.75, 0.25, 0.25}; - + gl::GAME_SHADER->bind(); while (!glfwWindowShouldClose(wn)) { - // We want each frame to last for exactly 1/50th second, - // so capture the starting time so we can sleep for the - // needed amount of time at the end of the frame. - auto start_of_frame = std::chrono::steady_clock::now(); + // We want each frame to last for exactly 1/50th second, + // so capture the starting time so we can sleep for the + // needed amount of time at the end of the frame. + auto start_of_frame = std::chrono::steady_clock::now(); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); player_tex.render(0, 0, 0.2, 0.2, tex::RenderBasis::MID, tex::RenderBasis::MID); - glfwSwapBuffers(wn); - glfwPollEvents(); - - std::this_thread::sleep_until(start_of_frame + std::chrono::milliseconds(20)); + glfwSwapBuffers(wn); + glfwPollEvents(); - } + std::this_thread::sleep_until(start_of_frame + std::chrono::milliseconds(20)); + } gl::GAME_SHADER->unbind(); - } void cleanup() { @@ -67,18 +64,16 @@ void cleanup() { gl::unload_all_shaders(); glfwDestroyWindow(wn); - glfwTerminate(); - + glfwTerminate(); } -} +} // namespace sniper int main() { - + sniper::init(); sniper::mainloop(); sniper::cleanup(); return 0; - } diff --git a/src/shader/basic_vert.glsl b/src/shader/basic_vert.glsl index 3554585..0d3fc49 100644 --- a/src/shader/basic_vert.glsl +++ b/src/shader/basic_vert.glsl @@ -1,7 +1,7 @@ #version 410 core -layout(location=0) in vec3 inVertexCoord; -layout(location=1) in vec2 inTexCoord; +layout(location = 0) in vec3 inVertexCoord; +layout(location = 1) in vec2 inTexCoord; out vec2 texCoord; @@ -9,5 +9,4 @@ void main() { gl_Position = vec4(inVertexCoord, 1.0); texCoord = inTexCoord; - } From f91b1bdefc009ec2da5173a08a85ce8b19eb1a79 Mon Sep 17 00:00:00 2001 From: dekrain Date: Fri, 30 Dec 2022 01:34:19 +0100 Subject: [PATCH 2/6] Change pointer alignment --- .clang-format | 4 ++-- src/graphics/shader.cpp | 10 +++++----- src/graphics/shader.hpp | 4 ++-- src/graphics/texture.cpp | 2 +- src/graphics/texture.hpp | 2 +- src/main.cpp | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.clang-format b/.clang-format index e96a7ce..5bce239 100644 --- a/.clang-format +++ b/.clang-format @@ -122,9 +122,9 @@ PenaltyBreakTemplateDeclaration: 10 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 60 PenaltyIndentedWhitespace: 0 -PointerAlignment: Right +PointerAlignment: Middle PPIndentWidth: -1 -ReferenceAlignment: Pointer +ReferenceAlignment: Left ReflowComments: true RemoveBracesLLVM: false SeparateDefinitionBlocks: Leave diff --git a/src/graphics/shader.cpp b/src/graphics/shader.cpp index 8600e0c..217deaa 100644 --- a/src/graphics/shader.cpp +++ b/src/graphics/shader.cpp @@ -9,15 +9,15 @@ namespace { // Load a whole file as a string. -const GLchar *load_file_as_string(const char *path) { +const GLchar * load_file_as_string(const char * path) { // TODO - do this with C++ classes. - FILE *fp = fopen(path, "r"); + FILE * fp = fopen(path, "r"); if (!fp) return nullptr; fseek(fp, 0, SEEK_END); int len = ftell(fp); - char *code = (char *)malloc(len + 1); + char * code = (char *)malloc(len + 1); rewind(fp); for (int pos = 0; pos < len; ++pos) { code[pos] = getc(fp); @@ -31,7 +31,7 @@ const GLchar *load_file_as_string(const char *path) { namespace gl { -Shader::Shader(const char *vertex_path, const char *fragment_path) { +Shader::Shader(const char * vertex_path, const char * fragment_path) { this->program_id = glCreateProgram(); // TODO - check for error @@ -46,7 +46,7 @@ Shader::Shader(const char *vertex_path, const char *fragment_path) { free((void *)fragcode); } -int Shader::create_subshader(const GLchar *code, int type) { +int Shader::create_subshader(const GLchar * code, int type) { int id = glCreateShader(type); if (!id) { diff --git a/src/graphics/shader.hpp b/src/graphics/shader.hpp index c864886..a901200 100644 --- a/src/graphics/shader.hpp +++ b/src/graphics/shader.hpp @@ -18,7 +18,7 @@ class Shader { // The OpenGL ID of this shader. unsigned program_id; // Create a single vertex or fragment shader. - int create_subshader(const char *code, int type); + int create_subshader(const char * code, int type); // Finalize the shader. void link(int vert, int frag); @@ -27,7 +27,7 @@ class Shader { public: // Take in the file paths. - Shader(const char *vertex_path, const char *fragment_path); + Shader(const char * vertex_path, const char * fragment_path); ~Shader(); void bind(); // set as active shader diff --git a/src/graphics/texture.cpp b/src/graphics/texture.cpp index b4ac27e..312c474 100644 --- a/src/graphics/texture.cpp +++ b/src/graphics/texture.cpp @@ -20,7 +20,7 @@ TextureAtlas::TextureAtlas(std::string name) { stbi_image_free(data); } -unsigned TextureAtlas::load(const unsigned char *buffer, int w, int h, int f) { +unsigned TextureAtlas::load(const unsigned char * buffer, int w, int h, int f) { unsigned ret; diff --git a/src/graphics/texture.hpp b/src/graphics/texture.hpp index 934ac78..d429189 100644 --- a/src/graphics/texture.hpp +++ b/src/graphics/texture.hpp @@ -20,7 +20,7 @@ class TextureAtlas { protected: // Load a buffer of width w and height h, of format f, into a GL texture and // return the ID. - static unsigned load(const unsigned char *buffer, int w, int h, int f); + static unsigned load(const unsigned char * buffer, int w, int h, int f); public: TextureAtlas(std::string filename); diff --git a/src/main.cpp b/src/main.cpp index b84b380..e9d4a8f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,7 +12,7 @@ namespace sniper { -GLFWwindow *wn; +GLFWwindow * wn; void init() { From c91c41324e7ab1eceee849a4b64eaaa6a1a1e4e1 Mon Sep 17 00:00:00 2001 From: dekrain Date: Fri, 30 Dec 2022 01:39:10 +0100 Subject: [PATCH 3/6] Make purpose of the script clear --- scripts/format.sh | 1 - scripts/reformat-all.sh | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) delete mode 100755 scripts/format.sh create mode 100755 scripts/reformat-all.sh diff --git a/scripts/format.sh b/scripts/format.sh deleted file mode 100755 index 02a9334..0000000 --- a/scripts/format.sh +++ /dev/null @@ -1 +0,0 @@ -clang-format -i src/main.cpp src/graphics/{mesh,shader,texture}.[ch]pp diff --git a/scripts/reformat-all.sh b/scripts/reformat-all.sh new file mode 100755 index 0000000..c92ff55 --- /dev/null +++ b/scripts/reformat-all.sh @@ -0,0 +1,2 @@ +# Use this only when changing the style spec. For local changes, use git clang-format +clang-format -i src/main.cpp src/graphics/{mesh,shader,texture}.[ch]pp From 7588abf65cb117e09bb0f0f695eae71e49ee3064 Mon Sep 17 00:00:00 2001 From: dekrain Date: Fri, 30 Dec 2022 03:41:21 +0100 Subject: [PATCH 4/6] Fix GLFW/glad order --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index e9d4a8f..af4099a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,8 +4,10 @@ #include #include -#include +// clang-format off #include +#include +// clang-format on #include #include From 60cb3e457be636c188cac87a8f27afd2eb6524f6 Mon Sep 17 00:00:00 2001 From: dekrain Date: Fri, 30 Dec 2022 20:16:04 +0100 Subject: [PATCH 5/6] Change format file glob --- scripts/reformat-all.sh | 2 +- src/graphics/stb_impls.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/reformat-all.sh b/scripts/reformat-all.sh index c92ff55..883fd73 100755 --- a/scripts/reformat-all.sh +++ b/scripts/reformat-all.sh @@ -1,2 +1,2 @@ # Use this only when changing the style spec. For local changes, use git clang-format -clang-format -i src/main.cpp src/graphics/{mesh,shader,texture}.[ch]pp +clang-format -i src/main.cpp src/graphics/*.[ch]pp diff --git a/src/graphics/stb_impls.cpp b/src/graphics/stb_impls.cpp index aaf1c48..f75774f 100644 --- a/src/graphics/stb_impls.cpp +++ b/src/graphics/stb_impls.cpp @@ -1,3 +1,5 @@ +// clang-format off + /** * Implementation of stb_image. */ From d93c588b741f6e9d849ea2b817bc24f306a0cff2 Mon Sep 17 00:00:00 2001 From: dekrain Date: Fri, 30 Dec 2022 20:42:05 +0100 Subject: [PATCH 6/6] Use find instead of shell globbing to find formatted files --- scripts/reformat-all.sh | 2 +- src/graphics/stb_impls.cpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/reformat-all.sh b/scripts/reformat-all.sh index 883fd73..879ead7 100755 --- a/scripts/reformat-all.sh +++ b/scripts/reformat-all.sh @@ -1,2 +1,2 @@ # Use this only when changing the style spec. For local changes, use git clang-format -clang-format -i src/main.cpp src/graphics/*.[ch]pp +clang-format -i $(find src -path 'glad' -prune -o -name 'stb_*' -o -name '*.[ch]pp' -print) diff --git a/src/graphics/stb_impls.cpp b/src/graphics/stb_impls.cpp index f75774f..aaf1c48 100644 --- a/src/graphics/stb_impls.cpp +++ b/src/graphics/stb_impls.cpp @@ -1,5 +1,3 @@ -// clang-format off - /** * Implementation of stb_image. */