[nostalgia/core] Cleanup
This commit is contained in:
parent
bde511dd85
commit
dd54e7363f
@ -41,7 +41,7 @@ void panic(const char *file, int line, const char *panicMsg, const ox::Error &er
|
|||||||
}
|
}
|
||||||
// disable all interrupt handling and IntrWait on no interrupts
|
// disable all interrupt handling and IntrWait on no interrupts
|
||||||
REG_IE = 0;
|
REG_IE = 0;
|
||||||
teagba_intrwait(0, 0);
|
teagba::intrwait(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,17 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
|
GlContext::GlContext(turbine::Context &tctx) noexcept:
|
||||||
|
turbineCtx(tctx),
|
||||||
|
drawer(*this) {
|
||||||
|
}
|
||||||
|
|
||||||
GlContext::~GlContext() noexcept {
|
GlContext::~GlContext() noexcept {
|
||||||
shutdownGfx(this);
|
shutdownGfx(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Result<ox::UniquePtr<Context>> init(turbine::Context *tctx, const InitParams ¶ms) noexcept {
|
ox::Result<ox::UniquePtr<Context>> init(turbine::Context *tctx, const InitParams ¶ms) noexcept {
|
||||||
auto ctx = ox::make_unique<GlContext>();
|
auto ctx = ox::make_unique<GlContext>(*tctx);
|
||||||
ctx->turbineCtx = tctx;
|
|
||||||
oxReturnError(initGfx(ctx.get(), params));
|
oxReturnError(initGfx(ctx.get(), params));
|
||||||
return ox::UPtr<Context>(ctx.release());
|
return ox::UPtr<Context>(ctx.release());
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
struct GlContext: public core::Context {
|
struct GlContext: public core::Context {
|
||||||
turbine::Context *turbineCtx = nullptr;
|
turbine::Context &turbineCtx;
|
||||||
glutils::GLProgram bgShader;
|
glutils::GLProgram bgShader;
|
||||||
glutils::GLProgram spriteShader;
|
glutils::GLProgram spriteShader;
|
||||||
ox::Array<renderer::CBB, 4> cbbs;
|
ox::Array<renderer::CBB, 4> cbbs;
|
||||||
@ -25,6 +25,7 @@ struct GlContext: public core::Context {
|
|||||||
ox::Array<renderer::Background, 4> backgrounds;
|
ox::Array<renderer::Background, 4> backgrounds;
|
||||||
ox::Optional<ox::Size> renderSize;
|
ox::Optional<ox::Size> renderSize;
|
||||||
renderer::Drawer drawer;
|
renderer::Drawer drawer;
|
||||||
|
explicit GlContext(turbine::Context &tctx) noexcept;
|
||||||
~GlContext() noexcept;
|
~GlContext() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,8 +19,10 @@ namespace nostalgia::core {
|
|||||||
|
|
||||||
namespace renderer {
|
namespace renderer {
|
||||||
|
|
||||||
|
Drawer::Drawer(Context &ctx) noexcept: m_ctx(ctx) {}
|
||||||
|
|
||||||
void Drawer::draw(turbine::Context &tctx) noexcept {
|
void Drawer::draw(turbine::Context &tctx) noexcept {
|
||||||
core::gl::drawMainView(m_ctx, turbine::getScreenSize(tctx));
|
core::gl::drawMainView(&m_ctx, turbine::getScreenSize(tctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr ox::StringView bgvshadTmpl = R"(
|
constexpr ox::StringView bgvshadTmpl = R"(
|
||||||
@ -348,17 +350,16 @@ ox::Error initGfx(
|
|||||||
for (auto &bg : gctx.cbbs) {
|
for (auto &bg : gctx.cbbs) {
|
||||||
initBackgroundBufferset(ctx, gctx.bgShader, &bg);
|
initBackgroundBufferset(ctx, gctx.bgShader, &bg);
|
||||||
}
|
}
|
||||||
gctx.drawer.m_ctx = ctx;
|
|
||||||
if (initParams.glInstallDrawer) {
|
if (initParams.glInstallDrawer) {
|
||||||
turbine::gl::addDrawer(*gctx.turbineCtx, &gctx.drawer);
|
turbine::gl::addDrawer(gctx.turbineCtx, &gctx.drawer);
|
||||||
initSpritesBufferset(ctx, gctx.spriteShader, &gctx.spriteBlocks);
|
initSpritesBufferset(ctx, gctx.spriteShader, &gctx.spriteBlocks);
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void shutdownGfx(Context *ctx) noexcept {
|
void shutdownGfx(Context &ctx) noexcept {
|
||||||
auto &gctx = static_cast<GlContext&>(*ctx);
|
auto &gctx = static_cast<GlContext&>(ctx);
|
||||||
turbine::gl::removeDrawer(*gctx.turbineCtx, &gctx.drawer);
|
turbine::gl::removeDrawer(gctx.turbineCtx, &gctx.drawer);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error initConsole(Context *ctx) noexcept {
|
ox::Error initConsole(Context *ctx) noexcept {
|
||||||
@ -405,7 +406,7 @@ ox::Error loadBgTileSheet(
|
|||||||
const ox::FileAddress &tilesheetAddr,
|
const ox::FileAddress &tilesheetAddr,
|
||||||
const ox::FileAddress &paletteAddr) noexcept {
|
const ox::FileAddress &paletteAddr) noexcept {
|
||||||
auto &gctx = static_cast<GlContext&>(*ctx);
|
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||||
auto &kctx = *gctx.turbineCtx;
|
auto &kctx = gctx.turbineCtx;
|
||||||
oxRequire(tilesheet, readObj<CompactTileSheet>(&kctx, tilesheetAddr));
|
oxRequire(tilesheet, readObj<CompactTileSheet>(&kctx, tilesheetAddr));
|
||||||
oxRequire(palette, readObj<Palette>(&kctx, paletteAddr ? paletteAddr : tilesheet->defaultPalette));
|
oxRequire(palette, readObj<Palette>(&kctx, paletteAddr ? paletteAddr : tilesheet->defaultPalette));
|
||||||
oxRequire(tsd, loadTileSheet(ctx, *tilesheet));
|
oxRequire(tsd, loadTileSheet(ctx, *tilesheet));
|
||||||
@ -419,7 +420,7 @@ ox::Error loadSpriteTileSheet(
|
|||||||
const ox::FileAddress &tilesheetAddr,
|
const ox::FileAddress &tilesheetAddr,
|
||||||
const ox::FileAddress &paletteAddr) noexcept {
|
const ox::FileAddress &paletteAddr) noexcept {
|
||||||
auto &gctx = static_cast<GlContext&>(*ctx);
|
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||||
auto &kctx = *gctx.turbineCtx;
|
auto &kctx = gctx.turbineCtx;
|
||||||
oxRequire(tilesheet, readObj<CompactTileSheet>(&kctx, tilesheetAddr));
|
oxRequire(tilesheet, readObj<CompactTileSheet>(&kctx, tilesheetAddr));
|
||||||
oxRequire(palette, readObj<Palette>(&kctx, paletteAddr ? paletteAddr : tilesheet->defaultPalette));
|
oxRequire(palette, readObj<Palette>(&kctx, paletteAddr ? paletteAddr : tilesheet->defaultPalette));
|
||||||
oxRequire(tsd, loadTileSheet(ctx, *tilesheet));
|
oxRequire(tsd, loadTileSheet(ctx, *tilesheet));
|
||||||
@ -467,7 +468,7 @@ void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void glearTileLayer(Context *ctx, unsigned bgIdx) noexcept {
|
void clearTileLayer(Context *ctx, unsigned bgIdx) noexcept {
|
||||||
auto &gctx = static_cast<GlContext&>(*ctx);
|
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||||
auto &bg = gctx.cbbs[static_cast<std::size_t>(bgIdx)];
|
auto &bg = gctx.cbbs[static_cast<std::size_t>(bgIdx)];
|
||||||
initBackgroundBufferObjects(&gctx, &bg);
|
initBackgroundBufferObjects(&gctx, &bg);
|
||||||
@ -483,14 +484,15 @@ void hideSprite(Context *ctx, unsigned idx) noexcept {
|
|||||||
gctx.spriteBlocks.updated = true;
|
gctx.spriteBlocks.updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSprite(Context *ctx,
|
void setSprite(
|
||||||
unsigned idx,
|
Context *ctx,
|
||||||
int x,
|
unsigned idx,
|
||||||
int y,
|
int x,
|
||||||
unsigned tileIdx,
|
int y,
|
||||||
unsigned spriteShape,
|
unsigned tileIdx,
|
||||||
unsigned spriteSize,
|
unsigned spriteShape,
|
||||||
unsigned flipX) noexcept {
|
unsigned spriteSize,
|
||||||
|
unsigned flipX) noexcept {
|
||||||
//oxTracef("nostalgia::core::gfx::gl", "setSprite(ctx, {}, {}, {}, {}, {}, {}, {})",
|
//oxTracef("nostalgia::core::gfx::gl", "setSprite(ctx, {}, {}, {}, {}, {}, {}, {})",
|
||||||
// idx, x, y, tileIdx, spriteShape, spriteSize, flipX);
|
// idx, x, y, tileIdx, spriteShape, spriteSize, flipX);
|
||||||
// Tonc Table 8.4
|
// Tonc Table 8.4
|
||||||
|
@ -53,8 +53,10 @@ struct Sprite {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class Drawer: public turbine::gl::Drawer {
|
class Drawer: public turbine::gl::Drawer {
|
||||||
|
private:
|
||||||
|
Context &m_ctx;
|
||||||
public:
|
public:
|
||||||
Context *m_ctx = nullptr;
|
explicit Drawer(Context &ctx) noexcept;
|
||||||
void draw(turbine::Context&) noexcept final;
|
void draw(turbine::Context&) noexcept final;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -62,5 +64,5 @@ 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, const InitParams&) noexcept;
|
||||||
void shutdownGfx(Context *ctx) noexcept;
|
void shutdownGfx(Context &ctx) noexcept;
|
||||||
}
|
}
|
@ -97,7 +97,7 @@ class DrawCommand: public TileSheetCommand {
|
|||||||
oldPalIdx = pOldPalIdx;
|
oldPalIdx = pOldPalIdx;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
TileSheet *m_img = nullptr;
|
TileSheet &m_img;
|
||||||
TileSheet::SubSheetIdx m_subSheetIdx;
|
TileSheet::SubSheetIdx m_subSheetIdx;
|
||||||
ox::Vector<Change, 8> m_changes;
|
ox::Vector<Change, 8> m_changes;
|
||||||
int m_palIdx = 0;
|
int m_palIdx = 0;
|
||||||
@ -108,10 +108,10 @@ class DrawCommand: public TileSheetCommand {
|
|||||||
TileSheet::SubSheetIdx subSheetIdx,
|
TileSheet::SubSheetIdx subSheetIdx,
|
||||||
std::size_t idx,
|
std::size_t idx,
|
||||||
int palIdx) noexcept:
|
int palIdx) noexcept:
|
||||||
m_img(&img),
|
m_img(img),
|
||||||
m_subSheetIdx(std::move(subSheetIdx)) {
|
m_subSheetIdx(std::move(subSheetIdx)) {
|
||||||
auto &subsheet = m_img->getSubSheet(m_subSheetIdx);
|
auto &subsheet = m_img.getSubSheet(m_subSheetIdx);
|
||||||
m_changes.emplace_back(static_cast<uint32_t>(idx), subsheet.getPixel(m_img->bpp, idx));
|
m_changes.emplace_back(static_cast<uint32_t>(idx), subsheet.getPixel(m_img.bpp, idx));
|
||||||
m_palIdx = palIdx;
|
m_palIdx = palIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,25 +120,25 @@ class DrawCommand: public TileSheetCommand {
|
|||||||
TileSheet::SubSheetIdx subSheetIdx,
|
TileSheet::SubSheetIdx subSheetIdx,
|
||||||
const ox::Vector<std::size_t> &idxList,
|
const ox::Vector<std::size_t> &idxList,
|
||||||
int palIdx) noexcept:
|
int palIdx) noexcept:
|
||||||
m_img(&img),
|
m_img(img),
|
||||||
m_subSheetIdx(std::move(subSheetIdx)) {
|
m_subSheetIdx(std::move(subSheetIdx)) {
|
||||||
auto &subsheet = m_img->getSubSheet(m_subSheetIdx);
|
auto &subsheet = m_img.getSubSheet(m_subSheetIdx);
|
||||||
for (const auto idx : idxList) {
|
for (const auto idx : idxList) {
|
||||||
m_changes.emplace_back(static_cast<uint32_t>(idx), subsheet.getPixel(m_img->bpp, idx));
|
m_changes.emplace_back(static_cast<uint32_t>(idx), subsheet.getPixel(m_img.bpp, idx));
|
||||||
}
|
}
|
||||||
m_palIdx = palIdx;
|
m_palIdx = palIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr auto append(std::size_t idx) noexcept {
|
constexpr auto append(std::size_t idx) noexcept {
|
||||||
auto &subsheet = m_img->getSubSheet(m_subSheetIdx);
|
auto &subsheet = m_img.getSubSheet(m_subSheetIdx);
|
||||||
if (m_changes.back().value->idx != idx && subsheet.getPixel(m_img->bpp, idx) != m_palIdx) {
|
if (m_changes.back().value->idx != idx && subsheet.getPixel(m_img.bpp, idx) != m_palIdx) {
|
||||||
// duplicate entries are bad
|
// duplicate entries are bad
|
||||||
auto existing = ox::find_if(m_changes.cbegin(), m_changes.cend(), [idx](const auto &c) {
|
auto existing = ox::find_if(m_changes.cbegin(), m_changes.cend(), [idx](const auto &c) {
|
||||||
return c.idx == idx;
|
return c.idx == idx;
|
||||||
});
|
});
|
||||||
if (existing == m_changes.cend()) {
|
if (existing == m_changes.cend()) {
|
||||||
m_changes.emplace_back(static_cast<uint32_t>(idx), subsheet.getPixel(m_img->bpp, idx));
|
m_changes.emplace_back(static_cast<uint32_t>(idx), subsheet.getPixel(m_img.bpp, idx));
|
||||||
subsheet.setPixel(m_img->bpp, idx, static_cast<uint8_t>(m_palIdx));
|
subsheet.setPixel(m_img.bpp, idx, static_cast<uint8_t>(m_palIdx));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,16 +154,16 @@ class DrawCommand: public TileSheetCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void redo() noexcept final {
|
void redo() noexcept final {
|
||||||
auto &subsheet = m_img->getSubSheet(m_subSheetIdx);
|
auto &subsheet = m_img.getSubSheet(m_subSheetIdx);
|
||||||
for (const auto &c : m_changes) {
|
for (const auto &c : m_changes) {
|
||||||
subsheet.setPixel(m_img->bpp, c.idx, static_cast<uint8_t>(m_palIdx));
|
subsheet.setPixel(m_img.bpp, c.idx, static_cast<uint8_t>(m_palIdx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void undo() noexcept final {
|
void undo() noexcept final {
|
||||||
auto &subsheet = m_img->getSubSheet(m_subSheetIdx);
|
auto &subsheet = m_img.getSubSheet(m_subSheetIdx);
|
||||||
for (const auto &c : m_changes) {
|
for (const auto &c : m_changes) {
|
||||||
subsheet.setPixel(m_img->bpp, c.idx, static_cast<uint8_t>(c.oldPalIdx));
|
subsheet.setPixel(m_img.bpp, c.idx, static_cast<uint8_t>(c.oldPalIdx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user