From 185db57faf42177d5e96e6ab1fcbb8088c17c506 Mon Sep 17 00:00:00 2001
From: Joseph Walton-Rivers <joseph@walton-rivers.uk>
Date: Fri, 17 Dec 2021 18:30:13 +0000
Subject: [PATCH] cleanup operations from clany-tidy

---
 fggl/CMakeLists.txt       |  2 +-
 fggl/data/model.cpp       |  6 -----
 fggl/data/model.hpp       |  4 ++--
 fggl/data/procedural.cpp  | 46 +++++++++++++++++++--------------------
 fggl/debug/debug.cpp      | 21 +++++++++---------
 fggl/debug/debug.h        | 32 +++++++++++++--------------
 fggl/gfx/ogl/renderer.cpp | 20 ++++++++++-------
 fggl/gfx/ogl/renderer.hpp | 14 ++++++------
 fggl/gfx/ogl/shader.cpp   |  6 ++---
 9 files changed, 75 insertions(+), 76 deletions(-)

diff --git a/fggl/CMakeLists.txt b/fggl/CMakeLists.txt
index 838c36e..95c97ae 100644
--- a/fggl/CMakeLists.txt
+++ b/fggl/CMakeLists.txt
@@ -2,7 +2,7 @@ configure_file(FgglConfig.h.in FgglConfig.h)
 
 find_program(CLANG_TIDY_FOUND clang-tidy)
 if ( CLANG_TIDY_FOUND )
-	set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=*,-llvmlibc-*,-fuchsia-*,-cppcoreguidelines-*,-android-*,-llvm-*,-altera-*)
+	set(CMAKE_CXX_CLANG_TIDY clang-tidy -checks=*,-llvmlibc-*,-fuchsia-*,-cppcoreguidelines-*,-android-*,-llvm-*,-altera-*,-modernize-use-trailing-return-type)
 endif()
 
 add_library(fggl fggl.cpp
diff --git a/fggl/data/model.cpp b/fggl/data/model.cpp
index 6c0a08a..fcb96eb 100644
--- a/fggl/data/model.cpp
+++ b/fggl/data/model.cpp
@@ -70,9 +70,3 @@ void Mesh::removeDups() {
 	m_index.shrink_to_fit();
 }
 
-Model::Model() {
-}
-
-Model::~Model() {
-}
-
diff --git a/fggl/data/model.hpp b/fggl/data/model.hpp
index bc90ed1..88ef649 100644
--- a/fggl/data/model.hpp
+++ b/fggl/data/model.hpp
@@ -108,8 +108,8 @@ namespace fggl::data {
 
 	class Model {
 		public:
-			Model();
-			~Model();
+			Model() = default;
+			~Model() = default;
 
 			inline void append(const Mesh& mesh) {
 				m_meshes.push_back( mesh );
diff --git a/fggl/data/procedural.cpp b/fggl/data/procedural.cpp
index 0f65c60..2df2b17 100644
--- a/fggl/data/procedural.cpp
+++ b/fggl/data/procedural.cpp
@@ -23,7 +23,7 @@ static void computeNormals( fggl::data::Mesh& mesh, const int* idx, const int* c
 	// FIXME this will touch any vertex that appears in idx more than once mutliple times...
 	for ( int i=0; i<nPoints; i++ ) {
 		auto& vertex = mesh.vertex( colIdx[ idx[i] ] );
-		vertex.normal = glm::vec3(0.0f);
+		vertex.normal = glm::vec3(0.0F);
 	}
 
 	// each vertex normal should be the sum of the triangles it's part of.
@@ -53,7 +53,7 @@ static void computeNormalsDirect( fggl::data::Mesh& mesh, const int* colIdx, int
 	// we're assuming all the normals are zero...
 	for ( int i=0; i<nPoints; i++ ) {
 		auto& vertex = mesh.vertex( colIdx[i] );
-		vertex.normal = glm::vec3(0.0f);
+		vertex.normal = glm::vec3(0.0F);
 	}
 
 	// We're assuming each vertex appears only once (because we're not indexed)
@@ -71,9 +71,9 @@ static void computeNormalsDirect( fggl::data::Mesh& mesh, const int* colIdx, int
 
 fggl::data::Mesh fggl::data::make_triangle() {
     constexpr fggl::math::vec3 pos[]{
-            {-0.5f, -0.5f, 0.0f},
-            {0.5f,  -0.5f, 0.0f},
-            {0.0f,  0.5f,  0.0f}
+            {-0.5F, -0.5F, 0.0F},
+            {0.5F,  -0.5F, 0.0F},
+            {0.0F,  0.5F,  0.0F}
     };
 
     // add points
@@ -81,8 +81,8 @@ fggl::data::Mesh fggl::data::make_triangle() {
     for (auto po : pos) {
         Vertex vert{};
         vert.posititon = po;
-	vert.normal = glm::vec3(0.0f, 0.0f, 0.0f);
-        vert.colour = fggl::math::vec3(1.0f, 1.0f, 1.0f);
+	vert.normal = glm::vec3(0.0F, 0.0F, 0.0F);
+        vert.colour = fggl::math::vec3(1.0F, 1.0F, 1.0F);
         mesh.push(vert);
     }
 
@@ -96,10 +96,10 @@ fggl::data::Mesh fggl::data::make_triangle() {
 
 fggl::data::Mesh fggl::data::make_quad_xy() {
 	constexpr fggl::math::vec3 pos[] {
-		{-0.5f, -0.5f, 0.0f},
-		{ 0.5f, -0.5f, 0.0f},
-		{ 0.5f,  0.5f, 0.0f},
-		{-0.5f,  0.5f, 0.0f}
+		{-0.5F, -0.5F, 0.0F},
+		{ 0.5F, -0.5F, 0.0F},
+		{ 0.5F,  0.5F, 0.0F},
+		{-0.5F,  0.5F, 0.0F}
 	};
 	constexpr int idx[] {
 		0, 1, 3,
@@ -107,12 +107,12 @@ fggl::data::Mesh fggl::data::make_quad_xy() {
 	};
 
 	fggl::data::Mesh mesh;
-	int colIdx[4];
+	std::array<int,4> colIdx;
 	for (int i = 0; i < 4; ++i){
 		Vertex vert{};
 		vert.posititon = pos[i];
-		vert.normal = glm::vec3(0.0f, 0.0f, 0.0f);
-		vert.colour = fggl::math::vec3(1.0f, 1.0f, 1.0f);
+		vert.normal = glm::vec3(0.0F, 0.0F, 0.0F);
+		vert.colour = fggl::math::vec3(1.0F, 1.0F, 1.0F);
 		colIdx[ i ] = mesh.pushVertex(vert);
 	}
 
@@ -125,10 +125,10 @@ fggl::data::Mesh fggl::data::make_quad_xy() {
 
 fggl::data::Mesh fggl::data::make_quad_xz() {
 	constexpr fggl::math::vec3 pos[] {
-		{-0.5f, 0.0f, -0.5f},
-		{ 0.5f, 0.0f, -0.5f},
-		{ 0.5f, 0.0f,  0.5f},
-		{-0.5f, 0.0f,  0.5f}
+		{-0.5F, 0.0F, -0.5F},
+		{ 0.5F, 0.0F, -0.5F},
+		{ 0.5F, 0.0F,  0.5F},
+		{-0.5F, 0.0F,  0.5F}
 	};
 	constexpr int idx[] {
 		0, 1, 3,
@@ -140,8 +140,8 @@ fggl::data::Mesh fggl::data::make_quad_xz() {
 	for (int i = 0; i < 4; ++i){
 		Vertex vert{};
 		vert.posititon = pos[i];
-		vert.normal = glm::vec3(0.0f, 0.0f, 0.0f);
-		vert.colour = fggl::math::vec3(1.0f, 1.0f, 1.0f);
+		vert.normal = glm::vec3(0.0F, 0.0F, 0.0F);
+		vert.colour = fggl::math::vec3(1.0F, 1.0F, 1.0F);
 		colIdx[ i ] = mesh.pushVertex(vert);
 	}
 
@@ -153,7 +153,7 @@ fggl::data::Mesh fggl::data::make_quad_xz() {
 }
 
 
-constexpr float HALF_PI = M_PI / 2.0f;
+constexpr float HALF_PI = M_PI / 2.0F;
 static void populateMesh(fggl::data::Mesh& mesh, const fggl::math::mat4 transform, 
 		          int nIdx, const fggl::math::vec3* pos, const int* idx ) {
 	int colIdx[nIdx];
@@ -164,8 +164,8 @@ static void populateMesh(fggl::data::Mesh& mesh, const fggl::math::mat4 transfor
 
 		Vertex vert{};
 		vert.posititon = rawPos;
-		vert.normal = glm::vec3(0.0f, 0.0f, 0.0f);
-		vert.colour = fggl::math::vec3(1.0f, 1.0f, 1.0f);
+		vert.normal = glm::vec3(0.0F, 0.0F, 0.0F);
+		vert.colour = fggl::math::vec3(1.0F, 1.0F, 1.0F);
 		colIdx[ i ] = mesh.pushVertex( vert );
 		mesh.pushIndex( colIdx[i] );
 	}
diff --git a/fggl/debug/debug.cpp b/fggl/debug/debug.cpp
index 9e825fd..f595510 100644
--- a/fggl/debug/debug.cpp
+++ b/fggl/debug/debug.cpp
@@ -7,14 +7,14 @@
 using fggl::gfx::Window;
 using fggl::debug::DebugUI;
 
-DebugUI::DebugUI(std::shared_ptr<Window> win) : m_visible(false) {
+DebugUI::DebugUI(std::shared_ptr<Window>& win) : m_visible(false) {
 	IMGUI_CHECKVERSION();
 	ImGui::CreateContext();
 
-    ImGuiIO& io = ImGui::GetIO();
-    io.IniFilename = nullptr;
+	ImGuiIO& io = ImGui::GetIO();
+	io.IniFilename = nullptr;
 
-    ImGui_ImplGlfw_InitForOpenGL(win->handle(), true);
+	ImGui_ImplGlfw_InitForOpenGL(win->handle(), true);
 	ImGui_ImplOpenGL3_Init("#version 130");
 }
 
@@ -32,13 +32,14 @@ void DebugUI::frameStart() {
 }
 
 void DebugUI::draw() {
-    for ( auto& [name, data] : m_windows) {
-        if ( data.m_visible ) {
-            data.m_callback( &data.m_visible );
-        }
-    }
+	for ( auto& [name, data] : m_windows) {
+		if ( data.m_visible ) {
+			data.m_callback( &data.m_visible );
+		}
+	}
 
 	ImGui::Render();
-	if ( m_visible )
+	if ( m_visible ) {
 		ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
+	}
 }
diff --git a/fggl/debug/debug.h b/fggl/debug/debug.h
index cdfb298..0b75b81 100644
--- a/fggl/debug/debug.h
+++ b/fggl/debug/debug.h
@@ -9,39 +9,39 @@
 
 namespace fggl::debug {
 
-    using DebugUIDraw = std::function<void(bool*)>;
+	using DebugUIDraw = std::function<void(bool*)>;
 
-    struct DebugWindow {
-        bool m_visible;
-        DebugUIDraw m_callback;
-    };
+	struct DebugWindow {
+		bool m_visible;
+		DebugUIDraw m_callback;
+	};
 
 	class DebugUI {
 		public:
-			explicit DebugUI(std::shared_ptr<gfx::Window> window);
+			explicit DebugUI(std::shared_ptr<gfx::Window>& window);
 			~DebugUI();
 
 			void frameStart();
 			void draw();
 
-            inline void addWindow(const std::string& name, DebugUIDraw window){
-                m_windows[name] = DebugWindow{
-                    .m_visible = true,
-                    .m_callback = std::move(window)
-                };
-            }
+			inline void addWindow(const std::string& name, DebugUIDraw window){
+				m_windows[name] = DebugWindow{
+					.m_visible = true,
+						.m_callback = std::move(window)
+				};
+			}
 
 			inline void visible(bool state) {
 				m_visible = state;
 			}
 
-            inline bool visible() const {
-                return m_visible;
-            }
+			inline bool visible() const {
+				return m_visible;
+			}
 
 		private:
 			bool m_visible;
-            std::unordered_map<std::string, DebugWindow> m_windows;
+			std::unordered_map<std::string, DebugWindow> m_windows;
 	};
 
 }
diff --git a/fggl/gfx/ogl/renderer.cpp b/fggl/gfx/ogl/renderer.cpp
index 1132df9..d869a66 100644
--- a/fggl/gfx/ogl/renderer.cpp
+++ b/fggl/gfx/ogl/renderer.cpp
@@ -21,8 +21,7 @@
  *   OpenGL ES for the FOSS thinkpad users who can't run anything even remotely modern
  */
  
-
-using namespace fggl::gfx;
+namespace fggl::gfx {
 
 template<typename T>
 static GLuint createArrayBuffer(std::vector<T>& vertexData) {
@@ -68,6 +67,9 @@ GlRenderToken MeshRenderer::upload(fggl::data::Mesh& mesh) {
 	return token;
 }
 
+//TODO(webpigeon): this shouldn't be hard-coded
+constexpr glm::vec3 DEFAULT_LIGHTPOS = glm::vec3(20.0F, 20.0F, 15.0F);
+
 void MeshRenderer::render(fggl::ecs3::World& ecs, ecs3::entity_t camera, float dt) {
     if ( camera == ecs::NULL_ENTITY ){
         std::cerr << "no camera" << std::endl;
@@ -88,16 +90,16 @@ void MeshRenderer::render(fggl::ecs3::World& ecs, ecs3::entity_t camera, float d
     glEnable(GL_DEPTH_TEST);
 
     // camera logic
-    const auto camTransform = ecs.get<math::Transform>(camera);
-    const auto camComp = ecs.get<gfx::Camera>(camera);
+    auto *const camTransform = ecs.get<math::Transform>(camera);
+    auto *const camComp = ecs.get<gfx::Camera>(camera);
     glm::mat4 proj = glm::perspective( camComp->fov, camComp->aspectRatio, camComp->nearPlane, camComp->farPlane);
     glm::mat4 view = glm::lookAt( camTransform->origin(), camComp->target, camTransform->up() );
 
     // lighting
-    glm::vec3 lightPos(20.0f, 20.0f, 15.0f);
+    glm::vec3 lightPos = DEFAULT_LIGHTPOS;
 
-    // TODO better performance if grouped by vao first
-    // TODO the nvidia performance presentation said I shouldn't use uniforms for large data
+    // TODO(webpigeon): better performance if grouped by vao first
+    // TODO(webpigeon): the nvidia performance presentation said I shouldn't use uniforms for large data
     for ( auto& entity : entities ) {
 	    const auto& transform = ecs.get<fggl::math::Transform>(entity);
 	    const auto& mesh = ecs.get<GlRenderToken>(entity);
@@ -114,8 +116,9 @@ void MeshRenderer::render(fggl::ecs3::World& ecs, ecs3::entity_t camera, float d
 
 	    // lighting
 	    GLint lightID = glGetUniformLocation(shader, "lightPos");
-	    if ( lightID != -1 )
+	    if ( lightID != -1 ) {
 		    glUniform3fv( lightID, 1, glm::value_ptr( lightPos ) );
+	    }
 
 	    glBindVertexArray( mesh->vao );
 
@@ -133,3 +136,4 @@ void MeshRenderer::render(fggl::ecs3::World& ecs, ecs3::entity_t camera, float d
     glBindVertexArray(0);
 }
 
+}
diff --git a/fggl/gfx/ogl/renderer.hpp b/fggl/gfx/ogl/renderer.hpp
index 2e900cb..fcbdb8d 100644
--- a/fggl/gfx/ogl/renderer.hpp
+++ b/fggl/gfx/ogl/renderer.hpp
@@ -9,19 +9,19 @@
 
 namespace fggl::gfx {
 
-    enum GlRenderType {
-        triangles = GL_TRIANGLES, trinagle_strip = GL_TRIANGLE_STRIP
-    };
+	enum GlRenderType {
+		triangles = GL_TRIANGLES, trinagle_strip = GL_TRIANGLE_STRIP
+	};
 
 	struct GlRenderToken {
-        constexpr static const char name[] = "RenderToken";
+		constexpr static const char name[] = "RenderToken";
 		GLuint vao;
 		GLuint buffs[2];
 		GLuint idxOffset;
-		GLuint idxSize;
+		GLsizei idxSize;
 		GLuint pipeline;
-        GLuint restartVertex;
-        GlRenderType renderType = triangles;
+		GLuint restartVertex;
+		GlRenderType renderType = triangles;
 	};
 
 	class GlMeshRenderer {
diff --git a/fggl/gfx/ogl/shader.cpp b/fggl/gfx/ogl/shader.cpp
index d9c0da5..82f1aa6 100644
--- a/fggl/gfx/ogl/shader.cpp
+++ b/fggl/gfx/ogl/shader.cpp
@@ -187,7 +187,7 @@ bool fggl::data::fggl_deserialize(std::filesystem::path &data, fggl::gfx::Binary
 		return false;
 	}
 
-	int rsize = std::fread( &out->format, sizeof(GLenum), 1, f);
+	auto rsize = std::fread( &out->format, sizeof(GLenum), 1, f);
 	if ( rsize != 1 ) {
 		std::cerr << "invalid read of type";
 		std::fclose(f);
@@ -203,7 +203,7 @@ bool fggl::data::fggl_deserialize(std::filesystem::path &data, fggl::gfx::Binary
 	}
 
 	out->data = std::malloc(out->size);
-	int readSize = std::fread( out->data, out->size, 1, f );
+	auto readSize = std::fread( out->data, out->size, 1, f );
 
 	auto result = true;
 	if ( readSize != 1 ) {
@@ -213,7 +213,7 @@ bool fggl::data::fggl_deserialize(std::filesystem::path &data, fggl::gfx::Binary
 	}
 
 	std::fclose(f);
-	return true;
+	return result;
 }
 
 #include <iostream>
-- 
GitLab