From d45af1f171410f1705c0155b03ce32f5f7fee4e3 Mon Sep 17 00:00:00 2001 From: Suede Worthey Date: Tue, 16 Apr 2024 14:34:04 -0500 Subject: [PATCH 1/3] Added radius check to nav path. Updated Nav path filter to check if path would go outside boundary set by camp radius to improve pulling. Added start position for nav filter to ensure it doesn't follow the player. --- PluginAPI.h | 2 ++ .../Detour/Include/DetourNavMeshQuery.h | 2 +- plugin/MQ2Navigation.cpp | 18 +++++++++++++++ plugin/MQ2Navigation.h | 1 + plugin/NavigationPath.cpp | 22 ++++++++++++++++++- plugin/NavigationPath.h | 18 ++++++++++++++- 6 files changed, 60 insertions(+), 3 deletions(-) diff --git a/PluginAPI.h b/PluginAPI.h index f2ded5df..e546ea1d 100644 --- a/PluginAPI.h +++ b/PluginAPI.h @@ -49,6 +49,8 @@ struct NavigationOptions bool paused = false; // pathing is paused bool track = true; // if spawn is to be tracked FacingType facing = FacingType::Forward; // Forward = normal, Backward = move along path facing backward. + int searchradius = 0; // the max search radius of the path + glm::vec3 searchstartpos; // the starting position of the search // set a new default log level while the path is running. info is the default. spdlog::level::level_enum logLevel = spdlog::level::info; diff --git a/dependencies/recast/Detour/Include/DetourNavMeshQuery.h b/dependencies/recast/Detour/Include/DetourNavMeshQuery.h index 61541e83..67330901 100644 --- a/dependencies/recast/Detour/Include/DetourNavMeshQuery.h +++ b/dependencies/recast/Detour/Include/DetourNavMeshQuery.h @@ -28,7 +28,7 @@ // setting is to use non-virtual functions, the actual implementations of the functions // are declared as inline for maximum speed. -//#define DT_VIRTUAL_QUERYFILTER 1 +#define DT_VIRTUAL_QUERYFILTER 1 /// Defines polygon filtering and traversal costs for navigation mesh query operations. /// @ingroup detour diff --git a/plugin/MQ2Navigation.cpp b/plugin/MQ2Navigation.cpp index 992623fc..4afe781f 100644 --- a/plugin/MQ2Navigation.cpp +++ b/plugin/MQ2Navigation.cpp @@ -1699,6 +1699,24 @@ void MQ2NavigationPlugin::ParseOptions(std::string_view line, int idx, Navigatio { args->tag = value; } + else if (key == "searchradius") + { + options.searchradius = GetIntFromString(value, 0); + } + else if (key == "searchstartpos") + { + std::vector parts = mq::split_view(value, ' ', false); + if (parts.size() == 3) + { + options.searchstartpos = { GetFloatFromString(parts[0], 0), GetFloatFromString(parts[1], 0), GetFloatFromString(parts[2], 0) }; + } + else if (parts.size() == 2) + { + options.searchstartpos = { GetFloatFromString(parts[0], 0), pLocalPlayer->FloorHeight, GetFloatFromString(parts[2], 0) }; + } + else + SPDLOG_ERROR("Invalid argument for searchstartpos: {}", value); + } } catch (const std::exception& ex) { diff --git a/plugin/MQ2Navigation.h b/plugin/MQ2Navigation.h index 24fed2fe..3bbe3bea 100644 --- a/plugin/MQ2Navigation.h +++ b/plugin/MQ2Navigation.h @@ -91,6 +91,7 @@ struct DestinationInfo { std::string command; glm::vec3 eqDestinationPos; + glm::vec3 searchStartPos; DestinationType type = DestinationType::None; diff --git a/plugin/NavigationPath.cpp b/plugin/NavigationPath.cpp index 428f6258..fa0183ad 100644 --- a/plugin/NavigationPath.cpp +++ b/plugin/NavigationPath.cpp @@ -181,7 +181,7 @@ void NavigationPath::SetNavMesh(const std::shared_ptr& navMesh, m_query.reset(); - m_filter = dtQueryFilter{}; + m_filter = NavPathFilter{}; m_filter.setIncludeFlags(+PolyFlags::All); m_filter.setExcludeFlags(+PolyFlags::Disabled); if (auto* mesh = g_mq2Nav->Get()) @@ -924,4 +924,24 @@ void NavigationLine::Update() } } +bool NavPathFilter::passFilter(const dtPolyRef ref, const dtMeshTile* tile, const dtPoly* poly) const +{ + if (m_searchRadius > 0) + { + glm::vec3 polyCenter = glm::vec3{ 0, 0, 0 }; + + for (int i = 0; i < poly->vertCount; ++i) + { + const float* v = &tile->verts[poly->verts[i] * 3]; + polyCenter += glm::vec3{ v[0], v[1], v[2] }; + } + + polyCenter /= poly->vertCount; + + if (distSqr(m_startPos, polyCenter) > (m_searchRadius * m_searchRadius)) + return false; + } + return dtQueryFilter::passFilter(ref, tile, poly); +} + //---------------------------------------------------------------------------- diff --git a/plugin/NavigationPath.h b/plugin/NavigationPath.h index f7b450ed..4b6a449a 100644 --- a/plugin/NavigationPath.h +++ b/plugin/NavigationPath.h @@ -57,6 +57,21 @@ struct StraightPath int alloc = 0; }; +class NavPathFilter : public dtQueryFilter +{ +private: + int m_searchRadius = 0; + glm::vec3 m_startPos; + +public: + inline NavPathFilter() { }; + inline virtual ~NavPathFilter() override { }; + virtual bool passFilter(const dtPolyRef ref, const dtMeshTile* tile, const dtPoly* poly) const override; + inline void SetSearchRadius(int radius) { m_searchRadius = radius; } + inline int GetSearchRadius() const { return m_searchRadius; } + inline void SetStartPos(const glm::vec3& pos) { m_startPos = pos; } +}; + class NavigationPath { friend class NavigationLine; @@ -176,7 +191,7 @@ class NavigationPath std::vector m_renderPath; bool m_followingLink = false; - dtQueryFilter m_filter; + NavPathFilter m_filter; glm::vec3 m_extents = { 5, 10, 5 }; // note: X, Z, Y mq::Signal<>::ScopedConnection m_navMeshConn; @@ -257,3 +272,4 @@ class NavigationLine : public Renderable }; extern NavigationLine::LineStyle gNavigationLineStyle; + From 16c5fc954b186aa4e88d08165b0dd3b3e4f37ad2 Mon Sep 17 00:00:00 2001 From: Suede Worthey Date: Fri, 7 Jun 2024 15:28:41 -0500 Subject: [PATCH 2/3] Fixed missing variable assignments. Changed searchStartPos to searchOrigin. --- PluginAPI.h | 4 ++-- plugin/MQ2Navigation.cpp | 6 +++--- plugin/MQ2Navigation.h | 1 - plugin/NavigationPath.cpp | 7 ++++++- plugin/NavigationPath.h | 8 ++++---- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/PluginAPI.h b/PluginAPI.h index e546ea1d..f3d7f2a2 100644 --- a/PluginAPI.h +++ b/PluginAPI.h @@ -49,8 +49,8 @@ struct NavigationOptions bool paused = false; // pathing is paused bool track = true; // if spawn is to be tracked FacingType facing = FacingType::Forward; // Forward = normal, Backward = move along path facing backward. - int searchradius = 0; // the max search radius of the path - glm::vec3 searchstartpos; // the starting position of the search + int searchRadius = 0; // the max search radius of the path + glm::vec3 searchOrigin; // the starting position / origin of the search // set a new default log level while the path is running. info is the default. spdlog::level::level_enum logLevel = spdlog::level::info; diff --git a/plugin/MQ2Navigation.cpp b/plugin/MQ2Navigation.cpp index 4afe781f..26cfca31 100644 --- a/plugin/MQ2Navigation.cpp +++ b/plugin/MQ2Navigation.cpp @@ -1701,18 +1701,18 @@ void MQ2NavigationPlugin::ParseOptions(std::string_view line, int idx, Navigatio } else if (key == "searchradius") { - options.searchradius = GetIntFromString(value, 0); + options.searchRadius = GetIntFromString(value, 0); } else if (key == "searchstartpos") { std::vector parts = mq::split_view(value, ' ', false); if (parts.size() == 3) { - options.searchstartpos = { GetFloatFromString(parts[0], 0), GetFloatFromString(parts[1], 0), GetFloatFromString(parts[2], 0) }; + options.searchOrigin = { GetFloatFromString(parts[0], 0), GetFloatFromString(parts[1], 0), GetFloatFromString(parts[2], 0) }; } else if (parts.size() == 2) { - options.searchstartpos = { GetFloatFromString(parts[0], 0), pLocalPlayer->FloorHeight, GetFloatFromString(parts[2], 0) }; + options.searchOrigin = { GetFloatFromString(parts[0], 0), pLocalPlayer->FloorHeight, GetFloatFromString(parts[2], 0) }; } else SPDLOG_ERROR("Invalid argument for searchstartpos: {}", value); diff --git a/plugin/MQ2Navigation.h b/plugin/MQ2Navigation.h index 3bbe3bea..24fed2fe 100644 --- a/plugin/MQ2Navigation.h +++ b/plugin/MQ2Navigation.h @@ -91,7 +91,6 @@ struct DestinationInfo { std::string command; glm::vec3 eqDestinationPos; - glm::vec3 searchStartPos; DestinationType type = DestinationType::None; diff --git a/plugin/NavigationPath.cpp b/plugin/NavigationPath.cpp index fa0183ad..d93e2668 100644 --- a/plugin/NavigationPath.cpp +++ b/plugin/NavigationPath.cpp @@ -330,6 +330,11 @@ std::unique_ptr NavigationPath::RecomputePath( glm::vec3 spos; // TODO: Cache the last known valid starting position to detect when moving off the mesh + if (m_destinationInfo && m_destinationInfo->options.searchRadius > 0) + { + m_filter.SetSearchOrigin(m_destinationInfo->options.searchOrigin); + m_filter.SetSearchRadius(m_destinationInfo->options.searchRadius); + } m_query->findNearestPoly( glm::value_ptr(startPos), @@ -938,7 +943,7 @@ bool NavPathFilter::passFilter(const dtPolyRef ref, const dtMeshTile* tile, cons polyCenter /= poly->vertCount; - if (distSqr(m_startPos, polyCenter) > (m_searchRadius * m_searchRadius)) + if (distSqr(m_searchOrigin, polyCenter) > (m_searchRadius * m_searchRadius)) return false; } return dtQueryFilter::passFilter(ref, tile, poly); diff --git a/plugin/NavigationPath.h b/plugin/NavigationPath.h index 4b6a449a..e848fb77 100644 --- a/plugin/NavigationPath.h +++ b/plugin/NavigationPath.h @@ -61,15 +61,15 @@ class NavPathFilter : public dtQueryFilter { private: int m_searchRadius = 0; - glm::vec3 m_startPos; + glm::vec3 m_searchOrigin; public: inline NavPathFilter() { }; inline virtual ~NavPathFilter() override { }; virtual bool passFilter(const dtPolyRef ref, const dtMeshTile* tile, const dtPoly* poly) const override; - inline void SetSearchRadius(int radius) { m_searchRadius = radius; } - inline int GetSearchRadius() const { return m_searchRadius; } - inline void SetStartPos(const glm::vec3& pos) { m_startPos = pos; } + void SetSearchRadius(int radius) { m_searchRadius = radius; } + //int GetSearchRadius() const { return m_searchRadius; } + void SetSearchOrigin(const glm::vec3& pos) { m_searchOrigin = pos; } }; class NavigationPath From 3b911363be2a9c0333d8cc8be161cc110064b767 Mon Sep 17 00:00:00 2001 From: Suede Worthey Date: Fri, 7 Jun 2024 15:40:58 -0500 Subject: [PATCH 3/3] Changed searchstartpos to searchorigin in ParseOptions. --- plugin/MQ2Navigation.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/MQ2Navigation.cpp b/plugin/MQ2Navigation.cpp index 26cfca31..147bc321 100644 --- a/plugin/MQ2Navigation.cpp +++ b/plugin/MQ2Navigation.cpp @@ -1703,7 +1703,7 @@ void MQ2NavigationPlugin::ParseOptions(std::string_view line, int idx, Navigatio { options.searchRadius = GetIntFromString(value, 0); } - else if (key == "searchstartpos") + else if (key == "searchorigin") { std::vector parts = mq::split_view(value, ' ', false); if (parts.size() == 3) @@ -1715,7 +1715,7 @@ void MQ2NavigationPlugin::ParseOptions(std::string_view line, int idx, Navigatio options.searchOrigin = { GetFloatFromString(parts[0], 0), pLocalPlayer->FloorHeight, GetFloatFromString(parts[2], 0) }; } else - SPDLOG_ERROR("Invalid argument for searchstartpos: {}", value); + SPDLOG_ERROR("Invalid argument for searchorigin: {}", value); } } catch (const std::exception& ex)