Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 330 vs 331 for /trunk/Source Code/AI/PathFinding/DivideRecast.cpp

Diff revisions: vs.
  @@ -11,11 +11,12 @@
11 11 DivideRecast::DivideRecast()
12 12 {
13 13 // Setup the default query filter
14 - _filter = New dtQueryFilter();
14 + _filter = MemoryManager_NEW dtQueryFilter();
15 15 _filter->setIncludeFlags(0xFFFF); // Include all
16 16 _filter->setExcludeFlags(0); // Exclude none
17 17 // Area flags for polys to consider in search, and their cost
18 - _filter->setAreaCost(SAMPLE_POLYAREA_GROUND, 1.0f); // TODO have a way of configuring the filter
18 + // TODO have a way of configuring the filter
19 + _filter->setAreaCost(SAMPLE_POLYAREA_GROUND, 1.0f);
19 20 _filter->setAreaCost(DT_TILECACHE_WALKABLE_AREA, 1.0f);
20 21
21 22 // Init path store. MaxVertex 0 means empty path slot
  @@ -27,7 +28,7 @@
27 28
28 29 DivideRecast::~DivideRecast()
29 30 {
30 - MemoryManager::SAFE_DELETE( _filter );
31 + MemoryManager::DELETE( _filter );
31 32 }
32 33
33 34 PathErrorCode DivideRecast::FindPath(const NavigationMesh& navMesh,
  @@ -61,18 +62,37 @@
61 62 if((status&DT_FAILURE) || (status&DT_STATUS_DETAIL_MASK))
62 63 return PATH_ERROR_NO_NEAREST_POLY_END; // couldn't find a polygon
63 64
64 - status = navQuery.findPath(StartPoly, EndPoly, StartNearest, EndNearest, _filter, PolyPath, &nPathCount, MAX_PATHPOLY) ;
65 - if((status&DT_FAILURE) || (status&DT_STATUS_DETAIL_MASK))
65 + status = navQuery.findPath(StartPoly,
66 + EndPoly,
67 + StartNearest,
68 + EndNearest,
69 + _filter,
70 + PolyPath,
71 + &nPathCount,
72 + MAX_PATHPOLY) ;
73 + if ((status&DT_FAILURE) || (status&DT_STATUS_DETAIL_MASK)) {
66 74 return PATH_ERROR_COULD_NOT_CREATE_PATH; // couldn't create a path
67 - if(nPathCount==0)
68 - return PATH_ERROR_COULD_NOT_FIND_PATH; // couldn't find a path
75 + }
69 76
70 - status = navQuery.findStraightPath(StartNearest, EndNearest, PolyPath, nPathCount, StraightPath, nullptr, nullptr, &nVertCount, MAX_PATHVERT) ;
71 - if((status&DT_FAILURE) || (status&DT_STATUS_DETAIL_MASK))
77 + if (nPathCount == 0) {
78 + return PATH_ERROR_COULD_NOT_FIND_PATH; // couldn't find a path
79 + }
80 + status = navQuery.findStraightPath(StartNearest,
81 + EndNearest,
82 + PolyPath,
83 + nPathCount,
84 + StraightPath,
85 + nullptr,
86 + nullptr,
87 + &nVertCount,
88 + MAX_PATHVERT) ;
89 + if ((status&DT_FAILURE) || (status&DT_STATUS_DETAIL_MASK)) {
72 90 return PATH_ERROR_NO_STRAIGHT_PATH_CREATE; // couldn't create a path
73 - if(nVertCount==0)
74 - return PATH_ERROR_NO_STRAIGHT_PATH_FIND; // couldn't find a path
91 + }
75 92
93 + if (nVertCount == 0) {
94 + return PATH_ERROR_NO_STRAIGHT_PATH_FIND; // couldn't find a path
95 + }
76 96 // At this point we have our path. Copy it to the path store
77 97 I32 nIndex=0 ;
78 98 for(I32 nVert = 0; nVert < nVertCount; nVert++) {
  @@ -80,7 +100,9 @@
80 100 _pathStore[pathSlot].PosY[nVert]=StraightPath[nIndex++];
81 101 _pathStore[pathSlot].PosZ[nVert]=StraightPath[nIndex++];
82 102
83 - //PRINT_FN("Path Vert %i, %f %f %f", nVert, m_PathStore[pathSlot].PosX[nVert], m_PathStore[pathSlot].PosY[nVert], m_PathStore[pathSlot].PosZ[nVert]) ;
103 + //PRINT_FN("Path Vert %i, %f %f %f", nVert, m_PathStore[pathSlot].PosX[nVert],
104 + // m_PathStore[pathSlot].PosY[nVert],
105 + // m_PathStore[pathSlot].PosZ[nVert]) ;
84 106 }
85 107
86 108 _pathStore[pathSlot].MaxVertex=nVertCount;
  @@ -126,7 +148,12 @@
126 148 return true;
127 149 }
128 150
129 - bool DivideRecast::getRandomPointAroundCircle(const NavigationMesh& navMesh, const vec3<F32>& centerPosition, F32 radius, const vec3<F32>& extents, vec3<F32>& resultPt, U8 maxIters) {
151 + bool DivideRecast::getRandomPointAroundCircle(const NavigationMesh& navMesh,
152 + const vec3<F32>& centerPosition,
153 + F32 radius,
154 + const vec3<F32>& extents,
155 + vec3<F32>& resultPt,
156 + U8 maxIters) {
130 157 const dtNavMeshQuery& query = navMesh.getNavQuery();
131 158 if (query.getAttachedNavMesh() == nullptr) {
132 159 return false;
  @@ -137,7 +164,13 @@
137 164 findNearestPolyOnNavmesh(navMesh, centerPosition, extents, resultPt, resultPoly);
138 165 U8 i = 0;
139 166 for (i = 0; i < maxIters; ++i) {
140 - query.findRandomPointAroundCircle(resultPoly, centerPosition._v, radius, _filter, frand, &resultPoly, resultPt._v);
167 + query.findRandomPointAroundCircle(resultPoly,
168 + centerPosition._v,
169 + radius,
170 + _filter,
171 + frand,
172 + &resultPoly,
173 + resultPt._v);
141 174 if (centerPosition.distanceSquared(resultPt) <= radiusSq) {
142 175 break;
143 176 }
  @@ -145,10 +178,19 @@
145 178 return (i != maxIters);
146 179 }
147 180
148 - bool DivideRecast::findNearestPointOnNavmesh(const NavigationMesh& navMesh, const vec3<F32>& position, const vec3<F32>& extents, F32 delta, vec3<F32>& resultPt, dtPolyRef &resultPoly) {
181 + bool DivideRecast::findNearestPointOnNavmesh(const NavigationMesh& navMesh,
182 + const vec3<F32>& position,
183 + const vec3<F32>& extents,
184 + F32 delta,
185 + vec3<F32>& resultPt,
186 + dtPolyRef &resultPoly) {
149 187 if (findNearestPolyOnNavmesh(navMesh, position, extents, resultPt, resultPoly) ){
150 188 if (position.distanceSquared(resultPt) > (delta * delta)) {
151 - if (findNearestPolyOnNavmesh(navMesh, position, &navMesh.getExtents()[0], resultPt, resultPoly)) {
189 + if (findNearestPolyOnNavmesh(navMesh,
190 + position,
191 + &navMesh.getExtents()[0],
192 + resultPt,
193 + resultPoly)) {
152 194 if (position.distanceSquared(resultPt) <= (delta * delta)) {
153 195 return true;
154 196 }
  @@ -159,13 +201,21 @@
159 201 return false;
160 202 }
161 203
162 - bool DivideRecast::findNearestPolyOnNavmesh(const NavigationMesh& navMesh, const vec3<F32>& position, const vec3<F32>& extents, vec3<F32>& resultPt, dtPolyRef &resultPoly) {
204 + bool DivideRecast::findNearestPolyOnNavmesh(const NavigationMesh& navMesh,
205 + const vec3<F32>& position,
206 + const vec3<F32>& extents,
207 + vec3<F32>& resultPt,
208 + dtPolyRef &resultPoly) {
163 209 if(navMesh.getNavQuery().getAttachedNavMesh() == nullptr){
164 210 resultPt.set(VECTOR3_ZERO);
165 211 return false;
166 212 }
167 213
168 - dtStatus status = navMesh.getNavQuery().findNearestPoly(position._v, extents._v, _filter, &resultPoly, resultPt._v);
214 + dtStatus status = navMesh.getNavQuery().findNearestPoly(position._v,
215 + extents._v,
216 + _filter,
217 + &resultPoly,
218 + resultPt._v);
169 219 if ((status & DT_FAILURE) || (status & DT_STATUS_DETAIL_MASK)) {
170 220 return false; // couldn't find a polygon
171 221 }