diff options
-rw-r--r-- | game/network/network.cpp | 4 | ||||
-rw-r--r-- | game/network/network.h | 5 | ||||
-rw-r--r-- | game/network/routeWalker.cpp | 9 | ||||
-rw-r--r-- | game/network/routeWalker.h | 3 | ||||
-rw-r--r-- | 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<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(¤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 <set> -#include <vector> class RouteWalker { public: - using Solution = std::vector<LinkWPtr>; + 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() |