@@ -106,7 +106,13 @@ inline Int IABS(Int x) { if (x>=0) return x; return -x;};
106106static Int frameToShowObstacles;
107107
108108
109- static UnsignedInt ZONE_UPDATE_FREQUENCY = 300 ;
109+ constexpr const UnsignedInt ZONE_UPDATE_FREQUENCY = 300 ;
110+ constexpr const UnsignedInt MAX_CELL_COUNT = 500 ;
111+ constexpr const UnsignedInt MAX_ADJUSTMENT_CELL_COUNT = 400 ;
112+ constexpr const UnsignedInt MAX_SAFE_PATH_CELL_COUNT = 2000 ;
113+
114+ constexpr const UnsignedInt PATHFIND_CELLS_PER_FRAME = 5000 ; // Number of cells we will search pathfinding per frame.
115+ constexpr const UnsignedInt CELL_INFOS_TO_ALLOCATE = 30000 ;
110116
111117// -----------------------------------------------------------------------------------
112118PathNode::PathNode () :
@@ -1093,8 +1099,6 @@ Real Path::computeFlightDistToGoal( const Coord3D *pos, Coord3D& goalPos )
10931099}
10941100// -----------------------------------------------------------------------------------
10951101
1096- enum { PATHFIND_CELLS_PER_FRAME=5000 }; // Number of cells we will search pathfinding per frame.
1097- enum {CELL_INFOS_TO_ALLOCATE = 30000 };
10981102PathfindCellInfo *PathfindCellInfo::s_infoArray = NULL ;
10991103PathfindCellInfo *PathfindCellInfo::s_firstFree = NULL ;
11001104
@@ -1565,8 +1569,18 @@ PathfindCell *PathfindCell::putOnSortedOpenList( PathfindCell *list )
15651569 {
15661570 // insertion sort
15671571 PathfindCell *c, *lastCell = NULL ;
1568- for ( c = list; c; c = c->getNextOpen () )
1572+ #if RETAIL_COMPATIBLE_PATHFINDING
1573+ // TheSuperHackers @bugfix In the retail compatible pathfinding, on rare ocassions, we get stuck in an infinite loop
1574+ // External code should pickup on the bad behaviour and cleanup properly, but we need to explicitly break out here
1575+ // The fixed pathfinding does not have this issue due to the proper cleanup of pathfindCells and their pathfindCellInfos
1576+ UnsignedInt cellCount = 0 ;
1577+ for (c = list; c && cellCount < PATHFIND_CELLS_PER_FRAME; c = c->getNextOpen ())
15691578 {
1579+ cellCount++;
1580+ #else
1581+ for (c = list; c; c = c->getNextOpen ())
1582+ {
1583+ #endif
15701584 if (c->m_info ->m_totalCost > m_info->m_totalCost )
15711585 break ;
15721586
@@ -4998,8 +5012,7 @@ Bool Pathfinder::adjustToLandingDestination(Object *obj, Coord3D *dest)
49985012 }
49995013 worldToCell ( &adjustDest, &cell );
50005014
5001- enum {MAX_CELLS_TO_TRY=400 };
5002- Int limit = MAX_CELLS_TO_TRY;
5015+ Int limit = MAX_ADJUSTMENT_CELL_COUNT;
50035016 Int i, j;
50045017 i = cell.x ;
50055018 j = cell.y ;
@@ -5076,8 +5089,7 @@ Bool Pathfinder::adjustDestination(Object *obj, const LocomotorSet& locomotorSet
50765089 layer = TheTerrainLogic->getLayerForDestination (groupDest);
50775090 }
50785091
5079- enum {MAX_CELLS_TO_TRY=400 };
5080- Int limit = MAX_CELLS_TO_TRY;
5092+ Int limit = MAX_ADJUSTMENT_CELL_COUNT;
50815093 Int i, j;
50825094 i = cell.x ;
50835095 j = cell.y ;
@@ -5160,8 +5172,8 @@ Bool Pathfinder::adjustTargetDestination(const Object *obj, const Object *target
51605172 if (worldToCell ( &adjustDest, &cell )) {
51615173 return false ; // outside of bounds.
51625174 }
5163- enum {MAX_CELLS_TO_TRY= 400 };
5164- Int limit = MAX_CELLS_TO_TRY ;
5175+
5176+ Int limit = MAX_ADJUSTMENT_CELL_COUNT ;
51655177 Int i, j;
51665178 i = cell.x ;
51675179 j = cell.y ;
@@ -5284,8 +5296,7 @@ Bool Pathfinder::adjustToPossibleDestination(Object *obj, const LocomotorSet& lo
52845296 }
52855297 }
52865298
5287- enum {MAX_CELLS_TO_TRY=400 };
5288- Int limit = MAX_CELLS_TO_TRY;
5299+ Int limit = MAX_ADJUSTMENT_CELL_COUNT;
52895300 Int i, j;
52905301 i = goalCellNdx.x ;
52915302 j = goalCellNdx.y ;
@@ -7910,7 +7921,6 @@ Bool Pathfinder::pathDestination( Object *obj, const LocomotorSet& locomotorSet
79107921 if (!obj) return false ;
79117922
79127923 Int cellCount = 0 ;
7913- #define MAX_CELL_COUNT 500
79147924
79157925 Coord3D adjustTo = *groupDest;
79167926 Coord3D *to = &adjustTo;
@@ -8205,7 +8215,6 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
82058215 if (!obj) return MAX_COST;
82068216
82078217 Int cellCount = 0 ;
8208- #define MAX_CELL_COUNT 500
82098218
82108219 Coord3D adjustTo = *rawTo;
82118220 Coord3D *to = &adjustTo;
@@ -10805,7 +10814,7 @@ Path *Pathfinder::findSafePath( const Object *obj, const LocomotorSet& locomotor
1080510814// Int startTimeMS = ::GetTickCount();
1080610815#endif
1080710816
10808- const Int MAX_CELLS = 2000 ; // this is a rather expensive operation, so limit the search.
10817+ const Int MAX_CELLS = MAX_SAFE_PATH_CELL_COUNT ; // this is a rather expensive operation, so limit the search.
1080910818
1081010819 Bool centerInCell;
1081110820 Int radius;
0 commit comments