From 49ff05eda05f4f06eda3b6a2a6b116005db42e57 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 13 Mar 2021 20:42:40 +0000 Subject: 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! --- game/network/network.cpp | 4 ++-- game/network/network.h | 5 ++--- game/network/routeWalker.cpp | 9 +++++---- game/network/routeWalker.h | 3 +-- 4 files changed, 10 insertions(+), 11 deletions(-) (limited to 'game/network') 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 +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 +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 #include #include -#include class Texture; class Shader; @@ -23,8 +22,8 @@ public: [[nodiscard]] NodePtr nodeAt(glm::vec3); [[nodiscard]] std::pair newNodeAt(glm::vec3); - [[nodiscard]] std::vector routeFromTo(const Link::End &, glm::vec3) const; - [[nodiscard]] std::vector 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 #include #include +#include RouteWalker::RouteWalker() : solutionLength {std::numeric_limits::max()} { } @@ -27,10 +28,10 @@ RouteWalker::findRouteTo(const Link::End & currentEnd, const NodePtr & dest, flo return; } visited.insert(¤tEnd); - 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(¤tEnd); 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 -#include class RouteWalker { public: - using Solution = std::vector; + using Solution = Link::Nexts; RouteWalker(); -- cgit v1.2.3