~rebel/horde3d/trunk

« back to all changes in this revision

Viewing changes to trunk/Tools/Dependencies/RecastNavigation/Detour/Source/DetourNode.cpp

  • Committer: felix
  • Date: 2015-07-07 12:57:07 UTC
  • Revision ID: svn-v4:5ce291ac-9df0-446f-9e4f-d57731c4dda7::1699
- Updated RecastNavigation to latest version and fixed multiple issues.
- Adapted GameDetourComponent, GameDetourCrowdComponent, DetourCrowdDemo and AAA accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include "DetourCommon.h"
23
23
#include <string.h>
24
24
 
 
25
#ifdef DT_POLYREF64
 
26
// From Thomas Wang, https://gist.github.com/badboy/6267743
 
27
inline unsigned int dtHashRef(dtPolyRef a)
 
28
{
 
29
        a = (~a) + (a << 18); // a = (a << 18) - a - 1;
 
30
        a = a ^ (a >> 31);
 
31
        a = a * 21; // a = (a + (a << 2)) + (a << 4);
 
32
        a = a ^ (a >> 11);
 
33
        a = a + (a << 6);
 
34
        a = a ^ (a >> 22);
 
35
        return (unsigned int)a;
 
36
}
 
37
#else
25
38
inline unsigned int dtHashRef(dtPolyRef a)
26
39
{
27
40
        a += ~(a<<15);
32
45
        a ^=  (a>>16);
33
46
        return (unsigned int)a;
34
47
}
 
48
#endif
35
49
 
36
50
//////////////////////////////////////////////////////////////////////////////////////////
37
51
dtNodePool::dtNodePool(int maxNodes, int hashSize) :
70
84
        m_nodeCount = 0;
71
85
}
72
86
 
73
 
dtNode* dtNodePool::findNode(dtPolyRef id)
 
87
unsigned int dtNodePool::findNodes(dtPolyRef id, dtNode** nodes, const int maxNodes)
74
88
{
 
89
        int n = 0;
75
90
        unsigned int bucket = dtHashRef(id) & (m_hashSize-1);
76
91
        dtNodeIndex i = m_first[bucket];
77
92
        while (i != DT_NULL_IDX)
78
93
        {
79
94
                if (m_nodes[i].id == id)
 
95
                {
 
96
                        if (n >= maxNodes)
 
97
                                return n;
 
98
                        nodes[n++] = &m_nodes[i];
 
99
                }
 
100
                i = m_next[i];
 
101
        }
 
102
 
 
103
        return n;
 
104
}
 
105
 
 
106
dtNode* dtNodePool::findNode(dtPolyRef id, unsigned char state)
 
107
{
 
108
        unsigned int bucket = dtHashRef(id) & (m_hashSize-1);
 
109
        dtNodeIndex i = m_first[bucket];
 
110
        while (i != DT_NULL_IDX)
 
111
        {
 
112
                if (m_nodes[i].id == id && m_nodes[i].state == state)
80
113
                        return &m_nodes[i];
81
114
                i = m_next[i];
82
115
        }
83
116
        return 0;
84
117
}
85
118
 
86
 
dtNode* dtNodePool::getNode(dtPolyRef id)
 
119
dtNode* dtNodePool::getNode(dtPolyRef id, unsigned char state)
87
120
{
88
121
        unsigned int bucket = dtHashRef(id) & (m_hashSize-1);
89
122
        dtNodeIndex i = m_first[bucket];
90
123
        dtNode* node = 0;
91
124
        while (i != DT_NULL_IDX)
92
125
        {
93
 
                if (m_nodes[i].id == id)
 
126
                if (m_nodes[i].id == id && m_nodes[i].state == state)
94
127
                        return &m_nodes[i];
95
128
                i = m_next[i];
96
129
        }
107
140
        node->cost = 0;
108
141
        node->total = 0;
109
142
        node->id = id;
 
143
        node->state = state;
110
144
        node->flags = 0;
111
145
        
112
146
        m_next[i] = m_first[bucket];