Permalink
Browse files

Detour version change! Added user ID per off-mesh connection. Fixed o…

…ff-mesh connection draw flags after using off-mesh con tool.
  • Loading branch information...
1 parent ccf401d commit 1be9de72d87dcfdecf6bea30f5461745f7d7afe6 @memononen memononen committed Nov 7, 2010
@@ -34,7 +34,7 @@ typedef unsigned int dtTileRef;
static const int DT_VERTS_PER_POLYGON = 6;
static const int DT_NAVMESH_MAGIC = 'D'<<24 | 'N'<<16 | 'A'<<8 | 'V'; //'DNAV';
-static const int DT_NAVMESH_VERSION = 5;
+static const int DT_NAVMESH_VERSION = 6;
static const int DT_NAVMESH_STATE_MAGIC = 'D'<<24 | 'N'<<16 | 'M'<<8 | 'S'; //'DNMS';
static const int DT_NAVMESH_STATE_VERSION = 1;
@@ -124,6 +124,7 @@ struct dtOffMeshConnection
unsigned short poly; // Poly Id
unsigned char flags; // Link flags
unsigned char side; // End point side.
+ unsigned int userId; // User ID to identify this connection.
};
struct dtMeshHeader
@@ -283,6 +284,9 @@ class dtNavMesh
// endPos[3] - (out) end point of the link.
// Returns: true if link is found.
dtStatus getOffMeshConnectionPolyEndPoints(dtPolyRef prevRef, dtPolyRef polyRef, float* startPos, float* endPos) const;
+
+ // Returns pointer to off-mesh connection based on polyref, or null if ref not valid.
+ const dtOffMeshConnection* getOffMeshConnectionByRef(dtPolyRef ref) const;
// Sets polygon flags.
dtStatus setPolyFlags(dtPolyRef ref, unsigned short flags);
@@ -47,6 +47,7 @@ struct dtNavMeshCreateParams
const unsigned short* offMeshConFlags; // Off-mesh connection flags.
const unsigned char* offMeshConAreas; // Off-mesh connection area ids.
const unsigned char* offMeshConDir; // Off-mesh connection direction flags (1 = bidir, 0 = oneway).
+ const unsigned int* offMeshConUserID; // Off-mesh connection user id (optional).
int offMeshConCount; // Number of off-mesh connections
// Tile location
unsigned int userId; // User ID bound to the tile.
@@ -1150,6 +1150,27 @@ dtStatus dtNavMesh::getOffMeshConnectionPolyEndPoints(dtPolyRef prevRef, dtPolyR
}
+const dtOffMeshConnection* dtNavMesh::getOffMeshConnectionByRef(dtPolyRef ref) const
+{
+ unsigned int salt, it, ip;
+
+ // Get current polygon
+ decodePolyId(ref, salt, it, ip);
+ if (it >= (unsigned int)m_maxTiles) return 0;
+ if (m_tiles[it].salt != salt || m_tiles[it].header == 0) return 0;
+ const dtMeshTile* tile = &m_tiles[it];
+ if (ip >= (unsigned int)tile->header->polyCount) return 0;
+ const dtPoly* poly = &tile->polys[ip];
+
+ // Make sure that the current poly is indeed off-mesh link.
+ if (poly->getType() != DT_POLYTYPE_OFFMESH_CONNECTION)
+ return 0;
+
+ const unsigned int idx = ip - tile->header->offMeshBase;
+ dtAssert(idx < (unsigned int)tile->header->offMeshConCount);
+ return &tile->offMeshCons[idx];
+}
+
dtStatus dtNavMesh::setPolyFlags(dtPolyRef ref, unsigned short flags)
{
@@ -530,6 +530,8 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData,
con->rad = params->offMeshConRad[i];
con->flags = params->offMeshConDir[i] ? DT_OFFMESH_CON_BIDIR : 0;
con->side = offMeshConClass[i*2+1];
+ if (params->offMeshConUserID)
+ con->userId = params->offMeshConUserID[i];
n++;
}
}
Binary file not shown.
Oops, something went wrong.

0 comments on commit 1be9de7

Please sign in to comment.