Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Add path height correction on world load #1178

Merged
merged 5 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dNavigation/dNavMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void dNavMesh::LoadNavmesh() {
m_NavMesh = mesh;
}

float dNavMesh::GetHeightAtPoint(const NiPoint3& location) {
float dNavMesh::GetHeightAtPoint(const NiPoint3& location, const float halfExtentsHeight) const {
if (m_NavMesh == nullptr) {
return location.y;
}
Expand All @@ -130,7 +130,7 @@ float dNavMesh::GetHeightAtPoint(const NiPoint3& location) {
pos[2] = location.z;

dtPolyRef nearestRef = 0;
float polyPickExt[3] = { 32.0f, 32.0f, 32.0f };
float polyPickExt[3] = { 32.0f, halfExtentsHeight, 32.0f };
dtQueryFilter filter{};

m_NavQuery->findNearestPoly(pos, polyPickExt, &filter, &nearestRef, 0);
Expand Down
10 changes: 9 additions & 1 deletion dNavigation/dNavMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ class dNavMesh {
dNavMesh(uint32_t zoneId);
~dNavMesh();

float GetHeightAtPoint(const NiPoint3& location);
/**
* Get the height at a point
*
* @param location The location to check for height at. This is the center of the search area.
* @param halfExtentsHeight The half extents height of the search area. This is the distance from the center to the top and bottom of the search area.
* The larger the value of halfExtentsHeight is, the larger the performance cost of the query.
* @return float The height at the point. If the point is not on the navmesh, the height of the point is returned.
*/
float GetHeightAtPoint(const NiPoint3& location, const float halfExtentsHeight = 32.0f) const;
std::vector<NiPoint3> GetPath(const NiPoint3& startPos, const NiPoint3& endPos, float speed = 10.0f);

class dtNavMesh* GetdtNavMesh() { return m_NavMesh; }
Expand Down
3 changes: 2 additions & 1 deletion dZoneManager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ set(DZONEMANAGER_SOURCES "dZoneManager.cpp"
"Spawner.cpp"
"Zone.cpp")

add_library(dZoneManager STATIC ${DZONEMANAGER_SOURCES})
add_library(dZoneManager STATIC ${DZONEMANAGER_SOURCES})
target_link_libraries(dZoneManager dPhysics)
12 changes: 9 additions & 3 deletions dZoneManager/Zone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "CDZoneTableTable.h"
#include "Spawner.h"
#include "dZoneManager.h"
#include "dpWorld.h"

#include "eTriggerCommandType.h"
#include "eTriggerEventType.h"
Expand Down Expand Up @@ -544,10 +545,15 @@ void Zone::LoadPath(std::istream& file) {
}
}

// We verify the waypoint heights against the navmesh because in many movement paths,
// the waypoint is located near 0 height,
if (path.pathType == PathType::Movement) {
if (dpWorld::Instance().IsLoaded()) {
// 2000 should be large enough for every world.
waypoint.position.y = dpWorld::Instance().GetNavMesh()->GetHeightAtPoint(waypoint.position, 2000.0f);
}
}
path.pathWaypoints.push_back(waypoint);
}



m_Paths.push_back(path);
}