summaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-03-13 20:42:40 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-03-13 20:42:50 +0000
commit49ff05eda05f4f06eda3b6a2a6b116005db42e57 (patch)
tree8848b18fe92ee26e0c6a40e61d3436c4c8d9979a /game
parentSimplified TestLink extending LinkStraight (diff)
downloadilt-49ff05eda05f4f06eda3b6a2a6b116005db42e57.tar.bz2
ilt-49ff05eda05f4f06eda3b6a2a6b116005db42e57.tar.xz
ilt-49ff05eda05f4f06eda3b6a2a6b116005db42e57.zip
Route Walker returns Link::Nexts, not vector links
This makes more sense when you realise that the existing navigation workings work on exactly the same type!
Diffstat (limited to 'game')
-rw-r--r--game/network/network.cpp4
-rw-r--r--game/network/network.h5
-rw-r--r--game/network/routeWalker.cpp9
-rw-r--r--game/network/routeWalker.h3
4 files changed, 10 insertions, 11 deletions
diff --git a/game/network/network.cpp b/game/network/network.cpp
index 7349ff0..6eaccef 100644
--- a/game/network/network.cpp
+++ b/game/network/network.cpp
@@ -47,7 +47,7 @@ Network::joinLinks(const LinkPtr & l, const LinkPtr & ol)
}
}
-std::vector<LinkWPtr>
+Link::Nexts
Network::routeFromTo(const Link::End & start, glm::vec3 dest) const
{
auto destNode {findNodeAt(dest)};
@@ -57,7 +57,7 @@ Network::routeFromTo(const Link::End & start, glm::vec3 dest) const
return routeFromTo(start, destNode);
}
-std::vector<LinkWPtr>
+Link::Nexts
Network::routeFromTo(const Link::End & end, const NodePtr & dest) const
{
return RouteWalker().findRouteTo(end, dest);
diff --git a/game/network/network.h b/game/network/network.h
index f84c90c..31fc744 100644
--- a/game/network/network.h
+++ b/game/network/network.h
@@ -10,7 +10,6 @@
#include <sorting.hpp>
#include <string>
#include <utility>
-#include <vector>
class Texture;
class Shader;
@@ -23,8 +22,8 @@ public:
[[nodiscard]] NodePtr nodeAt(glm::vec3);
[[nodiscard]] std::pair<NodePtr, bool> newNodeAt(glm::vec3);
- [[nodiscard]] std::vector<LinkWPtr> routeFromTo(const Link::End &, glm::vec3) const;
- [[nodiscard]] std::vector<LinkWPtr> routeFromTo(const Link::End &, const NodePtr &) const;
+ [[nodiscard]] Link::Nexts routeFromTo(const Link::End &, glm::vec3) const;
+ [[nodiscard]] Link::Nexts routeFromTo(const Link::End &, const NodePtr &) const;
protected:
static void joinLinks(const LinkPtr & l, const LinkPtr & ol);
diff --git a/game/network/routeWalker.cpp b/game/network/routeWalker.cpp
index 496f9f3..d669db2 100644
--- a/game/network/routeWalker.cpp
+++ b/game/network/routeWalker.cpp
@@ -4,6 +4,7 @@
#include <limits>
#include <memory>
#include <utility>
+#include <vector>
RouteWalker::RouteWalker() : solutionLength {std::numeric_limits<float>::max()} { }
@@ -27,10 +28,10 @@ RouteWalker::findRouteTo(const Link::End & currentEnd, const NodePtr & dest, flo
return;
}
visited.insert(&currentEnd);
- for (const auto & nexts : currentEnd.nexts) {
- const auto link = nexts.first.lock();
- currentSolution.push_back(link);
- findRouteTo(link->ends[!nexts.second], dest, length + link->length);
+ for (const auto & next : currentEnd.nexts) {
+ const auto link = next.first.lock();
+ currentSolution.emplace_back(next);
+ findRouteTo(link->ends[!next.second], dest, length + link->length);
currentSolution.pop_back();
}
visited.erase(&currentEnd);
diff --git a/game/network/routeWalker.h b/game/network/routeWalker.h
index 7b1e1c8..d70103f 100644
--- a/game/network/routeWalker.h
+++ b/game/network/routeWalker.h
@@ -3,11 +3,10 @@
#include "link.h"
#include <set>
-#include <vector>
class RouteWalker {
public:
- using Solution = std::vector<LinkWPtr>;
+ using Solution = Link::Nexts;
RouteWalker();