diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-05-02 14:44:31 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-05-02 14:44:31 +0100 |
commit | f2654cf7d46b0e55d288cc48bdd6af872fb021f4 (patch) | |
tree | b3bc31345a2ea16fd6b76b0435247027fab48808 | |
parent | Bump to release GCC version (diff) | |
download | ilt-f2654cf7d46b0e55d288cc48bdd6af872fb021f4.tar.bz2 ilt-f2654cf7d46b0e55d288cc48bdd6af872fb021f4.tar.xz ilt-f2654cf7d46b0e55d288cc48bdd6af872fb021f4.zip |
Fix warnings produced by new clang-tidy
-rw-r--r-- | application/main.cpp | 4 | ||||
-rw-r--r-- | game/network/rail.cpp | 2 | ||||
-rw-r--r-- | game/objectives/freeroam.cpp | 2 | ||||
-rw-r--r-- | game/objectives/goto.cpp | 2 | ||||
-rw-r--r-- | game/terrain.cpp | 7 | ||||
-rw-r--r-- | gfx/manualCameraController.cpp | 6 | ||||
-rw-r--r-- | gfx/models/mesh.cpp | 16 | ||||
-rw-r--r-- | gfx/models/mesh.h | 3 | ||||
-rw-r--r-- | lib/maths.cpp | 3 | ||||
-rw-r--r-- | 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>(&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<Vertex> 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<long>(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<Go>(std::accumulate(links.begin(), links.end(), 0, + return std::make_unique<Go>(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 <cache.h> -#include <cmath> #include <gfx/gl/shader.h> #include <gfx/image.h> #include <gfx/models/mesh.h> #include <gfx/models/vertex.hpp> #include <glm/glm.hpp> #include <location.hpp> +#include <maths.h> #include <random> #include <stb_image.h> @@ -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 <cstddef>
+
+#define offset_ptr(T, m) (((char *)1) + offsetof(T, m) - 1)
Mesh::Mesh(const std::span<const Vertex> vertices, const std::span<const unsigned int> 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<const Vertex> vertices, const std::span<const unsigne glGenBuffers(2, m_vertexArrayBuffers.data());
glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffers[0]);
- glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * vertices.size(), vertices.data(), GL_STATIC_DRAW);
+ glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)(sizeof(Vertex) * vertices.size()), vertices.data(), GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, pos));
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), offset_ptr(Vertex, pos));
glEnableVertexAttribArray(1);
- glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, texCoord));
+ glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), offset_ptr(Vertex, texCoord));
glEnableVertexAttribArray(2);
- glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *)offsetof(Vertex, normal));
+ glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), offset_ptr(Vertex, normal));
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vertexArrayBuffers[1]);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices[0]) * indices.size(), indices.data(), GL_STATIC_DRAW);
+ glBufferData(
+ GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)(sizeof(indices[0]) * indices.size()), indices.data(), GL_STATIC_DRAW);
glBindVertexArray(0);
}
diff --git a/gfx/models/mesh.h b/gfx/models/mesh.h index 8825aa2..c9f1204 100644 --- a/gfx/models/mesh.h +++ b/gfx/models/mesh.h @@ -3,7 +3,6 @@ #include <GL/glew.h>
#include <array>
-#include <cstddef>
#include <memory>
#include <span>
#include <special_members.hpp>
@@ -27,7 +26,7 @@ private: GLuint m_vertexArrayObject;
std::array<GLuint, NUM_BUFFERS> m_vertexArrayBuffers;
- size_t m_numIndices;
+ GLsizei m_numIndices;
GLenum mode;
};
using MeshPtr = std::shared_ptr<const Mesh>;
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<typename T> +inline constexpr auto +sq(T v) +{ + return v * v; +} + +template<typename R = float, typename Ta, typename Tb> +inline constexpr auto +rdiv(Ta a, Tb b) +{ + return ((R)a / (R)b); +} + constexpr inline glm::vec2 operator!(const glm::vec3 & v) { |