From 8e4eacf48f193cabfe02c6f35f2dc458c6d6e7b0 Mon Sep 17 00:00:00 2001 From: karl Date: Sat, 2 Jan 2021 15:12:34 +0100 Subject: [PATCH] Add clang-format, format main --- .clang-format | 13 +++++++ main.cpp | 97 ++++++++++++++++++++++++------------------------- tools/format.sh | 13 +++++++ 3 files changed, 74 insertions(+), 49 deletions(-) create mode 100644 .clang-format create mode 100755 tools/format.sh diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..a63e137 --- /dev/null +++ b/.clang-format @@ -0,0 +1,13 @@ +--- +BasedOnStyle: LLVM +AllowShortBlocksOnASingleLine: 'true' +AllowShortCaseLabelsOnASingleLine: 'true' +AllowShortFunctionsOnASingleLine: Inline +AllowShortIfStatementsOnASingleLine: WithoutElse +AllowShortLambdasOnASingleLine: Inline +AllowShortLoopsOnASingleLine: 'false' +AlwaysBreakBeforeMultilineStrings: 'true' +IndentWidth: '4' +ColumnLimit: 100 + +... diff --git a/main.cpp b/main.cpp index dbfc343..134eed7 100644 --- a/main.cpp +++ b/main.cpp @@ -1,40 +1,37 @@ -#include #include +#include #include -#include "Rendering/Shader.h" +#include "ECS/Components/DirectionalLight.h" +#include "ECS/Components/ObjMesh.h" +#include "ECS/Components/PathMove.h" +#include "ECS/Components/SineAnimation.h" +#include "ECS/Components/Texture.h" #include "ECS/ECS.h" #include "ECS/Events/InputEvent.h" #include "ECS/Events/MouseMoveEvent.h" #include "ECS/Systems/GravitySystem.h" -#include "ECS/Systems/PositionDebugSystem.h" +#include "ECS/Systems/InteractivePathSystem.h" #include "ECS/Systems/KeyboardMovementSystem.h" -#include "ECS/Systems/RenderSystem.h" #include "ECS/Systems/MouseLookSystem.h" #include "ECS/Systems/PathMoveSystem.h" -#include "ECS/Components/ObjMesh.h" -#include "ECS/Components/Texture.h" -#include "ECS/Components/SineAnimation.h" +#include "ECS/Systems/PositionDebugSystem.h" +#include "ECS/Systems/RenderSystem.h" #include "ECS/Systems/SineAnimationSystem.h" -#include "ECS/Components/DirectionalLight.h" -#include "ECS/Components/PathMove.h" -#include "ECS/Systems/InteractivePathSystem.h" +#include "Rendering/Shader.h" using namespace ECS; - World *world = World::createWorld(); - static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods) { - if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) - glfwSetWindowShouldClose(window, GLFW_TRUE); + if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) glfwSetWindowShouldClose(window, GLFW_TRUE); world->emit({key, action}); } -static void mouse_callback(GLFWwindow* window, double xpos, double ypos) { +static void mouse_callback(GLFWwindow *window, double xpos, double ypos) { world->emit({xpos, ypos}); } @@ -50,9 +47,8 @@ int main(int argc, char **argv) { GLFWwindow *window; /* Initialize the library */ - if (!glfwInit()) - return -1; - + if (!glfwInit()) return -1; + // Anti Aliasing glfwWindowHint(GLFW_SAMPLES, aa_samples); @@ -74,8 +70,7 @@ int main(int argc, char **argv) { // glad: load all OpenGL function pointers // --------------------------------------- - if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) - { + if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { std::cout << "Failed to initialize GLAD" << std::endl; return -1; } @@ -95,7 +90,7 @@ int main(int argc, char **argv) { world->registerSystem(new SineAnimationSystem()); world->registerSystem(new InteractivePathSystem()); - RenderSystem* renderSystem = new RenderSystem(); + RenderSystem *renderSystem = new RenderSystem(); world->registerSystem(renderSystem); Entity *player = world->create(); @@ -103,33 +98,30 @@ int main(int argc, char **argv) { player->assign(glm::vec3(5.f, 5.f, 5.f)); player->assign(0.1); player->assign(70.0f, 900, 600, 0.1f, 100.0f); - player->assign(3.0, PathMove::Path(std::vector{ - glm::vec3(0.0, 2.0, 0.0), - glm::vec3(0.0, 2.5, -1.0), - glm::vec3(0.0, 2.5, -2.0), - glm::vec3(3.0, 3.0, -3.0), - glm::vec3(4.0, 2.0, -4.0), - glm::vec3(3.0, 2.0, -5.0), - glm::vec3(0.0, 2.0, -10.0) - }), - PathMove::Views(std::vector{ - glm::angleAxis(glm::radians(0.f), glm::vec3(0.f, 1.f, 0.f)), - glm::angleAxis(glm::radians(10.f), glm::vec3(0.f, 1.f, 0.f)), - glm::angleAxis(glm::radians(20.f), glm::vec3(0.f, 1.f, 0.f)), - glm::angleAxis(glm::radians(40.f), glm::vec3(0.f, 1.f, 0.f)), - glm::angleAxis(glm::radians(90.f), glm::vec3(0.f, 1.f, 0.f)), - glm::angleAxis(glm::radians(120.f), glm::vec3(0.f, 1.f, 0.f)), - glm::angleAxis(glm::radians(180.f), glm::vec3(0.f, 1.f, 0.f)) - }) - ); + player->assign( + 3.0, + PathMove::Path(std::vector{glm::vec3(0.0, 2.0, 0.0), glm::vec3(0.0, 2.5, -1.0), + glm::vec3(0.0, 2.5, -2.0), glm::vec3(3.0, 3.0, -3.0), + glm::vec3(4.0, 2.0, -4.0), glm::vec3(3.0, 2.0, -5.0), + glm::vec3(0.0, 2.0, -10.0)}), + PathMove::Views( + std::vector{glm::angleAxis(glm::radians(0.f), glm::vec3(0.f, 1.f, 0.f)), + glm::angleAxis(glm::radians(10.f), glm::vec3(0.f, 1.f, 0.f)), + glm::angleAxis(glm::radians(20.f), glm::vec3(0.f, 1.f, 0.f)), + glm::angleAxis(glm::radians(40.f), glm::vec3(0.f, 1.f, 0.f)), + glm::angleAxis(glm::radians(90.f), glm::vec3(0.f, 1.f, 0.f)), + glm::angleAxis(glm::radians(120.f), glm::vec3(0.f, 1.f, 0.f)), + glm::angleAxis(glm::radians(180.f), glm::vec3(0.f, 1.f, 0.f))})); player->get()->set_origin(glm::vec3(0.0, 3.0, 4.0)); Entity *monkey = world->create(); monkey->assign(); - monkey->assign(std::vector{ObjMesh("Resources/Monkey.obj",ObjMesh::Settings(0.0, 8.0, 0.4, 0.6)), - ObjMesh("Resources/MonkeySimple.obj", ObjMesh::Settings(8.0, 100.0, 0.4, 0.6))}); + monkey->assign(std::vector{ + ObjMesh("Resources/Monkey.obj", ObjMesh::Settings(0.0, 8.0, 0.4, 0.6)), + ObjMesh("Resources/MonkeySimple.obj", ObjMesh::Settings(8.0, 100.0, 0.4, 0.6))}); monkey->assign("Resources/Marble010_2K_Color.jpg", Texture::Settings(true), false); - monkey->get()->addNormalmap("Resources/Marble010_2K_Normal.jpg", Texture::Settings(true)); + monkey->get()->addNormalmap("Resources/Marble010_2K_Normal.jpg", + Texture::Settings(true)); monkey->assign(glm::vec3(0.0, 0.3, 0.0), 0.5); monkey->assign(0.6, 0.6); monkey->get()->set_origin(glm::vec3(0.0f, 2.0f, -6.0f)); @@ -138,7 +130,8 @@ int main(int argc, char **argv) { wall1->assign(); wall1->assign(ObjMesh("Resources/Wall.obj", ObjMesh::Settings())); wall1->assign("Resources/Facade001_2K_Color.png", Texture::Settings(true), true); - wall1->get()->addNormalmap("Resources/Facade001_2K_Normal.jpg", Texture::Settings(true)); + wall1->get()->addNormalmap("Resources/Facade001_2K_Normal.jpg", + Texture::Settings(true)); wall1->assign(0.2, 0.8); wall1->get()->set_origin(glm::vec3(0.0f, 0.0f, -2.0f)); @@ -146,7 +139,8 @@ int main(int argc, char **argv) { wall2->assign(); wall2->assign(ObjMesh("Resources/Wall.obj", ObjMesh::Settings())); wall2->assign("Resources/Facade001_2K_Color.png", Texture::Settings(true), true); - wall2->get()->addNormalmap("Resources/Facade001_2K_Normal.jpg", Texture::Settings(true)); + wall2->get()->addNormalmap("Resources/Facade001_2K_Normal.jpg", + Texture::Settings(true)); wall2->assign(0.2, 0.8); wall2->get()->set_origin(glm::vec3(0.0f, 0.0f, -10.0f)); @@ -154,7 +148,8 @@ int main(int argc, char **argv) { wall3->assign(); wall3->assign(ObjMesh("Resources/Wall.obj", ObjMesh::Settings())); wall3->assign("Resources/Facade001_2K_Color.png", Texture::Settings(true), true); - wall3->get()->addNormalmap("Resources/Facade001_2K_Normal.jpg", Texture::Settings(true)); + wall3->get()->addNormalmap("Resources/Facade001_2K_Normal.jpg", + Texture::Settings(true)); wall3->assign(0.2, 0.8); wall3->get()->set_origin(glm::vec3(4.0f, 0.0f, -6.0f)); wall3->get()->rotate(90.0, glm::vec3(0.0, 1.0, 0.0)); @@ -163,7 +158,8 @@ int main(int argc, char **argv) { wall4->assign(); wall4->assign(ObjMesh("Resources/Wall.obj", ObjMesh::Settings())); wall4->assign("Resources/Facade001_2K_Color.png", Texture::Settings(true), true); - wall4->get()->addNormalmap("Resources/Facade001_2K_Normal.jpg", Texture::Settings(true)); + wall4->get()->addNormalmap("Resources/Facade001_2K_Normal.jpg", + Texture::Settings(true)); wall4->assign(0.2, 0.8); wall4->get()->set_origin(glm::vec3(-4.0f, 0.0f, -6.0f)); wall4->get()->rotate(90.0, glm::vec3(0.0, 1.0, 0.0)); @@ -172,7 +168,8 @@ int main(int argc, char **argv) { ground->assign(); ground->assign(ObjMesh("Resources/Ground.obj", ObjMesh::Settings())); ground->assign("Resources/Ground003_2K_Color.jpg", Texture::Settings(true), false); - ground->get()->addNormalmap("Resources/Ground003_2K_Normal.jpg", Texture::Settings(true)); + ground->get()->addNormalmap("Resources/Ground003_2K_Normal.jpg", + Texture::Settings(true)); ground->assign(1.0, 0.0); ground->get()->set_origin(glm::vec3(0.0f, 0.0f, 0.0f)); @@ -214,7 +211,9 @@ int main(int argc, char **argv) { renderSystem->render(world, defaultShader, shadowShader, debugShader); ring->get()->rotate(delta * 100.0, glm::vec3(0.0, 1.0, 0.0)); - sun->get()->direction = glm::normalize(glm::vec3(glm::rotate(glm::mat4(1), (float)elapsed_time * 0.5f, glm::vec3(0.0, 1.0, 0.0)) * glm::vec4(1.0, 1.0, 1.0, 0.0))); + sun->get()->direction = glm::normalize(glm::vec3( + glm::rotate(glm::mat4(1), (float)elapsed_time * 0.5f, glm::vec3(0.0, 1.0, 0.0)) * + glm::vec4(1.0, 1.0, 1.0, 0.0))); /* Swap front and back buffers */ glfwSwapBuffers(window); diff --git a/tools/format.sh b/tools/format.sh new file mode 100755 index 0000000..ec33b0f --- /dev/null +++ b/tools/format.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +if [[ "$OSTYPE" == "darwin"* ]]; then + clang_format_command="clang-format" + clang_tidy_command="run-clang-tidy" +fi +if [[ "$OSTYPE" == "linux"* ]]; then + clang_format_command="clang-format-11" + clang_tidy_command="run-clang-tidy-11" +fi + +eval "$clang_format_command -i *.h *.cpp -style=file" +eval "$clang_tidy_command -fix"