now template

This commit is contained in:
Vladislav Alpatov
2025-03-01 21:11:46 +03:00
parent 9ba3bc754a
commit 6d0d267743
43 changed files with 224 additions and 256 deletions

View File

@@ -13,15 +13,15 @@ namespace omath::pathfinding
{
struct PathNode final
{
std::optional<Vector3> cameFrom;
std::optional<Vector3<float>> cameFrom;
float gCost = 0.f;
};
std::vector<Vector3> Astar::ReconstructFinalPath(const std::unordered_map<Vector3, PathNode>& closedList,
const Vector3& current)
std::vector<Vector3<float>> Astar::ReconstructFinalPath(const std::unordered_map<Vector3<float>, PathNode>& closedList,
const Vector3<float>& current)
{
std::vector<Vector3> path;
std::vector<Vector3<float>> path;
std::optional currentOpt = current;
while (currentOpt)
@@ -39,7 +39,7 @@ namespace omath::pathfinding
std::ranges::reverse(path);
return path;
}
auto Astar::GetPerfectNode(const std::unordered_map<Vector3, PathNode>& openList, const Vector3& endVertex)
auto Astar::GetPerfectNode(const std::unordered_map<Vector3<float>, PathNode>& openList, const Vector3<float>& endVertex)
{
return std::ranges::min_element(openList,
[&endVertex](const auto& a, const auto& b)
@@ -50,10 +50,10 @@ namespace omath::pathfinding
});
}
std::vector<Vector3> Astar::FindPath(const Vector3& start, const Vector3& end, const NavigationMesh& navMesh)
std::vector<Vector3<float>> Astar::FindPath(const Vector3<float>& start, const Vector3<float>& end, const NavigationMesh& navMesh)
{
std::unordered_map<Vector3, PathNode> closedList;
std::unordered_map<Vector3, PathNode> openList;
std::unordered_map<Vector3<float>, PathNode> closedList;
std::unordered_map<Vector3<float>, PathNode> openList;
auto maybeStartVertex = navMesh.GetClosestVertex(start);
auto maybeEndVertex = navMesh.GetClosestVertex(end);

View File

@@ -7,7 +7,7 @@
#include <algorithm>
namespace omath::pathfinding
{
std::expected<Vector3, std::string> NavigationMesh::GetClosestVertex(const Vector3 &point) const
std::expected<Vector3<float>, std::string> NavigationMesh::GetClosestVertex(const Vector3<float> &point) const
{
const auto res = std::ranges::min_element(m_verTextMap,
[&point](const auto& a, const auto& b)
@@ -21,7 +21,7 @@ namespace omath::pathfinding
return res->first;
}
const std::vector<Vector3>& NavigationMesh::GetNeighbors(const Vector3 &vertex) const
const std::vector<Vector3<float>>& NavigationMesh::GetNeighbors(const Vector3<float> &vertex) const
{
return m_verTextMap.at(vertex);
}
@@ -73,18 +73,18 @@ namespace omath::pathfinding
while (offset < raw.size())
{
Vector3 vertex;
Vector3<float> vertex;
loadFromVector(raw, offset, vertex);
uint16_t neighborsCount;
loadFromVector(raw, offset, neighborsCount);
std::vector<Vector3> neighbors;
std::vector<Vector3<float>> neighbors;
neighbors.reserve(neighborsCount);
for (size_t i = 0; i < neighborsCount; ++i)
{
Vector3 neighbor;
Vector3<float> neighbor;
loadFromVector(raw, offset, neighbor);
neighbors.push_back(neighbor);
}