View Single Post
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