Avoid sorting proto-palettes breaking mappings

The sorting was performed without updating the mappings, which broke the world.
We can instead sort the IDs as they are inserted into the packing queue,
which should also be faster than moving the actual proto-pal objects around.
This commit is contained in:
ISSOtm
2022-04-24 15:03:27 +02:00
committed by Eldred Habert
parent ed104a9f70
commit fcce42d3d2
3 changed files with 17 additions and 31 deletions

View File

@@ -574,6 +574,7 @@ public:
for (uint32_t x = 0; x < 8; ++x) {
row <<= 1;
uint8_t index = palette.indexOf(tile.pixel(x, y).cgbColor());
assert(index < palette.size()); // The color should be in the palette
if (index & 1) {
row |= 1;
}
@@ -948,12 +949,6 @@ contained:;
}
}
// Sort the proto-palettes by size, which improves the packing algorithm's efficiency
// We sort after all insertions to avoid moving items: https://stackoverflow.com/a/2710332
std::sort(
protoPalettes.begin(), protoPalettes.end(),
[](ProtoPalette const &lhs, ProtoPalette const &rhs) { return lhs.size() < rhs.size(); });
auto [mappings, palettes] = options.palSpecType == Options::NO_SPEC
? generatePalettes(protoPalettes, png)
: makePalsAsSpecified(protoPalettes, png);