diff --git a/CHANGELOG.md b/CHANGELOG.md index d61cd0ac..5083eb0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d - Fix default object sprites retaining dimensions and transparency of the previous sprite. - Fix connections not being deleted when the map name text box is cleared. - Fix the map border not updating when a tileset is changed. +- Improve the poor speed of the API functions `setMetatileTile` and `setMetatileTiles`. - Stop the Tileset Editor from scrolling to the initially selected metatile when saving. - Fix the selection outline sticking in single-tile mode on the Prefab tab. diff --git a/include/mainwindow.h b/include/mainwindow.h index 87ea30aa..f68fc2c6 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -333,7 +333,7 @@ private: MapSortOrder mapSortOrder; - bool needsFullRedraw = false; + bool tilesetNeedsRedraw = false; bool setMap(QString, bool scrollTreeView = false); void redrawMapScene(); diff --git a/include/ui/tileseteditor.h b/include/ui/tileseteditor.h index 09a828c3..06aa2168 100644 --- a/include/ui/tileseteditor.h +++ b/include/ui/tileseteditor.h @@ -52,11 +52,11 @@ public: public slots: void applyUserShortcuts(); + void onSelectedMetatileChanged(uint16_t); private slots: void onHoveredMetatileChanged(uint16_t); void onHoveredMetatileCleared(); - void onSelectedMetatileChanged(uint16_t); void onHoveredTileChanged(uint16_t); void onHoveredTileCleared(); void onSelectedTilesChanged(); diff --git a/src/scriptapi/apimap.cpp b/src/scriptapi/apimap.cpp index fde049db..21f38a51 100644 --- a/src/scriptapi/apimap.cpp +++ b/src/scriptapi/apimap.cpp @@ -5,7 +5,7 @@ #include "config.h" #include "imageproviders.h" -// TODO: "needsFullRedraw" is used when redrawing the map after +// TODO: "tilesetNeedsRedraw" is used when redrawing the map after // changing a metatile's tiles via script. It is unnecessarily // resource intensive. The map metatiles that need to be updated are // not marked as changed, so they will not be redrawn if the cache @@ -16,13 +16,22 @@ void MainWindow::tryRedrawMapArea(bool forceRedraw) { if (!forceRedraw) return; - if (this->needsFullRedraw) { + if (this->tilesetNeedsRedraw) { + // Refresh anything that can display metatiles this->editor->map_item->draw(true); this->editor->collision_item->draw(true); this->editor->selected_border_metatiles_item->draw(); this->editor->updateMapBorder(); this->editor->updateMapConnections(); - this->needsFullRedraw = false; + if (this->tilesetEditor) + this->tilesetEditor->updateTilesets(this->editor->map->layout->tileset_primary_label, this->editor->map->layout->tileset_secondary_label); + if (this->editor->metatile_selector_item) + this->editor->metatile_selector_item->draw(); + if (this->editor->selected_border_metatiles_item) + this->editor->selected_border_metatiles_item->draw(); + if (this->editor->current_metatile_selection_item) + this->editor->current_metatile_selection_item->draw(); + this->tilesetNeedsRedraw = false; } else { this->editor->map_item->draw(); this->editor->collision_item->draw(); @@ -569,16 +578,6 @@ void MainWindow::saveMetatilesByMetatileId(int metatileId) { Tileset * tileset = Tileset::getMetatileTileset(metatileId, this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary); if (this->editor->project && tileset) this->editor->project->saveTilesetMetatiles(tileset); - - // Refresh anything that can display metatiles (except the actual map view) - if (this->tilesetEditor) - this->tilesetEditor->updateTilesets(this->editor->map->layout->tileset_primary_label, this->editor->map->layout->tileset_secondary_label); - if (this->editor->metatile_selector_item) - this->editor->metatile_selector_item->draw(); - if (this->editor->selected_border_metatiles_item) - this->editor->selected_border_metatiles_item->draw(); - if (this->editor->current_metatile_selection_item) - this->editor->current_metatile_selection_item->draw(); } void MainWindow::saveMetatileAttributesByMetatileId(int metatileId) { @@ -588,7 +587,7 @@ void MainWindow::saveMetatileAttributesByMetatileId(int metatileId) { // If the Tileset Editor is currently displaying the updated metatile, refresh it if (this->tilesetEditor && this->tilesetEditor->getSelectedMetatileId() == metatileId) - this->tilesetEditor->updateTilesets(this->editor->map->layout->tileset_primary_label, this->editor->map->layout->tileset_secondary_label); + this->tilesetEditor->onSelectedMetatileChanged(metatileId); } Metatile * MainWindow::getMetatile(int metatileId) { @@ -735,7 +734,7 @@ void MainWindow::setMetatileTiles(int metatileId, QJSValue tilesObj, int tileSta metatile->tiles[tileStart] = Tile(); this->saveMetatilesByMetatileId(metatileId); - this->needsFullRedraw = true; + this->tilesetNeedsRedraw = true; this->tryRedrawMapArea(forceRedraw); } @@ -751,7 +750,7 @@ void MainWindow::setMetatileTiles(int metatileId, int tileId, bool xflip, bool y metatile->tiles[i] = tile; this->saveMetatilesByMetatileId(metatileId); - this->needsFullRedraw = true; + this->tilesetNeedsRedraw = true; this->tryRedrawMapArea(forceRedraw); }