[keel,nostalgia] Make core calls take Context references instead of pointers
This commit is contained in:
parent
72c130d8a9
commit
453e08497d
@ -103,11 +103,7 @@ class AssetRef: public ox::SignalHandler {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
constexpr const T &operator*() const & noexcept {
|
||||
return *m_ctr->get();
|
||||
}
|
||||
|
||||
constexpr const T &&operator*() const && noexcept {
|
||||
constexpr const T &operator*() const noexcept {
|
||||
return *m_ctr->get();
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ class Context {
|
||||
|
||||
};
|
||||
|
||||
ox::Result<ox::UniquePtr<Context>> init(turbine::Context *tctx, const InitParams& = {}) noexcept;
|
||||
ox::Result<ox::UniquePtr<Context>> init(turbine::Context &tctx, InitParams const& = {}) noexcept;
|
||||
|
||||
}
|
||||
|
||||
|
@ -36,44 +36,44 @@ oxModelBegin(Sprite)
|
||||
oxModelEnd()
|
||||
|
||||
[[nodiscard]]
|
||||
uint8_t bgStatus(Context *ctx) noexcept;
|
||||
uint8_t bgStatus(Context &ctx) noexcept;
|
||||
|
||||
void setBgStatus(Context *ctx, uint32_t status) noexcept;
|
||||
void setBgStatus(Context &ctx, uint32_t status) noexcept;
|
||||
|
||||
bool bgStatus(Context *ctx, unsigned bg) noexcept;
|
||||
bool bgStatus(Context &ctx, unsigned bg) noexcept;
|
||||
|
||||
void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept;
|
||||
void setBgStatus(Context &ctx, unsigned bg, bool status) noexcept;
|
||||
|
||||
void setBgCbb(Context *ctx, unsigned bgIdx, unsigned cbb) noexcept;
|
||||
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,
|
||||
Context &ctx,
|
||||
unsigned cbb,
|
||||
ox::FileAddress const&tilesheetAddr,
|
||||
ox::FileAddress const&paletteAddr = nullptr) noexcept;
|
||||
|
||||
ox::Error loadSpriteTileSheet(
|
||||
Context *ctx,
|
||||
Context &ctx,
|
||||
ox::FileAddress const&tilesheetAddr,
|
||||
ox::FileAddress const&paletteAddr) noexcept;
|
||||
|
||||
ox::Error initConsole(Context *ctx) noexcept;
|
||||
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;
|
||||
|
||||
void setTile(Context *ctx, unsigned bgIdx, int column, int row, uint8_t tile) noexcept;
|
||||
void setTile(Context &ctx, unsigned bgIdx, int column, int row, uint8_t tile) noexcept;
|
||||
|
||||
void clearTileLayer(Context *ctx, unsigned bgIdx) noexcept;
|
||||
void clearTileLayer(Context &ctx, unsigned bgIdx) noexcept;
|
||||
|
||||
void hideSprite(Context *ctx, unsigned) noexcept;
|
||||
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;
|
||||
|
||||
void setSprite(Context *ctx, Sprite const&s) noexcept;
|
||||
void setSprite(Context &ctx, Sprite const&s) noexcept;
|
||||
|
||||
}
|
||||
|
||||
|
@ -11,12 +11,12 @@ namespace nostalgia::core {
|
||||
GbaContext::GbaContext(turbine::Context *tctx) noexcept: turbineCtx(tctx) {
|
||||
}
|
||||
|
||||
ox::Error initGfx(Context *ctx, InitParams const&) noexcept;
|
||||
ox::Error initGfx(Context &ctx, InitParams const&) noexcept;
|
||||
|
||||
ox::Result<ox::UniquePtr<Context>> init(turbine::Context *tctx, InitParams const¶ms) noexcept {
|
||||
auto ctx = ox::make_unique<GbaContext>(tctx);
|
||||
oxReturnError(initGfx(ctx.get(), params));
|
||||
return ox::UPtr<Context>(ctx.release());
|
||||
ox::Result<ox::UniquePtr<Context>> init(turbine::Context &tctx, InitParams const¶ms) noexcept {
|
||||
auto ctx = ox::make_unique<GbaContext>(&tctx);
|
||||
oxReturnError(initGfx(*ctx, params));
|
||||
return ox::UPtr<Context>(std::move(ctx));
|
||||
}
|
||||
|
||||
}
|
@ -71,42 +71,43 @@ 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*, InitParams const&) noexcept {
|
||||
ox::Error initGfx(Context&, InitParams const&) noexcept {
|
||||
for (auto bgCtl = ®_BG0CTL; bgCtl <= ®_BG3CTL; bgCtl += 2) {
|
||||
teagba::bgSetSbb(bgCtl, 28);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void shutdownGfx(Context*) noexcept {
|
||||
}
|
||||
|
||||
uint8_t bgStatus(Context*) noexcept {
|
||||
uint8_t bgStatus(Context&) noexcept {
|
||||
return (REG_DISPCTL >> 8u) & 0b1111u;
|
||||
}
|
||||
|
||||
void setBgStatus(Context*, uint32_t status) noexcept {
|
||||
void setBgStatus(Context&, uint32_t status) noexcept {
|
||||
constexpr auto BgStatus = 8;
|
||||
REG_DISPCTL = (REG_DISPCTL & ~0b111100000000u) | status << BgStatus;
|
||||
}
|
||||
|
||||
bool bgStatus(Context*, unsigned bg) noexcept {
|
||||
bool bgStatus(Context&, unsigned bg) noexcept {
|
||||
return (REG_DISPCTL >> (8 + bg)) & 1;
|
||||
}
|
||||
|
||||
void setBgStatus(Context*, unsigned bg, bool status) noexcept {
|
||||
void setBgStatus(Context&, unsigned bg, bool status) noexcept {
|
||||
constexpr auto Bg0Status = 8;
|
||||
const auto mask = static_cast<uint32_t>(status) << (Bg0Status + bg);
|
||||
REG_DISPCTL = REG_DISPCTL | ((REG_DISPCTL & ~mask) | mask);
|
||||
}
|
||||
|
||||
void setBgCbb(Context*, unsigned bgIdx, unsigned cbb) noexcept {
|
||||
static void setBgCbb(Context*, unsigned bgIdx, unsigned cbb) noexcept {
|
||||
auto &bgCtl = regBgCtl(bgIdx);
|
||||
const auto &cbbData = g_cbbData[cbb];
|
||||
teagba::bgSetBpp(&bgCtl, cbbData.bpp);
|
||||
teagba::bgSetCbb(&bgCtl, cbb);
|
||||
}
|
||||
|
||||
void setBgCbb(Context&, unsigned bgIdx, unsigned cbb) noexcept {
|
||||
setBgCbb(nullptr, bgIdx, cbb);
|
||||
}
|
||||
|
||||
static ox::Error loadBgTileSheet(
|
||||
const ox::MemFS &rom,
|
||||
unsigned cbb,
|
||||
@ -136,20 +137,20 @@ static ox::Error loadBgTileSheet(
|
||||
}
|
||||
|
||||
ox::Error loadBgTileSheet(
|
||||
Context *ctx,
|
||||
Context &ctx,
|
||||
unsigned cbb,
|
||||
ox::FileAddress const&tilesheetAddr,
|
||||
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());
|
||||
return loadBgTileSheet(rom, cbb, tilesheetAddr, paletteAddr);
|
||||
}
|
||||
|
||||
ox::Error loadSpriteTileSheet(
|
||||
Context *ctx,
|
||||
Context &ctx,
|
||||
ox::FileAddress const&tilesheetAddr,
|
||||
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());
|
||||
oxRequire(tsStat, gctx.rom().stat(tilesheetAddr));
|
||||
oxRequire(ts, rom.directAccess(tilesheetAddr));
|
||||
@ -166,8 +167,8 @@ ox::Error loadSpriteTileSheet(
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error loadBgPalette(Context *ctx, unsigned, ox::FileAddress const&paletteAddr) noexcept {
|
||||
auto &gctx = static_cast<GbaContext&>(*ctx);
|
||||
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;
|
||||
target.palette = MEM_BG_PALETTE;
|
||||
@ -177,8 +178,8 @@ ox::Error loadBgPalette(Context *ctx, unsigned, ox::FileAddress const&paletteAdd
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error loadSpritePalette(Context *ctx, unsigned cbb, ox::FileAddress const&paletteAddr) noexcept {
|
||||
auto &gctx = static_cast<GbaContext&>(*ctx);
|
||||
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;
|
||||
target.palette = &MEM_SPRITE_PALETTE[cbb];
|
||||
@ -188,25 +189,16 @@ ox::Error loadSpritePalette(Context *ctx, unsigned cbb, ox::FileAddress const&pa
|
||||
return {};
|
||||
}
|
||||
|
||||
// Do NOT rely on Context in the GBA version of this function.
|
||||
ox::Error initConsole(Context *ctx) noexcept {
|
||||
ox::Error initConsole(Context &ctx) noexcept {
|
||||
constexpr ox::FileAddress TilesheetAddr("/TileSheets/Charset.ng");
|
||||
constexpr ox::FileAddress PaletteAddr("/Palettes/Charset.npal");
|
||||
setBgStatus(ctx, 0b0001);
|
||||
if (!ctx) {
|
||||
oxRequire(rom, keel::loadRom());
|
||||
const ox::FileSystem32 romFs(ox::FileStore32(rom, 32 * ox::units::MB));
|
||||
oxReturnError(loadBgTileSheet(romFs, 0, TilesheetAddr, PaletteAddr));
|
||||
setBgCbb(nullptr, 0, 0);
|
||||
return {};
|
||||
} else {
|
||||
oxReturnError(loadBgTileSheet(ctx, 0, TilesheetAddr, PaletteAddr));
|
||||
setBgCbb(ctx, 0, 0);
|
||||
return {};
|
||||
}
|
||||
oxReturnError(loadBgTileSheet(ctx, 0, TilesheetAddr, PaletteAddr));
|
||||
setBgCbb(ctx, 0, 0);
|
||||
return {};
|
||||
}
|
||||
|
||||
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);
|
||||
for (auto i = 0u; i < str.bytes(); i++) {
|
||||
const auto c = charMap[static_cast<std::size_t>(str[i])];
|
||||
@ -214,18 +206,18 @@ void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
void setTile(Context*, unsigned bgIdx, int column, int row, uint8_t tile) noexcept {
|
||||
void setTile(Context&, unsigned bgIdx, int column, int row, uint8_t tile) noexcept {
|
||||
const auto tileIdx = static_cast<std::size_t>(row * GbaTileColumns + column);
|
||||
MEM_BG_MAP[bgIdx][tileIdx] = tile;
|
||||
}
|
||||
|
||||
// Do NOT use Context in the GBA version of this function.
|
||||
void clearTileLayer(Context*, unsigned bgIdx) noexcept {
|
||||
void clearTileLayer(Context&, unsigned bgIdx) noexcept {
|
||||
memset(MEM_BG_MAP[bgIdx].data(), 0, GbaTileRows * GbaTileColumns);
|
||||
}
|
||||
|
||||
[[maybe_unused]]
|
||||
void hideSprite(Context*, unsigned idx) noexcept {
|
||||
void hideSprite(Context&, unsigned idx) noexcept {
|
||||
//oxAssert(g_spriteUpdates < config::GbaSpriteBufferLen, "Sprite update buffer overflow");
|
||||
teagba::GbaSpriteAttrUpdate oa;
|
||||
oa.attr0 = 2 << 8;
|
||||
@ -233,7 +225,7 @@ void hideSprite(Context*, unsigned idx) noexcept {
|
||||
teagba::addSpriteUpdate(oa);
|
||||
}
|
||||
|
||||
void setSprite(Context*,
|
||||
void setSprite(Context&,
|
||||
unsigned idx,
|
||||
int x,
|
||||
int y,
|
||||
|
@ -7,5 +7,5 @@
|
||||
#include <nostalgia/core/context.hpp>
|
||||
|
||||
namespace nostalgia::core {
|
||||
ox::Error initGfx(Context *ctx, InitParams const&) noexcept;
|
||||
ox::Error initGfx(Context &ctx, InitParams const&) noexcept;
|
||||
}
|
||||
|
@ -3,33 +3,44 @@
|
||||
*/
|
||||
|
||||
|
||||
#include <nostalgia/core/core.hpp>
|
||||
#include <ox/std/def.hpp>
|
||||
|
||||
#include <keel/media.hpp>
|
||||
#include <turbine/turbine.hpp>
|
||||
|
||||
#include <teagba/addresses.hpp>
|
||||
#include <teagba/bios.hpp>
|
||||
#include <teagba/gfx.hpp>
|
||||
|
||||
#include <nostalgia/core/core.hpp>
|
||||
|
||||
#include "gfx.hpp"
|
||||
|
||||
#define HEAP_BEGIN (reinterpret_cast<char*>(MEM_EWRAM_BEGIN))
|
||||
#define HEAP_SIZE ((MEM_EWRAM_END - MEM_EWRAM_BEGIN) / 2)
|
||||
#define HEAP_END (reinterpret_cast<char*>(MEM_EWRAM_BEGIN + HEAP_SIZE))
|
||||
|
||||
namespace ox {
|
||||
|
||||
using namespace nostalgia::core;
|
||||
|
||||
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
|
||||
REG_DISPCTL = teagba::DispCtl_Bg0;
|
||||
clearTileLayer(nullptr, 0);
|
||||
// reset heap to make sure we have enough memory to allocate context data
|
||||
ox::heapmgr::initHeap(HEAP_BEGIN, HEAP_END);
|
||||
auto tctx = turbine::init(keel::loadRomFs("").unwrap(), "Nostalgia").unwrap();
|
||||
auto ctx = init(*tctx).unwrap();
|
||||
oxIgnoreError(initGfx(*ctx, {}));
|
||||
oxIgnoreError(initConsole(*ctx));
|
||||
setBgStatus(*ctx, 0, true);
|
||||
clearTileLayer(*ctx, 0);
|
||||
ox::BString<23> serr = "Error code: ";
|
||||
serr += static_cast<int64_t>(err);
|
||||
puts(nullptr, 32 + 1, 1, "SADNESS...");
|
||||
puts(nullptr, 32 + 1, 4, "UNEXPECTED STATE:");
|
||||
puts(nullptr, 32 + 2, 6, panicMsg);
|
||||
puts(*ctx, 32 + 1, 1, "SADNESS...");
|
||||
puts(*ctx, 32 + 1, 4, "UNEXPECTED STATE:");
|
||||
puts(*ctx, 32 + 2, 6, panicMsg);
|
||||
if (err) {
|
||||
puts(nullptr, 32 + 2, 8, serr);
|
||||
puts(*ctx, 32 + 2, 8, serr);
|
||||
}
|
||||
puts(nullptr, 32 + 1, 15, "PLEASE RESTART THE SYSTEM");
|
||||
puts(*ctx, 32 + 1, 15, "PLEASE RESTART THE SYSTEM");
|
||||
// print to terminal if in mGBA
|
||||
oxErrf("\033[31;1;1mPANIC:\033[0m [{}:{}]: {}\n", file, line, panicMsg);
|
||||
if (err.msg) {
|
||||
|
@ -137,7 +137,7 @@ ox::Array<char, 128> charMap = {
|
||||
0, // ~
|
||||
};
|
||||
|
||||
void setSprite(Context *c, const Sprite &s) noexcept {
|
||||
void setSprite(Context &c, const Sprite &s) noexcept {
|
||||
setSprite(c, s.idx, s.x, s.y, s.tileIdx, s.spriteShape, s.spriteSize, s.flipX);
|
||||
}
|
||||
|
||||
|
@ -16,9 +16,9 @@ GlContext::~GlContext() noexcept {
|
||||
shutdownGfx(*this);
|
||||
}
|
||||
|
||||
ox::Result<ox::UniquePtr<Context>> init(turbine::Context *tctx, InitParams const¶ms) noexcept {
|
||||
auto ctx = ox::make_unique<GlContext>(*tctx);
|
||||
oxReturnError(initGfx(ctx.get(), params));
|
||||
ox::Result<ox::UniquePtr<Context>> init(turbine::Context &tctx, InitParams const¶ms) noexcept {
|
||||
auto ctx = ox::make_unique<GlContext>(tctx);
|
||||
oxReturnError(initGfx(*ctx, params));
|
||||
return ox::UPtr<Context>(ctx.release());
|
||||
}
|
||||
|
||||
|
@ -368,7 +368,7 @@ static void loadSpriteTexture(
|
||||
}
|
||||
|
||||
ox::Error initGfx(
|
||||
Context *ctx,
|
||||
Context &ctx,
|
||||
InitParams const&initParams) noexcept {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
@ -376,7 +376,7 @@ ox::Error initGfx(
|
||||
const auto bgFshad = ox::sfmt(renderer::bgfshadTmpl, glutils::GlslVersion);
|
||||
const auto spriteVshad = ox::sfmt(renderer::spritevshadTmpl, glutils::GlslVersion);
|
||||
const auto spriteFshad = ox::sfmt(renderer::spritefshadTmpl, glutils::GlslVersion);
|
||||
auto &gctx = glctx(*ctx);
|
||||
auto &gctx = glctx(ctx);
|
||||
oxReturnError(glutils::buildShaderProgram(bgVshad.c_str(), bgFshad.c_str()).moveTo(&gctx.bgShader));
|
||||
oxReturnError(
|
||||
glutils::buildShaderProgram(spriteVshad.c_str(), spriteFshad.c_str()).moveTo(&gctx.spriteShader));
|
||||
@ -430,15 +430,15 @@ static ox::Result<TileSheetData> loadTileSheet(
|
||||
}
|
||||
|
||||
ox::Error loadBgTileSheet(
|
||||
Context *ctx,
|
||||
Context &ctx,
|
||||
uint_t cbb,
|
||||
ox::FileAddress const&tilesheetAddr,
|
||||
ox::FileAddress const&paletteAddr) noexcept {
|
||||
auto &gctx = glctx(*ctx);
|
||||
auto &gctx = glctx(ctx);
|
||||
auto &kctx = gctx.turbineCtx.keelCtx;
|
||||
oxRequire(tilesheet, readObj<CompactTileSheet>(kctx, tilesheetAddr));
|
||||
oxRequire(palette, readObj<Palette>(kctx, paletteAddr ? paletteAddr : tilesheet->defaultPalette));
|
||||
oxRequire(tsd, loadTileSheet(*ctx, *tilesheet).to([](TileSheetData const&t) -> TileSheetData {
|
||||
oxRequire(tsd, loadTileSheet(ctx, *tilesheet).to([](TileSheetData const&t) -> TileSheetData {
|
||||
return {
|
||||
.pixels = resizeTileSheetData(t.pixels, t.size(), Scale),
|
||||
.width = t.width * Scale,
|
||||
@ -451,20 +451,20 @@ ox::Error loadBgTileSheet(
|
||||
}
|
||||
|
||||
ox::Error loadSpriteTileSheet(
|
||||
Context *ctx,
|
||||
Context &ctx,
|
||||
ox::FileAddress const&tilesheetAddr,
|
||||
ox::FileAddress const&paletteAddr) noexcept {
|
||||
auto &gctx = glctx(*ctx);
|
||||
auto &gctx = glctx(ctx);
|
||||
auto &kctx = gctx.turbineCtx.keelCtx;
|
||||
oxRequire(tilesheet, readObj<CompactTileSheet>(kctx, tilesheetAddr));
|
||||
oxRequire(palette, readObj<Palette>(kctx, paletteAddr ? paletteAddr : tilesheet->defaultPalette));
|
||||
oxRequire(tsd, loadTileSheet(*ctx, *tilesheet));
|
||||
oxRequire(tsd, loadTileSheet(ctx, *tilesheet));
|
||||
renderer::loadSpriteTexture(gctx, tsd.pixels.data(), tsd.width, tsd.height);
|
||||
renderer::loadSpritePalette(gctx, *palette);
|
||||
return {};
|
||||
}
|
||||
|
||||
ox::Error initConsole(Context *ctx) noexcept {
|
||||
ox::Error initConsole(Context &ctx) noexcept {
|
||||
constexpr ox::FileAddress TilesheetAddr("/TileSheets/Charset.ng");
|
||||
constexpr ox::FileAddress PaletteAddr("/Palettes/Charset.npal");
|
||||
setBgStatus(ctx, 0b0001);
|
||||
@ -472,7 +472,7 @@ ox::Error initConsole(Context *ctx) noexcept {
|
||||
return loadBgTileSheet(ctx, 0, TilesheetAddr, PaletteAddr);
|
||||
}
|
||||
|
||||
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<uint_t>(column);
|
||||
for (auto i = 0u; i < str.bytes(); ++i) {
|
||||
setTile(
|
||||
@ -484,14 +484,14 @@ void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept {
|
||||
}
|
||||
}
|
||||
|
||||
void setBgCbb(Context *ctx, uint_t bgIdx, uint_t cbbIdx) noexcept {
|
||||
auto &gctx = glctx(*ctx);
|
||||
void setBgCbb(Context &ctx, uint_t bgIdx, uint_t cbbIdx) noexcept {
|
||||
auto &gctx = glctx(ctx);
|
||||
auto &bg = gctx.backgrounds[bgIdx];
|
||||
bg.cbbIdx = cbbIdx;
|
||||
}
|
||||
|
||||
uint8_t bgStatus(Context *ctx) noexcept {
|
||||
const auto &gctx = glctx(*ctx);
|
||||
uint8_t bgStatus(Context &ctx) noexcept {
|
||||
const auto &gctx = glctx(ctx);
|
||||
uint8_t out = 0;
|
||||
for (uint_t i = 0; i < gctx.cbbs.size(); ++i) {
|
||||
out |= static_cast<uint8_t>(static_cast<uint_t>(gctx.backgrounds[i].enabled) << i);
|
||||
@ -499,33 +499,33 @@ uint8_t bgStatus(Context *ctx) noexcept {
|
||||
return out;
|
||||
}
|
||||
|
||||
void setBgStatus(Context *ctx, uint32_t status) noexcept {
|
||||
auto &gctx = glctx(*ctx);
|
||||
void setBgStatus(Context &ctx, uint32_t status) noexcept {
|
||||
auto &gctx = glctx(ctx);
|
||||
for (uint_t i = 0; i < gctx.cbbs.size(); ++i) {
|
||||
gctx.backgrounds[i].enabled = (status >> i) & 1;
|
||||
}
|
||||
}
|
||||
|
||||
bool bgStatus(Context *ctx, uint_t bg) noexcept {
|
||||
const auto &gctx = glctx(*ctx);
|
||||
bool bgStatus(Context &ctx, uint_t bg) noexcept {
|
||||
const auto &gctx = glctx(ctx);
|
||||
return gctx.backgrounds[bg].enabled;
|
||||
}
|
||||
|
||||
void setBgStatus(Context *ctx, uint_t bg, bool status) noexcept {
|
||||
auto &gctx = glctx(*ctx);
|
||||
void setBgStatus(Context &ctx, uint_t bg, bool status) noexcept {
|
||||
auto &gctx = glctx(ctx);
|
||||
gctx.backgrounds[bg].enabled = status;
|
||||
}
|
||||
|
||||
|
||||
void clearTileLayer(Context *ctx, uint_t bgIdx) noexcept {
|
||||
auto &gctx = glctx(*ctx);
|
||||
void clearTileLayer(Context &ctx, uint_t bgIdx) noexcept {
|
||||
auto &gctx = glctx(ctx);
|
||||
auto &bg = gctx.cbbs[static_cast<std::size_t>(bgIdx)];
|
||||
initBackgroundBufferObjects(bg);
|
||||
bg.updated = true;
|
||||
}
|
||||
|
||||
void hideSprite(Context *ctx, uint_t idx) noexcept {
|
||||
auto &gctx = glctx(*ctx);
|
||||
void hideSprite(Context &ctx, uint_t idx) noexcept {
|
||||
auto &gctx = glctx(ctx);
|
||||
auto vbo = &gctx.spriteBlocks.vertices[idx * renderer::SpriteVertexVboLength];
|
||||
auto ebo = &gctx.spriteBlocks.elements[idx * renderer::SpriteVertexEboLength];
|
||||
renderer::setSpriteBufferObject(idx * renderer::SpriteVertexVboRows, 0,
|
||||
@ -534,7 +534,7 @@ void hideSprite(Context *ctx, uint_t idx) noexcept {
|
||||
}
|
||||
|
||||
void setSprite(
|
||||
Context *ctx,
|
||||
Context &ctx,
|
||||
uint_t idx,
|
||||
int x,
|
||||
int y,
|
||||
@ -565,7 +565,7 @@ void setSprite(
|
||||
const auto dim = dimensions[(spriteShape << 2) | spriteSize];
|
||||
const auto uX = static_cast<int>(x) % 255;
|
||||
const auto uY = static_cast<int>(y + 8) % 255 - 8;
|
||||
auto &gctx = glctx(*ctx);
|
||||
auto &gctx = glctx(ctx);
|
||||
auto i = 0u;
|
||||
const auto set = [&](int xIt, int yIt) {
|
||||
const auto fX = static_cast<float>(uX + xIt * 8) / 8;
|
||||
@ -601,7 +601,7 @@ void setSprite(
|
||||
}
|
||||
|
||||
void setTile(
|
||||
Context *ctx,
|
||||
Context &ctx,
|
||||
uint_t bgIdx,
|
||||
int column,
|
||||
int row,
|
||||
@ -610,7 +610,7 @@ void setTile(
|
||||
"nostalgia.core.gfx.setTile",
|
||||
"bgIdx: {}, column: {}, row: {}, tile: {}",
|
||||
bgIdx, column, row, tile);
|
||||
auto &gctx = glctx(*ctx);
|
||||
auto &gctx = glctx(ctx);
|
||||
const auto z = static_cast<uint_t>(bgIdx);
|
||||
const auto y = static_cast<uint_t>(row);
|
||||
const auto x = static_cast<uint_t>(column);
|
||||
|
@ -63,6 +63,6 @@ class Drawer: public turbine::gl::Drawer {
|
||||
}
|
||||
|
||||
namespace nostalgia::core {
|
||||
ox::Error initGfx(Context *ctx, InitParams const&) noexcept;
|
||||
ox::Error initGfx(Context &ctx, InitParams const&) noexcept;
|
||||
void shutdownGfx(Context &ctx) noexcept;
|
||||
}
|
@ -13,12 +13,12 @@ class Scene {
|
||||
const SceneStatic &m_sceneStatic;
|
||||
|
||||
public:
|
||||
explicit Scene(const SceneStatic &sceneStatic) noexcept;
|
||||
explicit Scene(SceneStatic const&sceneStatic) noexcept;
|
||||
|
||||
ox::Error setupDisplay(core::Context &ctx) const noexcept;
|
||||
|
||||
private:
|
||||
void setupLayer(core::Context*, const ox::Vector<uint16_t> &layer, unsigned layerNo) const noexcept;
|
||||
void setupLayer(core::Context&, ox::Vector<uint16_t> const&layer, unsigned layerNo) const noexcept;
|
||||
|
||||
};
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
namespace nostalgia::scene {
|
||||
|
||||
Scene::Scene(const SceneStatic &sceneStatic) noexcept:
|
||||
Scene::Scene(SceneStatic const&sceneStatic) noexcept:
|
||||
m_sceneStatic(sceneStatic) {
|
||||
}
|
||||
|
||||
@ -18,19 +18,19 @@ ox::Error Scene::setupDisplay(core::Context &ctx) const noexcept {
|
||||
}
|
||||
const auto &palette = m_sceneStatic.palettes[0];
|
||||
oxReturnError(core::loadBgTileSheet(
|
||||
&ctx, 0, m_sceneStatic.tilesheet, palette));
|
||||
ctx, 0, m_sceneStatic.tilesheet, palette));
|
||||
// disable all backgrounds
|
||||
core::setBgStatus(&ctx, 0);
|
||||
core::setBgStatus(ctx, 0);
|
||||
for (auto layerNo = 0u; const auto &layer : m_sceneStatic.tileMapIdx) {
|
||||
setupLayer(&ctx, layer, layerNo);
|
||||
setupLayer(ctx, layer, layerNo);
|
||||
++layerNo;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void Scene::setupLayer(
|
||||
core::Context *ctx,
|
||||
const ox::Vector<uint16_t> &layer,
|
||||
core::Context &ctx,
|
||||
ox::Vector<uint16_t> const&layer,
|
||||
unsigned layerNo) const noexcept {
|
||||
core::setBgStatus(ctx, layerNo, true);
|
||||
core::setBgCbb(ctx, layerNo, 0);
|
||||
|
@ -11,7 +11,7 @@ namespace nostalgia::scene {
|
||||
SceneEditorView::SceneEditorView(turbine::Context *tctx, const SceneStatic &sceneStatic):
|
||||
m_sceneStatic(sceneStatic),
|
||||
m_scene(m_sceneStatic) {
|
||||
oxThrowError(core::init(tctx, {.glInstallDrawer = false}).moveTo(&m_cctx));
|
||||
oxThrowError(core::init(*tctx, {.glInstallDrawer = false}).moveTo(&m_cctx));
|
||||
}
|
||||
|
||||
ox::Error SceneEditorView::setupScene() noexcept {
|
||||
|
@ -34,7 +34,7 @@ static void keyEventHandler(turbine::Context &tctx, turbine::Key key, bool down)
|
||||
|
||||
ox::Error run(ox::UniquePtr<ox::FileSystem> &&fs) noexcept {
|
||||
oxRequireM(tctx, turbine::init(std::move(fs), "Nostalgia"));
|
||||
oxRequireM(cctx, core::init(tctx.get()));
|
||||
oxRequireM(cctx, core::init(*tctx));
|
||||
constexpr ox::FileAddress SceneAddr("/Scenes/Chester.nscn");
|
||||
oxRequire(scn, keel::readObj<scene::SceneStatic>(tctx->keelCtx, SceneAddr));
|
||||
turbine::setUpdateHandler(*tctx, updateHandler);
|
||||
|
@ -65,7 +65,7 @@ static ox::Error run(const ox::ClArgs &args) noexcept {
|
||||
oxReturnError(ox::FileSystem32::format(dstBuff.data(), dstBuff.size()));
|
||||
ox::FileSystem32 dst(dstBuff);
|
||||
oxRequire(ctx, keel::init(ox::make_unique<ox::PassThroughFS>(argSrc), "nost-pack"));
|
||||
keel::TypeStore ts(*ctx->rom, "/.nostalgia/type_descriptors");
|
||||
keel::TypeStore ts(*ctx->rom, ox::String("/.nostalgia/type_descriptors"));
|
||||
oxReturnError(generateTypes(&ts));
|
||||
oxReturnError(keel::pack(*ctx, ts, dst));
|
||||
oxRequireM(pl, keel::GbaPreloader::make());
|
||||
|
Loading…
Reference in New Issue
Block a user