Added few more asserts. Moved hash function to common.
This commit is contained in:
parent
3f0995dc1c
commit
c6ce6e2ba9
@ -182,6 +182,17 @@ inline unsigned int dtIlog2(unsigned int v)
|
|||||||
|
|
||||||
inline int dtAlign4(int x) { return (x+3) & ~3; }
|
inline int dtAlign4(int x) { return (x+3) & ~3; }
|
||||||
|
|
||||||
|
inline unsigned int dtHashInt(unsigned int a)
|
||||||
|
{
|
||||||
|
a += ~(a<<15);
|
||||||
|
a ^= (a>>10);
|
||||||
|
a += (a<<3);
|
||||||
|
a ^= (a>>6);
|
||||||
|
a += ~(a<<11);
|
||||||
|
a ^= (a>>16);
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
inline int dtOppositeTile(int side) { return (side+4) & 0x7; }
|
inline int dtOppositeTile(int side) { return (side+4) & 0x7; }
|
||||||
|
|
||||||
inline float dtVdot2D(const float* u, const float* v)
|
inline float dtVdot2D(const float* u, const float* v)
|
||||||
|
@ -80,16 +80,6 @@ public:
|
|||||||
inline unsigned short getNext(int i) const { return m_next[i]; }
|
inline unsigned short getNext(int i) const { return m_next[i]; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline unsigned int hashint(unsigned int a) const
|
|
||||||
{
|
|
||||||
a += ~(a<<15);
|
|
||||||
a ^= (a>>10);
|
|
||||||
a += (a<<3);
|
|
||||||
a ^= (a>>6);
|
|
||||||
a += ~(a<<11);
|
|
||||||
a ^= (a>>16);
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
|
|
||||||
dtNode* m_nodes;
|
dtNode* m_nodes;
|
||||||
unsigned short* m_first;
|
unsigned short* m_first;
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "DetourNode.h"
|
#include "DetourNode.h"
|
||||||
#include "DetourAlloc.h"
|
#include "DetourAlloc.h"
|
||||||
#include "DetourAssert.h"
|
#include "DetourAssert.h"
|
||||||
|
#include "DetourCommon.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -30,6 +31,9 @@ dtNodePool::dtNodePool(int maxNodes, int hashSize) :
|
|||||||
m_hashSize(hashSize),
|
m_hashSize(hashSize),
|
||||||
m_nodeCount(0)
|
m_nodeCount(0)
|
||||||
{
|
{
|
||||||
|
dtAssert(dtNextPow2(m_hashSize) == (unsigned int)m_hashSize);
|
||||||
|
dtAssert(m_maxNodes > 0);
|
||||||
|
|
||||||
m_nodes = (dtNode*)dtAlloc(sizeof(dtNode)*m_maxNodes, DT_ALLOC_PERM);
|
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_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_first = (unsigned short*)dtAlloc(sizeof(unsigned short)*hashSize, DT_ALLOC_PERM);
|
||||||
@ -57,7 +61,7 @@ void dtNodePool::clear()
|
|||||||
|
|
||||||
const dtNode* dtNodePool::findNode(unsigned int id) const
|
const dtNode* dtNodePool::findNode(unsigned int id) const
|
||||||
{
|
{
|
||||||
unsigned int bucket = hashint(id) & (m_hashSize-1);
|
unsigned int bucket = dtHashInt(id) & (m_hashSize-1);
|
||||||
unsigned short i = m_first[bucket];
|
unsigned short i = m_first[bucket];
|
||||||
while (i != DT_NULL_IDX)
|
while (i != DT_NULL_IDX)
|
||||||
{
|
{
|
||||||
@ -70,7 +74,7 @@ const dtNode* dtNodePool::findNode(unsigned int id) const
|
|||||||
|
|
||||||
dtNode* dtNodePool::getNode(unsigned int id)
|
dtNode* dtNodePool::getNode(unsigned int id)
|
||||||
{
|
{
|
||||||
unsigned int bucket = hashint(id) & (m_hashSize-1);
|
unsigned int bucket = dtHashInt(id) & (m_hashSize-1);
|
||||||
unsigned short i = m_first[bucket];
|
unsigned short i = m_first[bucket];
|
||||||
dtNode* node = 0;
|
dtNode* node = 0;
|
||||||
while (i != DT_NULL_IDX)
|
while (i != DT_NULL_IDX)
|
||||||
@ -107,6 +111,8 @@ dtNodeQueue::dtNodeQueue(int n) :
|
|||||||
m_capacity(n),
|
m_capacity(n),
|
||||||
m_size(0)
|
m_size(0)
|
||||||
{
|
{
|
||||||
|
dtAssert(m_capacity > 0);
|
||||||
|
|
||||||
m_heap = (dtNode**)dtAlloc(sizeof(dtNode*)*(m_capacity+1), DT_ALLOC_PERM);
|
m_heap = (dtNode**)dtAlloc(sizeof(dtNode*)*(m_capacity+1), DT_ALLOC_PERM);
|
||||||
dtAssert(m_heap);
|
dtAssert(m_heap);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user