From 76f3bb1ce60b5169e9c51a6397351e53db82025c Mon Sep 17 00:00:00 2001 From: KimLS Date: Fri, 22 Jan 2016 19:16:14 -0800 Subject: [PATCH] Changed how i calc partial and broken paths --- common/pathfind.cpp | 34 ++++++++++++++++++++++++++-------- common/pathfind.h | 9 +++++++++ zone/command.cpp | 31 ++++++++++++++----------------- zone/pathing.cpp | 31 ++++--------------------------- 4 files changed, 53 insertions(+), 52 deletions(-) diff --git a/common/pathfind.cpp b/common/pathfind.cpp index 2ce88935d..1d23dbfc0 100644 --- a/common/pathfind.cpp +++ b/common/pathfind.cpp @@ -188,7 +188,7 @@ PathfindingRoute PathfindingManager::FindRoute(const glm::vec3 &src_loc, const g glm::vec3 dest_location(dest_loc.x, dest_loc.z, dest_loc.y); PathfindingRoute ret; - + ret.m_status = PathComplete; ret.m_dest = dest_loc; ret.m_current_node = 0; ret.m_active = true; @@ -208,7 +208,7 @@ PathfindingRoute PathfindingManager::FindRoute(const glm::vec3 &src_loc, const g dtPolyRef start_ref; dtPolyRef end_ref; - glm::vec3 ext(10.0f, 10.0f, 10.0f); + glm::vec3 ext(15.0f, 15.0f, 15.0f); m_nav_query->findNearestPoly(¤t_location[0], &ext[0], &m_filter, &start_ref, 0); m_nav_query->findNearestPoly(&dest_location[0], &ext[0], &m_filter, &end_ref, 0); @@ -223,20 +223,34 @@ PathfindingRoute PathfindingManager::FindRoute(const glm::vec3 &src_loc, const g int npoly = 0; dtPolyRef path[256] = { 0 }; - m_nav_query->findPath(start_ref, end_ref, ¤t_location[0], &dest_location[0], &m_filter, path, &npoly, 256); + auto status = m_nav_query->findPath(start_ref, end_ref, ¤t_location[0], &dest_location[0], &m_filter, path, &npoly, 256); + + if (status & DT_OUT_OF_NODES || status & DT_BUFFER_TOO_SMALL) { + ret.m_status = PathPartial; + } + else if (status & DT_PARTIAL_RESULT) { + ret.m_status = PathBroken; + } if (npoly) { glm::vec3 epos = dest_location; if (path[npoly - 1] != end_ref) m_nav_query->closestPointOnPoly(path[npoly - 1], &dest_location[0], &epos[0], 0); - float straight_path[256 * 3]; - unsigned char straight_path_flags[256]; + float straight_path[512 * 3]; + unsigned char straight_path_flags[512]; int n_straight_polys; - dtPolyRef straight_path_polys[256]; - m_nav_query->findStraightPath(¤t_location[0], &epos[0], path, npoly, + dtPolyRef straight_path_polys[512]; + status = m_nav_query->findStraightPath(¤t_location[0], &epos[0], path, npoly, straight_path, straight_path_flags, - straight_path_polys, &n_straight_polys, 256, DT_STRAIGHTPATH_ALL_CROSSINGS); + straight_path_polys, &n_straight_polys, 512, DT_STRAIGHTPATH_ALL_CROSSINGS); + + if (ret.m_status == PathComplete && status & DT_OUT_OF_NODES || status & DT_BUFFER_TOO_SMALL) { + ret.m_status = PathPartial; + } + else if (ret.m_status == PathComplete && status & DT_PARTIAL_RESULT) { + ret.m_status = PathBroken; + } if (n_straight_polys) { ret.m_nodes.reserve(n_straight_polys); @@ -309,6 +323,10 @@ PathfindingRoute::~PathfindingRoute() bool PathfindingRoute::DestinationValid(const glm::vec3 &dest) { + if (m_status == PathPartial && m_current_node + 1 == m_nodes.size()) { + return false; + } + auto dist = vec_dist(dest, m_dest); if (dist <= max_dest_drift) { return true; diff --git a/common/pathfind.h b/common/pathfind.h index b15b69d86..b56ea57d9 100644 --- a/common/pathfind.h +++ b/common/pathfind.h @@ -43,6 +43,13 @@ struct PathfindingNode unsigned short flag; }; +enum PathfindingRouteStatus +{ + PathComplete, + PathPartial, + PathBroken +}; + class PathfindingRoute { public: @@ -56,11 +63,13 @@ public: unsigned short GetPreviousNodeFlag(); const std::vector& GetNodes() const { return m_nodes; } std::vector& GetNodesEdit() { return m_nodes; } + PathfindingRouteStatus GetStatus() { return m_status; } private: glm::vec3 m_dest; std::vector m_nodes; int m_current_node; bool m_active; + PathfindingRouteStatus m_status; friend class PathfindingManager; }; diff --git a/zone/command.cpp b/zone/command.cpp index 28815475e..7541a6f1a 100644 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -4101,10 +4101,9 @@ void command_path(Client *c, const Seperator *sep) bool first = true; auto route = zone->pathing.FindRoute(src, dest); auto &nodes = route.GetNodes(); - auto &last_node = nodes[nodes.size() - 1]; - auto dist = DistanceSquared(glm::vec4(last_node.position, 1.0f), glm::vec4(dest.x, dest.y, dest.z, 0.0f)); - if (dist > 10000.0f) { - c->Message(0, "Path from (%.2f, %.2f, %.2f) to (%.2f, %.2f, %.2f) found with %i nodes, broken path, would need warp.", + + if (route.GetStatus() == PathComplete) { + c->Message(0, "Path from (%.2f, %.2f, %.2f) to (%.2f, %.2f, %.2f) found with %i nodes, complete path.", src.x, src.y, src.z, @@ -4112,9 +4111,7 @@ void command_path(Client *c, const Seperator *sep) dest.y, dest.z, (int)nodes.size()); - return; - } - else if (dist > 100.0f) { + } else if (route.GetStatus() == PathPartial) { c->Message(0, "Path from (%.2f, %.2f, %.2f) to (%.2f, %.2f, %.2f) found with %i nodes, partial path.", src.x, src.y, @@ -4123,17 +4120,17 @@ void command_path(Client *c, const Seperator *sep) dest.y, dest.z, (int)nodes.size()); - return; } - - c->Message(0, "Path from (%.2f, %.2f, %.2f) to (%.2f, %.2f, %.2f) found with %i nodes, complete path.", - src.x, - src.y, - src.z, - dest.x, - dest.y, - dest.z, - (int)nodes.size()); + else { + c->Message(0, "Path from (%.2f, %.2f, %.2f) to (%.2f, %.2f, %.2f) found with %i nodes, broken path.", + src.x, + src.y, + src.z, + dest.x, + dest.y, + dest.z, + (int)nodes.size()); + } } void command_pvp(Client *c, const Seperator *sep) diff --git a/zone/pathing.cpp b/zone/pathing.cpp index 20d75b177..2d9d2a8d0 100644 --- a/zone/pathing.cpp +++ b/zone/pathing.cpp @@ -38,35 +38,12 @@ glm::vec3 Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &Wa m_pathing_route = zone->pathing.FindRoute(from, to); - auto &nodes = m_pathing_route.GetNodesEdit(); - auto &last_node = nodes[nodes.size() - 1]; - //Code to complete partial paths. - //If the path is too long then just warp to end. - if (nodes.size() < 256) { - auto dist = DistanceSquared(glm::vec4(last_node.position, 1.0f), glm::vec4(ToX, ToY, ToZ, 0.0f)); - if (dist > 10000.0f) { - auto flag_temp = last_node.flag; - last_node.flag = NavigationPolyFlagPortal; - - PathfindingNode end; - end.position.x = ToX; - end.position.y = ToY; - end.position.z = ToZ; - end.flag = flag_temp; - nodes.push_back(end); - } - else if (dist > 100.0f) { - PathfindingNode end; - end.position.x = ToX; - end.position.y = ToY; - end.position.z = ToZ; - end.flag = NavigationPolyFlagNormal; - nodes.push_back(end); - } - } - else { + if (m_pathing_route.GetStatus() == PathBroken) { + auto &nodes = m_pathing_route.GetNodesEdit(); + auto &last_node = nodes[nodes.size() - 1]; auto flag_temp = last_node.flag; last_node.flag = NavigationPolyFlagPortal; + PathfindingNode end; end.position.x = ToX; end.position.y = ToY;