.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Cyborg Factory > POD-Bot mm > Releases, Installers, Docs & Coding
Releases, Installers, Docs & Coding Where the official development happens

Reply
 
Thread Tools
a much faster version of waypoint checking code.
Old
  (#1)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default a much faster version of waypoint checking code. - 05-12-2004

PHP Code:
bool WaypointNodesValid()
{
   
int iTPoints 0;
   
int iCTPoints 0;
   
int iGoalPoints 0;
   
int iRescuePoints 0;
   
int iConnections;
   
int ij;

   for (
0g_iNumWaypointsi++)
   {
      
iConnections 0;

      for (
int n 0MAX_PATH_INDEXn++)
      {
         if (
paths[i]->index[n] != -1)
         {
            if (
paths[i]->index[n] > g_iNumWaypoints)
            {
               
SERVER_PRINT(UTIL_VarArgs("Node %d connected with invalid Waypoint Nr. %d!\n"ipaths[i]->index[n]));
               return 
FALSE;
            }
            
iConnections++;
            break;
         }
      }

      if (
iConnections == 0)
      {
         if (!
WaypointIsConnected(i))
         {
            
SERVER_PRINT(UTIL_VarArgs("Node %d isn't connected with any other Waypoint!\n"i));
            return 
FALSE;
         }
      }

      if (
paths[i]->iPathNumber != i)
      {
         
SERVER_PRINT(UTIL_VarArgs("Node %d pathnumber differs from index!\n"i));
         return 
FALSE;
      }

      if (
paths[i]->flags W_FL_CAMP)
      {
         if (
paths[i]->fcampendx == 0.0 && paths[i]->fcampendy == 0.0)
         {
            
SERVER_PRINT(UTIL_VarArgs("Node %d Camp-Endposition not set!\n"i));
            return 
FALSE;
         }
      }
      else if (
paths[i]->flags W_FL_TERRORIST)
         
iTPoints++;
      else if (
paths[i]->flags W_FL_COUNTER)
         
iCTPoints++;
      else if (
paths[i]->flags W_FL_GOAL)
         
iGoalPoints++;
      else if (
paths[i]->flags W_FL_RESCUE)
         
iRescuePoints++;

      
int x 0;

      while (
MAX_PATH_INDEX)
      {
         if (
paths[i]->index[x] != -1)
         {
            if (
paths[i]->index[x] >= g_iNumWaypoints || paths[i]->index[x] < -1)
            {
               
SERVER_PRINT(UTIL_VarArgs("Node %d - Pathindex %d out of Range!\n"ix));
               
g_engfuncs.pfnSetOrigin(pHostEdictpaths[i]->origin);
               
g_bWaypointOn TRUE;
               
bEditNoclip TRUE;
               return 
FALSE;
            }
            else if (
paths[i]->index[x] == i)
            {
               
SERVER_PRINT(UTIL_VarArgs("Node %d - Pathindex %d points to itself!\n"ix));
               
g_engfuncs.pfnSetOrigin(pHostEdictpaths[i]->origin);
               
g_bWaypointOn TRUE;
               
bEditNoclip TRUE;
               return 
FALSE;
            }
         }
         
x++;
      }
   }
   if (
g_iMapType MAP_CS)
   {
      if (
iRescuePoints == 0)
      {
         
SERVER_PRINT("You didn't set a Rescue Point!\n");
         return 
FALSE;
      }
   }
   if (
iTPoints == 0)
   {
      
SERVER_PRINT("You didn't set any Terrorist Important Point!\n");
      return 
FALSE;
   }
   else if (
iCTPoints == 0)
   {
      
SERVER_PRINT("You didn't set any CT Important Point!\n");
      return 
FALSE;
   }
   else if (
iGoalPoints == 0)
   {
      
SERVER_PRINT("You didn't set any Goal Point!\n");
      return 
FALSE;
   }

   
bool rgbVisited[MAX_WAYPOINTS];
   
PATHNODE *stack NULL;

   
// first check incoming connectivity
   // initialize the "visited" table
   
for (0g_iNumWaypointsi++)
      
rgbVisited[i] = FALSE;

   
// check from Waypoint nr. 0
   
stack = (PATHNODE *)malloc(sizeof(PATHNODE));
   
stack->NextNode NULL;
   
stack->iIndex 0;

   while (
stack)
   {
      
// pop a node from the stack
      
PATHNODE *current stack;
      
stack stack->NextNode;

      
rgbVisited[current->iIndex] = TRUE;

      for (
0MAX_PATH_INDEXj++)
      {
         
int iIndex paths[current->iIndex]->index[j];
         if (
rgbVisited[iIndex])
            continue; 
// skip this waypoint as it's already visited
         
if (iIndex >= && iIndex g_iNumWaypoints)
         {
            
PATHNODE *newnode = (PATHNODE *)malloc(sizeof(PATHNODE));
            
newnode->NextNode stack;
            
newnode->iIndex iIndex;
            
stack newnode;
         }
      }

      
free(current);
   }

   for (
0g_iNumWaypointsi++)
   {
      if (!
rgbVisited[i])
      {
         
SERVER_PRINT(UTIL_VarArgs("Path broken from Waypoint Nr. 0 to Waypoint Nr. %d!\n"i));
         
g_engfuncs.pfnSetOrigin(pHostEdictpaths[i]->origin);
         
g_bWaypointOn TRUE;
         
bEditNoclip TRUE;
         return 
FALSE;
      }
   }

   
// then check outgoing connectivity
   
std::vector<intin_paths[MAX_WAYPOINTS]; // store incoming paths for speedup

   
for (0g_iNumWaypointsi++)
      for (
0MAX_PATH_INDEXj++)
         if (
paths[i]->index[j] >= && paths[i]->index[j] < g_iNumWaypoints)
            
in_paths[paths[i]->index[j]].push_back(i);

   
// initialize the "visited" table
   
for (0g_iNumWaypointsi++)
      
rgbVisited[i] = FALSE;

   
// check from Waypoint nr. 0
   
stack = (PATHNODE *)malloc(sizeof(PATHNODE));
   
stack->NextNode NULL;
   
stack->iIndex 0;

   while (
stack)
   {
      
// pop a node from the stack
      
PATHNODE *current stack;
      
stack stack->NextNode;

      
rgbVisited[current->iIndex] = TRUE;

      for (
0< (int)in_paths[current->iIndex].size(); j++)
      {
         if (
rgbVisited[in_paths[current->iIndex][j]])
            continue; 
// skip this waypoint as it's already visited
         
PATHNODE *newnode = (PATHNODE *)malloc(sizeof(PATHNODE));
         
newnode->NextNode stack;
         
newnode->iIndex in_paths[current->iIndex][j];
         
stack newnode;
      }
      
free(current);
   }

   for (
0g_iNumWaypointsi++)
   {
      if (!
rgbVisited[i])
      {
         
SERVER_PRINT(UTIL_VarArgs("Path broken from Waypoint Nr. %d to Waypoint Nr. 0!\n"i));
         
g_engfuncs.pfnSetOrigin(pHostEdictpaths[i]->origin);
         
g_bWaypointOn TRUE;
         
bEditNoclip TRUE;
         return 
FALSE;
      }
   }

   return 
TRUE;

  
Reply With Quote
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
Re: a much faster version of waypoint checking code.
Old
  (#3)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default Re: a much faster version of waypoint checking code. - 08-12-2004

here's a bit of explanations on the code above...
the original POD-Bot uses Floyd-Warshall algorithm to find all paths between all nodes... but this is just not necessary:
1. we needn't find the shortest path, finding a random path is enough
2. have you noticed that POD-Bot only reports "path broken from 0 to n" or "from n to 0" ? so actually we only need to verify connections between waypoint nr. 0 and the other waypoints
I just do a traverse in the waypoint graph with Depth-first Search.
because I'm lazy, I used the std::vector. you can try using a linked list instead if you don't want to use standard library.
  
Reply With Quote
Re: a much faster version of waypoint checking code.
Old
  (#4)
@$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. - 08-12-2004

just a note : linked list and std:vector is a bit difference, since vector allows you very fast random access, while a linked list ( without additional tables ) does not


  
Reply With Quote
Re: a much faster version of waypoint checking code.
Old
  (#5)
sPlOrYgOn
<-- He did it.
 
sPlOrYgOn's Avatar
 
Status: Offline
Posts: 1,558
Join Date: Jan 2004
Location: Los Angeles, California, USA, North America, Earth, Solar System, Milky Way.
Default Re: a much faster version of waypoint checking code. - 09-12-2004

thanks Whistler
It definately feels faster on my slow comp
  
Reply With Quote
Re: a much faster version of waypoint checking code.
Old
  (#6)
Huntkillaz
Member
 
Huntkillaz's Avatar
 
Status: Offline
Posts: 594
Join Date: Mar 2004
Location: Middle Earth (New Zealand)
Default Re: a much faster version of waypoint checking code. - 09-12-2004

ooo can i test it plzzzzzzzzzzzzzzzzzzz...(just emai it to huntakillaz at gmail)

my super slow comp should be good for this


●_•
  
Reply With Quote
Re: a much faster version of waypoint checking code.
Old
  (#7)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default Re: a much faster version of waypoint checking code. - 11-12-2004

Quote:
Originally Posted by Huntkillaz
ooo can i test it plzzzzzzzzzzzzzzzzzzz...(just emai it to huntakillaz at gmail)

my super slow comp should be good for this
download the YaPB from http://yapb.bots-united.com and try "yapb wp save".
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com