TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dtNodePool Class Reference

#include <DetourNode.h>

Public Member Functions

 dtNodePool (int maxNodes, int hashSize)
 
 ~dtNodePool ()
 
void operator= (const dtNodePool &)
 
void clear ()
 
dtNodegetNode (dtPolyRef id, unsigned char state=0)
 
dtNodefindNode (dtPolyRef id, unsigned char state)
 
unsigned int findNodes (dtPolyRef id, dtNode **nodes, const int maxNodes)
 
unsigned int getNodeIdx (const dtNode *node) const
 
dtNodegetNodeAtIdx (unsigned int idx)
 
const dtNodegetNodeAtIdx (unsigned int idx) const
 
int getMemUsed () const
 
int getMaxNodes () const
 
int getHashSize () const
 
dtNodeIndex getFirst (int bucket) const
 
dtNodeIndex getNext (int i) const
 
int getNodeCount () const
 

Private Attributes

dtNodem_nodes
 
dtNodeIndexm_first
 
dtNodeIndexm_next
 
const int m_maxNodes
 
const int m_hashSize
 
int m_nodeCount
 

Constructor & Destructor Documentation

dtNodePool::dtNodePool ( int  maxNodes,
int  hashSize 
)
38  :
39  m_nodes(0),
40  m_first(0),
41  m_next(0),
42  m_maxNodes(maxNodes),
43  m_hashSize(hashSize),
44  m_nodeCount(0)
45 {
46  dtAssert(dtNextPow2(m_hashSize) == (unsigned int)m_hashSize);
47  dtAssert(m_maxNodes > 0);
48 
51  m_first = (dtNodeIndex*)dtAlloc(sizeof(dtNodeIndex)*hashSize, DT_ALLOC_PERM);
52 
56 
57  memset(m_first, 0xff, sizeof(dtNodeIndex)*m_hashSize);
58  memset(m_next, 0xff, sizeof(dtNodeIndex)*m_maxNodes);
59 }
int m_nodeCount
Definition: DetourNode.h:104
void * dtAlloc(int size, dtAllocHint hint)
Definition: DetourAlloc.cpp:41
Definition: DetourNode.h:34
Memory persist after a function call.
Definition: DetourAlloc.h:26
#define dtAssert
Definition: DetourAssert.h:30
const int m_maxNodes
Definition: DetourNode.h:102
dtNodeIndex * m_first
Definition: DetourNode.h:100
unsigned int dtNextPow2(unsigned int v)
Definition: DetourCommon.h:417
const int m_hashSize
Definition: DetourNode.h:103
dtNode * m_nodes
Definition: DetourNode.h:99
unsigned short dtNodeIndex
Definition: DetourNode.h:31
dtNodeIndex * m_next
Definition: DetourNode.h:101

+ Here is the call graph for this function:

dtNodePool::~dtNodePool ( )
62 {
63  dtFree(m_nodes);
64  dtFree(m_next);
65  dtFree(m_first);
66 }
dtNodeIndex * m_first
Definition: DetourNode.h:100
dtNode * m_nodes
Definition: DetourNode.h:99
dtNodeIndex * m_next
Definition: DetourNode.h:101
void dtFree(void *ptr)
Definition: DetourAlloc.cpp:46

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Function Documentation

void dtNodePool::clear ( )
69 {
70  memset(m_first, 0xff, sizeof(dtNodeIndex)*m_hashSize);
71  m_nodeCount = 0;
72 }
int m_nodeCount
Definition: DetourNode.h:104
dtNodeIndex * m_first
Definition: DetourNode.h:100
const int m_hashSize
Definition: DetourNode.h:103
unsigned short dtNodeIndex
Definition: DetourNode.h:31

+ Here is the caller graph for this function:

dtNode * dtNodePool::findNode ( dtPolyRef  id,
unsigned char  state 
)
94 {
95  unsigned int bucket = dtHashRef(id) & (m_hashSize-1);
96  dtNodeIndex i = m_first[bucket];
97  while (i != DT_NULL_IDX)
98  {
99  if (m_nodes[i].id == id && m_nodes[i].state == state)
100  return &m_nodes[i];
101  i = m_next[i];
102  }
103  return 0;
104 }
unsigned int dtHashRef(dtPolyRef a)
Definition: DetourNode.cpp:25
dtNodeIndex * m_first
Definition: DetourNode.h:100
static const dtNodeIndex DT_NULL_IDX
Definition: DetourNode.h:32
const int m_hashSize
Definition: DetourNode.h:103
dtNode * m_nodes
Definition: DetourNode.h:99
unsigned short dtNodeIndex
Definition: DetourNode.h:31
dtNodeIndex * m_next
Definition: DetourNode.h:101

+ Here is the call graph for this function:

unsigned int dtNodePool::findNodes ( dtPolyRef  id,
dtNode **  nodes,
const int  maxNodes 
)
75 {
76  int n = 0;
77  unsigned int bucket = dtHashRef(id) & (m_hashSize-1);
78  dtNodeIndex i = m_first[bucket];
79  while (i != DT_NULL_IDX)
80  {
81  if (m_nodes[i].id == id)
82  {
83  if (n >= maxNodes)
84  return n;
85  nodes[n++] = &m_nodes[i];
86  }
87  i = m_next[i];
88  }
89 
90  return n;
91 }
unsigned int dtHashRef(dtPolyRef a)
Definition: DetourNode.cpp:25
dtNodeIndex * m_first
Definition: DetourNode.h:100
static const dtNodeIndex DT_NULL_IDX
Definition: DetourNode.h:32
const int m_hashSize
Definition: DetourNode.h:103
dtNode * m_nodes
Definition: DetourNode.h:99
unsigned short dtNodeIndex
Definition: DetourNode.h:31
dtNodeIndex * m_next
Definition: DetourNode.h:101

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

dtNodeIndex dtNodePool::getFirst ( int  bucket) const
inline
93 { return m_first[bucket]; }
dtNodeIndex * m_first
Definition: DetourNode.h:100
int dtNodePool::getHashSize ( ) const
inline
92 { return m_hashSize; }
const int m_hashSize
Definition: DetourNode.h:103
int dtNodePool::getMaxNodes ( ) const
inline
90 { return m_maxNodes; }
const int m_maxNodes
Definition: DetourNode.h:102

+ Here is the caller graph for this function:

int dtNodePool::getMemUsed ( ) const
inline
83  {
84  return sizeof(*this) +
85  sizeof(dtNode)*m_maxNodes +
86  sizeof(dtNodeIndex)*m_maxNodes +
87  sizeof(dtNodeIndex)*m_hashSize;
88  }
Definition: DetourNode.h:34
const int m_maxNodes
Definition: DetourNode.h:102
const int m_hashSize
Definition: DetourNode.h:103
unsigned short dtNodeIndex
Definition: DetourNode.h:31
dtNodeIndex dtNodePool::getNext ( int  i) const
inline
94 { return m_next[i]; }
dtNodeIndex * m_next
Definition: DetourNode.h:101
dtNode * dtNodePool::getNode ( dtPolyRef  id,
unsigned char  state = 0 
)
107 {
108  unsigned int bucket = dtHashRef(id) & (m_hashSize-1);
109  dtNodeIndex i = m_first[bucket];
110  dtNode* node = 0;
111  while (i != DT_NULL_IDX)
112  {
113  if (m_nodes[i].id == id && m_nodes[i].state == state)
114  return &m_nodes[i];
115  i = m_next[i];
116  }
117 
118  if (m_nodeCount >= m_maxNodes)
119  return 0;
120 
122  m_nodeCount++;
123 
124  // Init node
125  node = &m_nodes[i];
126  node->pidx = 0;
127  node->cost = 0;
128  node->total = 0;
129  node->id = id;
130  node->state = state;
131  node->flags = 0;
132 
133  m_next[i] = m_first[bucket];
134  m_first[bucket] = i;
135 
136  return node;
137 }
int m_nodeCount
Definition: DetourNode.h:104
Definition: DetourNode.h:34
unsigned int dtHashRef(dtPolyRef a)
Definition: DetourNode.cpp:25
const int m_maxNodes
Definition: DetourNode.h:102
unsigned int flags
Node flags. A combination of dtNodeFlags.
Definition: DetourNode.h:41
dtNodeIndex * m_first
Definition: DetourNode.h:100
dtPolyRef id
Polygon ref the node corresponds to.
Definition: DetourNode.h:42
unsigned int pidx
Index to parent node.
Definition: DetourNode.h:39
static const dtNodeIndex DT_NULL_IDX
Definition: DetourNode.h:32
const int m_hashSize
Definition: DetourNode.h:103
float cost
Cost from previous node to current node.
Definition: DetourNode.h:37
dtNode * m_nodes
Definition: DetourNode.h:99
float total
Cost up to the node.
Definition: DetourNode.h:38
unsigned short dtNodeIndex
Definition: DetourNode.h:31
dtNodeIndex * m_next
Definition: DetourNode.h:101
unsigned int state
extra state information. A polyRef can have multiple nodes with different extra info. see DT_MAX_STATES_PER_NODE
Definition: DetourNode.h:40

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

dtNode* dtNodePool::getNodeAtIdx ( unsigned int  idx)
inline
71  {
72  if (!idx) return 0;
73  return &m_nodes[idx-1];
74  }
dtNode * m_nodes
Definition: DetourNode.h:99

+ Here is the caller graph for this function:

const dtNode* dtNodePool::getNodeAtIdx ( unsigned int  idx) const
inline
77  {
78  if (!idx) return 0;
79  return &m_nodes[idx-1];
80  }
dtNode * m_nodes
Definition: DetourNode.h:99
int dtNodePool::getNodeCount ( ) const
inline
95 { return m_nodeCount; }
int m_nodeCount
Definition: DetourNode.h:104
unsigned int dtNodePool::getNodeIdx ( const dtNode node) const
inline
65  {
66  if (!node) return 0;
67  return (unsigned int)(node - m_nodes)+1;
68  }
dtNode * m_nodes
Definition: DetourNode.h:99

+ Here is the caller graph for this function:

void dtNodePool::operator= ( const dtNodePool )
inline
55 {}

Member Data Documentation

dtNodeIndex* dtNodePool::m_first
private
const int dtNodePool::m_hashSize
private
const int dtNodePool::m_maxNodes
private
dtNodeIndex* dtNodePool::m_next
private
int dtNodePool::m_nodeCount
private
dtNode* dtNodePool::m_nodes
private

The documentation for this class was generated from the following files: