From 774c60cc8815c816ad57d53023c6c47c3e74f61f Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sat, 20 Aug 2022 12:14:11 -0400 Subject: [PATCH 1/2] Clean up loadTilesetMetatiles --- src/project.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/project.cpp b/src/project.cpp index beda1e79..f8a04aa5 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -1583,14 +1583,14 @@ void Project::loadTilesetMetatiles(Tileset* tileset) { QFile metatiles_file(tileset->metatiles_path); if (metatiles_file.open(QIODevice::ReadOnly)) { QByteArray data = metatiles_file.readAll(); - int metatile_data_length = projectConfig.getTripleLayerMetatilesEnabled() ? 24 : 16; - int num_metatiles = data.length() / metatile_data_length; - int num_layers = projectConfig.getTripleLayerMetatilesEnabled() ? 3 : 2; + int tilesPerMetatile = projectConfig.getTripleLayerMetatilesEnabled() ? 12 : 8; + int bytesPerMetatile = 2 * tilesPerMetatile; + int num_metatiles = data.length() / bytesPerMetatile; QList metatiles; for (int i = 0; i < num_metatiles; i++) { Metatile *metatile = new Metatile; - int index = i * (2 * 4 * num_layers); - for (int j = 0; j < 4 * num_layers; j++) { + int index = i * bytesPerMetatile; + for (int j = 0; j < tilesPerMetatile; j++) { uint16_t tileRaw = static_cast(data[index++]); tileRaw |= static_cast(data[index++]) << 8; metatile->tiles.append(Tile(tileRaw)); From b8636548dca941494e72b5787386ffc00dfa071c Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sat, 20 Aug 2022 16:08:53 -0400 Subject: [PATCH 2/2] Move function call outside loop --- src/project.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/project.cpp b/src/project.cpp index f8a04aa5..3682d66b 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -1078,8 +1078,8 @@ void Project::saveTilesetMetatiles(Tileset *tileset) { QFile metatiles_file(tileset->metatiles_path); if (metatiles_file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { QByteArray data; + int numTiles = projectConfig.getTripleLayerMetatilesEnabled() ? 12 : 8; for (Metatile *metatile : tileset->metatiles) { - int numTiles = projectConfig.getTripleLayerMetatilesEnabled() ? 12 : 8; for (int i = 0; i < numTiles; i++) { uint16_t tile = metatile->tiles.at(i).rawValue(); data.append(static_cast(tile));