# Began work on new pathfinder
Created CTerrain::getSlope(x,y), and added a new order type to support high-level pathing. This was SVN commit r3735.
This commit is contained in:
parent
604225f971
commit
baf357d2ea
@ -182,6 +182,41 @@ float CTerrain::getVertexGroundLevel(int x, int z) const
|
||||
return HEIGHT_SCALE * m_Heightmap[z*m_MapSize + x];
|
||||
}
|
||||
|
||||
float CTerrain::getSlope(float x, float y) const
|
||||
{
|
||||
x /= (float)CELL_SIZE;
|
||||
y /= (float)CELL_SIZE;
|
||||
|
||||
int xi = (int)floor(x);
|
||||
int yi = (int)floor(y);
|
||||
|
||||
if (xi < 0)
|
||||
{
|
||||
xi = 0;
|
||||
}
|
||||
else if (xi >= (int)m_MapSize-1)
|
||||
{
|
||||
xi = m_MapSize - 2;
|
||||
}
|
||||
|
||||
if (yi < 0)
|
||||
{
|
||||
yi = 0;
|
||||
}
|
||||
else if (yi >= (int)m_MapSize-1)
|
||||
{
|
||||
yi = m_MapSize - 2;
|
||||
}
|
||||
|
||||
float h00 = m_Heightmap[yi*m_MapSize + xi];
|
||||
float h01 = m_Heightmap[yi*m_MapSize + xi + m_MapSize];
|
||||
float h10 = m_Heightmap[yi*m_MapSize + xi + 1];
|
||||
float h11 = m_Heightmap[yi*m_MapSize + xi + m_MapSize + 1];
|
||||
|
||||
return MAX(MAX(h00, h01), MAX(h10, h11)) -
|
||||
MIN(MIN(h00, h01), MIN(h10, h11));
|
||||
}
|
||||
|
||||
float CTerrain::getExactGroundLevel(float x, float y) const
|
||||
{
|
||||
x /= (float)CELL_SIZE;
|
||||
|
@ -42,6 +42,8 @@ public:
|
||||
float getExactGroundLevel( float x, float y ) const ;
|
||||
inline float getExactGroundLevel( const CVector2D& v ) const { return( getExactGroundLevel( v.x, v.y ) ); }
|
||||
|
||||
float getSlope(float x, float y) const ;
|
||||
|
||||
// resize this terrain such that each side has given number of patches
|
||||
void Resize(u32 size);
|
||||
|
||||
|
@ -471,6 +471,11 @@ void CEntity::update( size_t timestep )
|
||||
break;
|
||||
updateCollisionPatch();
|
||||
return;
|
||||
case CEntityOrder::ORDER_GOTO_WAYPOINT:
|
||||
if ( processGotoWaypoint( current, timestep ) )
|
||||
break;
|
||||
updateCollisionPatch();
|
||||
return;
|
||||
case CEntityOrder::ORDER_GOTO:
|
||||
case CEntityOrder::ORDER_RUN:
|
||||
if( processGoto( current, timestep ) )
|
||||
|
@ -225,6 +225,7 @@ private:
|
||||
|
||||
bool processGotoNoPathing( CEntityOrder* current, size_t timestep_milli );
|
||||
bool processGoto( CEntityOrder* current, size_t timestep_milli );
|
||||
bool processGotoWaypoint( CEntityOrder* current, size_t timestep_milli );
|
||||
|
||||
bool processPatrol( CEntityOrder* current, size_t timestep_milli );
|
||||
|
||||
|
@ -85,6 +85,7 @@ public:
|
||||
ORDER_GOTO_NOPATHING,
|
||||
ORDER_GOTO_SMOOTHED,
|
||||
ORDER_GOTO_COLLISION,
|
||||
ORDER_GOTO_WAYPOINT,
|
||||
ORDER_GOTO,
|
||||
ORDER_RUN,
|
||||
ORDER_PATROL,
|
||||
|
@ -592,6 +592,26 @@ bool CEntity::processGoto( CEntityOrder* current, size_t UNUSED(timestep_millis)
|
||||
return( true );
|
||||
}
|
||||
|
||||
bool CEntity::processGotoWaypoint( CEntityOrder* current, size_t UNUSED(timestep_milli) )
|
||||
{
|
||||
CVector2D pos( m_position.X, m_position.Z );
|
||||
CVector2D path_to = current->m_data[0].location;
|
||||
m_orderQueue.pop_front();
|
||||
float Distance = ( path_to - pos ).length();
|
||||
|
||||
// Let's just check we're going somewhere...
|
||||
if( Distance < 0.1f )
|
||||
{
|
||||
m_isRunning = false;
|
||||
m_shouldRun = false;
|
||||
return( false );
|
||||
}
|
||||
|
||||
g_Pathfinder.requestLowLevelPath( me, path_to );
|
||||
|
||||
return( true );
|
||||
}
|
||||
|
||||
bool CEntity::processPatrol( CEntityOrder* current, size_t UNUSED(timestep_millis) )
|
||||
{
|
||||
// float timestep=timestep_millis/1000.0f;
|
||||
|
@ -13,6 +13,20 @@ CPathfindEngine::CPathfindEngine()
|
||||
|
||||
void CPathfindEngine::requestPath( HEntity entity, const CVector2D& destination )
|
||||
{
|
||||
// pathSparse( entity, destination );
|
||||
/* TODO: Add code to generate high level path
|
||||
For now, just the one high level waypoint to the final
|
||||
destination is added
|
||||
*/
|
||||
CEntityOrder waypoint;
|
||||
waypoint.m_type = CEntityOrder::ORDER_GOTO_WAYPOINT;
|
||||
waypoint.m_data[0].location = destination;
|
||||
entity->m_orderQueue.push_front( waypoint );
|
||||
}
|
||||
|
||||
void CPathfindEngine::requestLowLevelPath( HEntity entity, const CVector2D& destination )
|
||||
{
|
||||
/* Temporary - will be replaced by low-level A* */
|
||||
pathSparse( entity, destination );
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ class CPathfindEngine : public Singleton<CPathfindEngine>
|
||||
public:
|
||||
CPathfindEngine();
|
||||
void requestPath( HEntity entity, const CVector2D& destination );
|
||||
void requestLowLevelPath( HEntity entity, const CVector2D& destination );
|
||||
void requestContactPath( HEntity entity, CEntityOrder* current );
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user