diff --git a/source/simulation2/helpers/HierarchicalPathfinder.cpp b/source/simulation2/helpers/HierarchicalPathfinder.cpp index aff9fc2254..7868a50f25 100644 --- a/source/simulation2/helpers/HierarchicalPathfinder.cpp +++ b/source/simulation2/helpers/HierarchicalPathfinder.cpp @@ -403,26 +403,18 @@ void HierarchicalPathfinder::Update(Grid* grid, const Grid& dir { PROFILE3("Hierarchical Update"); - std::vector > processedChunks; - for (int j = 0; j < dirtinessGrid.m_H; ++j) + for (int cj = 0; cj < m_ChunksH; ++cj) { - 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; - - std::pair chunkID(i / CHUNK_SIZE, j / CHUNK_SIZE); - - if (std::find(processedChunks.begin(), processedChunks.end(), chunkID) == processedChunks.end()) - { - processedChunks.push_back(chunkID); - for (const std::pair& 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); - } - } + for (const std::pair& passClassMask : m_PassClassMasks) + { + pass_class_t passClass = passClassMask.second; + Chunk& a = m_Chunks[passClass].at(ci + cj*m_ChunksW); + a.InitRegions(ci, cj, grid, passClass); + } } } @@ -450,6 +442,23 @@ void HierarchicalPathfinder::Update(Grid* grid, const Grid& dir } } +bool HierarchicalPathfinder::IsChunkDirty(int ci, int cj, const Grid& 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. */ diff --git a/source/simulation2/helpers/HierarchicalPathfinder.h b/source/simulation2/helpers/HierarchicalPathfinder.h index d928838ea6..a0015ff2b4 100644 --- a/source/simulation2/helpers/HierarchicalPathfinder.h +++ b/source/simulation2/helpers/HierarchicalPathfinder.h @@ -86,6 +86,8 @@ public: void Update(Grid* grid, const Grid& dirtinessGrid); + bool IsChunkDirty(int ci, int cj, const Grid& dirtinessGrid); + RegionID Get(u16 i, u16 j, pass_class_t passClass); /**