Skip to content

Commit

Permalink
Fix for issue 150
Browse files Browse the repository at this point in the history
  • Loading branch information
memononen committed Feb 3, 2011
1 parent 98e7390 commit 9bb9aba
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions DebugUtils/Source/DetourDebugDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void duDebugDrawNavMeshNodes(struct duDebugDraw* dd, const dtNavMeshQuery& query
dd->begin(DU_DRAW_POINTS, 4.0f);
for (int i = 0; i < pool->getHashSize(); ++i)
{
for (unsigned short j = pool->getFirst(i); j != DT_NULL_IDX; j = pool->getNext(j))
for (dtNodeIndex j = pool->getFirst(i); j != DT_NULL_IDX; j = pool->getNext(j))
{
const dtNode* node = pool->getNodeAtIdx(j+1);
if (!node) continue;
Expand All @@ -282,7 +282,7 @@ void duDebugDrawNavMeshNodes(struct duDebugDraw* dd, const dtNavMeshQuery& query
dd->begin(DU_DRAW_LINES, 2.0f);
for (int i = 0; i < pool->getHashSize(); ++i)
{
for (unsigned short j = pool->getFirst(i); j != DT_NULL_IDX; j = pool->getNext(j))
for (dtNodeIndex j = pool->getFirst(i); j != DT_NULL_IDX; j = pool->getNext(j))
{
const dtNode* node = pool->getNodeAtIdx(j+1);
if (!node) continue;
Expand Down
18 changes: 10 additions & 8 deletions Detour/Include/DetourNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ enum dtNodeFlags
DT_NODE_CLOSED = 0x02,
};

static const unsigned short DT_NULL_IDX = 0xffff;
typedef unsigned short dtNodeIndex;
static const dtNodeIndex DT_NULL_IDX = ~0;

struct dtNode
{
Expand All @@ -39,6 +40,7 @@ struct dtNode
dtPolyRef id; // Polygon ref the node corresponds to.
};


class dtNodePool
{
public:
Expand Down Expand Up @@ -70,22 +72,22 @@ class dtNodePool
inline int getMemUsed() const
{
return sizeof(*this) +
sizeof(dtNode)*m_maxNodes +
sizeof(unsigned short)*m_maxNodes +
sizeof(unsigned short)*m_hashSize;
sizeof(dtNode)*m_maxNodes +
sizeof(dtNodeIndex)*m_maxNodes +
sizeof(dtNodeIndex)*m_hashSize;
}

inline int getMaxNodes() const { return m_maxNodes; }

inline int getHashSize() const { return m_hashSize; }
inline unsigned short getFirst(int bucket) const { return m_first[bucket]; }
inline unsigned short getNext(int i) const { return m_next[i]; }
inline dtNodeIndex getFirst(int bucket) const { return m_first[bucket]; }
inline dtNodeIndex getNext(int i) const { return m_next[i]; }

private:

dtNode* m_nodes;
unsigned short* m_first;
unsigned short* m_next;
dtNodeIndex* m_first;
dtNodeIndex* m_next;
const int m_maxNodes;
const int m_hashSize;
int m_nodeCount;
Expand Down
16 changes: 8 additions & 8 deletions Detour/Source/DetourNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ dtNodePool::dtNodePool(int maxNodes, int hashSize) :
dtAssert(m_maxNodes > 0);

m_nodes = (dtNode*)dtAlloc(sizeof(dtNode)*m_maxNodes, DT_ALLOC_PERM);
m_next = (unsigned short*)dtAlloc(sizeof(unsigned short)*m_maxNodes, DT_ALLOC_PERM);
m_first = (unsigned short*)dtAlloc(sizeof(unsigned short)*hashSize, DT_ALLOC_PERM);
m_next = (dtNodeIndex*)dtAlloc(sizeof(dtNodeIndex)*m_maxNodes, DT_ALLOC_PERM);
m_first = (dtNodeIndex*)dtAlloc(sizeof(dtNodeIndex)*hashSize, DT_ALLOC_PERM);

dtAssert(m_nodes);
dtAssert(m_next);
dtAssert(m_first);

memset(m_first, 0xff, sizeof(unsigned short)*m_hashSize);
memset(m_next, 0xff, sizeof(unsigned short)*m_maxNodes);
memset(m_first, 0xff, sizeof(dtNodeIndex)*m_hashSize);
memset(m_next, 0xff, sizeof(dtNodeIndex)*m_maxNodes);
}

dtNodePool::~dtNodePool()
Expand All @@ -66,14 +66,14 @@ dtNodePool::~dtNodePool()

void dtNodePool::clear()
{
memset(m_first, 0xff, sizeof(unsigned short)*m_hashSize);
memset(m_first, 0xff, sizeof(dtNodeIndex)*m_hashSize);
m_nodeCount = 0;
}

dtNode* dtNodePool::findNode(dtPolyRef id)
{
unsigned int bucket = dtHashRef(id) & (m_hashSize-1);
unsigned short i = m_first[bucket];
dtNodeIndex i = m_first[bucket];
while (i != DT_NULL_IDX)
{
if (m_nodes[i].id == id)
Expand All @@ -86,7 +86,7 @@ dtNode* dtNodePool::findNode(dtPolyRef id)
dtNode* dtNodePool::getNode(dtPolyRef id)
{
unsigned int bucket = dtHashRef(id) & (m_hashSize-1);
unsigned short i = m_first[bucket];
dtNodeIndex i = m_first[bucket];
dtNode* node = 0;
while (i != DT_NULL_IDX)
{
Expand All @@ -98,7 +98,7 @@ dtNode* dtNodePool::getNode(dtPolyRef id)
if (m_nodeCount >= m_maxNodes)
return 0;

i = (unsigned short)m_nodeCount;
i = (dtNodeIndex)m_nodeCount;
m_nodeCount++;

// Init node
Expand Down
Binary file modified RecastDemo/Bin/Recast.app/Contents/MacOS/Recast
Binary file not shown.

0 comments on commit 9bb9aba

Please sign in to comment.