19 #ifndef DETOURNAVMESH_H
20 #define DETOURNAVMESH_H
22 #include <AtomsUtils/Globals.h>
23 #include <AtomsUtils/NavigationMesh/Detour/DetourAlloc.h>
24 #include <AtomsUtils/NavigationMesh/Detour/DetourStatus.h>
31 #ifndef USE_64BIT_ADDRESS
32 #define USE_64BIT_ADDRESS 1
39 typedef unsigned long long Type_uint64;
42 typedef uint64_t Type_uint64;
73 static const int DT_VERTS_PER_POLYGON = 6;
82 static const int DT_NAVMESH_MAGIC =
'D'<<24 |
'N'<<16 |
'A'<<8 |
'V';
85 static const int DT_NAVMESH_VERSION = 7;
88 static const int DT_NAVMESH_STATE_MAGIC =
'D'<<24 |
'N'<<16 |
'M'<<8 |
'S';
91 static const int DT_NAVMESH_STATE_VERSION = 1;
97 static const unsigned short DT_EXT_LINK = 0x8000;
100 static const unsigned int DT_NULL_LINK = 0xffffffff;
103 static const unsigned char DT_OFFMESH_CON_BIDIR = 0x01;
104 static const unsigned char DT_OFFMESH_CON_POINT = 0x02;
105 static const unsigned char DT_OFFMESH_CON_SEGMENT = 0x04;
106 static const unsigned char DT_OFFMESH_CON_CHEAPAREA = 0x08;
110 static const int DT_MAX_AREAS = 64;
113 static const int DT_MIN_SALT_BITS = 5;
114 static const int DT_SALT_BASE = 1;
117 static const int DT_MAX_OFFMESH_SEGMENT_PARTS = 4;
118 static const int DT_INVALID_SEGMENT_PART = 0xffff;
121 static const unsigned char DT_CONNECTION_INTERNAL = (1 << 7);
122 static const unsigned char DT_LINK_FLAG_OFFMESH_CON = (1 << 6);
123 static const unsigned char DT_LINK_FLAG_OFFMESH_CON_BIDIR = (1 << 5);
124 static const unsigned char DT_LINK_FLAG_OFFMESH_CON_BACKTRACKER = (1 << 4);
125 static const unsigned char DT_LINK_FLAG_OFFMESH_CON_ENABLED = (1 << 3);
126 static const unsigned char DT_LINK_FLAG_SIDE_MASK = 7;
129 static const unsigned char DT_CLINK_VALID_FWD = 0x01;
130 static const unsigned char DT_CLINK_VALID_BCK = 0x02;
133 static const unsigned int DT_CLINK_FIRST = 0x80000000;
184 unsigned short verts[DT_VERTS_PER_POLYGON];
187 unsigned short neis[DT_VERTS_PER_POLYGON];
272 flags = ((conFlags & DT_OFFMESH_CON_BIDIR) ? 0x80 : 0);
307 flags = ((conFlags & DT_OFFMESH_CON_BIDIR) ? 0x80 : 0) |
308 ((conFlags & DT_OFFMESH_CON_CHEAPAREA) ? 0x40 : 0);
446 dtStatus
init(
unsigned char* data,
const int dataSize,
const int flags);
500 dtMeshTile const** tiles,
const int maxTiles)
const;
663 salt = (
unsigned int)((ref >> (m_polyBits+m_tileBits)) & saltMask);
664 it = (
unsigned int)((ref >> m_polyBits) & tileMask);
665 ip = (
unsigned int)(ref & polyMask);
675 return (
unsigned int)((ref >> (m_polyBits+m_tileBits)) & saltMask);
685 return (
unsigned int)((ref >> m_polyBits) & tileMask);
695 return (
unsigned int)(ref & polyMask);
703 return decodePolyIdTile(ref);
711 return decodePolyIdPoly(ref);
725 inline const dtLink& getLink(
const dtMeshTile* tile,
unsigned int linkIdx)
const
744 inline bool isEmpty()
const
747 return (m_tileWidth > 0 && m_tileHeight > 0) ==
false;
750 inline unsigned int getSaltBits()
const
755 void applyAreaCostOrder(
unsigned char* costOrder);
760 bool getNeighbourCoords(
const int x,
const int y,
const int side,
int& outX,
int& outY)
const
766 case 0: ++outX;
break;
767 case 1: ++outX; ++outY;
break;
768 case 2: ++outY;
break;
769 case 3: --outX; ++outY;
break;
770 case 4: --outX;
break;
771 case 5: --outX; --outY;
break;
772 case 6: --outY;
break;
773 case 7: ++outX; --outY;
break;
779 unsigned int getTileIndex(
const dtMeshTile* tile)
const
781 return (
unsigned int)(tile - m_tiles);
799 dtMeshTile** tiles,
const int maxTiles)
const;
803 dtMeshTile** tiles,
const int maxTiles)
const;
827 unsigned char flags,
bool bCheckExisting =
true);
836 dtPolyRef* polys,
const int maxPolys,
bool bExcludeUnwalkable =
false)
const;
839 const float* extents,
float* nearestPt,
bool bExcludeUnwalkable =
false)
const;
841 const float* extents,
float* nearestPt)
const;
844 const float* pos,
float* closest)
const;
853 unsigned char m_areaCostOrder[DT_MAX_AREAS];
877 static const int MaxTiles = 32;
891 if (RequestedSize < MaxTiles)
896 if (NumAllocated < RequestedSize)
900 NumAllocated = RequestedSize;
903 return AllocatedTiles;
A simple dynamic array of integers.
Definition: DetourAlloc.h:147
Definition: DetourNavMesh.h:427
dtPolyRef findNearestPolyInTile(const dtMeshTile *tile, const float *center, const float *extents, float *nearestPt, bool bExcludeUnwalkable=false) const
Find nearest polygon within a tile.
int m_maxTiles
Max number of tiles.
Definition: DetourNavMesh.h:849
unsigned int m_saltBits
Number of salt bits in the tile ID.
Definition: DetourNavMesh.h:859
const dtOffMeshSegmentConnection * getOffMeshSegmentConnectionByRef(dtPolyRef ref) const
dtMeshTile * m_tiles
List of tiles.
Definition: DetourNavMesh.h:857
dtStatus getPolyArea(dtPolyRef ref, unsigned char *resultArea) const
int m_tileLutSize
Tile hash lookup size (must be pot).
Definition: DetourNavMesh.h:850
unsigned int decodeClusterIdTile(dtClusterRef ref) const
Definition: DetourNavMesh.h:701
void unconnectClusterLinks(dtMeshTile *tile, dtMeshTile *target)
Removes cluster links at specified side.
unsigned int decodePolyIdSalt(dtPolyRef ref) const
Definition: DetourNavMesh.h:672
const dtMeshTile * getTileByRef(dtTileRef ref) const
int m_tileLutMask
Tile hash lookup mask.
Definition: DetourNavMesh.h:851
dtNavMeshParams m_params
Current initialization params. TODO: do not store this info twice.
Definition: DetourNavMesh.h:846
unsigned int decodePolyIdPoly(dtPolyRef ref) const
Definition: DetourNavMesh.h:692
dtStatus addTile(unsigned char *data, int dataSize, int flags, dtTileRef lastRef, dtTileRef *result)
const dtMeshTile * getTile(int i) const
void getTileAndPolyByRefUnsafe(const dtPolyRef ref, const dtMeshTile **tile, const dtPoly **poly) const
void updateOffMeshConnectionByUserId(unsigned int userId, unsigned char newArea, unsigned short newFlags)
bool isValidPolyRef(dtPolyRef ref) const
int getNeighbourTilesCountAt(const int x, const int y, const int side) const
Returns neighbour tile count based on side of given tile.
void connectClusterLink(dtMeshTile *tile0, unsigned int cluster0, dtMeshTile *tile1, unsigned int cluster1, unsigned char flags, bool bCheckExisting=true)
Try to connect clusters.
void connectExtLinks(dtMeshTile *tile, dtMeshTile *target, int side, bool updateCLinks)
Builds external polygon links for a tile.
dtMeshTile * m_nextFree
Freelist of tiles.
Definition: DetourNavMesh.h:856
void updateOffMeshSegmentConnectionByUserId(unsigned int userId, unsigned char newArea, unsigned short newFlags)
dtStatus restoreTileState(dtMeshTile *tile, const unsigned char *data, const int maxDataSize)
int getTilesAt(const int x, const int y, dtMeshTile const **tiles, const int maxTiles) const
dtMeshTile * getTile(int i)
Returns pointer to tile in the tile array.
int queryPolygonsInTile(const dtMeshTile *tile, const float *qmin, const float *qmax, dtPolyRef *polys, const int maxPolys, bool bExcludeUnwalkable=false) const
Queries polygons within a tile.
dtTileRef getTileRefAt(int x, int y, int layer) const
int findConnectingPolys(const float *va, const float *vb, const dtMeshTile *fromTile, int fromPolyIdx, const dtMeshTile *tile, int side, dtChunkArray< FConnectingPolyData > &cons) const
Returns all polygons in neighbour tile based on portal defined by the segment.
int getTileCountAt(const int x, const int y) const
int getNeighbourTilesAt(const int x, const int y, const int side, dtMeshTile **tiles, const int maxTiles) const
Returns neighbour tile based on side.
unsigned int decodeClusterIdCluster(dtClusterRef ref) const
Definition: DetourNavMesh.h:709
dtClusterLink & getClusterLink(dtMeshTile *tile, unsigned int linkIdx)
Helper for accessing cluster links.
Definition: DetourNavMesh.h:731
const dtMeshTile * getTileAt(const int x, const int y, const int layer) const
const dtOffMeshConnection * getOffMeshConnectionByRef(dtPolyRef ref) const
dtStatus setPolyArea(dtPolyRef ref, unsigned char area)
dtPolyRef encodePolyId(unsigned int salt, unsigned int it, unsigned int ip) const
Definition: DetourNavMesh.h:646
dtStatus getTileAndPolyByRef(const dtPolyRef ref, const dtMeshTile **tile, const dtPoly **poly) const
unsigned int m_tileBits
Number of tile bits in the tile ID.
Definition: DetourNavMesh.h:860
const dtNavMeshParams * getParams() const
The navigation mesh initialization params.
dtStatus removeTile(dtTileRef ref, unsigned char **data, int *dataSize)
dtTileRef getTileRef(const dtMeshTile *tile) const
void closestPointOnPolyInTile(const dtMeshTile *tile, unsigned int ip, const float *pos, float *closest) const
Returns closest point on polygon.
void connectIntLinks(dtMeshTile *tile)
Builds internal polygons links for a tile.
unsigned int decodePolyIdTile(dtPolyRef ref) const
Definition: DetourNavMesh.h:682
dtPolyRef getPolyRefBase(const dtMeshTile *tile) const
void decodePolyId(dtPolyRef ref, unsigned int &salt, unsigned int &it, unsigned int &ip) const
Definition: DetourNavMesh.h:658
dtStatus storeTileState(const dtMeshTile *tile, unsigned char *data, const int maxDataSize) const
void applyWorldOffset(const float *offset)
Shift navigation mesh by provided offset.
dtStatus getOffMeshConnectionPolyEndPoints(dtPolyRef prevRef, dtPolyRef polyRef, const float *currentPos, float *startPos, float *endPos) const
dtStatus setPolyFlags(dtPolyRef ref, unsigned short flags)
void baseOffMeshLinks(dtMeshTile *tile)
Builds internal polygons links for a tile.
void calcTileLoc(const float *pos, int *tx, int *ty) const
int getTileStateSize(const dtMeshTile *tile) const
void unconnectExtLinks(dtMeshTile *tile, dtMeshTile *target)
Removes external links at specified side.
dtStatus init(unsigned char *data, const int dataSize, const int flags)
dtMeshTile ** m_posLookup
Tile hash lookup.
Definition: DetourNavMesh.h:855
void connectExtOffMeshLinks(dtMeshTile *tile, dtMeshTile *target, int side, bool updateCLinks)
Builds external polygon links for a tile.
dtStatus getPolyFlags(dtPolyRef ref, unsigned short *resultFlags) const
dtClusterRef getClusterRefBase(const dtMeshTile *tile) const
unsigned int m_polyBits
Number of poly bits in the tile ID.
Definition: DetourNavMesh.h:861
int getTilesAt(const int x, const int y, dtMeshTile **tiles, const int maxTiles) const
Returns neighbour tile based on side.
float m_tileHeight
Dimensions of each tile.
Definition: DetourNavMesh.h:848
void linkOffMeshHelper(dtMeshTile *tile0, unsigned int polyIdx0, dtMeshTile *tile1, unsigned int polyIdx1, unsigned char side, unsigned char edge)
Helper for creating links in off-mesh connections.
dtLink & getLink(dtMeshTile *tile, unsigned int linkIdx)
Helper for accessing links.
Definition: DetourNavMesh.h:720
dtStatus init(const dtNavMeshParams *params)
ATOMSUTILS_EXPORT dtNavMesh * dtAllocNavMesh()
Type_uint64 dtTileRef
Definition: DetourNavMesh.h:51
ATOMSUTILS_EXPORT void dtFreeNavMesh(dtNavMesh *navmesh)
Type_uint64 dtPolyRef
Definition: DetourNavMesh.h:47
AtomsCore namespace.
Definition: Base64.h:13
dtStraightPathOptions
Options for dtNavMeshQuery::findStraightPath.
Definition: DetourNavMesh.h:153
@ DT_STRAIGHTPATH_AREA_CROSSINGS
Add a vertex at every polygon edge crossing where area changes.
Definition: DetourNavMesh.h:154
@ DT_STRAIGHTPATH_ALL_CROSSINGS
Add a vertex at every polygon edge crossing.
Definition: DetourNavMesh.h:155
ATOMSUTILS_EXPORT void * dtAlloc(int size, dtAllocHint hint)
@ DT_ALLOC_TEMP
Memory used temporarily within a function.
Definition: DetourAlloc.h:31
Type_uint64 dtClusterRef
A handle to a cluster within a navigation mesh tile.
Definition: DetourNavMesh.h:54
ATOMSUTILS_EXPORT void dtFree(void *ptr)
dtTileFlags
Definition: DetourNavMesh.h:139
@ DT_TILE_FREE_DATA
The navigation mesh owns the tile memory and is responsible for freeing it.
Definition: DetourNavMesh.h:140
dtDetailTriEdgeFlags
Definition: DetourNavMesh.h:170
@ DT_DETAIL_EDGE_BOUNDARY
Detail triangle edge is part of the poly boundary.
Definition: DetourNavMesh.h:171
dtStraightPathFlags
Vertex flags returned by dtNavMeshQuery::findStraightPath.
Definition: DetourNavMesh.h:145
@ DT_STRAIGHTPATH_END
The vertex is the end position in the path.
Definition: DetourNavMesh.h:147
@ DT_STRAIGHTPATH_START
The vertex is the start position in the path.
Definition: DetourNavMesh.h:146
@ DT_STRAIGHTPATH_OFFMESH_CONNECTION
The vertex is the start of an off-mesh connection.
Definition: DetourNavMesh.h:148
dtPolyTypes
Flags representing the type of a navigation mesh polygon.
Definition: DetourNavMesh.h:160
@ DT_POLYTYPE_GROUND
The polygon is a standard convex polygon that is part of the surface of the mesh.
Definition: DetourNavMesh.h:162
@ DT_POLYTYPE_OFFMESH_SEGMENT
The polygon is an off-mesh connection consisting of four vertices.
Definition: DetourNavMesh.h:166
@ DT_POLYTYPE_OFFMESH_POINT
The polygon is an off-mesh connection consisting of two vertices.
Definition: DetourNavMesh.h:164
Definition: DetourNavMesh.h:876
Definition: DetourNavMesh.h:238
unsigned short bmax[3]
Maximum bounds of the node's AABB. [(x, y, z)].
Definition: DetourNavMesh.h:240
int i
The node's index. (Negative for escape sequence.)
Definition: DetourNavMesh.h:241
unsigned short bmin[3]
Minimum bounds of the node's AABB. [(x, y, z)].
Definition: DetourNavMesh.h:239
Cluster of polys.
Definition: DetourNavMesh.h:320
unsigned int numLinks
Number of cluster links.
Definition: DetourNavMesh.h:323
float center[3]
Center pos of cluster.
Definition: DetourNavMesh.h:321
unsigned int firstLink
Link in dtMeshTile.links array.
Definition: DetourNavMesh.h:322
Links between clusters.
Definition: DetourNavMesh.h:328
dtClusterRef ref
Destination tile and cluster.
Definition: DetourNavMesh.h:329
unsigned int next
Next link in dtMeshTile.links array.
Definition: DetourNavMesh.h:330
unsigned char flags
Link traversing data.
Definition: DetourNavMesh.h:331
Definition: DetourNavMesh.h:225
unsigned char bmax
If a boundary link, defines the maximum sub-edge area.
Definition: DetourNavMesh.h:231
unsigned char edge
Index of the polygon edge that owns this link.
Definition: DetourNavMesh.h:228
unsigned int next
Index of the next link.
Definition: DetourNavMesh.h:227
unsigned char bmin
If a boundary link, defines the minimum sub-edge area.
Definition: DetourNavMesh.h:230
dtPolyRef ref
Neighbour reference. (The neighbor that is linked to.)
Definition: DetourNavMesh.h:226
unsigned char side
If a boundary link, defines on which side the link is.
Definition: DetourNavMesh.h:229
Definition: DetourNavMesh.h:374
dtPoly * polys
The tile polygons. [Size: dtMeshHeader::polyCount].
Definition: DetourNavMesh.h:379
dtChunkArray< dtLink > dynamicLinksO
Dynamic links array (indices starting from dtMeshHeader::maxLinkCount)
Definition: DetourNavMesh.h:405
int flags
Tile flags. (See: dtTileFlags)
Definition: DetourNavMesh.h:399
dtCluster * clusters
Cluster data.
Definition: DetourNavMesh.h:402
unsigned int dynamicFreeListC
Index of the next free dynamic link.
Definition: DetourNavMesh.h:408
unsigned int salt
Counter describing modifications to the tile.
Definition: DetourNavMesh.h:375
unsigned char * detailTris
The detail mesh's triangles. [(vertA, vertB, vertC) * dtMeshHeader::detailTriCount].
Definition: DetourNavMesh.h:388
float * detailVerts
The detail mesh's unique vertices. [(x, y, z) * dtMeshHeader::detailVertCount].
Definition: DetourNavMesh.h:385
dtMeshHeader * header
The tile header.
Definition: DetourNavMesh.h:378
int dataSize
Size of the tile data.
Definition: DetourNavMesh.h:398
unsigned char * data
The tile data. (Not directly accessed under normal situations.)
Definition: DetourNavMesh.h:397
dtOffMeshConnection * offMeshCons
The tile off-mesh connections. [Size: dtMeshHeader::offMeshConCount].
Definition: DetourNavMesh.h:394
unsigned int linksFreeList
Index to the next free link.
Definition: DetourNavMesh.h:377
float * verts
The tile vertices. [Size: dtMeshHeader::vertCount].
Definition: DetourNavMesh.h:380
dtBVNode * bvTree
Definition: DetourNavMesh.h:392
unsigned short * polyClusters
Cluster Id for each ground type polygon [Size: dtMeshHeader::polyCount].
Definition: DetourNavMesh.h:403
dtLink * links
The tile links. [Size: dtMeshHeader::maxLinkCount].
Definition: DetourNavMesh.h:381
dtMeshTile * next
The next free tile, or the next tile in the spatial grid.
Definition: DetourNavMesh.h:400
dtChunkArray< dtClusterLink > dynamicLinksC
Dynamic links array (indices starting from DT_CLINK_FIRST)
Definition: DetourNavMesh.h:407
dtOffMeshSegmentConnection * offMeshSeg
The tile off-mesh connections. [Size: dtMeshHeader::offMeshSegConCount].
Definition: DetourNavMesh.h:395
dtPolyDetail * detailMeshes
The tile's detail sub-meshes. [Size: dtMeshHeader::detailMeshCount].
Definition: DetourNavMesh.h:382
unsigned int dynamicFreeListO
Index of the next free dynamic link.
Definition: DetourNavMesh.h:406
Definition: DetourNavMesh.h:788
Definition: DetourNavMesh.h:416
int maxPolys
The maximum number of polygons each tile can contain.
Definition: DetourNavMesh.h:421
int maxTiles
The maximum number of tiles the navigation mesh can contain.
Definition: DetourNavMesh.h:420
float tileHeight
The height of each tile. (Along the z-axis.)
Definition: DetourNavMesh.h:419
float orig[3]
The world space origin of the navigation mesh's tile space. [(x, y, z)].
Definition: DetourNavMesh.h:417
float tileWidth
The width of each tile. (Along the x-axis.)
Definition: DetourNavMesh.h:418
Definition: DetourNavMesh.h:282
unsigned char side
End point side.
Definition: DetourNavMesh.h:299
float pos[6]
The endpoints of the connection. [(ax, ay, az, bx, by, bz)].
Definition: DetourNavMesh.h:284
float height
The snap height of endpoints (less than 0 = use step height)
Definition: DetourNavMesh.h:290
bool getBiDirectional() const
Gets the link direction.
Definition: DetourNavMesh.h:312
unsigned char flags
Link flags.
Definition: DetourNavMesh.h:302
void setFlags(unsigned char conFlags)
Sets link flags.
Definition: DetourNavMesh.h:305
unsigned int userId
The id of the offmesh connection. (User assigned when the navigation mesh is built....
Definition: DetourNavMesh.h:293
bool getSnapToCheapestArea() const
Gets the link snap mode.
Definition: DetourNavMesh.h:315
unsigned short poly
The polygon reference of the connection within the tile.
Definition: DetourNavMesh.h:296
float rad
The radius of the endpoints. [Limit: >= 0].
Definition: DetourNavMesh.h:287
Definition: DetourNavMesh.h:245
float startB[3]
Start point of segment B.
Definition: DetourNavMesh.h:248
void setFlags(unsigned char conFlags)
Sets link flags.
Definition: DetourNavMesh.h:270
float height
The snap height of endpoints (less than 0 = use step height)
Definition: DetourNavMesh.h:255
float endA[3]
End point of segment A.
Definition: DetourNavMesh.h:247
unsigned char npolys
Number of created polys.
Definition: DetourNavMesh.h:264
float startA[3]
Start point of segment A.
Definition: DetourNavMesh.h:246
float rad
The radius of the endpoints. [Limit: >= 0].
Definition: DetourNavMesh.h:252
float endB[3]
End point of segment B.
Definition: DetourNavMesh.h:249
unsigned short firstPoly
First poly in segment pool (+ header->offMeshSegPolyBase)
Definition: DetourNavMesh.h:261
unsigned int userId
The id of the offmesh connection. (User assigned when the navigation mesh is built....
Definition: DetourNavMesh.h:258
bool getBiDirectional() const
Gets the link direction.
Definition: DetourNavMesh.h:276
unsigned char flags
Link flags.
Definition: DetourNavMesh.h:267
Defines the location of detail sub-mesh data within a dtMeshTile.
Definition: DetourNavMesh.h:214
unsigned int vertBase
The offset of the vertices in the dtMeshTile::detailVerts array.
Definition: DetourNavMesh.h:215
unsigned char triCount
The number of triangles in the sub-mesh.
Definition: DetourNavMesh.h:218
unsigned char vertCount
The number of vertices in the sub-mesh.
Definition: DetourNavMesh.h:217
unsigned int triBase
The offset of the triangles in the dtMeshTile::detailTris array.
Definition: DetourNavMesh.h:216
Definition: DetourNavMesh.h:178
unsigned char areaAndtype
Definition: DetourNavMesh.h:197
unsigned short flags
The user defined polygon flags.
Definition: DetourNavMesh.h:190
void setArea(unsigned char a)
Sets the user defined area id. [Limit: < #DT_MAX_AREAS].
Definition: DetourNavMesh.h:200
void setType(unsigned char t)
Sets the polygon type. (See: dtPolyTypes.)
Definition: DetourNavMesh.h:203
unsigned int firstLink
Index to first link in linked list. (Or #DT_NULL_LINK if there is no link.)
Definition: DetourNavMesh.h:180
unsigned short verts[DT_VERTS_PER_POLYGON]
Definition: DetourNavMesh.h:184
unsigned char getType() const
Gets the polygon type. (See: dtPolyTypes)
Definition: DetourNavMesh.h:209
unsigned short neis[DT_VERTS_PER_POLYGON]
Packed data representing neighbor polygons references and flags for each edge.
Definition: DetourNavMesh.h:187
unsigned char vertCount
The number of vertices in the polygon.
Definition: DetourNavMesh.h:193
unsigned char getArea() const
Gets the user defined area id.
Definition: DetourNavMesh.h:206