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

Enabling wangfilling for BucketFillTool and StampBrush #1638

Merged
merged 16 commits into from
Jul 13, 2017

Conversation

Bdtrotte
Copy link
Contributor

@Bdtrotte Bdtrotte commented Jul 4, 2017

and hopefully implementing a new dock/view/model for assigning tiles to a wang set

@Bdtrotte
Copy link
Contributor Author

Bdtrotte commented Jul 9, 2017

The latest changes assert a new important rule for wangIds. If the edge count of a wangSet == 1, then for a wangId to be valid, all the edges must == 0. The same applies for corners. This is because for the purposes of finding tiles with wangIds, it is much faster if half the Id is already known; without the standardization all possibilities must be checked. Furthermore, when moving from a set with no edges, to one with them, it makes sense that the previously non-existent edges be thought of as wildcards.

@Bdtrotte
Copy link
Contributor Author

Bdtrotte commented Jul 9, 2017

With painting working, and a whole lot more refined, I feel this PR is one step away from being merged (not including reviews). All thats left is to alter things to support undo commands, and cleaning up some quarks with how the UI behaves.

@Bdtrotte
Copy link
Contributor Author

Undo now works when painting wangIds onto tiles. There is still the case where one removes wangIds from tiles by changing the edge/corner counts of the wangSet. Currently there is no way to retrieve this once done, in the next push this will be fixed.

Also, some more test files have been added with a real tileset to show off some of the fun!

Copy link
Member

@bjorn bjorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some great work! It took me about 4 hours to go through it all. I made quite some comments, but I think they are mostly minor.

I could probably merge in the evening when you have time to address the comments by then, and we could talk about the next steps.

@@ -591,6 +591,12 @@ void MapReaderPrivate::readTilesetWangSets(Tileset &tileset)
const QXmlStreamAttributes tileAtts = xml.attributes();
int tileId = tileAtts.value(QLatin1String("tileid")).toInt();
unsigned wangId = tileAtts.value(QLatin1String("wangid")).toUInt();

if (!wangSet->wangIdIsValid(wangId)) {
xml.skipCurrentElement();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is probably a case where it would be better to raise an error using xml.raiseError(...) and return, because this means the file is invalid and it is not nice to silently ignore that.

int previousEdgeColors = mEdgeColors;
mEdgeColors = newEdgeColors;

for (WangId wangId : mWangIdToWangTile.keys()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allocates a temporary list of all WangIds. You could instead just iterate the other hash, right?

for (WangId wangId : mTileInfoToWangId) {

Also applies to tilesChangedOnSetCornerColors.

void WangSet::removeWangTile(const WangTile &wangTile)
{
WangId wangId = mTileInfoToWangId.value(wangTileToTileInfo(wangTile), 0);
mTileInfoToWangId.remove(wangTileToTileInfo(wangTile));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simplified to:

WangId wangId = mTileInfoToWangId.take(wangTileToTileInfo(wangTile));


if (Tile *tile = mTileset->tileAt(tileInfo))
tiles.append(tile);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this do the same thing?

    for (const WangTile &wangTile : mWangIdToWangTile)
        tiles.append(wangTile.tile());

With both methods there can be duplicates, but I guess that is not really a problem.

if (mCornerColors > 1)
mask |= 0xf0f0f0f0;

for (WangId usedId : mWangIdToWangTile.keys()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid allocating a temporary list, I think this should be:

for (WangId usedId : mTileInfoToWangId) {

However, I do not fully understand why this function isn't simply doing:

return mWangIdToWangTile.contains(wangId);

Why the need for the mask, and could this be avoided?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is originally what I was doing, but ran into some problems when there was less certainty about the wangId (I was searching for something with at least all ones in a corner only set, but the wangSet had the corners as wildcards (0)). The mask just allows that, though it should now never happen, the spaces in the wangId which don't matter can be different. Though now that I have made more clear rules about wangIds, this could be changed.

int cornerEdgePermutations = edges * corners;

for (int i = 0; i < 8; ++i) {
int bellowPermutations = qPow(cornerEdgePermutations, i/2) * ((i&1)? edges : 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "below"

{
mWangSet = wangSet;

resetModel();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While sometimes it may be unavoidable, please implement this properly when possible:

beginResetModel();
mWangSet = wangSet;
endResetModel();


int rowCount(const QModelIndex &parent = QModelIndex()) const override;

int columnCount(const QModelIndex &parent = QModelIndex()) const override;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you derive from QAbstractListModel, you can remove this override because the list model already returns a column count of 1 by default.

setSelectionMode(QAbstractItemView::SingleSelection);
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
setItemDelegate(new WangTemplateDelegate(this, this));
setTabKeyNavigation(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add:

setUniformItemSizes(true);

I didn't notice an actual performance difference, but the view may be able to avoid getting the size hint very often.

You can remove the setTabKeyNavigation(true);. That is the default, but actually it won't work anyway because Tab is used to show/hide the all menu bars and dock widgets. Alternatively it could be set to false explicitly.

void WangTemplateView::setModel(QAbstractItemModel *model)
{
QListView::setModel(model);
updateBackgroundColor();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since updateBackgroundColor does not change color based on the model, this override can be removed. It could be called from the constructor and you should connect it to StyleHelper::styleApplied, as done in TilesetView.

@Bdtrotte
Copy link
Contributor Author

There is one more change I would like to put on this pr, which is to send a signal from the TilesetView to the wangDock when it changes the current WangId used, and when it changes the used status of a certain wangId, so that the template view updates accordingly. After that it will be complete, and ready for merge.

@bjorn bjorn merged commit 09dc14d into mapeditor:wip/wangtiles Jul 13, 2017
@Bdtrotte Bdtrotte deleted the wip/wangtiles branch July 13, 2017 21:44
@bjorn bjorn mentioned this pull request Apr 14, 2021
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.

2 participants