Improve speed of setMetatileTiles

This commit is contained in:
GriffinR 2023-08-18 18:46:25 -04:00
parent 7b03678b8e
commit 4f459f5a06
4 changed files with 18 additions and 18 deletions

View file

@ -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 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 connections not being deleted when the map name text box is cleared.
- Fix the map border not updating when a tileset is changed. - 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. - 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. - Fix the selection outline sticking in single-tile mode on the Prefab tab.

View file

@ -333,7 +333,7 @@ private:
MapSortOrder mapSortOrder; MapSortOrder mapSortOrder;
bool needsFullRedraw = false; bool tilesetNeedsRedraw = false;
bool setMap(QString, bool scrollTreeView = false); bool setMap(QString, bool scrollTreeView = false);
void redrawMapScene(); void redrawMapScene();

View file

@ -52,11 +52,11 @@ public:
public slots: public slots:
void applyUserShortcuts(); void applyUserShortcuts();
void onSelectedMetatileChanged(uint16_t);
private slots: private slots:
void onHoveredMetatileChanged(uint16_t); void onHoveredMetatileChanged(uint16_t);
void onHoveredMetatileCleared(); void onHoveredMetatileCleared();
void onSelectedMetatileChanged(uint16_t);
void onHoveredTileChanged(uint16_t); void onHoveredTileChanged(uint16_t);
void onHoveredTileCleared(); void onHoveredTileCleared();
void onSelectedTilesChanged(); void onSelectedTilesChanged();

View file

@ -5,7 +5,7 @@
#include "config.h" #include "config.h"
#include "imageproviders.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 // changing a metatile's tiles via script. It is unnecessarily
// resource intensive. The map metatiles that need to be updated are // resource intensive. The map metatiles that need to be updated are
// not marked as changed, so they will not be redrawn if the cache // not marked as changed, so they will not be redrawn if the cache
@ -16,13 +16,22 @@
void MainWindow::tryRedrawMapArea(bool forceRedraw) { void MainWindow::tryRedrawMapArea(bool forceRedraw) {
if (!forceRedraw) return; if (!forceRedraw) return;
if (this->needsFullRedraw) { if (this->tilesetNeedsRedraw) {
// Refresh anything that can display metatiles
this->editor->map_item->draw(true); this->editor->map_item->draw(true);
this->editor->collision_item->draw(true); this->editor->collision_item->draw(true);
this->editor->selected_border_metatiles_item->draw(); this->editor->selected_border_metatiles_item->draw();
this->editor->updateMapBorder(); this->editor->updateMapBorder();
this->editor->updateMapConnections(); 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 { } else {
this->editor->map_item->draw(); this->editor->map_item->draw();
this->editor->collision_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); Tileset * tileset = Tileset::getMetatileTileset(metatileId, this->editor->map->layout->tileset_primary, this->editor->map->layout->tileset_secondary);
if (this->editor->project && tileset) if (this->editor->project && tileset)
this->editor->project->saveTilesetMetatiles(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) { 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 the Tileset Editor is currently displaying the updated metatile, refresh it
if (this->tilesetEditor && this->tilesetEditor->getSelectedMetatileId() == metatileId) 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) { Metatile * MainWindow::getMetatile(int metatileId) {
@ -735,7 +734,7 @@ void MainWindow::setMetatileTiles(int metatileId, QJSValue tilesObj, int tileSta
metatile->tiles[tileStart] = Tile(); metatile->tiles[tileStart] = Tile();
this->saveMetatilesByMetatileId(metatileId); this->saveMetatilesByMetatileId(metatileId);
this->needsFullRedraw = true; this->tilesetNeedsRedraw = true;
this->tryRedrawMapArea(forceRedraw); this->tryRedrawMapArea(forceRedraw);
} }
@ -751,7 +750,7 @@ void MainWindow::setMetatileTiles(int metatileId, int tileId, bool xflip, bool y
metatile->tiles[i] = tile; metatile->tiles[i] = tile;
this->saveMetatilesByMetatileId(metatileId); this->saveMetatilesByMetatileId(metatileId);
this->needsFullRedraw = true; this->tilesetNeedsRedraw = true;
this->tryRedrawMapArea(forceRedraw); this->tryRedrawMapArea(forceRedraw);
} }