Skip to content

Commit 4860f5b

Browse files
committed
Add multithreading to GenerateWaypointNodes
1 parent 61416a4 commit 4860f5b

4 files changed

Lines changed: 147 additions & 106 deletions

File tree

include/NavKit/adapter/RecastAdapter.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class RecastAdapter {
6666

6767
dtPolyRef getPoly(int tileIndex, int polyIndex) const;
6868

69-
dtStatus findNearestPoly(const float *recastPos, dtPolyRef *polyRef, float *nearestPt, bool includeExcludedAreas) const;
69+
dtStatus findNearestPoly(const float *recastPos, dtPolyRef *polyRef, float *nearestPt,
70+
bool includeExcludedAreas) const;
7071

7172
void findPfSeedPointAreas();
7273

@@ -112,9 +113,13 @@ class RecastAdapter {
112113

113114
Vec3 calculateCentroid(dtPolyRef polyRef) const;
114115

115-
std::vector<dtPolyRef> getClosestReachablePolys(Vec3 navpowerPos, dtPolyRef navpowerStart, int maxPolys) const;
116+
const dtNavMesh *getNavMesh() const;
116117

117-
std::vector<dtPolyRef> getClosestPolys(Vec3 navPowerPos, int maxPolys) const;
118+
std::vector<dtPolyRef> getClosestReachablePolys(
119+
dtNavMeshQuery *navQuery, Vec3 navpowerPos, dtPolyRef navpowerStart, int maxPolys) const;
120+
121+
std::vector<dtPolyRef> getClosestPolys(
122+
dtNavMeshQuery *navQuery, Vec3 navPowerPos, int maxPolys) const;
118123

119124
Sample_TileMesh *sample;
120125
BuildContext *buildContext;

include/NavKit/util/GridGenerator.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "../model/ReasoningGrid.h"
44
#include "../util/Pathfinding.h"
55
#include <DetourNavMesh.h>
6+
#include <unordered_map>
67

78
class Properties;
89

@@ -15,7 +16,7 @@ class GridGenerator {
1516

1617
static bool initRecastAirgAdapter();
1718

18-
std::map<int, std::vector<int> > m_WaypointMap{};
19+
std::unordered_map<int, std::vector<int> > m_WaypointMap{};
1920
std::map<int, std::vector<Pathfinding::SGCell> > waypointCells{};
2021

2122
static void build();
@@ -36,17 +37,17 @@ class GridGenerator {
3637

3738
void GenerateLayerIndices();
3839

39-
static Pathfinding::ZPFLocation *MapLocation_Internal(Pathfinding::ZPFLocation *result, const float4 *vPosNavPower,
40-
float fAcceptance, dtPolyRef startPolyRef);
40+
static Pathfinding::ZPFLocation *MapLocation_Internal(dtNavMeshQuery *navQuery, Pathfinding::ZPFLocation *result,
41+
const float4 *vPosNavPower, float fAcceptance, dtPolyRef startPolyRef);
4142

42-
static bool MapLocation(const float4 *vNavPowerPos, Pathfinding::ZPFLocation *lMapped);
43+
static bool MapLocation(dtNavMeshQuery *navQuery, const float4 *vNavPowerPos, Pathfinding::ZPFLocation *lMapped);
4344

44-
static float4 MapToCell(const float4 *vCellNavPowerUpperLeft, const NavPower::Area &area);
45+
static float4 MapToCell(dtNavMeshQuery *navQuery, const float4 *vCellNavPowerUpperLeft, const NavPower::Area &area);
4546

46-
static bool IsInside(Pathfinding::ZPFLocation *location);
47+
static bool IsInside(dtNavMeshQuery *navQuery, Pathfinding::ZPFLocation *location);
4748

48-
static bool NearestOuterEdge(Pathfinding::ZPFLocation &location, float tolerance, float4 *edgeNavPowerResult,
49-
float4 *edgeNavPowerNormal);
49+
static bool NearestOuterEdge(dtNavMeshQuery *navQuery, Pathfinding::ZPFLocation &lFrom, float fRadius,
50+
float4 *edgeNavPowerResult, float4 *edgeNavPowerNormal);
5051

5152
static void buildVisionAndDeadEndData();
5253

src/adapter/RecastAdapter.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,9 @@ Vec3 RecastAdapter::calculateCentroid(const dtPolyRef polyRef) const {
842842
return {x, y, z};
843843
}
844844

845+
const dtNavMesh* RecastAdapter::getNavMesh() const {
846+
return sample->getNavMesh();
847+
}
845848
/**
846849
* Find up to the maxPolys closest polys within the specified radius of the position which are reachable from the starting area.
847850
* @param navpowerPos
@@ -850,12 +853,12 @@ Vec3 RecastAdapter::calculateCentroid(const dtPolyRef polyRef) const {
850853
* @return
851854
*/
852855
std::vector<dtPolyRef> RecastAdapter::getClosestReachablePolys(
856+
dtNavMeshQuery* navQuery,
853857
Vec3 navpowerPos,
854858
const dtPolyRef start,
855859
const int maxPolys) const {
856860
std::vector<dtPolyRef> polys;
857861
const dtNavMesh *navMesh = sample->getNavMesh();
858-
const dtNavMeshQuery *navQuery = sample->getNavMeshQuery();
859862
if (!navMesh || !navQuery || start == 0) {
860863
return polys;
861864
}
@@ -914,10 +917,9 @@ std::vector<dtPolyRef> RecastAdapter::getClosestReachablePolys(
914917
* @param maxPolys
915918
* @return
916919
*/
917-
std::vector<dtPolyRef> RecastAdapter::getClosestPolys(Vec3 navPowerPos, const int maxPolys) const {
920+
std::vector<dtPolyRef> RecastAdapter::getClosestPolys(dtNavMeshQuery* navQuery, Vec3 navPowerPos, const int maxPolys) const {
918921
std::vector<dtPolyRef> polys;
919922
const dtNavMesh *navMesh = sample->getNavMesh();
920-
const dtNavMeshQuery *navQuery = sample->getNavMeshQuery();
921923
if (!navMesh || !navQuery) {
922924
return polys;
923925
}

0 commit comments

Comments
 (0)