[nostalgia/core] Fix getTileIdx(TileSheet, SubSheetId)

This commit is contained in:
Gary Talent 2024-06-03 23:17:50 -05:00
parent f82db6905c
commit 8798d2d718

View File

@ -52,7 +52,7 @@ TileSheet::SubSheet const *getSubsheet(TileSheet const&ts, SubSheetId const id)
static ox::Optional<size_t> getPixelIdx( static ox::Optional<size_t> getPixelIdx(
TileSheet::SubSheet const&ss, TileSheet::SubSheet const&ss,
SubSheetId const id, SubSheetId const id,
size_t idx, size_t &idx,
int8_t const bpp) noexcept { int8_t const bpp) noexcept {
for (auto const&child: ss.subsheets) { for (auto const&child: ss.subsheets) {
if (child.id == id) { if (child.id == id) {
@ -63,11 +63,12 @@ static ox::Optional<size_t> getPixelIdx(
} }
idx += pixelCnt(child, bpp); idx += pixelCnt(child, bpp);
} }
return {}; return ox::Optional<size_t>{};
} }
size_t getTileIdx(TileSheet const&ts, SubSheetId const id) noexcept { size_t getTileIdx(TileSheet const&ts, SubSheetId const id) noexcept {
auto const out = getPixelIdx(ts.subsheet, id, 0, ts.bpp); size_t idx{};
auto const out = getPixelIdx(ts.subsheet, id, idx, ts.bpp);
return out.or_value(0) / PixelsPerTile; return out.or_value(0) / PixelsPerTile;
} }