[nostalgia/core] Add getTileCnt and fix getTileIdx
This commit is contained in:
parent
ff2eb5b11b
commit
1dff26d895
@ -14,6 +14,7 @@ std::size_t idx(TileSheet::SubSheet const&ss, ox::Point const&pt) noexcept {
|
|||||||
return ptToIdx(pt, ss.columns);
|
return ptToIdx(pt, ss.columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
static TileSheet::SubSheet const*getSubsheet(TileSheet::SubSheet const&ss, SubSheetId const id) noexcept {
|
static TileSheet::SubSheet const*getSubsheet(TileSheet::SubSheet const&ss, SubSheetId const id) noexcept {
|
||||||
if (ss.id == id) {
|
if (ss.id == id) {
|
||||||
return &ss;
|
return &ss;
|
||||||
@ -26,6 +27,24 @@ static TileSheet::SubSheet const*getSubsheet(TileSheet::SubSheet const&ss, SubSh
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
static size_t getTileCnt(TileSheet::SubSheet const&ss, int const bpp) noexcept {
|
||||||
|
if (ss.subsheets.empty()) {
|
||||||
|
auto const bytesPerTile = bpp == 4 ? 32u : 64u;
|
||||||
|
return ss.pixels.size() / bytesPerTile;
|
||||||
|
} else {
|
||||||
|
size_t out{};
|
||||||
|
for (auto const&child : ss.subsheets) {
|
||||||
|
out += getTileCnt(child, bpp);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t getTileCnt(TileSheet const&ts) noexcept {
|
||||||
|
return getTileCnt(ts.subsheet, ts.bpp);
|
||||||
|
}
|
||||||
|
|
||||||
TileSheet::SubSheet const*getSubsheet(TileSheet const&ts, SubSheetId const id) noexcept {
|
TileSheet::SubSheet const*getSubsheet(TileSheet const&ts, SubSheetId const id) noexcept {
|
||||||
return getSubsheet(ts.subsheet, id);
|
return getSubsheet(ts.subsheet, id);
|
||||||
}
|
}
|
||||||
@ -42,7 +61,7 @@ static ox::Optional<size_t> getPixelIdx(
|
|||||||
if (auto out = getPixelIdx(child, id, idx, bpp)) {
|
if (auto out = getPixelIdx(child, id, idx, bpp)) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
idx += pixelCnt(ss, bpp);
|
idx += pixelCnt(child, bpp);
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user