summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--test/test-network.cpp4
-rw-r--r--ui/builders/join.cpp2
-rw-r--r--ui/builders/join.h4
-rw-r--r--ui/editNetwork.h2
13 files changed, 37 insertions, 37 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;
diff --git a/test/test-network.cpp b/test/test-network.cpp
index af2c76e..bfcf64b 100644
--- a/test/test-network.cpp
+++ b/test/test-network.cpp
@@ -19,8 +19,8 @@
#include <vector>
struct TestLink : public LinkStraight {
- TestLink(NodePtr a, NodePtr b) : TestLink {a, b, glm::distance(a->pos, b->pos)} { }
- TestLink(NodePtr a, NodePtr b, float l) : Link {{std::move(a), 0}, {std::move(b), pi}, l} { }
+ TestLink(Node::Ptr a, Node::Ptr b) : TestLink {a, b, glm::distance(a->pos, b->pos)} { }
+ TestLink(Node::Ptr a, Node::Ptr b, float l) : Link {{std::move(a), 0}, {std::move(b), pi}, l} { }
using StraightLink = TestLink;
};
diff --git a/ui/builders/join.cpp b/ui/builders/join.cpp
index 90b1d61..cc2ca2d 100644
--- a/ui/builders/join.cpp
+++ b/ui/builders/join.cpp
@@ -37,7 +37,7 @@ BuilderJoin::click(Network * network, const GeoData *, const SDL_MouseButtonEven
}
void
-BuilderJoin::create(Network * network, const NodePtr & p1, const NodePtr & p2) const
+BuilderJoin::create(Network * network, const Node::Ptr & p1, const Node::Ptr & p2) const
{
network->addJoins(p1->pos, p2->pos);
}
diff --git a/ui/builders/join.h b/ui/builders/join.h
index d4fb534..30d39cd 100644
--- a/ui/builders/join.h
+++ b/ui/builders/join.h
@@ -9,7 +9,7 @@ class BuilderJoin : public EditNetwork::Builder {
std::string hint() const override;
void click(Network * network, const GeoData * geoData, const SDL_MouseButtonEvent & e, const Ray & ray) override;
- void create(Network * network, const NodePtr & p1, const NodePtr & p2) const;
+ void create(Network * network, const Node::Ptr & p1, const Node::Ptr & p2) const;
- NodePtr p1;
+ Node::Ptr p1;
};
diff --git a/ui/editNetwork.h b/ui/editNetwork.h
index 72e0955..6f3b009 100644
--- a/ui/editNetwork.h
+++ b/ui/editNetwork.h
@@ -21,7 +21,7 @@ public:
void render(const Shader &) const override;
void render(const UIShader & shader, const UIComponent::Position & pos) const override;
- using NetworkClickPos = std::variant<glm::vec3, NodePtr>;
+ using NetworkClickPos = std::variant<glm::vec3, Node::Ptr>;
class Builder {
public: