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