sometimes it may be useful to describe the functionality of some piece of posted code in a few sentences ...
this is a version of this podbot function checking paths before saving, to avoid whatever, right ? that stuff that can be found in every forum to be ignored by nocheck ?
here a fast way to check if there is a near waypoint, can also be found in
http://www.lampel.net/johannes/joebo...XPDoc-beta.pdf
PHP Code:
int CWaypointGraph::getNearest(const Vector &VOrigin,bool bVisible, bool bReachable, float fMin, float fMax,long lFlags){
//
// note that this function only searches for the nearest waypoint within a distance of min. 1,5*8192/64 = 192
// and maximum of 255 units.
//
float fDistance, fNearest = 1E30;
int iMinIndex = -1;
vector<int>::iterator iter,end;
int iHash = getHashcode(VOrigin); // get hashcode for that location
int iOX,iOY,iXBase,iYBase;
fNearest = fMax = fMax * fMax;
fMin = fMin * fMin;
for(iOY = -1; iOY <= 1; iOY ++){ // and check the buckets around there
iYBase = iHash + iOY * 64;
if(iYBase < 0 || iYBase > 4095 )
continue;
for(iOX = -1; iOX <= 1; iOX ++){
iXBase = iYBase + iOX;
if(iXBase < 0 || iXBase > 4095 )
continue;
end = m_pLHash[iXBase].end();
for(iter=m_pLHash[iXBase].begin();iter != end; iter ++){
fDistance = (VOrigin - m_pWaypoints[*iter].m_VOrigin).squareLength();
if(fDistance < fNearest && fDistance >= fMin){
if(bVisible){ // if we have to check if it's visible
#ifdef __JOEBOTXPDLL
if(!FVisibleEx(VOrigin,m_pWaypoints[*iter].m_VOrigin)){
continue;
}
#endif
}
if(bReachable){ // so do we gotta check if it's reachable ?!
//todo
if(!g_pMap.getReachable(VOrigin,m_pWaypoints[*iter].m_VOrigin))
continue;
}
if(m_pWaypoints[*iter].m_lFlags & lFlags != lFlags)
continue;
fNearest = fDistance;
iMinIndex = *iter;
}
}
}
}
if(iMinIndex == -1){
return getNearesto(VOrigin,bVisible,bReachable,sqrt(fMin),sqrt(fMax),lFlags);
}
return iMinIndex;
}
void CWaypointGraph::addToHashTable(int iWP){
int iHash = getHashcode(m_pWaypoints[iWP].m_VOrigin);
m_pLHash[iHash].push_back(iWP);
}
bool CWaypointGraph::removeFromHashtable(int iRemove){
// let's first assume that the origin stored at this waypoint is still right
int iHash = getHashcode(m_pWaypoints[iRemove].m_VOrigin);
vector<int>::iterator iter;
for(iter = m_pLHash[iHash].begin(); iter != m_pLHash[iHash].end(); iter ++){// look into the bucket and delete it
if(*iter == iRemove){
m_pLHash[iHash].erase(iter);
return true;
}
}
// not found : so maybe the origin isnt still right ?!
// let's loop thru all and see if we can get it
for(iHash = 0; iHash < 4096; iHash ++){
for(iter = m_pLHash[iHash].begin(); iter != m_pLHash[iHash].end(); iter ++){
if(*iter == iRemove){
m_pLHash[iHash].erase(iter);
return true;
}
}
}
return false;
}