summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-10-13 20:27:46 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2022-10-13 20:27:46 +0100
commitfab2d34959c52383f6be3cb6634c6776b41f62a8 (patch)
treecbf8f4b717d50af882689b5e012c2e3737f44077 /game
parentInheritable of standard typedefs (diff)
downloadilt-fab2d34959c52383f6be3cb6634c6776b41f62a8.tar.bz2
ilt-fab2d34959c52383f6be3cb6634c6776b41f62a8.tar.xz
ilt-fab2d34959c52383f6be3cb6634c6776b41f62a8.zip
Standard typedefs for Node
Diffstat (limited to 'game')
-rw-r--r--game/network/link.h6
-rw-r--r--game/network/network.cpp14
-rw-r--r--game/network/network.h14
-rw-r--r--game/network/rail.cpp8
-rw-r--r--game/network/rail.h8
-rw-r--r--game/network/routeWalker.cpp4
-rw-r--r--game/network/routeWalker.h4
-rw-r--r--game/objectives/goto.cpp2
-rw-r--r--game/objectives/goto.h2
9 files changed, 31 insertions, 31 deletions
diff --git a/game/network/link.h b/game/network/link.h
index 6441c8b..2beb808 100644
--- a/game/network/link.h
+++ b/game/network/link.h
@@ -6,6 +6,7 @@
#include <maths.h>
#include <memory>
#include <special_members.hpp>
+#include <stdTypeDefs.hpp>
#include <utility>
#include <vector>
@@ -14,7 +15,7 @@ class Ray;
// Generic network node
// something that can be travelled to
// it has location
-class Node {
+class Node : public StdTypeDefs<Node> {
public:
explicit Node(glm::vec3 p) noexcept : pos(p) {};
virtual ~Node() noexcept = default;
@@ -23,7 +24,6 @@ public:
glm::vec3 pos;
};
-using NodePtr = std::shared_ptr<Node>;
// Generic network link
// something that can be travelled along
@@ -38,7 +38,7 @@ public:
using Nexts = std::vector<Next>;
struct End {
- NodePtr node;
+ Node::Ptr node;
float dir;
Nexts nexts {};
};
diff --git a/game/network/network.cpp b/game/network/network.cpp
index 9683143..25dc384 100644
--- a/game/network/network.cpp
+++ b/game/network/network.cpp
@@ -13,13 +13,13 @@
Network::Network(const std::string & tn) : texture {Texture::cachedTexture.get(tn)} { }
-NodePtr
+Node::Ptr
Network::nodeAt(glm::vec3 pos)
{
return newNodeAt(pos).first;
}
-std::pair<NodePtr, bool>
+std::pair<Node::Ptr, bool>
Network::newNodeAt(glm::vec3 pos)
{
const auto [n, i] = candidateNodeAt(pos);
@@ -29,7 +29,7 @@ Network::newNodeAt(glm::vec3 pos)
return {n, !i};
}
-NodePtr
+Node::Ptr
Network::findNodeAt(glm::vec3 pos) const
{
if (const auto n = nodes.find(pos); n != nodes.end()) {
@@ -38,7 +38,7 @@ Network::findNodeAt(glm::vec3 pos) const
return {};
}
-std::pair<NodePtr, bool>
+std::pair<Node::Ptr, bool>
Network::candidateNodeAt(glm::vec3 pos) const
{
if (const auto n = nodes.find(pos); n != nodes.end()) {
@@ -47,12 +47,12 @@ Network::candidateNodeAt(glm::vec3 pos) const
return {std::make_shared<Node>(pos), false};
}
-NodePtr
+Node::Ptr
Network::intersectRayNodes(const Ray & ray) const
{
// Click within 2m of a node
if (const auto node = std::find_if(nodes.begin(), nodes.end(),
- [&ray](const NodePtr & node) {
+ [&ray](const Node::Ptr & node) {
glm::vec3 ipos, inorm;
return glm::intersectRaySphere(ray.start, ray.direction, node->pos, 2.F, ipos, inorm);
});
@@ -88,7 +88,7 @@ Network::routeFromTo(const Link::End & start, glm::vec3 dest) const
}
Link::Nexts
-Network::routeFromTo(const Link::End & end, const NodePtr & dest) const
+Network::routeFromTo(const Link::End & end, const Node::Ptr & dest) const
{
return RouteWalker().findRouteTo(end, dest);
}
diff --git a/game/network/network.h b/game/network/network.h
index 34e6a60..4ef6a4f 100644
--- a/game/network/network.h
+++ b/game/network/network.h
@@ -21,15 +21,15 @@ public:
explicit Network(const std::string & textureName);
virtual ~Network() = default;
- [[nodiscard]] NodePtr findNodeAt(glm::vec3) const;
- [[nodiscard]] NodePtr nodeAt(glm::vec3);
- [[nodiscard]] std::pair<NodePtr, bool> newNodeAt(glm::vec3);
- [[nodiscard]] std::pair<NodePtr, bool> candidateNodeAt(glm::vec3) const;
+ [[nodiscard]] Node::Ptr findNodeAt(glm::vec3) const;
+ [[nodiscard]] Node::Ptr nodeAt(glm::vec3);
+ [[nodiscard]] std::pair<Node::Ptr, bool> newNodeAt(glm::vec3);
+ [[nodiscard]] std::pair<Node::Ptr, bool> candidateNodeAt(glm::vec3) const;
[[nodiscard]] virtual LinkPtr intersectRayLinks(const Ray &) const = 0;
- [[nodiscard]] virtual NodePtr intersectRayNodes(const Ray &) const;
+ [[nodiscard]] virtual Node::Ptr intersectRayNodes(const Ray &) const;
[[nodiscard]] Link::Nexts routeFromTo(const Link::End &, glm::vec3) const;
- [[nodiscard]] Link::Nexts routeFromTo(const Link::End &, const NodePtr &) const;
+ [[nodiscard]] Link::Nexts routeFromTo(const Link::End &, const Node::Ptr &) const;
virtual LinkCPtr addStraight(glm::vec3, glm::vec3) = 0;
virtual CLinks addJoins(glm::vec3, glm::vec3) = 0;
@@ -37,7 +37,7 @@ public:
protected:
static void joinLinks(const LinkPtr & l, const LinkPtr & ol);
- using Nodes = std::set<NodePtr, PtrMemberSorter<NodePtr, &Node::pos>>;
+ using Nodes = std::set<Node::Ptr, PtrMemberSorter<Node::Ptr, &Node::pos>>;
Nodes nodes;
std::shared_ptr<Texture> texture;
};
diff --git a/game/network/rail.cpp b/game/network/rail.cpp
index 73ab3bf..5fec7c1 100644
--- a/game/network/rail.cpp
+++ b/game/network/rail.cpp
@@ -128,9 +128,9 @@ round_sleepers(const float v)
return round_frac(v, sleepers);
}
-RailLinkStraight::RailLinkStraight(const NodePtr & a, const NodePtr & b) : RailLinkStraight(a, b, b->pos - a->pos) { }
+RailLinkStraight::RailLinkStraight(const Node::Ptr & a, const Node::Ptr & b) : RailLinkStraight(a, b, b->pos - a->pos) { }
-RailLinkStraight::RailLinkStraight(NodePtr a, NodePtr b, const glm::vec3 & diff) :
+RailLinkStraight::RailLinkStraight(Node::Ptr a, Node::Ptr b, const glm::vec3 & diff) :
Link({std::move(a), vector_yaw(diff)}, {std::move(b), vector_yaw(-diff)}, glm::length(diff))
{
if (glGenVertexArrays) {
@@ -149,12 +149,12 @@ RailLinkStraight::RailLinkStraight(NodePtr a, NodePtr b, const glm::vec3 & diff)
}
}
-RailLinkCurve::RailLinkCurve(const NodePtr & a, const NodePtr & b, glm::vec2 c) :
+RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, glm::vec2 c) :
RailLinkCurve(a, b, c ^ a->pos.z, {!c, a->pos, b->pos})
{
}
-RailLinkCurve::RailLinkCurve(const NodePtr & a, const NodePtr & b, glm::vec3 c, const Arc arc) :
+RailLinkCurve::RailLinkCurve(const Node::Ptr & a, const Node::Ptr & b, glm::vec3 c, const Arc arc) :
Link({a, normalize(arc.first + half_pi)}, {b, normalize(arc.second - half_pi)},
(glm::length(a->pos - c)) * arc_length(arc)),
LinkCurve {c, glm::length(ends[0].node->pos - c), arc}
diff --git a/game/network/rail.h b/game/network/rail.h
index c1cb579..78d4a86 100644
--- a/game/network/rail.h
+++ b/game/network/rail.h
@@ -38,18 +38,18 @@ RailLink::~RailLink() = default;
class RailLinkStraight : public RailLink, public LinkStraight {
public:
- RailLinkStraight(const NodePtr &, const NodePtr &);
+ RailLinkStraight(const Node::Ptr &, const Node::Ptr &);
private:
- RailLinkStraight(NodePtr, NodePtr, const glm::vec3 & diff);
+ RailLinkStraight(Node::Ptr, Node::Ptr, const glm::vec3 & diff);
};
class RailLinkCurve : public RailLink, public LinkCurve {
public:
- RailLinkCurve(const NodePtr &, const NodePtr &, glm::vec2);
+ RailLinkCurve(const Node::Ptr &, const Node::Ptr &, glm::vec2);
private:
- RailLinkCurve(const NodePtr &, const NodePtr &, glm::vec3, const Arc);
+ RailLinkCurve(const Node::Ptr &, const Node::Ptr &, glm::vec3, const Arc);
};
class RailLinks : public NetworkOf<RailLink>, public WorldObject {
diff --git a/game/network/routeWalker.cpp b/game/network/routeWalker.cpp
index d669db2..cdbc879 100644
--- a/game/network/routeWalker.cpp
+++ b/game/network/routeWalker.cpp
@@ -9,7 +9,7 @@
RouteWalker::RouteWalker() : solutionLength {std::numeric_limits<float>::max()} { }
RouteWalker::Solution
-RouteWalker::findRouteTo(const Link::End & currentEnd, const NodePtr & dest)
+RouteWalker::findRouteTo(const Link::End & currentEnd, const Node::Ptr & dest)
{
findRouteTo(currentEnd, dest, 0);
return bestSolution;
@@ -17,7 +17,7 @@ RouteWalker::findRouteTo(const Link::End & currentEnd, const NodePtr & dest)
void
// NOLINTNEXTLINE(misc-no-recursion)
-RouteWalker::findRouteTo(const Link::End & currentEnd, const NodePtr & dest, float length)
+RouteWalker::findRouteTo(const Link::End & currentEnd, const Node::Ptr & dest, float length)
{
if (currentEnd.node == dest && length < solutionLength) {
bestSolution = currentSolution;
diff --git a/game/network/routeWalker.h b/game/network/routeWalker.h
index e0577ae..ebdf66e 100644
--- a/game/network/routeWalker.h
+++ b/game/network/routeWalker.h
@@ -9,10 +9,10 @@ public:
RouteWalker();
- Solution findRouteTo(const Link::End & currentEnd, const NodePtr & dest);
+ Solution findRouteTo(const Link::End & currentEnd, const Node::Ptr & dest);
private:
- void findRouteTo(const Link::End & currentEnd, const NodePtr & dest, float length);
+ void findRouteTo(const Link::End & currentEnd, const Node::Ptr & dest, float length);
std::set<const Link::End *> visited;
Solution bestSolution, currentSolution;
diff --git a/game/objectives/goto.cpp b/game/objectives/goto.cpp
index 8581a2d..2d9ce75 100644
--- a/game/objectives/goto.cpp
+++ b/game/objectives/goto.cpp
@@ -9,7 +9,7 @@
#include <numeric>
#include <vector>
-GoTo::GoTo(Orders * o, const Link::End & cp, float d, const NodePtr & dest) :
+GoTo::GoTo(Orders * o, const Link::End & cp, float d, const Node::Ptr & dest) :
Objective(o), links(RouteWalker().findRouteTo(cp, dest)), startDist {d}
{
}
diff --git a/game/objectives/goto.h b/game/objectives/goto.h
index acd5e48..ad51ecf 100644
--- a/game/objectives/goto.h
+++ b/game/objectives/goto.h
@@ -8,7 +8,7 @@ class Orders;
class GoTo : public Objective {
public:
- GoTo(Orders * os, const Link::End &, float, const NodePtr & dest);
+ GoTo(Orders * os, const Link::End &, float, const Node::Ptr & dest);
[[nodiscard]] ActivityPtr createActivity() const override;
[[nodiscard]] Link::Next navigate(Link::Nexts::const_iterator, Link::Nexts::const_iterator) const override;