summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-02-14 14:32:25 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-02-14 14:32:25 +0000
commit169068b417323232cc6aac440f3d7a2d918b5917 (patch)
tree6a97eba1b3027feaa8e5530f7df625c0430a61b1
parentAdd our first vehicle (diff)
downloadilt-169068b417323232cc6aac440f3d7a2d918b5917.tar.bz2
ilt-169068b417323232cc6aac440f3d7a2d918b5917.tar.xz
ilt-169068b417323232cc6aac440f3d7a2d918b5917.zip
Code tidy-up
-rw-r--r--game/network/link.h2
-rw-r--r--game/network/rail.cpp4
-rw-r--r--game/network/rail.h9
-rw-r--r--game/vehicles/railloco.cpp8
-rw-r--r--game/vehicles/railloco.h3
-rw-r--r--game/vehicles/vehicle.cpp6
-rw-r--r--game/vehicles/vehicle.h3
-rw-r--r--iwyu.json8
-rw-r--r--test/test-maths.cpp2
-rw-r--r--utility/maths.cpp1
10 files changed, 32 insertions, 14 deletions
diff --git a/game/network/link.h b/game/network/link.h
index 3fabf05..d4ae4c6 100644
--- a/game/network/link.h
+++ b/game/network/link.h
@@ -37,7 +37,7 @@ public:
NO_COPY(Link);
NO_MOVE(Link);
- virtual Transform positionAt(float dist, unsigned char start) const = 0;
+ [[nodiscard]] virtual Transform positionAt(float dist, unsigned char start) const = 0;
std::array<End, 2> ends;
float length;
diff --git a/game/network/rail.cpp b/game/network/rail.cpp
index 56feec0..1f3cc01 100644
--- a/game/network/rail.cpp
+++ b/game/network/rail.cpp
@@ -8,7 +8,7 @@
#include <gfx/models/texture.h>
#include <gfx/models/vertex.hpp>
#include <glm/gtx/transform.hpp>
-#include <glm/gtx/vector_angle.hpp>
+#include <initializer_list>
#include <maths.h>
#include <type_traits>
#include <utility>
@@ -17,7 +17,7 @@ RailLinks::RailLinks() : texture {Texture::cachedTexture.get("rails.jpg")} { }
void RailLinks::tick(TickDuration) { }
void
-RailLinks::joinLinks(LinkPtr l) const
+RailLinks::joinLinks(const LinkPtr & l) const
{
for (const auto & ol : links.objects) {
if (l != ol) {
diff --git a/game/network/rail.h b/game/network/rail.h
index 58c26c3..ac944f3 100644
--- a/game/network/rail.h
+++ b/game/network/rail.h
@@ -3,6 +3,7 @@
#include "collection.hpp"
#include "game/worldobject.h"
+#include "gfx/gl/transform.h"
#include "gfx/models/mesh.h"
#include "gfx/models/vertex.hpp"
#include "gfx/renderable.h"
@@ -36,7 +37,7 @@ protected:
class RailLinkStraight : public RailLink {
public:
RailLinkStraight(const NodePtr &, const NodePtr &);
- Transform positionAt(float dist, unsigned char start) const override;
+ [[nodiscard]] Transform positionAt(float dist, unsigned char start) const override;
private:
RailLinkStraight(NodePtr, NodePtr, const glm::vec3 & diff);
@@ -45,7 +46,7 @@ private:
class RailLinkCurve : public RailLink {
public:
RailLinkCurve(const NodePtr &, const NodePtr &, glm::vec2);
- Transform positionAt(float dist, unsigned char start) const override;
+ [[nodiscard]] Transform positionAt(float dist, unsigned char start) const override;
private:
RailLinkCurve(const NodePtr &, const NodePtr &, glm::vec3, const Arc);
@@ -65,7 +66,7 @@ public:
{
const auto node1 = *nodes.insert(std::make_shared<Node>(a)).first;
const auto node2 = *nodes.insert(std::make_shared<Node>(b)).first;
- auto l = links.create<T>(node1, node2, std::forward<Params>(params)...);
+ auto l {links.create<T>(node1, node2, std::forward<Params>(params)...)};
joinLinks(l);
return l;
}
@@ -76,7 +77,7 @@ private:
Nodes nodes;
void render(const Shader &) const override;
void tick(TickDuration elapsed) override;
- void joinLinks(LinkPtr) const;
+ void joinLinks(const LinkPtr &) const;
std::shared_ptr<Texture> texture;
};
diff --git a/game/vehicles/railloco.cpp b/game/vehicles/railloco.cpp
index baa9b81..54582c2 100644
--- a/game/vehicles/railloco.cpp
+++ b/game/vehicles/railloco.cpp
@@ -1,8 +1,12 @@
#include "railloco.h"
-#include "game/vehicles/vehicle.h"
#include "gfx/gl/transform.h"
+#include <algorithm>
+#include <array>
#include <glm/glm.hpp>
#include <maths.h>
+#include <memory>
+#include <utility>
+#include <vector>
void
RailLoco::tick(TickDuration dur)
@@ -27,4 +31,4 @@ RailLoco::tick(TickDuration dur)
location = link->positionAt(linkDist, linkDir);
}
-Brush47::Brush47(LinkPtr l) : RailLoco(l, "brush47.obj", "brush47.png") { }
+Brush47::Brush47(const LinkPtr & l) : RailLoco(l, "brush47.obj", "brush47.png") { }
diff --git a/game/vehicles/railloco.h b/game/vehicles/railloco.h
index 05e3e48..833b661 100644
--- a/game/vehicles/railloco.h
+++ b/game/vehicles/railloco.h
@@ -1,3 +1,4 @@
+#include "game/network/link.h"
#include "game/worldobject.h"
#include "vehicle.h"
#include <string>
@@ -10,5 +11,5 @@ public:
class Brush47 : public RailLoco {
public:
- Brush47(LinkPtr p);
+ explicit Brush47(const LinkPtr & p);
};
diff --git a/game/vehicles/vehicle.cpp b/game/vehicles/vehicle.cpp
index 4c4ac71..c12181f 100644
--- a/game/vehicles/vehicle.cpp
+++ b/game/vehicles/vehicle.cpp
@@ -1,6 +1,10 @@
#include "vehicle.h"
+#include "game/network/link.h"
+#include <array>
+#include <memory>
+#include <utility>
-Vehicle::Vehicle(LinkPtr l, const std::string & obj, const std::string & tex) :
+Vehicle::Vehicle(const LinkPtr & l, const std::string & obj, const std::string & tex) :
Physical(l->ends.front().first->pos, obj, tex), link(l)
{
}
diff --git a/game/vehicles/vehicle.h b/game/vehicles/vehicle.h
index 01be6a6..cd2249d 100644
--- a/game/vehicles/vehicle.h
+++ b/game/vehicles/vehicle.h
@@ -4,12 +4,11 @@
#include "game/physical.h"
#include <game/network/link.h>
#include <game/worldobject.h>
-#include <glm/glm.hpp>
#include <string>
class Vehicle : public WorldObject, public Physical {
public:
- Vehicle(LinkPtr link, const std::string & obj, const std::string & tex);
+ Vehicle(const LinkPtr & link, const std::string & obj, const std::string & tex);
LinkPtr link; // Which link are we travelling along
unsigned char linkDir {0}; // Starting end e0->e1 or e1->e0
float linkDist {0}; // distance long current link
diff --git a/iwyu.json b/iwyu.json
index 763fb95..54e4e0c 100644
--- a/iwyu.json
+++ b/iwyu.json
@@ -81,6 +81,14 @@
},
{
"include": [
+ "@<boost/test/data/.*>",
+ "private",
+ "<boost/test/data/test_case.hpp>",
+ "public"
+ ]
+ },
+ {
+ "include": [
"@<boost/test/tools/.*>",
"private",
"<boost/test/unit_test.hpp>",
diff --git a/test/test-maths.cpp b/test/test-maths.cpp
index 6187c46..b620aae 100644
--- a/test/test-maths.cpp
+++ b/test/test-maths.cpp
@@ -4,7 +4,9 @@
#include <boost/test/unit_test.hpp>
#include <stream_support.hpp>
+#include <glm/glm.hpp>
#include <maths.h>
+#include <tuple>
constexpr auto quarter_pi = pi / 4.F;
using vecter_to_angle = std::tuple<glm::vec3, float>;
diff --git a/utility/maths.cpp b/utility/maths.cpp
index fb14a17..0bd3eac 100644
--- a/utility/maths.cpp
+++ b/utility/maths.cpp
@@ -3,7 +3,6 @@
#include <glm/glm.hpp>
#include <glm/gtx/rotate_vector.hpp>
#include <glm/gtx/transform.hpp>
-#include <glm/gtx/vector_angle.hpp>
glm::mat4
flat_orientation(const glm::vec3 & diff)