[nostalgia/core] Make Context::turbineCtx private
This commit is contained in:
parent
1bff41d9f1
commit
f8eaf9b325
@ -19,18 +19,11 @@ namespace nostalgia::core {
|
|||||||
class Context {
|
class Context {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
turbine::Context *turbineCtx = nullptr;
|
|
||||||
|
|
||||||
Context() noexcept = default;
|
Context() noexcept = default;
|
||||||
Context(Context &other) noexcept = delete;
|
Context(Context &other) noexcept = delete;
|
||||||
Context(const Context &other) noexcept = delete;
|
Context(const Context &other) noexcept = delete;
|
||||||
Context(const Context &&other) noexcept = delete;
|
Context(const Context &&other) noexcept = delete;
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
const auto &rom() const noexcept {
|
|
||||||
return *turbineCtx->rom;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ox::Result<ox::UniquePtr<Context>> init(turbine::Context *tctx, const InitParams& = {}) noexcept;
|
ox::Result<ox::UniquePtr<Context>> init(turbine::Context *tctx, const InitParams& = {}) noexcept;
|
||||||
|
@ -2,7 +2,7 @@ enable_language(CXX ASM)
|
|||||||
set_source_files_properties(gfx.cpp PROPERTIES COMPILE_FLAGS -marm)
|
set_source_files_properties(gfx.cpp PROPERTIES COMPILE_FLAGS -marm)
|
||||||
target_sources(
|
target_sources(
|
||||||
NostalgiaCore PRIVATE
|
NostalgiaCore PRIVATE
|
||||||
core.cpp
|
context.cpp
|
||||||
gfx.cpp
|
gfx.cpp
|
||||||
panic.cpp
|
panic.cpp
|
||||||
)
|
)
|
||||||
|
@ -2,20 +2,19 @@
|
|||||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../context.hpp"
|
|
||||||
#include "../gfx.hpp"
|
#include "../gfx.hpp"
|
||||||
|
|
||||||
#include "../core.hpp"
|
#include "context.hpp"
|
||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
ox::Error initGfx(Context *ctx, const InitParams&) noexcept;
|
ox::Error initGfx(Context *ctx, const InitParams&) noexcept;
|
||||||
|
|
||||||
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 {
|
||||||
ox::UPtr<Context> ctx = ox::make_unique<Context>();
|
auto ctx = ox::make_unique<GbaContext>();
|
||||||
ctx->turbineCtx = tctx;
|
ctx->turbineCtx = tctx;
|
||||||
oxReturnError(initGfx(ctx.get(), params));
|
oxReturnError(initGfx(ctx.get(), params));
|
||||||
return ctx;
|
return ox::UPtr<Context>(ctx.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
22
src/nostalgia/core/gba/context.hpp
Normal file
22
src/nostalgia/core/gba/context.hpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../context.hpp"
|
||||||
|
|
||||||
|
namespace nostalgia::core {
|
||||||
|
|
||||||
|
struct GbaContext: public core::Context {
|
||||||
|
|
||||||
|
turbine::Context *turbineCtx = nullptr;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
const auto &rom() const noexcept {
|
||||||
|
return *turbineCtx->rom;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -16,6 +16,8 @@
|
|||||||
#include <nostalgia/core/context.hpp>
|
#include <nostalgia/core/context.hpp>
|
||||||
#include <nostalgia/core/gfx.hpp>
|
#include <nostalgia/core/gfx.hpp>
|
||||||
|
|
||||||
|
#include "context.hpp"
|
||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
struct BgCbbData {
|
struct BgCbbData {
|
||||||
@ -102,14 +104,14 @@ ox::Error initConsole(Context *ctx) noexcept {
|
|||||||
constexpr ox::FileAddress PaletteAddr("/Palettes/Charset.npal");
|
constexpr ox::FileAddress PaletteAddr("/Palettes/Charset.npal");
|
||||||
setBgStatus(ctx, 0b0001);
|
setBgStatus(ctx, 0b0001);
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
ctx = new(ox_alloca(sizeof(Context))) Context;
|
const auto gctx = new(ox_alloca(sizeof(GbaContext))) GbaContext;
|
||||||
oxRequire(rom, keel::loadRom());
|
oxRequire(rom, keel::loadRom());
|
||||||
auto romFs = new(ox_alloca(sizeof(ox::FileSystem32)))
|
auto romFs = new(ox_alloca(sizeof(ox::FileSystem32)))
|
||||||
ox::FileSystem32(ox::FileStore32(rom, 32 * ox::units::MB));
|
ox::FileSystem32(ox::FileStore32(rom, 32 * ox::units::MB));
|
||||||
oxRequireM(tctx, turbine::init(ox::UPtr<ox::FileSystem>(romFs), ""));
|
oxRequireM(tctx, turbine::init(ox::UPtr<ox::FileSystem>(romFs), ""));
|
||||||
ctx->turbineCtx = tctx.release();
|
gctx->turbineCtx = tctx.release();
|
||||||
oxReturnError(loadBgTileSheet(ctx, 0, TilesheetAddr, PaletteAddr));
|
oxReturnError(loadBgTileSheet(gctx, 0, TilesheetAddr, PaletteAddr));
|
||||||
setBgCbb(ctx, 0, 0);
|
setBgCbb(gctx, 0, 0);
|
||||||
return {};
|
return {};
|
||||||
} else {
|
} else {
|
||||||
oxReturnError(loadBgTileSheet(ctx, 0, TilesheetAddr, PaletteAddr));
|
oxReturnError(loadBgTileSheet(ctx, 0, TilesheetAddr, PaletteAddr));
|
||||||
@ -129,8 +131,9 @@ ox::Error loadBgTileSheet(Context *ctx,
|
|||||||
unsigned cbb,
|
unsigned cbb,
|
||||||
const ox::FileAddress &tilesheetAddr,
|
const ox::FileAddress &tilesheetAddr,
|
||||||
const ox::FileAddress &paletteAddr) noexcept {
|
const ox::FileAddress &paletteAddr) noexcept {
|
||||||
oxRequire(tsStat, ctx->rom().stat(tilesheetAddr));
|
auto &gctx = static_cast<GbaContext&>(*ctx);
|
||||||
oxRequire(ts, static_cast<const ox::MemFS&>(ctx->rom()).directAccess(tilesheetAddr));
|
oxRequire(tsStat, gctx.rom().stat(tilesheetAddr));
|
||||||
|
oxRequire(ts, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(tilesheetAddr));
|
||||||
GbaTileMapTarget target;
|
GbaTileMapTarget target;
|
||||||
target.pal.palette = MEM_BG_PALETTE;
|
target.pal.palette = MEM_BG_PALETTE;
|
||||||
target.cbbData = &g_cbbData[cbb];
|
target.cbbData = &g_cbbData[cbb];
|
||||||
@ -138,8 +141,8 @@ ox::Error loadBgTileSheet(Context *ctx,
|
|||||||
oxReturnError(ox::readMC(ts, tsStat.size, &target));
|
oxReturnError(ox::readMC(ts, tsStat.size, &target));
|
||||||
// load external palette if available
|
// load external palette if available
|
||||||
if (paletteAddr) {
|
if (paletteAddr) {
|
||||||
oxRequire(palStat, ctx->rom().stat(paletteAddr));
|
oxRequire(palStat, gctx.rom().stat(paletteAddr));
|
||||||
oxRequire(pal, static_cast<const ox::MemFS&>(ctx->rom()).directAccess(paletteAddr));
|
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
|
||||||
oxReturnError(ox::readMC(pal, palStat.size, &target.pal));
|
oxReturnError(ox::readMC(pal, palStat.size, &target.pal));
|
||||||
}
|
}
|
||||||
// update bpp of all bgs with the updated cbb
|
// update bpp of all bgs with the updated cbb
|
||||||
@ -155,35 +158,38 @@ ox::Error loadBgTileSheet(Context *ctx,
|
|||||||
ox::Error loadSpriteTileSheet(Context *ctx,
|
ox::Error loadSpriteTileSheet(Context *ctx,
|
||||||
const ox::FileAddress &tilesheetAddr,
|
const ox::FileAddress &tilesheetAddr,
|
||||||
const ox::FileAddress &paletteAddr) noexcept {
|
const ox::FileAddress &paletteAddr) noexcept {
|
||||||
oxRequire(tsStat, ctx->rom().stat(tilesheetAddr));
|
auto &gctx = static_cast<GbaContext&>(*ctx);
|
||||||
oxRequire(ts, static_cast<const ox::MemFS&>(ctx->rom()).directAccess(tilesheetAddr));
|
oxRequire(tsStat, gctx.rom().stat(tilesheetAddr));
|
||||||
|
oxRequire(ts, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(tilesheetAddr));
|
||||||
GbaTileMapTarget target;
|
GbaTileMapTarget target;
|
||||||
target.pal.palette = MEM_SPRITE_PALETTE;
|
target.pal.palette = MEM_SPRITE_PALETTE;
|
||||||
target.tileMap = MEM_SPRITE_TILES;
|
target.tileMap = MEM_SPRITE_TILES;
|
||||||
oxReturnError(ox::readMC(ts, tsStat.size, &target));
|
oxReturnError(ox::readMC(ts, tsStat.size, &target));
|
||||||
// load external palette if available
|
// load external palette if available
|
||||||
if (paletteAddr) {
|
if (paletteAddr) {
|
||||||
oxRequire(palStat, ctx->rom().stat(paletteAddr));
|
oxRequire(palStat, gctx.rom().stat(paletteAddr));
|
||||||
oxRequire(pal, static_cast<const ox::MemFS&>(ctx->rom()).directAccess(paletteAddr));
|
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
|
||||||
oxReturnError(ox::readMC(pal, palStat.size, &target.pal));
|
oxReturnError(ox::readMC(pal, palStat.size, &target.pal));
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error loadBgPalette(Context *ctx, unsigned, const ox::FileAddress &paletteAddr) noexcept {
|
ox::Error loadBgPalette(Context *ctx, unsigned, const ox::FileAddress &paletteAddr) noexcept {
|
||||||
|
auto &gctx = static_cast<GbaContext&>(*ctx);
|
||||||
GbaPaletteTarget target;
|
GbaPaletteTarget target;
|
||||||
target.palette = MEM_BG_PALETTE;
|
target.palette = MEM_BG_PALETTE;
|
||||||
oxRequire(palStat, ctx->rom().stat(paletteAddr));
|
oxRequire(palStat, gctx.rom().stat(paletteAddr));
|
||||||
oxRequire(pal, static_cast<const ox::MemFS&>(ctx->rom()).directAccess(paletteAddr));
|
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
|
||||||
oxReturnError(ox::readMC(pal, palStat.size, &target));
|
oxReturnError(ox::readMC(pal, palStat.size, &target));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error loadSpritePalette(Context *ctx, unsigned cbb, const ox::FileAddress &paletteAddr) noexcept {
|
ox::Error loadSpritePalette(Context *ctx, unsigned cbb, const ox::FileAddress &paletteAddr) noexcept {
|
||||||
|
auto &gctx = static_cast<GbaContext&>(*ctx);
|
||||||
GbaPaletteTarget target;
|
GbaPaletteTarget target;
|
||||||
target.palette = &MEM_SPRITE_PALETTE[cbb];
|
target.palette = &MEM_SPRITE_PALETTE[cbb];
|
||||||
oxRequire(palStat, ctx->rom().stat(paletteAddr));
|
oxRequire(palStat, gctx.rom().stat(paletteAddr));
|
||||||
oxRequire(pal, static_cast<const ox::MemFS&>(ctx->rom()).directAccess(paletteAddr));
|
oxRequire(pal, static_cast<const ox::MemFS&>(gctx.rom()).directAccess(paletteAddr));
|
||||||
oxReturnError(ox::readMC(pal, palStat.size, &target));
|
oxReturnError(ox::readMC(pal, palStat.size, &target));
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -7,5 +7,5 @@
|
|||||||
#include "../context.hpp"
|
#include "../context.hpp"
|
||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
ox::Error initGfx(Context *ctx, const InitParams &) noexcept;
|
ox::Error initGfx(Context *ctx, const InitParams&) noexcept;
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,8 @@
|
|||||||
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
* Copyright 2016 - 2022 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ox/std/memops.hpp>
|
|
||||||
|
|
||||||
#include <nostalgia/core/core.hpp>
|
#include <nostalgia/core/core.hpp>
|
||||||
#include <nostalgia/core/gfx.hpp>
|
|
||||||
|
|
||||||
#include <teagba/addresses.hpp>
|
#include <teagba/addresses.hpp>
|
||||||
#include <teagba/bios.hpp>
|
#include <teagba/bios.hpp>
|
||||||
|
@ -19,11 +19,6 @@ namespace nostalgia::core {
|
|||||||
|
|
||||||
extern ox::Array<char, 128> charMap;
|
extern ox::Array<char, 128> charMap;
|
||||||
|
|
||||||
enum class TileSheetSpace {
|
|
||||||
Background,
|
|
||||||
Sprite
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Sprite {
|
struct Sprite {
|
||||||
unsigned idx = 0;
|
unsigned idx = 0;
|
||||||
int x = 0;
|
int x = 0;
|
||||||
@ -84,6 +79,5 @@ void setSprite(Context *ctx, const Sprite &s) noexcept;
|
|||||||
|
|
||||||
namespace nostalgia::core::gl {
|
namespace nostalgia::core::gl {
|
||||||
void drawMainView(core::Context*, ox::Size const&) noexcept;
|
void drawMainView(core::Context*, ox::Size const&) noexcept;
|
||||||
void drawMainView(core::Context*) noexcept;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,10 +12,10 @@ GlContext::~GlContext() noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
ox::UPtr<Context> ctx = ox::make_unique<GlContext>();
|
auto ctx = ox::make_unique<GlContext>();
|
||||||
ctx->turbineCtx = tctx;
|
ctx->turbineCtx = tctx;
|
||||||
oxReturnError(initGfx(ctx.get(), params));
|
oxReturnError(initGfx(ctx.get(), params));
|
||||||
return ctx;
|
return ox::UPtr<Context>(ctx.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
struct GlContext: public core::Context {
|
struct GlContext: public core::Context {
|
||||||
|
turbine::Context *turbineCtx = nullptr;
|
||||||
glutils::GLProgram bgShader;
|
glutils::GLProgram bgShader;
|
||||||
glutils::GLProgram spriteShader;
|
glutils::GLProgram spriteShader;
|
||||||
ox::Array<renderer::CBB, 4> cbbs;
|
ox::Array<renderer::CBB, 4> cbbs;
|
||||||
|
@ -17,12 +17,16 @@
|
|||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
|
|
||||||
void draw(Context *ctx) noexcept;
|
namespace gl {
|
||||||
|
|
||||||
|
void drawMainView(core::Context *ctx, ox::Size const&renderSz) noexcept;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
namespace renderer {
|
namespace renderer {
|
||||||
|
|
||||||
void Drawer::draw(turbine::Context&) noexcept {
|
void Drawer::draw(turbine::Context &tctx) noexcept {
|
||||||
core::draw(m_ctx);
|
core::gl::drawMainView(m_ctx, turbine::getScreenSize(tctx));
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr ox::StringView bgvshadTmpl = R"(
|
constexpr ox::StringView bgvshadTmpl = R"(
|
||||||
@ -311,23 +315,23 @@ ox::Error initGfx(Context *ctx, const InitParams &initParams) noexcept {
|
|||||||
const auto bgFshad = ox::sfmt(renderer::bgfshadTmpl, glutils::GlslVersion);
|
const auto bgFshad = ox::sfmt(renderer::bgfshadTmpl, glutils::GlslVersion);
|
||||||
const auto spriteVshad = ox::sfmt(renderer::spritevshadTmpl, glutils::GlslVersion);
|
const auto spriteVshad = ox::sfmt(renderer::spritevshadTmpl, glutils::GlslVersion);
|
||||||
const auto spriteFshad = ox::sfmt(renderer::spritefshadTmpl, glutils::GlslVersion);
|
const auto spriteFshad = ox::sfmt(renderer::spritefshadTmpl, glutils::GlslVersion);
|
||||||
const auto gctx = static_cast<GlContext*>(ctx);
|
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||||
oxReturnError(glutils::buildShaderProgram(bgVshad.c_str(), bgFshad.c_str()).moveTo(&gctx->bgShader));
|
oxReturnError(glutils::buildShaderProgram(bgVshad.c_str(), bgFshad.c_str()).moveTo(&gctx.bgShader));
|
||||||
oxReturnError(glutils::buildShaderProgram(spriteVshad.c_str(), spriteFshad.c_str()).moveTo(&gctx->spriteShader));
|
oxReturnError(glutils::buildShaderProgram(spriteVshad.c_str(), spriteFshad.c_str()).moveTo(&gctx.spriteShader));
|
||||||
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;
|
gctx.drawer.m_ctx = ctx;
|
||||||
if (initParams.glInstallDrawer) {
|
if (initParams.glInstallDrawer) {
|
||||||
turbine::gl::addDrawer(*ctx->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 {
|
||||||
const auto gctx = static_cast<GlContext*>(ctx);
|
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||||
turbine::gl::removeDrawer(*ctx->turbineCtx, &gctx->drawer);
|
turbine::gl::removeDrawer(*gctx.turbineCtx, &gctx.drawer);
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error initConsole(Context *ctx) noexcept {
|
ox::Error initConsole(Context *ctx) noexcept {
|
||||||
@ -345,7 +349,7 @@ struct TileSheetData {
|
|||||||
};
|
};
|
||||||
|
|
||||||
ox::Result<TileSheetData> loadTileSheet(Context *ctx, const CompactTileSheet &tilesheet) noexcept {
|
ox::Result<TileSheetData> loadTileSheet(Context *ctx, const CompactTileSheet &tilesheet) noexcept {
|
||||||
const 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;
|
||||||
constexpr int width = 8;
|
constexpr int width = 8;
|
||||||
@ -363,7 +367,7 @@ ox::Result<TileSheetData> loadTileSheet(Context *ctx, const CompactTileSheet &ti
|
|||||||
pixels[i * 2 + 1] = tilesheet.pixels[i] >> 4;
|
pixels[i * 2 + 1] = tilesheet.pixels[i] >> 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
renderer::loadSpriteTexture(gctx, pixels.data(), width, height);
|
renderer::loadSpriteTexture(&gctx, pixels.data(), width, height);
|
||||||
return TileSheetData{std::move(pixels), width, height};
|
return TileSheetData{std::move(pixels), width, height};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,26 +375,26 @@ ox::Error loadBgTileSheet(Context *ctx,
|
|||||||
unsigned cbb,
|
unsigned cbb,
|
||||||
const ox::FileAddress &tilesheetAddr,
|
const ox::FileAddress &tilesheetAddr,
|
||||||
const ox::FileAddress &paletteAddr) noexcept {
|
const ox::FileAddress &paletteAddr) noexcept {
|
||||||
auto &kctx = *ctx->turbineCtx;
|
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||||
const auto gctx = static_cast<GlContext*>(ctx);
|
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));
|
||||||
renderer::loadBgTexture(gctx, cbb, tsd.pixels.data(), tsd.width, tsd.height);
|
renderer::loadBgTexture(&gctx, cbb, tsd.pixels.data(), tsd.width, tsd.height);
|
||||||
renderer::loadBgPalette(gctx, *palette);
|
renderer::loadBgPalette(&gctx, *palette);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error loadSpriteTileSheet(Context *ctx,
|
ox::Error loadSpriteTileSheet(Context *ctx,
|
||||||
const ox::FileAddress &tilesheetAddr,
|
const ox::FileAddress &tilesheetAddr,
|
||||||
const ox::FileAddress &paletteAddr) noexcept {
|
const ox::FileAddress &paletteAddr) noexcept {
|
||||||
auto &kctx = *ctx->turbineCtx;
|
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||||
const auto gctx = static_cast<GlContext*>(ctx);
|
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));
|
||||||
renderer::loadSpriteTexture(gctx, tsd.pixels.data(), tsd.width, tsd.height);
|
renderer::loadSpriteTexture(&gctx, tsd.pixels.data(), tsd.width, tsd.height);
|
||||||
renderer::loadSpritePalette(gctx, *palette);
|
renderer::loadSpritePalette(&gctx, *palette);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,51 +405,47 @@ void puts(Context *ctx, int column, int row, ox::CRStringView str) noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
void setBgCbb(Context *ctx, unsigned bgIdx, unsigned cbbIdx) noexcept {
|
void setBgCbb(Context *ctx, unsigned bgIdx, unsigned cbbIdx) noexcept {
|
||||||
const auto gctx = static_cast<GlContext*>(ctx);
|
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||||
auto &bg = gctx->backgrounds[bgIdx];
|
auto &bg = gctx.backgrounds[bgIdx];
|
||||||
bg.cbbIdx = cbbIdx;
|
bg.cbbIdx = cbbIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t bgStatus(Context *ctx) noexcept {
|
uint8_t bgStatus(Context *ctx) noexcept {
|
||||||
const auto gctx = static_cast<GlContext*>(ctx);
|
const auto &gctx = static_cast<GlContext&>(*ctx);
|
||||||
uint8_t out = 0;
|
uint8_t out = 0;
|
||||||
for (unsigned i = 0; i < gctx->cbbs.size(); ++i) {
|
for (unsigned i = 0; i < gctx.cbbs.size(); ++i) {
|
||||||
out |= gctx->backgrounds[i].enabled << i;
|
out |= gctx.backgrounds[i].enabled << i;
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBgStatus(Context *ctx, uint32_t status) noexcept {
|
void setBgStatus(Context *ctx, uint32_t status) noexcept {
|
||||||
const auto gctx = static_cast<GlContext*>(ctx);
|
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||||
for (unsigned i = 0; i < gctx->cbbs.size(); ++i) {
|
for (unsigned i = 0; i < gctx.cbbs.size(); ++i) {
|
||||||
gctx->backgrounds[i].enabled = (status >> i) & 1;
|
gctx.backgrounds[i].enabled = (status >> i) & 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bgStatus(Context *ctx, unsigned bg) noexcept {
|
bool bgStatus(Context *ctx, unsigned bg) noexcept {
|
||||||
const auto gctx = static_cast<GlContext*>(ctx);
|
const auto &gctx = static_cast<GlContext&>(*ctx);
|
||||||
return gctx->backgrounds[bg].enabled;
|
return gctx.backgrounds[bg].enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept {
|
void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept {
|
||||||
const auto gctx = static_cast<GlContext*>(ctx);
|
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||||
gctx->backgrounds[bg].enabled = status;
|
gctx.backgrounds[bg].enabled = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void draw(Context *ctx) noexcept {
|
|
||||||
gl::drawMainView(ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
void clearTileLayer(Context *ctx, unsigned bgIdx) noexcept {
|
void clearTileLayer(Context *ctx, unsigned bgIdx) noexcept {
|
||||||
const 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(ctx, &bg);
|
initBackgroundBufferObjects(&gctx, &bg);
|
||||||
bg.updated = true;
|
bg.updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hideSprite(Context *ctx, unsigned idx) noexcept {
|
void hideSprite(Context *ctx, unsigned idx) noexcept {
|
||||||
auto &gctx = *static_cast<GlContext*>(ctx);
|
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||||
auto vbo = &gctx.spriteBlocks.vertices[idx * renderer::SpriteVertexVboLength];
|
auto vbo = &gctx.spriteBlocks.vertices[idx * renderer::SpriteVertexVboLength];
|
||||||
auto ebo = &gctx.spriteBlocks.elements[idx * renderer::SpriteVertexEboLength];
|
auto ebo = &gctx.spriteBlocks.elements[idx * renderer::SpriteVertexEboLength];
|
||||||
renderer::setSpriteBufferObject(ctx, idx * renderer::SpriteVertexVboRows, 0,
|
renderer::setSpriteBufferObject(ctx, idx * renderer::SpriteVertexVboRows, 0,
|
||||||
@ -517,12 +517,12 @@ void setTile(Context *ctx, unsigned bgIdx, int column, int row, uint8_t tile) no
|
|||||||
"nostalgia::core::gfx::setTile",
|
"nostalgia::core::gfx::setTile",
|
||||||
"bgIdx: {}, column: {}, row: {}, tile: {}",
|
"bgIdx: {}, column: {}, row: {}, tile: {}",
|
||||||
bgIdx, column, row, tile);
|
bgIdx, column, row, tile);
|
||||||
const auto gctx = static_cast<GlContext*>(ctx);
|
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||||
const auto z = static_cast<unsigned>(bgIdx);
|
const auto z = static_cast<unsigned>(bgIdx);
|
||||||
const auto y = static_cast<unsigned>(row);
|
const auto y = static_cast<unsigned>(row);
|
||||||
const auto x = static_cast<unsigned>(column);
|
const auto x = static_cast<unsigned>(column);
|
||||||
const auto i = renderer::bgVertexRow(x, y);
|
const auto i = renderer::bgVertexRow(x, y);
|
||||||
auto &bg = gctx->cbbs[z];
|
auto &bg = gctx.cbbs[z];
|
||||||
auto vbo = &bg.vertices[i * renderer::BgVertexVboLength];
|
auto vbo = &bg.vertices[i * renderer::BgVertexVboLength];
|
||||||
auto ebo = &bg.elements[i * renderer::BgVertexEboLength];
|
auto ebo = &bg.elements[i * renderer::BgVertexEboLength];
|
||||||
renderer::setTileBufferObject(
|
renderer::setTileBufferObject(
|
||||||
@ -545,10 +545,6 @@ void drawMainView(core::Context *ctx, ox::Size const&renderSz) noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawMainView(core::Context *ctx) noexcept {
|
|
||||||
drawMainView(ctx, getScreenSize(*ctx->turbineCtx));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user