diff --git a/source/simulation2/components/CCmpTerritoryManager.cpp b/source/simulation2/components/CCmpTerritoryManager.cpp index 577c4d5dfd..ca0ced11d7 100644 --- a/source/simulation2/components/CCmpTerritoryManager.cpp +++ b/source/simulation2/components/CCmpTerritoryManager.cpp @@ -451,9 +451,7 @@ void CCmpTerritoryManager::CalculateTerritories() FloodFill(entityGrid, influenceGrid, openTiles, falloff); // TODO: we should do a sparse grid and only add the non-zero regions, for performance - for (u16 j = 0; j < entityGrid.m_H; ++j) - for (u16 i = 0; i < entityGrid.m_W; ++i) - playerGrid.set(i, j, playerGrid.get(i, j) + entityGrid.get(i, j)); + playerGrid.add(entityGrid); } playerGrids.push_back(std::make_pair(it->first, playerGrid)); diff --git a/source/simulation2/helpers/Grid.h b/source/simulation2/helpers/Grid.h index 1a47b028f3..ba5bf77ec1 100644 --- a/source/simulation2/helpers/Grid.h +++ b/source/simulation2/helpers/Grid.h @@ -82,6 +82,17 @@ public: memset(m_Data, 0, m_W*m_H*sizeof(T)); } + // Add two grids of the same size + void add(const Grid& g) + { +#if GRID_BOUNDS_DEBUG + ENSURE(g.m_W == m_W && g.m_H == m_H); +#endif + for (int j=0; j < m_H; ++j) + for (int i=0; i < m_W; ++i) + m_Data[j*m_W + i] += g.m_Data[j*m_W + i]; + } + void set(int i, int j, const T& value) { #if GRID_BOUNDS_DEBUG