Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions Generals/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ inline Int IABS(Int x) { if (x>=0) return x; return -x;};
//-----------------------------------------------------------------------------------
static Int frameToShowObstacles;

constexpr const UnsignedInt MAX_CELL_COUNT = 500;
constexpr const UnsignedInt MAX_ADJUSTMENT_CELL_COUNT = 400;
constexpr const UnsignedInt MAX_SAFE_PATH_CELL_COUNT = 2000;

constexpr const UnsignedInt PATHFIND_CELLS_PER_FRAME = 5000; // Number of cells we will search pathfinding per frame.
constexpr const UnsignedInt CELL_INFOS_TO_ALLOCATE = 30000;

//-----------------------------------------------------------------------------------
PathNode::PathNode() :
m_nextOpti(0),
Expand Down Expand Up @@ -1077,8 +1084,6 @@ Real Path::computeFlightDistToGoal( const Coord3D *pos, Coord3D& goalPos )
}
//-----------------------------------------------------------------------------------

enum { PATHFIND_CELLS_PER_FRAME=5000}; // Number of cells we will search pathfinding per frame.
enum {CELL_INFOS_TO_ALLOCATE = 30000};
PathfindCellInfo *PathfindCellInfo::s_infoArray = NULL;
PathfindCellInfo *PathfindCellInfo::s_firstFree = NULL;

Expand Down Expand Up @@ -1547,8 +1552,18 @@ PathfindCell *PathfindCell::putOnSortedOpenList( PathfindCell *list )
{
// insertion sort
PathfindCell *c, *lastCell = NULL;
for( c = list; c; c = c->getNextOpen() )
#if RETAIL_COMPATIBLE_PATHFINDING
// TheSuperHackers @bugfix In the retail compatible pathfinding, on rare ocassions, we get stuck in an infinite loop
// External code should pickup on the bad behaviour and cleanup properly, but we need to explicitly break out here
// The fixed pathfinding does not have this issue due to the proper cleanup of pathfindCells and their pathfindCellInfos
UnsignedInt cellCount = 0;
for (c = list; c && cellCount < PATHFIND_CELLS_PER_FRAME; c = c->getNextOpen())
{
cellCount++;
#else
for (c = list; c; c = c->getNextOpen())
{
#endif
if (c->m_info->m_totalCost > m_info->m_totalCost)
break;

Expand Down Expand Up @@ -4715,8 +4730,7 @@ Bool Pathfinder::adjustToLandingDestination(Object *obj, Coord3D *dest)
}
worldToCell( &adjustDest, &cell );

enum {MAX_CELLS_TO_TRY=400};
Int limit = MAX_CELLS_TO_TRY;
Int limit = MAX_ADJUSTMENT_CELL_COUNT;
Int i, j;
i = cell.x;
j = cell.y;
Expand Down Expand Up @@ -4793,8 +4807,7 @@ Bool Pathfinder::adjustDestination(Object *obj, const LocomotorSet& locomotorSet
layer = TheTerrainLogic->getLayerForDestination(groupDest);
}

enum {MAX_CELLS_TO_TRY=400};
Int limit = MAX_CELLS_TO_TRY;
Int limit = MAX_ADJUSTMENT_CELL_COUNT;
Int i, j;
i = cell.x;
j = cell.y;
Expand Down Expand Up @@ -4877,8 +4890,8 @@ Bool Pathfinder::adjustTargetDestination(const Object *obj, const Object *target
if (worldToCell( &adjustDest, &cell )) {
return false; // outside of bounds.
}
enum {MAX_CELLS_TO_TRY=400};
Int limit = MAX_CELLS_TO_TRY;

Int limit = MAX_ADJUSTMENT_CELL_COUNT;
Int i, j;
i = cell.x;
j = cell.y;
Expand Down Expand Up @@ -5001,8 +5014,7 @@ Bool Pathfinder::adjustToPossibleDestination(Object *obj, const LocomotorSet& lo
}
}

enum {MAX_CELLS_TO_TRY=400};
Int limit = MAX_CELLS_TO_TRY;
Int limit = MAX_ADJUSTMENT_CELL_COUNT;
Int i, j;
i = goalCellNdx.x;
j = goalCellNdx.y;
Expand Down Expand Up @@ -7511,7 +7523,6 @@ Bool Pathfinder::pathDestination( Object *obj, const LocomotorSet& locomotorSet
if (!obj) return false;

Int cellCount = 0;
#define MAX_CELL_COUNT 500

Coord3D adjustTo = *groupDest;
Coord3D *to = &adjustTo;
Expand Down Expand Up @@ -7806,7 +7817,6 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
if (!obj) return MAX_COST;

Int cellCount = 0;
#define MAX_CELL_COUNT 500

Coord3D adjustTo = *rawTo;
Coord3D *to = &adjustTo;
Expand Down Expand Up @@ -10328,7 +10338,7 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
// Int startTimeMS = ::GetTickCount();
#endif

const Int MAX_CELLS = 2000; // this is a rather expensive operation, so limit the search.
const Int MAX_CELLS = MAX_SAFE_PATH_CELL_COUNT; // this is a rather expensive operation, so limit the search.

Bool centerInCell;
Int radius;
Expand Down
39 changes: 24 additions & 15 deletions GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ inline Int IABS(Int x) { if (x>=0) return x; return -x;};
static Int frameToShowObstacles;


static UnsignedInt ZONE_UPDATE_FREQUENCY = 300;
constexpr const UnsignedInt ZONE_UPDATE_FREQUENCY = 300;
constexpr const UnsignedInt MAX_CELL_COUNT = 500;
constexpr const UnsignedInt MAX_ADJUSTMENT_CELL_COUNT = 400;
constexpr const UnsignedInt MAX_SAFE_PATH_CELL_COUNT = 2000;

constexpr const UnsignedInt PATHFIND_CELLS_PER_FRAME = 5000; // Number of cells we will search pathfinding per frame.
constexpr const UnsignedInt CELL_INFOS_TO_ALLOCATE = 30000;

//-----------------------------------------------------------------------------------
PathNode::PathNode() :
Expand Down Expand Up @@ -1093,8 +1099,6 @@ Real Path::computeFlightDistToGoal( const Coord3D *pos, Coord3D& goalPos )
}
//-----------------------------------------------------------------------------------

enum { PATHFIND_CELLS_PER_FRAME=5000}; // Number of cells we will search pathfinding per frame.
enum {CELL_INFOS_TO_ALLOCATE = 30000};
PathfindCellInfo *PathfindCellInfo::s_infoArray = NULL;
PathfindCellInfo *PathfindCellInfo::s_firstFree = NULL;

Expand Down Expand Up @@ -1565,8 +1569,18 @@ PathfindCell *PathfindCell::putOnSortedOpenList( PathfindCell *list )
{
// insertion sort
PathfindCell *c, *lastCell = NULL;
for( c = list; c; c = c->getNextOpen() )
#if RETAIL_COMPATIBLE_PATHFINDING
// TheSuperHackers @bugfix In the retail compatible pathfinding, on rare ocassions, we get stuck in an infinite loop
// External code should pickup on the bad behaviour and cleanup properly, but we need to explicitly break out here
// The fixed pathfinding does not have this issue due to the proper cleanup of pathfindCells and their pathfindCellInfos
UnsignedInt cellCount = 0;
for (c = list; c && cellCount < PATHFIND_CELLS_PER_FRAME; c = c->getNextOpen())
{
cellCount++;
#else
for (c = list; c; c = c->getNextOpen())
{
#endif
if (c->m_info->m_totalCost > m_info->m_totalCost)
break;

Expand Down Expand Up @@ -4998,8 +5012,7 @@ Bool Pathfinder::adjustToLandingDestination(Object *obj, Coord3D *dest)
}
worldToCell( &adjustDest, &cell );

enum {MAX_CELLS_TO_TRY=400};
Int limit = MAX_CELLS_TO_TRY;
Int limit = MAX_ADJUSTMENT_CELL_COUNT;
Int i, j;
i = cell.x;
j = cell.y;
Expand Down Expand Up @@ -5076,8 +5089,7 @@ Bool Pathfinder::adjustDestination(Object *obj, const LocomotorSet& locomotorSet
layer = TheTerrainLogic->getLayerForDestination(groupDest);
}

enum {MAX_CELLS_TO_TRY=400};
Int limit = MAX_CELLS_TO_TRY;
Int limit = MAX_ADJUSTMENT_CELL_COUNT;
Int i, j;
i = cell.x;
j = cell.y;
Expand Down Expand Up @@ -5160,8 +5172,8 @@ Bool Pathfinder::adjustTargetDestination(const Object *obj, const Object *target
if (worldToCell( &adjustDest, &cell )) {
return false; // outside of bounds.
}
enum {MAX_CELLS_TO_TRY=400};
Int limit = MAX_CELLS_TO_TRY;

Int limit = MAX_ADJUSTMENT_CELL_COUNT;
Int i, j;
i = cell.x;
j = cell.y;
Expand Down Expand Up @@ -5284,8 +5296,7 @@ Bool Pathfinder::adjustToPossibleDestination(Object *obj, const LocomotorSet& lo
}
}

enum {MAX_CELLS_TO_TRY=400};
Int limit = MAX_CELLS_TO_TRY;
Int limit = MAX_ADJUSTMENT_CELL_COUNT;
Int i, j;
i = goalCellNdx.x;
j = goalCellNdx.y;
Expand Down Expand Up @@ -7910,7 +7921,6 @@ Bool Pathfinder::pathDestination( Object *obj, const LocomotorSet& locomotorSet
if (!obj) return false;

Int cellCount = 0;
#define MAX_CELL_COUNT 500

Coord3D adjustTo = *groupDest;
Coord3D *to = &adjustTo;
Expand Down Expand Up @@ -8205,7 +8215,6 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
if (!obj) return MAX_COST;

Int cellCount = 0;
#define MAX_CELL_COUNT 500

Coord3D adjustTo = *rawTo;
Coord3D *to = &adjustTo;
Expand Down Expand Up @@ -10805,7 +10814,7 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
// Int startTimeMS = ::GetTickCount();
#endif

const Int MAX_CELLS = 2000; // this is a rather expensive operation, so limit the search.
const Int MAX_CELLS = MAX_SAFE_PATH_CELL_COUNT; // this is a rather expensive operation, so limit the search.

Bool centerInCell;
Int radius;
Expand Down
Loading