Skip to content

Commit 5a61854

Browse files
committed
Also optimised DislodgePixelCircle to skip half the pixels outside the radius
1 parent ac91469 commit 5a61854

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Source/Managers/SceneMan.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -934,10 +934,17 @@ MovableObject* SceneMan::DislodgePixelBool(int posX, int posY, bool deletePixel)
934934

935935
std::vector<MovableObject*>* SceneMan::DislodgePixelCircle(const Vector& centre, float radius, bool deletePixels) {
936936
std::vector<MovableObject*>* pixelList = new std::vector<MovableObject*>();
937-
for (int x = 0; x <= static_cast<int>(radius) * 2; x++) {
938-
for (int y = 0; y <= static_cast<int>(radius) * 2; y++) {
937+
int limit = static_cast<int>(radius) * 2;
938+
for (int x = 0; x <= limit; x++) {
939+
for (int y = 0; y <= limit; y++) {
939940
Vector checkPos = Vector(static_cast<float>(x) - radius, static_cast<float>(y) - radius) + centre;
940-
if (!ShortestDistance(centre, checkPos, true).MagnitudeIsGreaterThan(radius)) {
941+
Vector distance = ShortestDistance(centre, checkPos, true);
942+
943+
if (distance.MagnitudeIsGreaterThan(radius) && y > limit / 2) {
944+
break;
945+
}
946+
947+
if (!distance.MagnitudeIsGreaterThan(radius)) {
941948
MovableObject* px = DislodgePixelBool(checkPos.m_X, checkPos.m_Y, deletePixels);
942949
if (px) {
943950
pixelList->push_back(px);

0 commit comments

Comments
 (0)