mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user