[nostalgia/core] Add functions for mapping tile idx to subsheet
This commit is contained in:
parent
1cf09433e8
commit
caa59f3724
@ -158,6 +158,12 @@ struct TileSheet {
|
||||
[[nodiscard]]
|
||||
std::size_t idx(TileSheet::SubSheet const&ss, ox::Point const&pt) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
TileSheet::SubSheet const*getSubsheet(TileSheet const&ts, SubSheetId const id) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
size_t getTileIdx(TileSheet const&ts, SubSheetId id) noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
uint8_t getPixel4Bpp(TileSheet::SubSheet const&ss, std::size_t idx) noexcept;
|
||||
|
||||
|
@ -14,6 +14,44 @@ std::size_t idx(TileSheet::SubSheet const&ss, ox::Point const&pt) noexcept {
|
||||
return ptToIdx(pt, ss.columns);
|
||||
}
|
||||
|
||||
static TileSheet::SubSheet const*getSubsheet(TileSheet::SubSheet const&ss, SubSheetId const id) noexcept {
|
||||
if (ss.id == id) {
|
||||
return &ss;
|
||||
}
|
||||
for (auto const&child : ss.subsheets) {
|
||||
if (auto out = getSubsheet(child, id)) {
|
||||
return out;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
TileSheet::SubSheet const*getSubsheet(TileSheet const&ts, SubSheetId const id) noexcept {
|
||||
return getSubsheet(ts.subsheet, id);
|
||||
}
|
||||
|
||||
static ox::Optional<size_t> getPixelIdx(
|
||||
TileSheet::SubSheet const&ss,
|
||||
SubSheetId const id,
|
||||
size_t idx,
|
||||
int8_t const bpp) noexcept {
|
||||
for (auto const&child : ss.subsheets) {
|
||||
if (child.id == id) {
|
||||
return ox::Optional<size_t>(ox::in_place, idx);
|
||||
}
|
||||
if (auto out = getPixelIdx(child, id, idx, bpp)) {
|
||||
return out;
|
||||
}
|
||||
idx += pixelCnt(ss, bpp);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
size_t getTileIdx(TileSheet const&ts, SubSheetId const id) noexcept {
|
||||
auto const out = getPixelIdx(ts.subsheet, id, 0, ts.bpp);
|
||||
return out.or_value(0) / PixelsPerTile;
|
||||
}
|
||||
|
||||
uint8_t getPixel4Bpp(TileSheet::SubSheet const&ss, std::size_t idx) noexcept {
|
||||
if (idx & 1) {
|
||||
return ss.pixels[idx / 2] >> 4;
|
||||
|
Loading…
x
Reference in New Issue
Block a user