summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-10-25 17:53:16 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2022-10-28 02:10:47 +0100
commitf2954a08d726c3c94212fb848adc3fe3cf298cf1 (patch)
tree343dd4e525c786c069a4eaf4dc6029f9d44b603e /game
parentAdd AnyPtr for accepting pointers of any kind into a function (diff)
downloadilt-f2954a08d726c3c94212fb848adc3fe3cf298cf1.tar.bz2
ilt-f2954a08d726c3c94212fb848adc3fe3cf298cf1.tar.xz
ilt-f2954a08d726c3c94212fb848adc3fe3cf298cf1.zip
Move findDir into member function findNodeDirection
Diffstat (limited to 'game')
-rw-r--r--game/network/network.h4
-rw-r--r--game/network/network.impl.h15
-rw-r--r--game/network/rail.cpp15
3 files changed, 21 insertions, 13 deletions
diff --git a/game/network/network.h b/game/network/network.h
index 25f0200..f1ac23f 100644
--- a/game/network/network.h
+++ b/game/network/network.h
@@ -40,6 +40,8 @@ public:
virtual Link::CCollection addJoins(glm::vec3, glm::vec3) = 0;
virtual Link::CCollection addExtend(glm::vec3, glm::vec3) = 0;
+ virtual float findNodeDirection(Node::AnyCPtr) const = 0;
+
protected:
static void joinLinks(const Link::Ptr & l, const Link::Ptr & ol);
@@ -86,6 +88,8 @@ public:
Link::CCollection addJoins(glm::vec3, glm::vec3) override;
Link::CCollection addExtend(glm::vec3, glm::vec3) override;
+ float findNodeDirection(Node::AnyCPtr) const override;
+
void render(const Shader &) const override;
protected:
diff --git a/game/network/network.impl.h b/game/network/network.impl.h
index d112bf7..cee8155 100644
--- a/game/network/network.impl.h
+++ b/game/network/network.impl.h
@@ -38,6 +38,21 @@ NetworkOf<T>::intersectRayLinks(const Ray & ray) const
}
template<typename T>
+float
+NetworkOf<T>::findNodeDirection(Node::AnyCPtr n) const
+{
+ for (const auto & l : links.objects) {
+ for (const auto & e : l->ends) {
+ // cppcheck-suppress useStlAlgorithm
+ if (e.node.get() == n.get()) {
+ return e.dir;
+ }
+ }
+ }
+ throw std::runtime_error("Node exists but couldn't find it");
+}
+
+template<typename T>
Link::CCollection
NetworkOf<T>::candidateStraight(glm::vec3 n1, glm::vec3 n2)
{
diff --git a/game/network/rail.cpp b/game/network/rail.cpp
index 95b6d24..2efa87a 100644
--- a/game/network/rail.cpp
+++ b/game/network/rail.cpp
@@ -40,18 +40,7 @@ RailLinks::addLinksBetween(glm::vec3 start, glm::vec3 end)
std::swap(start, end);
}
// Find start link/end - opposite entry dir to existing link; so pi +...
- const auto findDir = [this](const auto & n) {
- for (const auto & l : links.objects) {
- for (const auto & e : l->ends) {
- // cppcheck-suppress useStlAlgorithm
- if (e.node == n) {
- return e.dir;
- }
- }
- }
- throw std::runtime_error("Node exists but couldn't find it");
- };
- float dir = pi + findDir(node1ins.first);
+ float dir = pi + findNodeDirection(node1ins.first);
if (dir == vector_yaw(end - start)) {
return addLink<RailLinkStraight>(start, end);
}
@@ -61,7 +50,7 @@ RailLinks::addLinksBetween(glm::vec3 start, glm::vec3 end)
const auto sm = glm::distance(flatStart, mid), em = glm::distance(flatEnd, mid);
return start.z + ((end.z - start.z) * (sm / (sm + em)));
};
- float dir2 = pi + findDir(node2ins.first);
+ float dir2 = pi + findNodeDirection(node2ins.first);
if (const auto radii = find_arcs_radius(flatStart, dir, flatEnd, dir2); radii.first < radii.second) {
const auto radius {radii.first};
const auto c1 = flatStart + sincosf(dir + half_pi) * radius;