From f2654cf7d46b0e55d288cc48bdd6af872fb021f4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 2 May 2021 14:44:31 +0100 Subject: Fix warnings produced by new clang-tidy --- application/main.cpp | 4 ---- game/network/rail.cpp | 2 +- game/objectives/freeroam.cpp | 2 +- game/objectives/goto.cpp | 2 +- game/terrain.cpp | 7 +++---- gfx/manualCameraController.cpp | 6 +++--- gfx/models/mesh.cpp | 16 ++++++++++------ gfx/models/mesh.h | 3 +-- lib/maths.cpp | 3 --- lib/maths.h | 14 ++++++++++++++ 10 files changed, 34 insertions(+), 25 deletions(-) diff --git a/application/main.cpp b/application/main.cpp index 2fc9f99..61206eb 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -129,7 +129,6 @@ public: shader.setUniform("ambientColor", {0.5, 0.5, 0.5}); auto t_start = std::chrono::high_resolution_clock::now(); - const auto framelen = std::chrono::milliseconds {1000} / 120; inputStack.objects.push_back(shared_from_this()); inputStack.objects.insert( @@ -147,9 +146,6 @@ public: world.apply(&Renderable::render, shader); windows.apply(&Window::SwapBuffers); - if (const auto snz = framelen - t_passed; snz.count() > 0) { - SDL_Delay(snz.count()); - } t_start = t_end; } diff --git a/game/network/rail.cpp b/game/network/rail.cpp index 0cb2725..1f432cb 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -155,7 +155,7 @@ RailLinkCurve::RailLinkCurve(const NodePtr & a, const NodePtr & b, glm::vec3 c, const auto step {glm::vec3 {-arc_length(arc), e0p.y - e1p.y, slength} / segs}; const auto trans {glm::translate(centreBase)}; - int segCount = segs; + auto segCount = std::lround(segs); std::vector vertices; vertices.reserve((segCount + 1) * railCrossSection.size()); for (glm::vec3 swing = {arc.second, e1p.y - centreBase.y, 0.F}; segCount >= 0; swing += step, --segCount) { diff --git a/game/objectives/freeroam.cpp b/game/objectives/freeroam.cpp index 0721ef2..b569d36 100644 --- a/game/objectives/freeroam.cpp +++ b/game/objectives/freeroam.cpp @@ -17,6 +17,6 @@ Link::Next FreeRoam::navigate(Link::Nexts::const_iterator begin, Link::Nexts::const_iterator end) const { static std::mt19937 gen(std::random_device {}()); - auto off = std::uniform_int_distribution<>(0, std::distance(begin, end) - 1)(gen); + auto off = std::uniform_int_distribution(0, std::distance(begin, end) - 1)(gen); return begin[off]; } diff --git a/game/objectives/goto.cpp b/game/objectives/goto.cpp index c089bc3..8581a2d 100644 --- a/game/objectives/goto.cpp +++ b/game/objectives/goto.cpp @@ -17,7 +17,7 @@ GoTo::GoTo(Orders * o, const Link::End & cp, float d, const NodePtr & dest) : ActivityPtr GoTo::createActivity() const { - return std::make_unique(std::accumulate(links.begin(), links.end(), 0, + return std::make_unique(std::accumulate(links.begin(), links.end(), 0.F, [](auto p, const auto & l) { return p += l.first.lock()->length; }) diff --git a/game/terrain.cpp b/game/terrain.cpp index bf16439..ddfa31b 100644 --- a/game/terrain.cpp +++ b/game/terrain.cpp @@ -1,13 +1,13 @@ #include "terrain.h" #include "gfx/models/texture.h" #include -#include #include #include #include #include #include #include +#include #include #include @@ -41,14 +41,13 @@ Terrain::Terrain() : grass {Texture::cachedTexture.get("grass.png")}, water {Tex const glm::ivec2 hsize {rsize(gen), rsize(gen)}; if (const auto lim1 = hpos - hsize; lim1.x > 0 && lim1.y > 0) { if (const auto lim2 = hpos + hsize; lim2.x < size && lim2.y < size) { - const float height = rheight(gen); + const auto height = (float)rheight(gen); const glm::ivec2 hsizesqrd {hsize.x * hsize.x, hsize.y * hsize.y}; for (auto z = lim1.y; z < lim2.y; z += 1) { for (auto x = lim1.x; x < lim2.x; x += 1) { const auto dist {hpos - glm::ivec2 {x, z}}; const glm::ivec2 distsqrd {dist.x * dist.x, dist.y * dist.y}; - const auto out { - (pow(x - hpos.x, 2) / pow(hsize.x, 2)) + (pow(z - hpos.y, 2) / pow(hsize.y, 2))}; + const auto out {rdiv(sq(x - hpos.x), sq(hsize.x)) + rdiv(sq(z - hpos.y), sq(hsize.y))}; if (out <= 1.0) { auto & vertex = vertices[x + (z * size)]; const auto m {1.F / (7.F * out - 8.F) + 1.F}; diff --git a/gfx/manualCameraController.cpp b/gfx/manualCameraController.cpp index 21eefc8..268920a 100644 --- a/gfx/manualCameraController.cpp +++ b/gfx/manualCameraController.cpp @@ -43,8 +43,8 @@ ManualCameraController::handleInput(SDL_Event & e) case SDL_MOUSEMOTION: if (mrb) { if (ctrl) { - direction -= 0.01F * e.motion.xrel; - pitch = std::clamp(pitch - 0.01F * e.motion.yrel, 0.1F, half_pi); + direction -= 0.01F * (float)e.motion.xrel; + pitch = std::clamp(pitch - 0.01F * (float)e.motion.yrel, 0.1F, half_pi); } else { focus += rotate_flat(-direction) * glm::vec2 {e.motion.xrel, e.motion.yrel}; @@ -52,7 +52,7 @@ ManualCameraController::handleInput(SDL_Event & e) } return true; case SDL_MOUSEWHEEL: - dist = std::clamp(dist - e.wheel.y * 4.F, 5.F, 200.F); + dist = std::clamp(dist - (float)e.wheel.y * 4.F, 5.F, 200.F); break; } return false; diff --git a/gfx/models/mesh.cpp b/gfx/models/mesh.cpp index 0834394..52ce6bb 100644 --- a/gfx/models/mesh.cpp +++ b/gfx/models/mesh.cpp @@ -1,8 +1,11 @@ #include "mesh.h" #include "vertex.hpp" +#include + +#define offset_ptr(T, m) (((char *)1) + offsetof(T, m) - 1) Mesh::Mesh(const std::span vertices, const std::span indices, GLenum m) : - m_vertexArrayObject {}, m_vertexArrayBuffers {}, m_numIndices {indices.size()}, mode {m} + m_vertexArrayObject {}, m_vertexArrayBuffers {}, m_numIndices {(GLsizei)indices.size()}, mode {m} { glGenVertexArrays(1, &m_vertexArrayObject); glBindVertexArray(m_vertexArrayObject); @@ -10,19 +13,20 @@ Mesh::Mesh(const std::span vertices, const std::span #include -#include #include #include #include @@ -27,7 +26,7 @@ private: GLuint m_vertexArrayObject; std::array m_vertexArrayBuffers; - size_t m_numIndices; + GLsizei m_numIndices; GLenum mode; }; using MeshPtr = std::shared_ptr; diff --git a/lib/maths.cpp b/lib/maths.cpp index 26eae47..0298363 100644 --- a/lib/maths.cpp +++ b/lib/maths.cpp @@ -148,9 +148,6 @@ float find_arcs_radius(glm::vec2 start, glm::vec2 ad, glm::vec2 end, glm::vec2 bd) { // Short name functions for big forula - auto sq = [](auto v) { - return v * v; - }; auto sqrt = [](float v) { return std::sqrt(v); }; diff --git a/lib/maths.h b/lib/maths.h index c4c1a51..c02123a 100644 --- a/lib/maths.h +++ b/lib/maths.h @@ -56,6 +56,20 @@ float vector_pitch(const glm::vec3 & diff); float round_frac(const float & v, const float & frac); +template +inline constexpr auto +sq(T v) +{ + return v * v; +} + +template +inline constexpr auto +rdiv(Ta a, Tb b) +{ + return ((R)a / (R)b); +} + constexpr inline glm::vec2 operator!(const glm::vec3 & v) { -- cgit v1.2.3