[nostalgia/core] Cleanup

This commit is contained in:
Gary Talent 2023-06-26 23:51:23 -05:00
parent 741026680a
commit 874592cffd
9 changed files with 48 additions and 38 deletions

View File

@ -53,12 +53,16 @@ void setBgCbb(Context *ctx, unsigned bgIdx, unsigned cbb) noexcept;
/** /**
* @param section describes which section of the selected TileSheetSpace to use (e.g. MEM_PALLETE_BG[section]) * @param section describes which section of the selected TileSheetSpace to use (e.g. MEM_PALLETE_BG[section])
*/ */
ox::Error loadBgTileSheet(Context *ctx, unsigned cbb, const ox::FileAddress &tilesheetAddr, ox::Error loadBgTileSheet(
const ox::FileAddress &paletteAddr = nullptr) noexcept; Context *ctx,
unsigned cbb,
ox::FileAddress const&tilesheetAddr,
ox::FileAddress const&paletteAddr = nullptr) noexcept;
ox::Error loadSpriteTileSheet(Context *ctx, ox::Error loadSpriteTileSheet(
const ox::FileAddress &tilesheetAddr, Context *ctx,
const ox::FileAddress &paletteAddr) noexcept; ox::FileAddress const&tilesheetAddr,
ox::FileAddress const&paletteAddr) noexcept;
ox::Error initConsole(Context *ctx) noexcept; ox::Error initConsole(Context *ctx) noexcept;
@ -73,7 +77,7 @@ void hideSprite(Context *ctx, unsigned) noexcept;
void setSprite(Context *ctx, unsigned idx, int x, int y, unsigned tileIdx, void setSprite(Context *ctx, unsigned idx, int x, int y, unsigned tileIdx,
unsigned spriteShape = 0, unsigned spriteSize = 0, unsigned flipX = 0) noexcept; unsigned spriteShape = 0, unsigned spriteSize = 0, unsigned flipX = 0) noexcept;
void setSprite(Context *ctx, const Sprite &s) noexcept; void setSprite(Context *ctx, Sprite const&s) noexcept;
} }

View File

@ -11,9 +11,9 @@ namespace nostalgia::core {
GbaContext::GbaContext(turbine::Context *tctx) noexcept: turbineCtx(tctx) { GbaContext::GbaContext(turbine::Context *tctx) noexcept: turbineCtx(tctx) {
} }
ox::Error initGfx(Context *ctx, const InitParams&) noexcept; ox::Error initGfx(Context *ctx, InitParams const&) noexcept;
ox::Result<ox::UniquePtr<Context>> init(turbine::Context *tctx, const InitParams &params) noexcept { ox::Result<ox::UniquePtr<Context>> init(turbine::Context *tctx, InitParams const&params) noexcept {
auto ctx = ox::make_unique<GbaContext>(tctx); auto ctx = ox::make_unique<GbaContext>(tctx);
oxReturnError(initGfx(ctx.get(), params)); oxReturnError(initGfx(ctx.get(), params));
return ox::UPtr<Context>(ctx.release()); return ox::UPtr<Context>(ctx.release());

View File

@ -15,7 +15,7 @@ struct GbaContext: public core::Context {
explicit GbaContext(turbine::Context *tctx) noexcept; explicit GbaContext(turbine::Context *tctx) noexcept;
[[nodiscard]] [[nodiscard]]
const auto &rom() const noexcept { auto const&rom() const noexcept {
return *turbine::rom(*turbineCtx); return *turbine::rom(*turbineCtx);
} }

View File

@ -69,7 +69,7 @@ constexpr ox::Error model(auto *io, ox::CommonPtrWith<GbaTileMapTarget> auto *t)
return io->template field<uint8_t, decltype(handleTileMap)>("tileMap", handleTileMap); return io->template field<uint8_t, decltype(handleTileMap)>("tileMap", handleTileMap);
} }
ox::Error initGfx(Context*, const InitParams&) noexcept { ox::Error initGfx(Context*, InitParams const&) noexcept {
for (auto bgCtl = &REG_BG0CTL; bgCtl <= &REG_BG3CTL; bgCtl += 2) { for (auto bgCtl = &REG_BG0CTL; bgCtl <= &REG_BG3CTL; bgCtl += 2) {
teagba::bgSetSbb(bgCtl, 28); teagba::bgSetSbb(bgCtl, 28);
} }
@ -108,8 +108,8 @@ void setBgCbb(Context*, unsigned bgIdx, unsigned cbb) noexcept {
static ox::Error loadBgTileSheet( static ox::Error loadBgTileSheet(
const ox::MemFS &rom, const ox::MemFS &rom,
unsigned cbb, unsigned cbb,
const ox::FileAddress &tilesheetAddr, ox::FileAddress const&tilesheetAddr,
const ox::FileAddress &paletteAddr) noexcept { ox::FileAddress const&paletteAddr) noexcept {
oxRequire(tsStat, rom.stat(tilesheetAddr)); oxRequire(tsStat, rom.stat(tilesheetAddr));
oxRequire(ts, rom.directAccess(tilesheetAddr)); oxRequire(ts, rom.directAccess(tilesheetAddr));
GbaTileMapTarget target; GbaTileMapTarget target;
@ -136,8 +136,8 @@ static ox::Error loadBgTileSheet(
ox::Error loadBgTileSheet( ox::Error loadBgTileSheet(
Context *ctx, Context *ctx,
unsigned cbb, unsigned cbb,
const ox::FileAddress &tilesheetAddr, ox::FileAddress const&tilesheetAddr,
const ox::FileAddress &paletteAddr) noexcept { ox::FileAddress const&paletteAddr) noexcept {
auto &gctx = static_cast<GbaContext&>(*ctx); auto &gctx = static_cast<GbaContext&>(*ctx);
auto &rom = static_cast<const ox::MemFS&>(gctx.rom()); auto &rom = static_cast<const ox::MemFS&>(gctx.rom());
return loadBgTileSheet(rom, cbb, tilesheetAddr, paletteAddr); return loadBgTileSheet(rom, cbb, tilesheetAddr, paletteAddr);
@ -145,8 +145,8 @@ ox::Error loadBgTileSheet(
ox::Error loadSpriteTileSheet( ox::Error loadSpriteTileSheet(
Context *ctx, Context *ctx,
const ox::FileAddress &tilesheetAddr, ox::FileAddress const&tilesheetAddr,
const ox::FileAddress &paletteAddr) noexcept { ox::FileAddress const&paletteAddr) noexcept {
auto &gctx = static_cast<GbaContext&>(*ctx); auto &gctx = static_cast<GbaContext&>(*ctx);
auto &rom = static_cast<const ox::MemFS&>(gctx.rom()); auto &rom = static_cast<const ox::MemFS&>(gctx.rom());
oxRequire(tsStat, gctx.rom().stat(tilesheetAddr)); oxRequire(tsStat, gctx.rom().stat(tilesheetAddr));
@ -164,7 +164,7 @@ ox::Error loadSpriteTileSheet(
return {}; return {};
} }
ox::Error loadBgPalette(Context *ctx, unsigned, const ox::FileAddress &paletteAddr) noexcept { ox::Error loadBgPalette(Context *ctx, unsigned, ox::FileAddress const&paletteAddr) noexcept {
auto &gctx = static_cast<GbaContext&>(*ctx); auto &gctx = static_cast<GbaContext&>(*ctx);
auto &rom = static_cast<const ox::MemFS&>(gctx.rom()); auto &rom = static_cast<const ox::MemFS&>(gctx.rom());
GbaPaletteTarget target; GbaPaletteTarget target;
@ -175,7 +175,7 @@ ox::Error loadBgPalette(Context *ctx, unsigned, const ox::FileAddress &paletteAd
return {}; return {};
} }
ox::Error loadSpritePalette(Context *ctx, unsigned cbb, const ox::FileAddress &paletteAddr) noexcept { ox::Error loadSpritePalette(Context *ctx, unsigned cbb, ox::FileAddress const&paletteAddr) noexcept {
auto &gctx = static_cast<GbaContext&>(*ctx); auto &gctx = static_cast<GbaContext&>(*ctx);
auto &rom = static_cast<const ox::MemFS&>(gctx.rom()); auto &rom = static_cast<const ox::MemFS&>(gctx.rom());
GbaPaletteTarget target; GbaPaletteTarget target;

View File

@ -7,5 +7,5 @@
#include <nostalgia/core/context.hpp> #include <nostalgia/core/context.hpp>
namespace nostalgia::core { namespace nostalgia::core {
ox::Error initGfx(Context *ctx, const InitParams&) noexcept; ox::Error initGfx(Context *ctx, InitParams const&) noexcept;
} }

View File

@ -15,7 +15,7 @@ namespace ox {
using namespace nostalgia::core; using namespace nostalgia::core;
void panic(const char *file, int line, const char *panicMsg, const ox::Error &err) noexcept { void panic(const char *file, int line, const char *panicMsg, ox::Error const&err) noexcept {
oxIgnoreError(initGfx(nullptr, {})); oxIgnoreError(initGfx(nullptr, {}));
oxIgnoreError(initConsole(nullptr)); oxIgnoreError(initConsole(nullptr));
// enable only BG 0 // enable only BG 0

View File

@ -16,7 +16,7 @@ GlContext::~GlContext() noexcept {
shutdownGfx(*this); shutdownGfx(*this);
} }
ox::Result<ox::UniquePtr<Context>> init(turbine::Context *tctx, const InitParams &params) noexcept { ox::Result<ox::UniquePtr<Context>> init(turbine::Context *tctx, InitParams const&params) noexcept {
auto ctx = ox::make_unique<GlContext>(*tctx); auto ctx = ox::make_unique<GlContext>(*tctx);
oxReturnError(initGfx(ctx.get(), params)); oxReturnError(initGfx(ctx.get(), params));
return ox::UPtr<Context>(ctx.release()); return ox::UPtr<Context>(ctx.release());

View File

@ -108,7 +108,7 @@ static void setSpriteBufferObject(
memcpy(ebo, elms.data(), sizeof(elms)); memcpy(ebo, elms.data(), sizeof(elms));
} }
static void setTileBufferObject( void setTileBufferObject(
unsigned vi, unsigned vi,
float x, float x,
float y, float y,
@ -204,8 +204,9 @@ static void initBackgroundBufferset(
glVertexAttribPointer(posAttr, 2, GL_FLOAT, GL_FALSE, BgVertexVboRowLength * sizeof(float), nullptr); glVertexAttribPointer(posAttr, 2, GL_FLOAT, GL_FALSE, BgVertexVboRowLength * sizeof(float), nullptr);
auto texCoordAttr = static_cast<GLuint>(glGetAttribLocation(shader, "vTexCoord")); auto texCoordAttr = static_cast<GLuint>(glGetAttribLocation(shader, "vTexCoord"));
glEnableVertexAttribArray(texCoordAttr); glEnableVertexAttribArray(texCoordAttr);
glVertexAttribPointer(texCoordAttr, 2, GL_FLOAT, GL_FALSE, BgVertexVboRowLength * sizeof(float), glVertexAttribPointer(
reinterpret_cast<void*>(2 * sizeof(float))); texCoordAttr, 2, GL_FLOAT, GL_FALSE, BgVertexVboRowLength * sizeof(bg->vertices[0]),
reinterpret_cast<void*>(2 * sizeof(bg->vertices[0])));
} }
static glutils::GLTexture loadTexture( static glutils::GLTexture loadTexture(
@ -283,7 +284,7 @@ static void drawSprites(GlContext *gctx, ox::Size const&renderSz) noexcept {
static void loadPalette( static void loadPalette(
GLuint shaderPgrm, GLuint shaderPgrm,
const Palette &pal, Palette const&pal,
bool firstIsTransparent = false) noexcept { bool firstIsTransparent = false) noexcept {
static constexpr std::size_t ColorCnt = 256; static constexpr std::size_t ColorCnt = 256;
ox::Array<GLfloat, ColorCnt * 4> palette{}; ox::Array<GLfloat, ColorCnt * 4> palette{};
@ -301,11 +302,11 @@ static void loadPalette(
glUniform4fv(uniformPalette, ColorCnt, palette.data()); glUniform4fv(uniformPalette, ColorCnt, palette.data());
} }
static void loadBgPalette(GlContext *gctx, const Palette &pal) noexcept { static void loadBgPalette(GlContext *gctx, Palette const&pal) noexcept {
loadPalette(gctx->bgShader, pal); loadPalette(gctx->bgShader, pal);
} }
static void loadSpritePalette(GlContext *gctx, const Palette &pal) noexcept { static void loadSpritePalette(GlContext *gctx, Palette const&pal) noexcept {
loadPalette(gctx->spriteShader, pal, true); loadPalette(gctx->spriteShader, pal, true);
} }
@ -332,7 +333,7 @@ static void loadSpriteTexture(
ox::Error initGfx( ox::Error initGfx(
Context *ctx, Context *ctx,
const InitParams &initParams) noexcept { InitParams const&initParams) noexcept {
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
const auto bgVshad = ox::sfmt(renderer::bgvshadTmpl, glutils::GlslVersion); const auto bgVshad = ox::sfmt(renderer::bgvshadTmpl, glutils::GlslVersion);
@ -364,8 +365,8 @@ struct TileSheetData {
int height = 0; int height = 0;
}; };
ox::Result<TileSheetData> loadTileSheet( static ox::Result<TileSheetData> loadTileSheet(
Context *ctx, const CompactTileSheet &tilesheet) noexcept { Context *ctx, CompactTileSheet const&tilesheet) noexcept {
auto &gctx = static_cast<GlContext&>(*ctx); auto &gctx = static_cast<GlContext&>(*ctx);
const unsigned bytesPerTile = tilesheet.bpp == 8 ? PixelsPerTile : PixelsPerTile / 2; const unsigned bytesPerTile = tilesheet.bpp == 8 ? PixelsPerTile : PixelsPerTile / 2;
const auto tiles = tilesheet.pixels.size() / bytesPerTile; const auto tiles = tilesheet.pixels.size() / bytesPerTile;
@ -391,8 +392,8 @@ ox::Result<TileSheetData> loadTileSheet(
ox::Error loadBgTileSheet( ox::Error loadBgTileSheet(
Context *ctx, Context *ctx,
unsigned cbb, unsigned cbb,
const ox::FileAddress &tilesheetAddr, ox::FileAddress const&tilesheetAddr,
const ox::FileAddress &paletteAddr) noexcept { ox::FileAddress const&paletteAddr) noexcept {
auto &gctx = static_cast<GlContext&>(*ctx); auto &gctx = static_cast<GlContext&>(*ctx);
auto &kctx = gctx.turbineCtx.keelCtx; auto &kctx = gctx.turbineCtx.keelCtx;
oxRequire(tilesheet, readObj<CompactTileSheet>(&kctx, tilesheetAddr)); oxRequire(tilesheet, readObj<CompactTileSheet>(&kctx, tilesheetAddr));
@ -405,8 +406,8 @@ ox::Error loadBgTileSheet(
ox::Error loadSpriteTileSheet( ox::Error loadSpriteTileSheet(
Context *ctx, Context *ctx,
const ox::FileAddress &tilesheetAddr, ox::FileAddress const&tilesheetAddr,
const ox::FileAddress &paletteAddr) noexcept { ox::FileAddress const&paletteAddr) noexcept {
auto &gctx = static_cast<GlContext&>(*ctx); auto &gctx = static_cast<GlContext&>(*ctx);
auto &kctx = gctx.turbineCtx.keelCtx; auto &kctx = gctx.turbineCtx.keelCtx;
oxRequire(tilesheet, readObj<CompactTileSheet>(&kctx, tilesheetAddr)); oxRequire(tilesheet, readObj<CompactTileSheet>(&kctx, tilesheetAddr));
@ -428,7 +429,12 @@ ox::Error initConsole(Context *ctx) noexcept {
void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept { void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept {
const auto col = static_cast<unsigned>(column); const auto col = static_cast<unsigned>(column);
for (auto i = 0u; i < str.bytes(); ++i) { for (auto i = 0u; i < str.bytes(); ++i) {
setTile(ctx, 0, static_cast<int>(col + i), row, static_cast<uint8_t>(charMap[static_cast<uint8_t>(str[i])])); setTile(
ctx,
0,
static_cast<int>(col + i),
row,
static_cast<uint8_t>(charMap[static_cast<uint8_t>(str[i])]));
} }
} }

View File

@ -63,6 +63,6 @@ class Drawer: public turbine::gl::Drawer {
} }
namespace nostalgia::core { namespace nostalgia::core {
ox::Error initGfx(Context *ctx, const InitParams&) noexcept; ox::Error initGfx(Context *ctx, InitParams const&) noexcept;
void shutdownGfx(Context &ctx) noexcept; void shutdownGfx(Context &ctx) noexcept;
} }