added additional methods

This commit is contained in:
2024-08-18 15:46:10 +03:00
parent a612832518
commit 6df8530ab5
3 changed files with 10 additions and 2 deletions

View File

@@ -30,6 +30,8 @@ namespace omath::pathfinding
[[nodiscard]] [[nodiscard]]
const std::vector<Vector3>& GetNeighbors(const Vector3& vertex) const; const std::vector<Vector3>& GetNeighbors(const Vector3& vertex) const;
[[nodiscard]]
bool Empty() const;
[[nodiscard]] std::vector<uint8_t> Serialize() const; [[nodiscard]] std::vector<uint8_t> Serialize() const;
void Deserialize(const std::vector<uint8_t>& raw); void Deserialize(const std::vector<uint8_t>& raw);

View File

@@ -6,6 +6,7 @@
#include <optional> #include <optional>
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#include <algorithm>
namespace omath::pathfinding namespace omath::pathfinding

View File

@@ -4,7 +4,7 @@
#include "omath/pathfinding/NavigationMesh.h" #include "omath/pathfinding/NavigationMesh.h"
#include <stdexcept> #include <stdexcept>
#include <algorithm>
namespace omath::pathfinding namespace omath::pathfinding
{ {
std::expected<Vector3, std::string> NavigationMesh::GetClossestVertex(const Vector3 &point) const std::expected<Vector3, std::string> NavigationMesh::GetClossestVertex(const Vector3 &point) const
@@ -26,6 +26,11 @@ namespace omath::pathfinding
return m_verTextMap.at(vertex); return m_verTextMap.at(vertex);
} }
bool NavigationMesh::Empty() const
{
return m_verTextMap.empty();
}
std::vector<uint8_t> NavigationMesh::Serialize() const std::vector<uint8_t> NavigationMesh::Serialize() const
{ {
auto dumpToVector =[]<typename T>(const T& t, std::vector<uint8_t>& vec){ auto dumpToVector =[]<typename T>(const T& t, std::vector<uint8_t>& vec){
@@ -58,7 +63,7 @@ namespace omath::pathfinding
{ {
throw std::runtime_error("Deserialize: Invalid input data size."); throw std::runtime_error("Deserialize: Invalid input data size.");
} }
std::memcpy(&value, vec.data() + offset, sizeof(value)); std::copy_n(vec.data() + offset, sizeof(value), (uint8_t*)&value);
offset += sizeof(value); offset += sizeof(value);
}; };