@@ -1327,6 +1327,21 @@ bool CNavArea::IsConnected( const CNavArea *area, NavDirType dir ) const
13271327 return false ;
13281328}
13291329
1330+ int CNavArea::GetConnected ( const CNavArea *area, NavDirType dir ) const
1331+ {
1332+ if ( area != this && dir != NUM_DIRECTIONS )
1333+ {
1334+ // check specific direction
1335+ FOR_EACH_VEC ( m_connect[ dir ], it )
1336+ {
1337+ if (area == m_connect[ dir ][ it ].area )
1338+ return it;
1339+ }
1340+ }
1341+
1342+ return m_connect[0 ].InvalidIndex ();
1343+ }
1344+
13301345// --------------------------------------------------------------------------------------------------------------
13311346/* *
13321347 * Compute change in actual ground height from this area to given area
@@ -2605,25 +2620,37 @@ float CNavArea::ComputeAdjacentConnectionHeightChange( const CNavArea *destinati
26052620{
26062621 VPROF_BUDGET ( " CNavArea::ComputeAdjacentConnectionHeightChange" , " NextBot" );
26072622
2623+ if ( destinationArea == this )
2624+ return 0 .0f ;
2625+
26082626 // find which side it is connected on
26092627 int dir;
2628+ int it;
26102629 for ( dir=0 ; dir<NUM_DIRECTIONS; ++dir )
26112630 {
2612- if ( IsConnected ( destinationArea, (NavDirType)dir ) )
2631+ it = GetConnected ( destinationArea, ( NavDirType )dir );
2632+ if ( it != m_connect[0 ].InvalidIndex () )
26132633 break ;
26142634 }
26152635
26162636 if ( dir == NUM_DIRECTIONS )
26172637 return FLT_MAX;
26182638
2639+ if ( m_connect[dir][it].deltaZ != FLT_MAX )
2640+ return m_connect[dir][it].deltaZ ;
2641+
26192642 Vector myEdge;
26202643 float halfWidth;
26212644 ComputePortal ( destinationArea, (NavDirType)dir, &myEdge, &halfWidth );
26222645
26232646 Vector otherEdge;
26242647 destinationArea->ComputePortal ( this , OppositeDirection ( (NavDirType)dir ), &otherEdge, &halfWidth );
26252648
2626- return otherEdge.z - myEdge.z ;
2649+ // cache it
2650+ const float deltaZ = otherEdge.z - myEdge.z ;
2651+ m_connect[dir][it].deltaZ = deltaZ;
2652+
2653+ return deltaZ;
26272654}
26282655
26292656
0 commit comments