Add name to pathfinding classes

This commit is contained in:
Jan Mrna 2025-09-27 18:36:22 +02:00
parent 76f10725ec
commit 1b0edb664c
3 changed files with 25 additions and 1 deletions

View File

@ -17,11 +17,18 @@ Path LinearPathFinder::CalculatePath(WorldPos target)
return path; return path;
} }
Path BFS::CalculatePath(WorldPos target)
{
auto path = Path{target};
return path;
}
std::unique_ptr<PathFinderBase> create(PathFinderType type) { std::unique_ptr<PathFinderBase> create(PathFinderType type) {
switch (type) { switch (type) {
case PathFinderType::LINEAR: case PathFinderType::LINEAR:
return std::move(std::make_unique<LinearPathFinder>()); return std::move(std::make_unique<LinearPathFinder>());
case PathFinderType::BFS: case PathFinderType::BFS:
return std::move(std::make_unique<BFS>());
case PathFinderType::COUNT: case PathFinderType::COUNT:
LOG_WARNING("Incorrect pathfinder type"); LOG_WARNING("Incorrect pathfinder type");
return nullptr; return nullptr;

View File

@ -27,6 +27,7 @@ public:
PathFinderBase& operator=(PathFinderBase&&) = delete; PathFinderBase& operator=(PathFinderBase&&) = delete;
void SetMap(std::shared_ptr<Map> map); void SetMap(std::shared_ptr<Map> map);
virtual const std::string_view& GetName() const = 0;
virtual Path CalculatePath(WorldPos target) = 0; virtual Path CalculatePath(WorldPos target) = 0;
private: private:
@ -35,11 +36,26 @@ private:
class LinearPathFinder : public PathFinderBase { class LinearPathFinder : public PathFinderBase {
public:
Path CalculatePath(WorldPos target) override; 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<PathFinderBase> create(PathFinderType type); std::unique_ptr<PathFinderBase> create(PathFinderType type);
} // pathfinder namespace } // pathfinder namespace

View File

@ -89,6 +89,7 @@ void PathFindingDemo::HandleActions(const std::vector<UserAction> &actions) {
using namespace pathfinder; using namespace pathfinder;
PathFinderType type = static_cast<PathFinderType>(action.Argument.number); PathFinderType type = static_cast<PathFinderType>(action.Argument.number);
m_PathFinder = create(type); m_PathFinder = create(type);
LOG_INFO("Switched to path finding method: ", m_PathFinder->GetName());
} }
}; };
} }