Skip to content

Commit 91a8dca

Browse files
authored
fix(partition): Fix circle fill algorithm in PartitionManager (#1426)
This reduces its cost by around 10%
1 parent 5f3c029 commit 91a8dca

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1838,6 +1838,8 @@ void PartitionData::hLineCircle(Int x1, Int x2, Int y)
18381838
}
18391839

18401840
// -----------------------------------------------------------------------------
1841+
// Marks all partition cells that intersect a circle of the given center and radius
1842+
// as covered by this object using a variation of the midpoint circle algorithm.
18411843
void PartitionData::doCircleFill(
18421844
Real centerX,
18431845
Real centerY,
@@ -1855,7 +1857,15 @@ void PartitionData::doCircleFill(
18551857

18561858
Int y = cellRadius - 1;
18571859
Int dec = 3 - 2*cellRadius;
1858-
for (Int x = 0; x < cellRadius; x++)
1860+
1861+
#if RETAIL_COMPATIBLE_CRC
1862+
// Cell coverage diverges at radii >= 240 between algorithms.
1863+
Int end = cellRadius - 1;
1864+
Int& endRef = (cellRadius < 240) ? y : end;
1865+
for (Int x = 0; x <= endRef; ++x)
1866+
#else
1867+
for (Int x = 0; x <= y; ++x)
1868+
#endif
18591869
{
18601870
hLineCircle(cellCenterX - x, cellCenterX + x, cellCenterY + y);
18611871
hLineCircle(cellCenterX - x, cellCenterX + x, cellCenterY - y);

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,8 @@ void PartitionData::hLineCircle(Int x1, Int x2, Int y)
18421842
}
18431843

18441844
// -----------------------------------------------------------------------------
1845+
// Marks all partition cells that intersect a circle of the given center and radius
1846+
// as covered by this object using a variation of the midpoint circle algorithm.
18451847
void PartitionData::doCircleFill(
18461848
Real centerX,
18471849
Real centerY,
@@ -1859,7 +1861,15 @@ void PartitionData::doCircleFill(
18591861

18601862
Int y = cellRadius - 1;
18611863
Int dec = 3 - 2*cellRadius;
1862-
for (Int x = 0; x < cellRadius; x++)
1864+
1865+
#if RETAIL_COMPATIBLE_CRC
1866+
// Cell coverage diverges at radii >= 240 between algorithms.
1867+
Int end = cellRadius - 1;
1868+
Int& endRef = (cellRadius < 240) ? y : end;
1869+
for (Int x = 0; x <= endRef; ++x)
1870+
#else
1871+
for (Int x = 0; x <= y; ++x)
1872+
#endif
18631873
{
18641874
hLineCircle(cellCenterX - x, cellCenterX + x, cellCenterY + y);
18651875
hLineCircle(cellCenterX - x, cellCenterX + x, cellCenterY - y);

0 commit comments

Comments
 (0)