[nostalgia/gfx] Fix BG tilesheet loading, add background offset functions
Some checks failed
Build / build (push) Failing after 20s

This commit is contained in:
2025-07-28 21:54:50 -05:00
parent c275c5f5e6
commit e61d4647b5
3 changed files with 21 additions and 9 deletions

View File

@@ -238,6 +238,10 @@ void setBgCbb(Context &ctx, unsigned bgIdx, unsigned cbbIdx) noexcept;
void setBgPriority(Context &ctx, uint_t bgIdx, uint_t priority) noexcept; void setBgPriority(Context &ctx, uint_t bgIdx, uint_t priority) noexcept;
void setBgOffset(Context &ctx, uint16_t bg, int16_t x, int16_t y) noexcept;
void scrollBgOffset(Context &ctx, uint16_t bg, int16_t x, int16_t y) noexcept;
void hideSprite(Context &ctx, unsigned) noexcept; void hideSprite(Context &ctx, unsigned) noexcept;
void showSprite(Context &ctx, unsigned) noexcept; void showSprite(Context &ctx, unsigned) noexcept;
@@ -260,8 +264,8 @@ constexpr ox::CStringView GlslVersion = "#version 330";
[[nodiscard]] [[nodiscard]]
ox::Size drawSize(int scale = 5) noexcept; ox::Size drawSize(int scale = 5) noexcept;
void draw(gfx::Context &ctx, ox::Size const &renderSz) noexcept; void draw(Context &ctx, ox::Size const &renderSz) noexcept;
void draw(gfx::Context&, int scale = 5) noexcept; void draw(Context&, int scale = 5) noexcept;
} }

View File

@@ -169,8 +169,8 @@ ox::Error loadBgTileSheet(
unsigned const cbb, unsigned const cbb,
CompactTileSheet const &ts, CompactTileSheet const &ts,
ox::Optional<unsigned> const &paletteBank) noexcept { ox::Optional<unsigned> const &paletteBank) noexcept {
auto const cnt = (ts.pixels.size() * PixelsPerTile) / (1 + (ts.bpp == 4)); auto const cnt = ts.pixels.size() >> (ts.bpp == 4);
for (size_t i = 0; i < cnt; ++i) { for (size_t i{}; i < cnt; ++i) {
auto const srcIdx = i * 2; auto const srcIdx = i * 2;
auto const p1 = static_cast<uint16_t>(ts.pixels[srcIdx]); auto const p1 = static_cast<uint16_t>(ts.pixels[srcIdx]);
auto const p2 = static_cast<uint16_t>(ts.pixels[srcIdx + 1]); auto const p2 = static_cast<uint16_t>(ts.pixels[srcIdx + 1]);
@@ -218,10 +218,10 @@ ox::Error loadSpriteTileSheet(
Context &ctx, Context &ctx,
CompactTileSheet const &ts, CompactTileSheet const &ts,
bool const loadDefaultPalette) noexcept { bool const loadDefaultPalette) noexcept {
for (size_t i = 0; i < ts.pixels.size(); i += 2) { for (size_t i{}; i < ts.pixels.size(); i += 2) {
uint16_t v = ts.pixels[i]; MEM_SPRITE_TILES[i >> 1] =
v |= static_cast<uint16_t>(ts.pixels[i + 1] << 8); static_cast<uint16_t>(ts.pixels[i]) |
MEM_SPRITE_TILES[i] = v; (static_cast<uint16_t>(ts.pixels[i + 1]) << 8);
} }
if (loadDefaultPalette && ts.defaultPalette) { if (loadDefaultPalette && ts.defaultPalette) {
OX_RETURN_ERROR(loadSpritePalette(ctx, ts.defaultPalette)); OX_RETURN_ERROR(loadSpritePalette(ctx, ts.defaultPalette));
@@ -294,6 +294,14 @@ void setBgPriority(Context&, uint_t const bgIdx, uint_t const priority) noexcept
bgCtl = (bgCtl & 0b1111'1111'1111'1100u) | (priority & 0b11); bgCtl = (bgCtl & 0b1111'1111'1111'1100u) | (priority & 0b11);
} }
void setBgOffset(Context&, uint16_t const bg, int16_t const x, int16_t const y) noexcept {
teagba::setBgOffset(bg, x, y);
}
void scrollBgOffset(Context&, uint16_t const bg, int16_t const x, int16_t const y) noexcept {
teagba::scrollBgOffset(bg, x, y);
}
void hideSprite(Context&, unsigned const idx) noexcept { void hideSprite(Context&, unsigned const idx) noexcept {
//oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow"); //oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow");
teagba::addSpriteUpdate({ teagba::addSpriteUpdate({

View File

@@ -249,7 +249,7 @@ void setBgTile(
} }
ox::Error initConsole(Context &ctx) noexcept { ox::Error initConsole(Context &ctx) noexcept {
constexpr ox::FileAddress TilesheetAddr = ox::StringLiteral("/TileSheets/Charset.ng"); constexpr ox::FileAddress TilesheetAddr = ox::StringLiteral("/TileSheets/Charset.nts");
constexpr ox::FileAddress PaletteAddr = ox::StringLiteral("/Palettes/Charset.npal"); constexpr ox::FileAddress PaletteAddr = ox::StringLiteral("/Palettes/Charset.npal");
setBgStatus(ctx, 0b0001); setBgStatus(ctx, 0b0001);
setBgCbb(ctx, 0, 0); setBgCbb(ctx, 0, 0);