Skip to content

Commit 0b94965

Browse files
committed
cache deltaZ for nav area height change
1 parent 809956e commit 0b94965

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

src/game/server/nav_area.cpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/game/server/nav_area.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct NavConnect
7070
{
7171
id = 0;
7272
length = -1;
73+
deltaZ = FLT_MAX;
7374
}
7475

7576
union
@@ -79,6 +80,7 @@ struct NavConnect
7980
};
8081

8182
mutable float length;
83+
mutable float deltaZ;
8284

8385
bool operator==( const NavConnect &other ) const
8486
{
@@ -368,6 +370,7 @@ class CNavArea : protected CNavAreaCriticalData
368370

369371
const NavConnectVector *GetAdjacentAreas( NavDirType dir ) const { return &m_connect[dir]; }
370372
bool IsConnected( const CNavArea *area, NavDirType dir ) const; // return true if given area is connected in given direction
373+
int GetConnected( const CNavArea* area, NavDirType dir ) const; // return it if given area is connected in given direction
371374
bool IsConnected( const CNavLadder *ladder, CNavLadder::LadderDirectionType dir ) const; // return true if given ladder is connected in given direction
372375
float ComputeGroundHeightChange( const CNavArea *area ); // compute change in actual ground height from this area to given area
373376

0 commit comments

Comments
 (0)