[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])
*/
ox::Error loadBgTileSheet(Context *ctx, unsigned cbb, const ox::FileAddress &tilesheetAddr,
const ox::FileAddress &paletteAddr = nullptr) noexcept;
ox::Error loadBgTileSheet(
Context *ctx,
unsigned cbb,
ox::FileAddress const&tilesheetAddr,
ox::FileAddress const&paletteAddr = nullptr) noexcept;
ox::Error loadSpriteTileSheet(Context *ctx,
const ox::FileAddress &tilesheetAddr,
const ox::FileAddress &paletteAddr) noexcept;
ox::Error loadSpriteTileSheet(
Context *ctx,
ox::FileAddress const&tilesheetAddr,
ox::FileAddress const&paletteAddr) 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,
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) {
}
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);
oxReturnError(initGfx(ctx.get(), params));
return ox::UPtr<Context>(ctx.release());

View File

@ -15,7 +15,7 @@ struct GbaContext: public core::Context {
explicit GbaContext(turbine::Context *tctx) noexcept;
[[nodiscard]]
const auto &rom() const noexcept {
auto const&rom() const noexcept {
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);
}
ox::Error initGfx(Context*, const InitParams&) noexcept {
ox::Error initGfx(Context*, InitParams const&) noexcept {
for (auto bgCtl = &REG_BG0CTL; bgCtl <= &REG_BG3CTL; bgCtl += 2) {
teagba::bgSetSbb(bgCtl, 28);
}
@ -108,8 +108,8 @@ void setBgCbb(Context*, unsigned bgIdx, unsigned cbb) noexcept {
static ox::Error loadBgTileSheet(
const ox::MemFS &rom,
unsigned cbb,
const ox::FileAddress &tilesheetAddr,
const ox::FileAddress &paletteAddr) noexcept {
ox::FileAddress const&tilesheetAddr,
ox::FileAddress const&paletteAddr) noexcept {
oxRequire(tsStat, rom.stat(tilesheetAddr));
oxRequire(ts, rom.directAccess(tilesheetAddr));
GbaTileMapTarget target;
@ -136,8 +136,8 @@ static ox::Error loadBgTileSheet(
ox::Error loadBgTileSheet(
Context *ctx,
unsigned cbb,
const ox::FileAddress &tilesheetAddr,
const ox::FileAddress &paletteAddr) noexcept {
ox::FileAddress const&tilesheetAddr,
ox::FileAddress const&paletteAddr) noexcept {
auto &gctx = static_cast<GbaContext&>(*ctx);
auto &rom = static_cast<const ox::MemFS&>(gctx.rom());
return loadBgTileSheet(rom, cbb, tilesheetAddr, paletteAddr);
@ -145,8 +145,8 @@ ox::Error loadBgTileSheet(
ox::Error loadSpriteTileSheet(
Context *ctx,
const ox::FileAddress &tilesheetAddr,
const ox::FileAddress &paletteAddr) noexcept {
ox::FileAddress const&tilesheetAddr,
ox::FileAddress const&paletteAddr) noexcept {
auto &gctx = static_cast<GbaContext&>(*ctx);
auto &rom = static_cast<const ox::MemFS&>(gctx.rom());
oxRequire(tsStat, gctx.rom().stat(tilesheetAddr));
@ -164,7 +164,7 @@ ox::Error loadSpriteTileSheet(
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 &rom = static_cast<const ox::MemFS&>(gctx.rom());
GbaPaletteTarget target;
@ -175,7 +175,7 @@ ox::Error loadBgPalette(Context *ctx, unsigned, const ox::FileAddress &paletteAd
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 &rom = static_cast<const ox::MemFS&>(gctx.rom());
GbaPaletteTarget target;

View File

@ -7,5 +7,5 @@
#include <nostalgia/core/context.hpp>
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;
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(initConsole(nullptr));
// enable only BG 0

View File

@ -16,7 +16,7 @@ GlContext::~GlContext() noexcept {
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);
oxReturnError(initGfx(ctx.get(), params));
return ox::UPtr<Context>(ctx.release());

View File

@ -108,7 +108,7 @@ static void setSpriteBufferObject(
memcpy(ebo, elms.data(), sizeof(elms));
}
static void setTileBufferObject(
void setTileBufferObject(
unsigned vi,
float x,
float y,
@ -124,10 +124,10 @@ static void setTileBufferObject(
y += 1.0f - ymod;
const auto textureRowf = static_cast<float>(textureRow);
const ox::Array<float, BgVertexVboLength> vertices {
x, y, 0, textureRowf + 1, // bottom left
x, y, 0, textureRowf + 1, // bottom left
x + xmod, y, 1, textureRowf + 1, // bottom right
x + xmod, y + ymod, 1, textureRowf + 0, // top right
x, y + ymod, 0, textureRowf + 0, // top left
x, y + ymod, 0, textureRowf + 0, // top left
};
memcpy(vbo, vertices.data(), sizeof(vertices));
const ox::Array<GLuint, BgVertexEboLength> elms {
@ -204,8 +204,9 @@ static void initBackgroundBufferset(
glVertexAttribPointer(posAttr, 2, GL_FLOAT, GL_FALSE, BgVertexVboRowLength * sizeof(float), nullptr);
auto texCoordAttr = static_cast<GLuint>(glGetAttribLocation(shader, "vTexCoord"));
glEnableVertexAttribArray(texCoordAttr);
glVertexAttribPointer(texCoordAttr, 2, GL_FLOAT, GL_FALSE, BgVertexVboRowLength * sizeof(float),
reinterpret_cast<void*>(2 * sizeof(float)));
glVertexAttribPointer(
texCoordAttr, 2, GL_FLOAT, GL_FALSE, BgVertexVboRowLength * sizeof(bg->vertices[0]),
reinterpret_cast<void*>(2 * sizeof(bg->vertices[0])));
}
static glutils::GLTexture loadTexture(
@ -283,7 +284,7 @@ static void drawSprites(GlContext *gctx, ox::Size const&renderSz) noexcept {
static void loadPalette(
GLuint shaderPgrm,
const Palette &pal,
Palette const&pal,
bool firstIsTransparent = false) noexcept {
static constexpr std::size_t ColorCnt = 256;
ox::Array<GLfloat, ColorCnt * 4> palette{};
@ -301,11 +302,11 @@ static void loadPalette(
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);
}
static void loadSpritePalette(GlContext *gctx, const Palette &pal) noexcept {
static void loadSpritePalette(GlContext *gctx, Palette const&pal) noexcept {
loadPalette(gctx->spriteShader, pal, true);
}
@ -332,7 +333,7 @@ static void loadSpriteTexture(
ox::Error initGfx(
Context *ctx,
const InitParams &initParams) noexcept {
InitParams const&initParams) noexcept {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
const auto bgVshad = ox::sfmt(renderer::bgvshadTmpl, glutils::GlslVersion);
@ -364,8 +365,8 @@ struct TileSheetData {
int height = 0;
};
ox::Result<TileSheetData> loadTileSheet(
Context *ctx, const CompactTileSheet &tilesheet) noexcept {
static ox::Result<TileSheetData> loadTileSheet(
Context *ctx, CompactTileSheet const&tilesheet) noexcept {
auto &gctx = static_cast<GlContext&>(*ctx);
const unsigned bytesPerTile = tilesheet.bpp == 8 ? PixelsPerTile : PixelsPerTile / 2;
const auto tiles = tilesheet.pixels.size() / bytesPerTile;
@ -391,8 +392,8 @@ ox::Result<TileSheetData> loadTileSheet(
ox::Error loadBgTileSheet(
Context *ctx,
unsigned cbb,
const ox::FileAddress &tilesheetAddr,
const ox::FileAddress &paletteAddr) noexcept {
ox::FileAddress const&tilesheetAddr,
ox::FileAddress const&paletteAddr) noexcept {
auto &gctx = static_cast<GlContext&>(*ctx);
auto &kctx = gctx.turbineCtx.keelCtx;
oxRequire(tilesheet, readObj<CompactTileSheet>(&kctx, tilesheetAddr));
@ -405,8 +406,8 @@ ox::Error loadBgTileSheet(
ox::Error loadSpriteTileSheet(
Context *ctx,
const ox::FileAddress &tilesheetAddr,
const ox::FileAddress &paletteAddr) noexcept {
ox::FileAddress const&tilesheetAddr,
ox::FileAddress const&paletteAddr) noexcept {
auto &gctx = static_cast<GlContext&>(*ctx);
auto &kctx = gctx.turbineCtx.keelCtx;
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 {
const auto col = static_cast<unsigned>(column);
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 {
ox::Error initGfx(Context *ctx, const InitParams&) noexcept;
ox::Error initGfx(Context *ctx, InitParams const&) noexcept;
void shutdownGfx(Context &ctx) noexcept;
}