Revert "Revert "improve astar cleanup performance. thanks @Andrettin""
This reverts commit 740701089f
.
This commit is contained in:
parent
9dd63b37fa
commit
9df43cc3d0
1 changed files with 4 additions and 1 deletions
|
@ -263,6 +263,7 @@ void InitAStar(int mapWidth, int mapHeight)
|
|||
memset(AStarMatrix, 0, AStarMatrixSize);
|
||||
|
||||
Threshold = AStarMapWidth * AStarMapHeight / MAX_CLOSE_SET_RATIO;
|
||||
CloseSetSize = Threshold;
|
||||
CloseSet = new int[Threshold];
|
||||
|
||||
OpenSetMaxSize = AStarMapWidth * AStarMapHeight / MAX_OPEN_SET_RATIO;
|
||||
|
@ -307,16 +308,19 @@ static void AStarPrepare()
|
|||
/**
|
||||
** Clean up A*
|
||||
*/
|
||||
static void CostMoveToCacheCleanUp();
|
||||
static void AStarCleanUp()
|
||||
{
|
||||
ProfileBegin("AStarCleanUp");
|
||||
|
||||
if (CloseSetSize >= Threshold) {
|
||||
AStarPrepare();
|
||||
CostMoveToCacheCleanUp();
|
||||
} else {
|
||||
for (int i = 0; i < CloseSetSize; ++i) {
|
||||
AStarMatrix[CloseSet[i]].CostFromStart = 0;
|
||||
AStarMatrix[CloseSet[i]].InGoal = 0;
|
||||
CostMoveToCache[CloseSet[i]] = CacheNotSet;
|
||||
}
|
||||
}
|
||||
ProfileEnd("AStarCleanUp");
|
||||
|
@ -936,7 +940,6 @@ int AStarFindPath(const Vec2i &startPos, const Vec2i &goalPos, int gw, int gh,
|
|||
|
||||
// Initialize
|
||||
AStarCleanUp();
|
||||
CostMoveToCacheCleanUp();
|
||||
|
||||
OpenSetSize = 0;
|
||||
CloseSetSize = 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue