aboutsummaryrefslogtreecommitdiff
path: root/dep/recastnavigation/recastnavigation.diff
blob: 42bab6474e390697798d4029d5304e30012ada95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
From b84e9ffbd1d1e1fb2f5d78cc53d2bb7b56c3fce3 Mon Sep 17 00:00:00 2001
From: jackpoz <giacomopoz@gmail.com>
Date: Fri, 20 Jun 2014 23:15:04 +0200
Subject: [PATCH] Add custom trinitycore changes

---
 Detour/Include/DetourNavMesh.h                 | 76 ++++++++------------------
 Detour/Source/DetourCommon.cpp                 |  4 +-
 Detour/Source/DetourNavMesh.cpp                | 32 ++++-------
 Detour/Source/DetourNavMeshBuilder.cpp         |  6 +-
 Detour/Source/DetourNavMeshQuery.cpp           |  9 +--
 Detour/Source/DetourNode.cpp                   | 29 +++-------
 DetourCrowd/Source/DetourObstacleAvoidance.cpp |  6 +-
 Recast/Include/Recast.h                        |  8 +--
 8 files changed, 59 insertions(+), 111 deletions(-)

diff --git a/Detour/Include/DetourNavMesh.h b/Detour/Include/DetourNavMesh.h
index 1060845..782ddbc 100644
--- a/Detour/Include/DetourNavMesh.h
+++ b/Detour/Include/DetourNavMesh.h
@@ -22,39 +22,35 @@
 #include "DetourAlloc.h"
 #include "DetourStatus.h"
 
-// Undefine (or define in a build cofnig) the following line to use 64bit polyref.
-// Generally not needed, useful for very large worlds.
-// Note: tiles build using 32bit refs are not compatible with 64bit refs!
-//#define DT_POLYREF64 1
-
-#ifdef DT_POLYREF64
-// TODO: figure out a multiplatform version of uint64_t
-// - maybe: https://code.google.com/p/msinttypes/
-// - or: http://www.azillionmonkeys.com/qed/pstdint.h
+
+// Edited by TC
+#if defined(WIN32) && !defined(__MINGW32__)
+/// Do not rename back to uint64. Otherwise mac complains about typedef redefinition
+typedef unsigned __int64    uint64_d;
+#else
 #include <stdint.h>
+#ifndef uint64_t
+#ifdef __linux__
+#include <linux/types.h>
+#endif
 #endif
+/// Do not rename back to uint64. Otherwise mac complains about typedef redefinition
+typedef uint64_t            uint64_d;
+#endif 
 
 // Note: If you want to use 64-bit refs, change the types of both dtPolyRef & dtTileRef.
 // It is also recommended that you change dtHashRef() to a proper 64-bit hash.
 
+// Edited by TC
+// We cannot have over 31 bits for either tile nor poly
+// without changing polyCount to use 64bits too.
 /// A handle to a polygon within a navigation mesh tile.
 /// @ingroup detour
-#ifdef DT_POLYREF64
-static const unsigned int DT_SALT_BITS = 16;
-static const unsigned int DT_TILE_BITS = 28;
-static const unsigned int DT_POLY_BITS = 20;
-typedef uint64_t dtPolyRef;
-#else
-typedef unsigned int dtPolyRef;
-#endif
+typedef uint64_d dtPolyRef; // Edited by TC
 
 /// A handle to a tile within a navigation mesh.
 /// @ingroup detour
-#ifdef DT_POLYREF64
-typedef uint64_t dtTileRef;
-#else
-typedef unsigned int dtTileRef;
-#endif
+typedef uint64_d dtTileRef; // Edited by TC
 
 /// The maximum number of vertices per navigation polygon.
 /// @ingroup detour
@@ -94,6 +90,12 @@ static const unsigned int DT_OFFMESH_CON_BIDIR = 1;
 /// @ingroup detour
 static const int DT_MAX_AREAS = 64;
 
+static const int STATIC_SALT_BITS = 12;
+static const int STATIC_TILE_BITS = 21;
+static const int STATIC_POLY_BITS = 31;
+// we cannot have over 31 bits for either tile nor poly
+// without changing polyCount to use 64bits too.
+
 /// Tile flags used for various functions and fields.
 /// For an example, see dtNavMesh::addTile().
 enum dtTileFlags
@@ -511,11 +513,7 @@ public:
 	///  @param[in]	ip		The index of the polygon within the tile.
 	inline dtPolyRef encodePolyId(unsigned int salt, unsigned int it, unsigned int ip) const
 	{
-#ifdef DT_POLYREF64
-		return ((dtPolyRef)salt << (DT_POLY_BITS+DT_TILE_BITS)) | ((dtPolyRef)it << DT_POLY_BITS) | (dtPolyRef)ip;
-#else
 		return ((dtPolyRef)salt << (m_polyBits+m_tileBits)) | ((dtPolyRef)it << m_polyBits) | (dtPolyRef)ip;
-#endif
 	}
 	
 	/// Decodes a standard polygon reference.
@@ -527,21 +525,12 @@ public:
 	///  @see #encodePolyId
 	inline void decodePolyId(dtPolyRef ref, unsigned int& salt, unsigned int& it, unsigned int& ip) const
 	{
-#ifdef DT_POLYREF64
-		const dtPolyRef saltMask = ((dtPolyRef)1<<DT_SALT_BITS)-1;
-		const dtPolyRef tileMask = ((dtPolyRef)1<<DT_TILE_BITS)-1;
-		const dtPolyRef polyMask = ((dtPolyRef)1<<DT_POLY_BITS)-1;
-		salt = (unsigned int)((ref >> (DT_POLY_BITS+DT_TILE_BITS)) & saltMask);
-		it = (unsigned int)((ref >> DT_POLY_BITS) & tileMask);
-		ip = (unsigned int)(ref & polyMask);
-#else
 		const dtPolyRef saltMask = ((dtPolyRef)1<<m_saltBits)-1;
 		const dtPolyRef tileMask = ((dtPolyRef)1<<m_tileBits)-1;
 		const dtPolyRef polyMask = ((dtPolyRef)1<<m_polyBits)-1;
 		salt = (unsigned int)((ref >> (m_polyBits+m_tileBits)) & saltMask);
 		it = (unsigned int)((ref >> m_polyBits) & tileMask);
 		ip = (unsigned int)(ref & polyMask);
-#endif
 	}
 
 	/// Extracts a tile's salt value from the specified polygon reference.
@@ -550,13 +539,8 @@ public:
 	///  @see #encodePolyId
 	inline unsigned int decodePolyIdSalt(dtPolyRef ref) const
 	{
-#ifdef DT_POLYREF64
-		const dtPolyRef saltMask = ((dtPolyRef)1<<DT_SALT_BITS)-1;
-		return (unsigned int)((ref >> (DT_POLY_BITS+DT_TILE_BITS)) & saltMask);
-#else
 		const dtPolyRef saltMask = ((dtPolyRef)1<<m_saltBits)-1;
 		return (unsigned int)((ref >> (m_polyBits+m_tileBits)) & saltMask);
-#endif
 	}
 	
 	/// Extracts the tile's index from the specified polygon reference.
@@ -565,13 +549,8 @@ public:
 	///  @see #encodePolyId
 	inline unsigned int decodePolyIdTile(dtPolyRef ref) const
 	{
-#ifdef DT_POLYREF64
-		const dtPolyRef tileMask = ((dtPolyRef)1<<DT_TILE_BITS)-1;
-		return (unsigned int)((ref >> DT_POLY_BITS) & tileMask);
-#else
 		const dtPolyRef tileMask = ((dtPolyRef)1<<m_tileBits)-1;
 		return (unsigned int)((ref >> m_polyBits) & tileMask);
-#endif
 	}
 	
 	/// Extracts the polygon's index (within its tile) from the specified polygon reference.
@@ -580,13 +559,8 @@ public:
 	///  @see #encodePolyId
 	inline unsigned int decodePolyIdPoly(dtPolyRef ref) const
 	{
-#ifdef DT_POLYREF64
-		const dtPolyRef polyMask = ((dtPolyRef)1<<DT_POLY_BITS)-1;
-		return (unsigned int)(ref & polyMask);
-#else
 		const dtPolyRef polyMask = ((dtPolyRef)1<<m_polyBits)-1;
 		return (unsigned int)(ref & polyMask);
-#endif
 	}
 
 	/// @}
@@ -645,11 +619,9 @@ private:
 	dtMeshTile* m_nextFree;				///< Freelist of tiles.
 	dtMeshTile* m_tiles;				///< List of tiles.
 		
-#ifndef DT_POLYREF64
 	unsigned int m_saltBits;			///< Number of salt bits in the tile ID.
 	unsigned int m_tileBits;			///< Number of tile bits in the tile ID.
 	unsigned int m_polyBits;			///< Number of poly bits in the tile ID.
-#endif
 };
 
 /// Allocates a navigation mesh object using the Detour allocator.
diff --git a/Detour/Source/DetourCommon.cpp b/Detour/Source/DetourCommon.cpp
index a98d8c8..b5700f5 100644
--- a/Detour/Source/DetourCommon.cpp
+++ b/Detour/Source/DetourCommon.cpp
@@ -16,14 +16,14 @@
 // 3. This notice may not be removed or altered from any source distribution.
 //
 
+#include <math.h>
 #include "DetourCommon.h"
-#include "DetourMath.h"
 
 //////////////////////////////////////////////////////////////////////////////////////////
 
 float dtSqrt(float x)
 {
-	return dtMathSqrtf(x);
+	return sqrtf(x);
 }
 
 void dtClosestPtPointTriangle(float* closest, const float* p,
diff --git a/Detour/Source/DetourNavMesh.cpp b/Detour/Source/DetourNavMesh.cpp
index 9d627be..5174050 100644
--- a/Detour/Source/DetourNavMesh.cpp
+++ b/Detour/Source/DetourNavMesh.cpp
@@ -16,13 +16,13 @@
 // 3. This notice may not be removed or altered from any source distribution.
 //
 
+#include <math.h>
 #include <float.h>
 #include <string.h>
 #include <stdio.h>
 #include "DetourNavMesh.h"
 #include "DetourNode.h"
 #include "DetourCommon.h"
-#include "DetourMath.h"
 #include "DetourAlloc.h"
 #include "DetourAssert.h"
 #include <new>
@@ -193,13 +193,11 @@ dtNavMesh::dtNavMesh() :
 	m_tileLutMask(0),
 	m_posLookup(0),
 	m_nextFree(0),
-	m_tiles(0)
+	m_tiles(0),
+	m_saltBits(0),
+	m_tileBits(0),
+	m_polyBits(0)
 {
-#ifndef DT_POLYREF64
-	m_saltBits = 0;
-	m_tileBits = 0;
-	m_polyBits = 0;
-#endif
 	memset(&m_params, 0, sizeof(dtNavMeshParams));
 	m_orig[0] = 0;
 	m_orig[1] = 0;
@@ -250,17 +248,11 @@ dtStatus dtNavMesh::init(const dtNavMeshParams* params)
 		m_nextFree = &m_tiles[i];
 	}
 	
-	// Init ID generator values.
-#ifndef DT_POLYREF64
-	m_tileBits = dtIlog2(dtNextPow2((unsigned int)params->maxTiles));
-	m_polyBits = dtIlog2(dtNextPow2((unsigned int)params->maxPolys));
-	// Only allow 31 salt bits, since the salt mask is calculated using 32bit uint and it will overflow.
-	m_saltBits = dtMin((unsigned int)31, 32 - m_tileBits - m_polyBits);
-
-	if (m_saltBits < 10)
-		return DT_FAILURE | DT_INVALID_PARAM;
-#endif
-	
+    // Edited by TC
+    m_tileBits = STATIC_TILE_BITS;
+    m_polyBits = STATIC_POLY_BITS; 
+    m_saltBits = STATIC_SALT_BITS; 
+
 	return DT_SUCCESS;
 }
 
@@ -1242,11 +1234,7 @@ dtStatus dtNavMesh::removeTile(dtTileRef ref, unsigned char** data, int* dataSiz
 	tile->offMeshCons = 0;
 
 	// Update salt, salt should never be zero.
-#ifdef DT_POLYREF64
-	tile->salt = (tile->salt+1) & ((1<<DT_SALT_BITS)-1);
-#else
 	tile->salt = (tile->salt+1) & ((1<<m_saltBits)-1);
-#endif
 	if (tile->salt == 0)
 		tile->salt++;
 
diff --git a/Detour/Source/DetourNavMeshBuilder.cpp b/Detour/Source/DetourNavMeshBuilder.cpp
index 1bf271b..9d8471b 100644
--- a/Detour/Source/DetourNavMeshBuilder.cpp
+++ b/Detour/Source/DetourNavMeshBuilder.cpp
@@ -16,13 +16,13 @@
 // 3. This notice may not be removed or altered from any source distribution.
 //
 
+#include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <float.h>
 #include "DetourNavMesh.h"
 #include "DetourCommon.h"
-#include "DetourMath.h"
 #include "DetourNavMeshBuilder.h"
 #include "DetourAlloc.h"
 #include "DetourAssert.h"
@@ -202,8 +202,8 @@ static int createBVTree(const unsigned short* verts, const int /*nverts*/,
 			if (z > it.bmax[2]) it.bmax[2] = z;
 		}
 		// Remap y
-		it.bmin[1] = (unsigned short)dtMathFloorf((float)it.bmin[1]*ch/cs);
-		it.bmax[1] = (unsigned short)dtMathCeilf((float)it.bmax[1]*ch/cs);
+		it.bmin[1] = (unsigned short)floorf((float)it.bmin[1]*ch/cs);
+		it.bmax[1] = (unsigned short)ceilf((float)it.bmax[1]*ch/cs);
 	}
 	
 	int curNode = 0;
diff --git a/Detour/Source/DetourNavMeshQuery.cpp b/Detour/Source/DetourNavMeshQuery.cpp
index 9debb4d..ec3a294 100644
--- a/Detour/Source/DetourNavMeshQuery.cpp
+++ b/Detour/Source/DetourNavMeshQuery.cpp
@@ -16,13 +16,13 @@
 // 3. This notice may not be removed or altered from any source distribution.
 //
 
+#include <math.h>
 #include <float.h>
 #include <string.h>
 #include "DetourNavMeshQuery.h"
 #include "DetourNavMesh.h"
 #include "DetourNode.h"
 #include "DetourCommon.h"
-#include "DetourMath.h"
 #include "DetourAlloc.h"
 #include "DetourAssert.h"
 #include <new>
@@ -99,8 +99,9 @@ inline float dtQueryFilter::getCost(const float* pa, const float* pb,
 	return dtVdist(pa, pb) * m_areaCost[curPoly->getArea()];
 }
 #endif	
-	
-static const float H_SCALE = 0.999f; // Search heuristic scale.
+
+// Edited by TC
+static const float H_SCALE = 2.0f; // Search heuristic scale. 
 
 
 dtNavMeshQuery* dtAllocNavMeshQuery()
@@ -3504,7 +3505,7 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen
 	dtVsub(hitNormal, centerPos, hitPos);
 	dtVnormalize(hitNormal);
 	
-	*hitDist = dtMathSqrtf(radiusSqr);
+	*hitDist = sqrtf(radiusSqr);
 	
 	return status;
 }
diff --git a/Detour/Source/DetourNode.cpp b/Detour/Source/DetourNode.cpp
index 5cf6548..1d18977 100644
--- a/Detour/Source/DetourNode.cpp
+++ b/Detour/Source/DetourNode.cpp
@@ -22,30 +22,17 @@
 #include "DetourCommon.h"
 #include <string.h>
 
-#ifdef DT_POLYREF64
-// From Thomas Wang, https://gist.github.com/badboy/6267743
 inline unsigned int dtHashRef(dtPolyRef a)
 {
-	a = (~a) + (a << 18); // a = (a << 18) - a - 1;
-	a = a ^ (a >> 31);
-	a = a * 21; // a = (a + (a << 2)) + (a << 4);
-	a = a ^ (a >> 11);
-	a = a + (a << 6);
-	a = a ^ (a >> 22);
-	return (unsigned int)a;
+    // Edited by TC
+    a = (~a) + (a << 18);
+    a = a ^ (a >> 31);
+    a = a * 21;
+    a = a ^ (a >> 11);
+    a = a + (a << 6);
+    a = a ^ (a >> 22);
+    return (unsigned int)a;
 }
-#else
-inline unsigned int dtHashRef(dtPolyRef a)
-{
-	a += ~(a<<15);
-	a ^=  (a>>10);
-	a +=  (a<<3);
-	a ^=  (a>>6);
-	a += ~(a<<11);
-	a ^=  (a>>16);
-	return (unsigned int)a;
-}
-#endif
 
 //////////////////////////////////////////////////////////////////////////////////////////
 dtNodePool::dtNodePool(int maxNodes, int hashSize) :
diff --git a/DetourCrowd/Source/DetourObstacleAvoidance.cpp b/DetourCrowd/Source/DetourObstacleAvoidance.cpp
index 0fad9ef..d3f90b7 100644
--- a/DetourCrowd/Source/DetourObstacleAvoidance.cpp
+++ b/DetourCrowd/Source/DetourObstacleAvoidance.cpp
@@ -18,10 +18,10 @@
 
 #include "DetourObstacleAvoidance.h"
 #include "DetourCommon.h"
-#include "DetourMath.h"
 #include "DetourAlloc.h"
 #include "DetourAssert.h"
 #include <string.h>
+#include <math.h>
 #include <float.h>
 #include <new>
 
@@ -58,7 +58,7 @@ static int isectRaySeg(const float* ap, const float* u,
 	dtVsub(v,bq,bp);
 	dtVsub(w,ap,bp);
 	float d = dtVperp2D(u,v);
-	if (dtMathFabs(d) < 1e-6f) return 0;
+	if (fabsf(d) < 1e-6f) return 0;
 	d = 1.0f/d;
 	t = dtVperp2D(v,w) * d;
 	if (t < 0 || t > 1) return 0;
@@ -482,7 +482,7 @@ int dtObstacleAvoidanceQuery::sampleVelocityAdaptive(const float* pos, const flo
 	const int nd = dtClamp(ndivs, 1, DT_MAX_PATTERN_DIVS);
 	const int nr = dtClamp(nrings, 1, DT_MAX_PATTERN_RINGS);
 	const float da = (1.0f/nd) * DT_PI*2;
-	const float dang = dtMathAtan2f(dvel[2], dvel[0]);
+	const float dang = atan2f(dvel[2], dvel[0]);
 	
 	// Always add sample at zero
 	pat[npat*2+0] = 0;
diff --git a/Recast/Include/Recast.h b/Recast/Include/Recast.h
index 83ca606..66974cd 100644
--- a/Recast/Include/Recast.h
+++ b/Recast/Include/Recast.h
@@ -243,7 +243,7 @@ struct rcConfig
 };
 
 /// Defines the number of bits allocated to rcSpan::smin and rcSpan::smax.
-static const int RC_SPAN_HEIGHT_BITS = 13;
+static const int RC_SPAN_HEIGHT_BITS = 16; // EDITED BY TC
 /// Defines the maximum value for rcSpan::smin and rcSpan::smax.
 static const int RC_SPAN_MAX_HEIGHT = (1<<RC_SPAN_HEIGHT_BITS)-1;
 
@@ -255,9 +255,9 @@ static const int RC_SPANS_PER_POOL = 2048;
 /// @see rcHeightfield
 struct rcSpan
 {
-	unsigned int smin : 13;			///< The lower limit of the span. [Limit: < #smax]
-	unsigned int smax : 13;			///< The upper limit of the span. [Limit: <= #RC_SPAN_MAX_HEIGHT]
-	unsigned int area : 6;			///< The area id assigned to the span.
+	unsigned int smin : 16;			///< The lower limit of the span. [Limit: < #smax]
+	unsigned int smax : 16;			///< The upper limit of the span. [Limit: <= #RC_SPAN_MAX_HEIGHT]
+	unsigned char area;			    ///< The area id assigned to the span.
 	rcSpan* next;					///< The next span higher up in column.
 };
 
-- 
1.9.0.msysgit.0