1
/* $Id: nodelist.hpp 10392 2007-06-29 23:45:13Z KUDr $ */
1
/* $Id: nodelist.hpp 15718 2009-03-15 00:32:18Z rubidium $ */
3
/** @file nodelist.hpp */
3
/** @file nodelist.hpp List of nodes used for the A-star pathfinder. */
50
51
~CNodeList_HashTableT()
53
55
/** return number of open nodes */
54
FORCEINLINE int OpenCount() {return m_open.Count();}
56
FORCEINLINE int OpenCount()
58
return m_open.Count();
55
61
/** return number of closed nodes */
56
FORCEINLINE int ClosedCount() {return m_closed.Count();}
62
FORCEINLINE int ClosedCount()
64
return m_closed.Count();
57
67
/** allocate new data item from m_arr */
58
FORCEINLINE Titem_* CreateNewNode()
68
FORCEINLINE Titem_ *CreateNewNode()
60
70
if (m_new_node == NULL) m_new_node = &m_arr.Add();
63
74
/** notify the nodelist, that we don't want to discard the given node */
64
75
FORCEINLINE void FoundBestNode(Titem_& item)
66
// for now it is enough to invalidate m_new_node if it is our given node
67
if (&item == m_new_node)
77
/* for now it is enough to invalidate m_new_node if it is our given node */
78
if (&item == m_new_node) {
69
// TODO: do we need to store best nodes found in some extra list/array? Probably not now.
81
/* TODO: do we need to store best nodes found in some extra list/array? Probably not now. */
71
84
/** insert given item as open node (into m_open and m_open_queue) */
72
85
FORCEINLINE void InsertOpenNode(Titem_& item)
74
87
assert(m_closed.Find(item.GetKey()) == NULL);
76
// TODO: check if m_open_queue is not full
89
/* TODO: check if m_open_queue is not full */
77
90
assert(!m_open_queue.IsFull());
78
91
m_open_queue.Push(item);
79
if (&item == m_new_node)
92
if (&item == m_new_node) {
82
97
/** return the best open node */
83
FORCEINLINE Titem_* GetBestOpenNode()
98
FORCEINLINE Titem_ *GetBestOpenNode()
85
100
if (!m_open_queue.IsEmpty()) {
86
101
Titem_& item = m_open_queue.GetHead();
91
107
/** remove and return the best open node */
92
FORCEINLINE Titem_* PopBestOpenNode()
108
FORCEINLINE Titem_ *PopBestOpenNode()
94
110
if (!m_open_queue.IsEmpty()) {
95
111
Titem_& item = m_open_queue.PopHead();
101
118
/** return the open node specified by a key or NULL if not found */
102
FORCEINLINE Titem_* FindOpenNode(const Key& key)
119
FORCEINLINE Titem_ *FindOpenNode(const Key& key)
104
Titem_* item = m_open.Find(key);
121
Titem_ *item = m_open.Find(key);
107
125
/** remove and return the open node specified by a key */
108
126
FORCEINLINE Titem_& PopOpenNode(const Key& key)
112
130
m_open_queue.RemoveByIdx(idxPop);
115
134
/** close node */
116
135
FORCEINLINE void InsertClosedNode(Titem_& item)
118
137
assert(m_open.Find(item.GetKey()) == NULL);
119
138
m_closed.Push(item);
121
141
/** return the closed node specified by a key or NULL if not found */
122
FORCEINLINE Titem_* FindClosedNode(const Key& key)
142
FORCEINLINE Titem_ *FindClosedNode(const Key& key)
124
Titem_* item = m_closed.Find(key);
144
Titem_ *item = m_closed.Find(key);