Skip to content

Commit

Permalink
WangFiller: Avoid processing points for correction multiple times
Browse files Browse the repository at this point in the history
I opted for ignoring already processed points rather than checking also whether
a point is already added to 'corrections', because the latter could get rather
slow when a lot of points are added.
  • Loading branch information
bjorn committed Oct 6, 2020
1 parent 6b35338 commit 2979823
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/tiled/wangfiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ void WangFiller::fillRegion(TileLayer &target,
QVector<QPoint> corrections;

auto resolve = [&] (int x, int y) {
const QPoint targetPos(x - target.x(),
y - target.y());

if (target.cellAt(targetPos).checked())
return;

WangTile wangTile;
if (!findBestMatch(target, grid, QPoint(x, y), wangTile)) {
// TODO: error feedback
Expand All @@ -158,15 +164,13 @@ void WangFiller::fillRegion(TileLayer &target,
auto cell = wangTile.makeCell();
cell.setChecked(true);

target.setCell(x - target.x(),
y - target.y(),
cell);
target.setCell(targetPos.x(), targetPos.y(), cell);

// Adjust the desired WangIds for the surrounding tiles based on the placed one
QPoint adjacentPoints[8];
QPoint adjacentPoints[WangId::NumIndexes];
getSurroundingPoints(QPoint(x, y), mStaggeredRenderer, adjacentPoints);

for (int i = 0; i < 8; ++i) {
for (int i = 0; i < WangId::NumIndexes; ++i) {
const QPoint p = adjacentPoints[i];
if (target.cellAt(p - target.position()).checked())
continue;
Expand Down

0 comments on commit 2979823

Please sign in to comment.