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 +-- test/test-network.cpp | 20 ++++++++++---------- 5 files changed, 20 insertions(+), 21 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 +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(); diff --git a/test/test-network.cpp b/test/test-network.cpp index e5a2074..7727434 100644 --- a/test/test-network.cpp +++ b/test/test-network.cpp @@ -132,7 +132,7 @@ BOOST_AUTO_TEST_CASE(routeTo_upStream_to2) const auto & start = links.objects.front()->ends[1]; auto r = this->routeFromTo(start, p200); BOOST_REQUIRE_EQUAL(r.size(), 1); - BOOST_CHECK_EQUAL(r[0].lock().get(), links.objects[1].get()); + BOOST_CHECK_EQUAL(r[0].first.lock().get(), links.objects[1].get()); } BOOST_AUTO_TEST_CASE(routeTo_upStream_to3) @@ -140,8 +140,8 @@ BOOST_AUTO_TEST_CASE(routeTo_upStream_to3) const auto & start = links.objects[0]->ends[1]; auto r = this->routeFromTo(start, p300); BOOST_REQUIRE_EQUAL(r.size(), 2); - BOOST_CHECK_EQUAL(r[0].lock().get(), links.objects[1].get()); - BOOST_CHECK_EQUAL(r[1].lock().get(), links.objects[2].get()); + BOOST_CHECK_EQUAL(r[0].first.lock().get(), links.objects[1].get()); + BOOST_CHECK_EQUAL(r[1].first.lock().get(), links.objects[2].get()); } BOOST_AUTO_TEST_CASE(routeTo_downStream_to0) @@ -149,8 +149,8 @@ BOOST_AUTO_TEST_CASE(routeTo_downStream_to0) const auto & start = links.objects[2]->ends[0]; auto r = this->routeFromTo(start, p000); BOOST_REQUIRE_EQUAL(r.size(), 2); - BOOST_CHECK_EQUAL(r[0].lock().get(), links.objects[1].get()); - BOOST_CHECK_EQUAL(r[1].lock().get(), links.objects[0].get()); + BOOST_CHECK_EQUAL(r[0].first.lock().get(), links.objects[1].get()); + BOOST_CHECK_EQUAL(r[1].first.lock().get(), links.objects[0].get()); } BOOST_AUTO_TEST_CASE(routeTo_upStream_3to300) @@ -158,8 +158,8 @@ BOOST_AUTO_TEST_CASE(routeTo_upStream_3to300) const auto & start = links.objects[3]->ends[1]; auto r = this->routeFromTo(start, p300); BOOST_REQUIRE_EQUAL(r.size(), 2); - BOOST_CHECK_EQUAL(r[0].lock().get(), links.objects[4].get()); - BOOST_CHECK_EQUAL(r[1].lock().get(), links.objects[2].get()); + BOOST_CHECK_EQUAL(r[0].first.lock().get(), links.objects[4].get()); + BOOST_CHECK_EQUAL(r[1].first.lock().get(), links.objects[2].get()); } BOOST_AUTO_TEST_CASE(routeTo_downStream_3to300) @@ -167,9 +167,9 @@ BOOST_AUTO_TEST_CASE(routeTo_downStream_3to300) const auto & start = links.objects[3]->ends[0]; auto r = this->routeFromTo(start, p300); BOOST_REQUIRE_EQUAL(r.size(), 3); - BOOST_CHECK_EQUAL(r[0].lock().get(), links.objects[0].get()); - BOOST_CHECK_EQUAL(r[1].lock().get(), links.objects[1].get()); - BOOST_CHECK_EQUAL(r[2].lock().get(), links.objects[2].get()); + BOOST_CHECK_EQUAL(r[0].first.lock().get(), links.objects[0].get()); + BOOST_CHECK_EQUAL(r[1].first.lock().get(), links.objects[1].get()); + BOOST_CHECK_EQUAL(r[2].first.lock().get(), links.objects[2].get()); } BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3