Skip to content

Commit

Permalink
WangFiller: Don't try to make changes outside of a fixed map
Browse files Browse the repository at this point in the history
This avoids the problem, that tiles set outside of the map by the
algorithm will affect the tiles inside the map, which is not desirable.

Also, explicitly set tiles that are outside of the map to empty.  This
seems like a good idea, since it means the preview will still highlight
those areas, but it will not affect the map once applied.
  • Loading branch information
bjorn committed Jul 6, 2023
1 parent 823d428 commit fa99847
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/tiled/wangbrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,6 @@ void WangBrush::updateBrush()
fill.region = completeRegion;
}

// Don't try to make changes outside of a fixed map
if (!mapDocument()->map()->infinite())
fill.region &= currentLayer->rect();

SharedTileLayer stamp = SharedTileLayer::create(QString(), 0, 0, 0, 0);

wangFiller.setCorrectionsEnabled(true);
Expand Down
16 changes: 16 additions & 0 deletions src/tiled/wangfiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@ void WangFiller::apply(TileLayer &target)
auto &grid = mFillRegion.grid;
auto &region = mFillRegion.region;

// Don't try to make changes outside of a fixed map. Instead, to still
// provide some feedback in previews, explicitly mark this area as empty.
if (!mMapRenderer->map()->infinite()) {
const auto emptyRegion = region.subtracted(mBack.rect());

Cell empty;
empty.setChecked(true);

for (const QRect &rect : emptyRegion)
for (int y = rect.top(); y <= rect.bottom(); ++y)
for (int x = rect.left(); x <= rect.right(); ++x)
target.setCell(x - target.x(), y - target.y(), empty);

region &= mBack.rect();
}

if (!mCorrectionsEnabled) {
// Set the Wang IDs at the border of the region to prefer the tiles in
// the filled region to connect with those outside of it.
Expand Down

0 comments on commit fa99847

Please sign in to comment.