From 1b0edb664c5c4e1ccdb245b4e3edf6b6aaa41a8d Mon Sep 17 00:00:00 2001 From: Jan Mrna Date: Sat, 27 Sep 2025 18:36:22 +0200 Subject: [PATCH] Add name to pathfinding classes --- cpp/src/pathfinder.cpp | 7 +++++++ cpp/src/pathfinder.hpp | 18 +++++++++++++++++- cpp/src/pathfindingdemo.cpp | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/cpp/src/pathfinder.cpp b/cpp/src/pathfinder.cpp index ef99171..fd290bb 100644 --- a/cpp/src/pathfinder.cpp +++ b/cpp/src/pathfinder.cpp @@ -17,11 +17,18 @@ Path LinearPathFinder::CalculatePath(WorldPos target) return path; } +Path BFS::CalculatePath(WorldPos target) +{ + auto path = Path{target}; + return path; +} + std::unique_ptr create(PathFinderType type) { switch (type) { case PathFinderType::LINEAR: return std::move(std::make_unique()); case PathFinderType::BFS: + return std::move(std::make_unique()); case PathFinderType::COUNT: LOG_WARNING("Incorrect pathfinder type"); return nullptr; diff --git a/cpp/src/pathfinder.hpp b/cpp/src/pathfinder.hpp index 12f5add..82b0993 100644 --- a/cpp/src/pathfinder.hpp +++ b/cpp/src/pathfinder.hpp @@ -27,6 +27,7 @@ public: PathFinderBase& operator=(PathFinderBase&&) = delete; void SetMap(std::shared_ptr map); + virtual const std::string_view& GetName() const = 0; virtual Path CalculatePath(WorldPos target) = 0; private: @@ -35,11 +36,26 @@ private: class LinearPathFinder : public PathFinderBase { + +public: Path CalculatePath(WorldPos target) override; + const std::string_view& GetName() const override { return m_Name; } + +private: + const std::string_view m_Name = "Linear Path"; +}; + +class BFS: public PathFinderBase { + +public: + Path CalculatePath(WorldPos target) override; + const std::string_view& GetName() const override { return m_Name; } + +private: + const std::string_view m_Name = "Breadth First Search"; }; std::unique_ptr create(PathFinderType type); - } // pathfinder namespace diff --git a/cpp/src/pathfindingdemo.cpp b/cpp/src/pathfindingdemo.cpp index d22f89a..b945f19 100644 --- a/cpp/src/pathfindingdemo.cpp +++ b/cpp/src/pathfindingdemo.cpp @@ -89,6 +89,7 @@ void PathFindingDemo::HandleActions(const std::vector &actions) { using namespace pathfinder; PathFinderType type = static_cast(action.Argument.number); m_PathFinder = create(type); + LOG_INFO("Switched to path finding method: ", m_PathFinder->GetName()); } }; }