Issue 86:Tiled world consisting of one tile - dtNavMesh::init fails. ___NOTE: dtPolyRef format changed___

This commit is contained in:
Mikko Mononen 2010-07-08 12:04:43 +00:00
parent fca9709196
commit 122ee3a7a1
2 changed files with 9 additions and 5 deletions

View File

@ -452,14 +452,14 @@ public:
// Encodes a tile id.
inline dtPolyRef encodePolyId(unsigned int salt, unsigned int it, unsigned int ip) const
{
return (salt << (m_polyBits+m_tileBits)) | ((it+1) << m_polyBits) | ip;
return (salt << (m_polyBits+m_tileBits)) | (it << m_polyBits) | ip;
}
// Decodes a tile id.
inline void decodePolyId(dtPolyRef ref, unsigned int& salt, unsigned int& it, unsigned int& ip) const
{
salt = (ref >> (m_polyBits+m_tileBits)) & ((1<<m_saltBits)-1);
it = ((ref >> m_polyBits) - 1) & ((1<<m_tileBits)-1);
it = (ref >> m_polyBits) & ((1<<m_tileBits)-1);
ip = ref & ((1<<m_polyBits)-1);
}
@ -472,7 +472,7 @@ public:
// Decodes a tile id.
inline unsigned int decodePolyIdTile(dtPolyRef ref) const
{
return ((ref >> m_polyBits) - 1) & ((1<<m_tileBits)-1);
return (ref >> m_polyBits) & ((1<<m_tileBits)-1);
}
// Decodes a poly id.

View File

@ -214,6 +214,7 @@ bool dtNavMesh::init(const dtNavMeshParams* params)
m_nextFree = 0;
for (int i = m_maxTiles-1; i >= 0; --i)
{
m_tiles[i].salt = 1;
m_tiles[i].next = m_nextFree;
m_nextFree = &m_tiles[i];
}
@ -832,8 +833,11 @@ bool dtNavMesh::removeTile(dtTileRef ref, unsigned char** data, int* dataSize)
tile->detailTris = 0;
tile->bvTree = 0;
tile->offMeshCons = 0;
tile->salt++;
// Update salt, salt should never be zero.
tile->salt = (tile->salt+1) & ((1<<m_saltBits)-1);
if (tile->salt == 0)
tile->salt++;
// Add to free list.
tile->next = m_nextFree;