1
0
forked from 0ad/0ad

improve performance of hierarchical pathfinder, refs #3588

This was SVN commit r17413.
This commit is contained in:
mimo 2015-12-09 19:56:30 +00:00
parent 73a26a22ca
commit 2451872731
2 changed files with 28 additions and 17 deletions

View File

@ -403,26 +403,18 @@ void HierarchicalPathfinder::Update(Grid<NavcellData>* grid, const Grid<u8>& dir
{ {
PROFILE3("Hierarchical Update"); PROFILE3("Hierarchical Update");
std::vector<std::pair<int, int> > processedChunks; for (int cj = 0; cj < m_ChunksH; ++cj)
for (int j = 0; j < dirtinessGrid.m_H; ++j)
{ {
for (int i = 0; i < dirtinessGrid.m_W; ++i) for (int ci = 0; ci < m_ChunksW; ++ci)
{ {
if (!dirtinessGrid.get(i, j)) if (!IsChunkDirty(ci, cj, dirtinessGrid))
continue; continue;
for (const std::pair<std::string, pass_class_t>& passClassMask : m_PassClassMasks)
std::pair<int, int> chunkID(i / CHUNK_SIZE, j / CHUNK_SIZE); {
pass_class_t passClass = passClassMask.second;
if (std::find(processedChunks.begin(), processedChunks.end(), chunkID) == processedChunks.end()) Chunk& a = m_Chunks[passClass].at(ci + cj*m_ChunksW);
{ a.InitRegions(ci, cj, grid, passClass);
processedChunks.push_back(chunkID); }
for (const std::pair<std::string, pass_class_t>& passClassMask : m_PassClassMasks)
{
pass_class_t passClass = passClassMask.second;
Chunk& a = m_Chunks[passClass].at(chunkID.second*m_ChunksW + chunkID.first);
a.InitRegions(chunkID.first, chunkID.second, grid, passClass);
}
}
} }
} }
@ -450,6 +442,23 @@ void HierarchicalPathfinder::Update(Grid<NavcellData>* grid, const Grid<u8>& dir
} }
} }
bool HierarchicalPathfinder::IsChunkDirty(int ci, int cj, const Grid<u8>& dirtinessGrid)
{
int i0 = ci * CHUNK_SIZE;
int j0 = cj * CHUNK_SIZE;
int i1 = std::min(i0 + CHUNK_SIZE, (int)dirtinessGrid.m_W);
int j1 = std::min(j0 + CHUNK_SIZE, (int)dirtinessGrid.m_H);
for (int j = j0; j < j1; ++j)
{
for (int i = i0; i < i1; ++i)
{
if (!dirtinessGrid.get(i, j))
continue;
return true;
}
}
return false;
}
/** /**
* Find edges between regions in this chunk and the adjacent below/left chunks. * Find edges between regions in this chunk and the adjacent below/left chunks.
*/ */

View File

@ -86,6 +86,8 @@ public:
void Update(Grid<NavcellData>* grid, const Grid<u8>& dirtinessGrid); void Update(Grid<NavcellData>* grid, const Grid<u8>& dirtinessGrid);
bool IsChunkDirty(int ci, int cj, const Grid<u8>& dirtinessGrid);
RegionID Get(u16 i, u16 j, pass_class_t passClass); RegionID Get(u16 i, u16 j, pass_class_t passClass);
/** /**