[nostalgia/core/gba] Cleanup

This commit is contained in:
Gary Talent 2023-12-23 01:50:26 -06:00
parent 2bad4ee416
commit 978f2f9c4f

View File

@ -96,31 +96,28 @@ constexpr ox::Error model(auto *io, ox::CommonPtrWith<GbaTileMapTarget> auto *t)
// cannot be seriously optimized without preloading TileSheets. // cannot be seriously optimized without preloading TileSheets.
size_t sectionIdx = 0; size_t sectionIdx = 0;
if (t->targetBpp == t->bpp) { if (t->targetBpp == t->bpp) {
TileSheetSetEntrySection const*section = &t->setEntry->sections[0];
size_t writeIt = 0;
uint16_t intermediate = 0; uint16_t intermediate = 0;
size_t const fourBpp = t->bpp == 4; size_t const fourBpp = t->bpp == 4;
const auto handleTileMap = [t, &intermediate, &section, &sectionIdx, &writeIt, fourBpp] const auto handleTileMap = [t, &intermediate, &sectionIdx, fourBpp]
(std::size_t i, uint8_t const*tile) { (std::size_t i, uint8_t const*tile) {
auto const tileIdx = static_cast<int>((i * (2 * fourBpp)) / PixelsPerTile); auto const tileIdx = static_cast<int>((i * (2 * fourBpp)) / PixelsPerTile);
if (!loadPixel(*t->setEntry, sectionIdx, tileIdx)) { if (!loadPixel(*t->setEntry, sectionIdx, tileIdx)) {
return ox::Error{}; return ox::Error{};
} }
if (writeIt & 1) { // i is odd if (i & 1) { // i is odd
intermediate |= static_cast<uint16_t>(*tile) << 8; intermediate |= static_cast<uint16_t>(*tile) << 8;
t->tileMap[writeIt / 2] = intermediate; t->tileMap[t->tileWriteIdx] = intermediate;
++t->tileWriteIdx; ++t->tileWriteIdx;
} else { // i is even } else { // i is even
intermediate = *tile & 0x00ff; intermediate = *tile & 0x00ff;
} }
++writeIt;
return ox::Error{}; return ox::Error{};
}; };
out = io->template field<uint8_t, decltype(handleTileMap)>("tileMap", handleTileMap); out = io->template field<uint8_t, decltype(handleTileMap)>("tileMap", handleTileMap);
} else if (t->targetBpp > t->bpp) { // 4 -> 8 bits } else if (t->targetBpp > t->bpp) { // 4 -> 8 bits
const auto handleTileMap = [t, &sectionIdx](std::size_t writeIt, uint8_t const*tile) { const auto handleTileMap = [t, &sectionIdx](std::size_t i, uint8_t const*tile) {
auto constexpr BytesPerTile4Bpp = 32; auto constexpr BytesPerTile4Bpp = 32;
auto const tileIdx = static_cast<int>(writeIt / BytesPerTile4Bpp); auto const tileIdx = static_cast<int>(i / BytesPerTile4Bpp);
if (!loadPixel(*t->setEntry, sectionIdx, tileIdx)) { if (!loadPixel(*t->setEntry, sectionIdx, tileIdx)) {
return ox::Error{}; return ox::Error{};
} }