View Single Post
Re: a much faster version of waypoint checking code.
Old
  (#2)
@$3.1415rin
Council Member, Author of JoeBOT
 
@$3.1415rin's Avatar
 
Status: Offline
Posts: 1,381
Join Date: Nov 2003
Location: Germany
Default Re: a much faster version of waypoint checking code. - 05-12-2004

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 bVisiblebool bReachablefloat fMinfloat 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 fDistancefNearest 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 = -1iOY <= 1iOY ++){ // and check the buckets around there
iYBase iHash iOY 64;
if(
iYBase || iYBase 4095 )
continue;
for(
iOX = -1iOX <= 1iOX ++){
iXBase iYBase iOX;
 
if(
iXBase || iXBase 4095 )
    continue;
 
end m_pLHash[iXBase].end();
for(
iter=m_pLHash[iXBase].begin();iter != enditer ++){
    
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 0iHash 4096iHash ++){
for(
iter m_pLHash[iHash].begin(); iter != m_pLHash[iHash].end(); iter ++){
if(*
iter == iRemove){
    
m_pLHash[iHash].erase(iter);
    return 
true;
}
}
}
return 
false;




Last edited by @$3.1415rin; 05-12-2004 at 10:22..
  
Reply With Quote