Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wang Improvements #2888

Merged
merged 41 commits into from
Oct 8, 2020
Merged

Wang Improvements #2888

merged 41 commits into from
Oct 8, 2020

Conversation

bjorn
Copy link
Member

@bjorn bjorn commented Aug 19, 2020

This change is about improving the Wang-related tools to make them more useful. The main goals are:

  • To support editing with the blob tileset.
  • To support erasing (transitions into nothing).
  • To support adjusting the map to make a change work, instead of aborting as soon as a tile can't be found.
  • To replace the Terrain Brush (if we also increase the limit on the colors from 15 to 255).

For now, the main change is to unify the colors, so that we don't have "edge" and "corner" colors, but a single color can be used on both edges and corners. This is the first step towards supporting blob tilesets.

See also: Neither terrain nor Wang can handle a “blob” tileset

@bjorn bjorn force-pushed the wip/wang-improvements branch 4 times, most recently from c50d24c to 878ddec Compare August 26, 2020 09:50
@bjorn
Copy link
Member Author

bjorn commented Sep 1, 2020

A short demonstration of how editing with a blob tileset could work:

blob

I imagine the tool will need several editing modes for convenience:

  • To change only tile corners.
  • To change only tile edges.
  • To change either corners or edges based on proximity (shown above).

And the appropriate mode could be selected based on whether the selected color exists on corners, edges or both.

@bjorn bjorn force-pushed the wip/wang-improvements branch 6 times, most recently from 784d202 to b803c10 Compare September 8, 2020 09:12
Removed the distinction between corner colors and edge colors. A WangSet
now has just one list of colors, which can be used at any index.

The tools will need some other way of knowing whether they are operating
on corners, edges or both now.
It's not ideal, but it works. Also added a blob tileset for testing.
This can be useful, mostly for testing purposes.
Probably more changes will be necessary since the logic that there
should be at least two colors affects a lot of places.

The Wang template view will still only show combinations of colors so in
case of a single color, this view shows a single tile with this color at
all indexes.
A mask is now constructed and used to search for Wang tiles matching
only certain color indexes, instead of repeating hash table lookups with
all possible variations.
The class is mostly based on how cells are allocated by the TileLayer.

It is used in the WangFiller. Not expected to improve performance in
this case, but it's more convenient since it sets/gets values by x,y
coordinates and can deal with negative values as well.
* Take stagger axis from map instead of passing it around as a parameter
  (might have been an optimization, but it seems a little premature).

* Use a matching tile searching algorithm that is similar to the Terrain
  Brush, in that it uses a mask to tell which indexes should definitely
  match and for other indexes it prefers, but doesn't require, to match
  the existing color.

* Removed the expensive look-ahead, where it tries to only place a tile
  once it has determined that it can also find matching neighbors. Let's
  be a little more optimistic for now (though it will cause gaps to appear
  in some cases).

* Automatically select the Wang Brush mode based on where the selected
  color is used (edge, corner or both).

* Fixed Wang Brush on infinite maps.

* Used WangFiller to place tiles with the WangBrush.
Planned to be used for a debugging helper, but a number of tools already
has this pointer anyway so it makes sense to move this functionality
down the hierarchy.
When Tiled is compiled in debug mode, each MapScene now provides an item
that can record arbitrary painting commands for debugging purposes.
This should enable erasing with the Wang Brush (there should also be
another way of entering the erasing mode, though).
Blob Wang sets with a single color.
It's no longer as smart (doesn't look ahead), but this way it's unified
with all other tools placing Wang tiles. We can add an option to make
the process smarter again later.
To select the erasing mode you currently have to capture the empty color
from the map (right-click on an empty area). But once you have that, the
tool allows you to erase.

In erasing mode, the WangFiller consideres the empty tile to be a valid
candidate as well. At the same time, is now sets the "checked" flag on
any cells it sets, to be able to tell them apart from empty cells.
Now when it turns out a neighboring tiles doesn't fit to a placed one,
and this neighbor is outside of the filled region, it can be queued for
correction. To avoid this growing into a random mess, the transition
penalty is now based on the distance between desired and chosen color of
each index, the same approach used by the Terrain Brush.

At the same time, when corrections are disabled, like when using Wang
mode with the fill tool or Stamp Brush, I've reintroduced the look-ahead
that makes sure that a chosen candidate will not cause an impossible
situation for any of its neighbors. This prevents most of the problems
when filling with incomplete Wang sets.
    undefined reference to `__imp__ZN5Tiled4GridINS_10WangFiller8CellInfoELi4EE5EMPTYE'

Not sure if there's a way to fix this while keeping the shared static
instance, but I guess a local static instance will do the job.
Micro-optimization, but why not.
Now a Wang set can be defined to be corner-based, edge-based or both.
This affects the way the Wang Brush works, the overlay drawn by the
Tileset Editor and the process of setting the WangIds on the tiles.

The Wang set type is saved, loaded, editable and generally used, but the
UI should probably be adjusted so that you select the type of Wang set
already when creating it (currently that always creates a "Mixed" set).

Also, the WangIds are not changed when the Wang set type is changed. It
might be a good idea to explicitly clear any WangIds when changing the
type as appropriate, though I'm a bit reluctant to do that due to data
loss.
Now uses prettier shapes, like the Terrain overlay and supports
simplified drawing for corner and edge Wang sets.
Terrains still exist in libtiled. Before that can be removed the
terraingenerator tool needs to be changed to generate Wang sets.
Now it will only change direction when the hovered tile changes.
Scripts can now add/remove Wang sets, change their properties and change
the Wang IDs of tiles in the set. No access exists yet to the Wang
colors.

Issue #2663
Disabled in code for now, since I'm not convinced about which overlay is
better.
The "Templates" tab is generally only helpful in some cases and confusing
in others, so let's now show it by default.
Disabled in code for now, since I'm not convinced about which overlay is
better.
It should be helpful to avoid trying to make edits that can't work out,
so I've reintroduced some code that determines the brush mode by looking
at where a color is used.

It might still make sense to add an explicit toggle for the user, to
override the "PaintEdgeAndCorner" mode.
@bjorn
Copy link
Member Author

bjorn commented Oct 1, 2020

Before this can be merged there are at least the following features still missing in Wang Brush that were present in Terrain Brush:

  • Alt modifier for "symmetry painting".
  • Shift modifier for drawing lines.

So I'll prioritize those features over other plans that could also be done in a separate pull request.

As previously supported by the Terrain Brush.
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.
@bjorn
Copy link
Member Author

bjorn commented Oct 6, 2020

Line drawing has been added, also in Edge mode:

wang-brush-line-drawing

Drawing with rotational symmetry was also added.

Unfortunately, I may have broken the erasing mode and there is still no button to select it, so I'll need to fix that before this can be merged.

As previously supported by the Terrain Brush, but now also supporting
the drawing of thinner lines in "Corner" and "Edge" modes.

Also make lines when moving fast with the mouse, to avoid gaps. This is
unfortunately not supported yet in "PaintEdgeAndCorner" mode.
@bjorn
Copy link
Member Author

bjorn commented Oct 8, 2020

Fixed the erasing mode again, was a bug in the last commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant