[turbine,nostalgia] Cleanup

This commit is contained in:
Gary Talent 2025-01-20 23:19:07 -06:00
parent 87e2fdefcf
commit 3c056276c1
17 changed files with 37 additions and 46 deletions

View File

@ -12,7 +12,7 @@ namespace nostalgia::gfx {
using Color16 = uint16_t; using Color16 = uint16_t;
/** /**
* Nostalgia Core logically uses 16 bit colors, but must translate that to 32 * Nostalgia logically uses 16 bit colors, but must translate that to 32
* bit colors in some implementations. * bit colors in some implementations.
*/ */
using Color32 = uint32_t; using Color32 = uint32_t;

View File

@ -4,10 +4,7 @@
#pragma once #pragma once
#include <ox/fs/fs.hpp> #include <ox/std/memory.hpp>
#include <ox/model/desctypes.hpp>
#include <ox/std/buffer.hpp>
#include <ox/std/size.hpp>
#include <turbine/context.hpp> #include <turbine/context.hpp>
@ -19,9 +16,7 @@ class Context;
void safeDelete(Context *ctx) noexcept; void safeDelete(Context *ctx) noexcept;
using ContextUPtr = ox::UPtr<Context>; ox::Result<ox::UPtr<Context>> init(turbine::Context &tctx, InitParams const&params = {}) noexcept;
ox::Result<ContextUPtr> init(turbine::Context &tctx, InitParams const&params = {}) noexcept;
keel::Context &keelCtx(Context &ctx) noexcept; keel::Context &keelCtx(Context &ctx) noexcept;

View File

@ -16,7 +16,7 @@
namespace nostalgia::gfx { namespace nostalgia::gfx {
struct Sprite { struct Sprite {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.Sprite"; static constexpr auto TypeName = "net.drinkingtea.nostalgia.gfx.Sprite";
static constexpr auto TypeVersion = 1; static constexpr auto TypeVersion = 1;
bool enabled = false; bool enabled = false;
int x = 0; int x = 0;
@ -46,7 +46,7 @@ OX_MODEL_BEGIN(Sprite)
OX_MODEL_END() OX_MODEL_END()
struct BgTile { struct BgTile {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.BgTile"; static constexpr auto TypeName = "net.drinkingtea.nostalgia.gfx.BgTile";
static constexpr auto TypeVersion = 1; static constexpr auto TypeVersion = 1;
unsigned tileIdx = 0; unsigned tileIdx = 0;
unsigned palBank = 0; unsigned palBank = 0;
@ -62,7 +62,7 @@ OX_MODEL_BEGIN(BgTile)
OX_MODEL_END() OX_MODEL_END()
struct TileSheetSetEntrySection { struct TileSheetSetEntrySection {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheetSetEntrySection"; static constexpr auto TypeName = "net.drinkingtea.nostalgia.gfx.TileSheetSetEntrySection";
static constexpr auto TypeVersion = 1; static constexpr auto TypeVersion = 1;
int32_t begin = 0; int32_t begin = 0;
int32_t tiles = 0; int32_t tiles = 0;
@ -78,7 +78,7 @@ OX_MODEL_BEGIN(TileSheetSetEntrySection)
OX_MODEL_END() OX_MODEL_END()
struct TileSheetSetEntry { struct TileSheetSetEntry {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheetSetEntry"; static constexpr auto TypeName = "net.drinkingtea.nostalgia.gfx.TileSheetSetEntry";
static constexpr auto TypeVersion = 1; static constexpr auto TypeVersion = 1;
ox::FileAddress tilesheet; ox::FileAddress tilesheet;
ox::Vector<TileSheetSetEntrySection> sections; ox::Vector<TileSheetSetEntrySection> sections;
@ -90,7 +90,7 @@ OX_MODEL_BEGIN(TileSheetSetEntry)
OX_MODEL_END() OX_MODEL_END()
struct TileSheetSet { struct TileSheetSet {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.TileSheetSet"; static constexpr auto TypeName = "net.drinkingtea.nostalgia.gfx.TileSheetSet";
static constexpr auto TypeVersion = 1; static constexpr auto TypeVersion = 1;
static constexpr auto Preloadable = true; static constexpr auto Preloadable = true;
int32_t bpp = 0; int32_t bpp = 0;

View File

@ -19,10 +19,10 @@ Context::Context(turbine::Context &tctx) noexcept: turbineCtx(tctx) {
ox::Error initGfx(Context &ctx, InitParams const&) noexcept; ox::Error initGfx(Context &ctx, InitParams const&) noexcept;
ox::Result<ContextUPtr> init(turbine::Context &tctx, InitParams const&params) noexcept { ox::Result<ox::UPtr<Context>> init(turbine::Context &tctx, InitParams const&params) noexcept {
auto ctx = ox::make_unique<Context>(tctx); auto ctx = ox::make_unique<Context>(tctx);
OX_RETURN_ERROR(initGfx(*ctx, params)); OX_RETURN_ERROR(initGfx(*ctx, params));
return ContextUPtr(std::move(ctx)); return ox::UPtr<Context>(std::move(ctx));
} }
keel::Context &keelCtx(Context &ctx) noexcept { keel::Context &keelCtx(Context &ctx) noexcept {

View File

@ -4,7 +4,6 @@
#include <ox/model/model.hpp> #include <ox/model/model.hpp>
#include <keel/asset.hpp>
#include <keel/module.hpp> #include <keel/module.hpp>
#include <nostalgia/gfx/palette.hpp> #include <nostalgia/gfx/palette.hpp>
@ -29,7 +28,7 @@ static class: public keel::Module {
public: public:
[[nodiscard]] [[nodiscard]]
ox::String id() const noexcept override { ox::String id() const noexcept override {
return ox::String("net.drinkingtea.nostalgia.core"); return ox::String{"net.drinkingtea.nostalgia.gfx"};
} }
[[nodiscard]] [[nodiscard]]
@ -92,6 +91,7 @@ static class: public keel::Module {
}, },
}; };
} }
} const mod; } const mod;
keel::Module const*keelModule() noexcept { keel::Module const*keelModule() noexcept {

View File

@ -23,10 +23,10 @@ Context::~Context() noexcept {
shutdownGfx(*this); shutdownGfx(*this);
} }
ox::Result<ContextUPtr> init(turbine::Context &tctx, InitParams const&params) noexcept { ox::Result<ox::UPtr<Context>> init(turbine::Context &tctx, InitParams const&params) noexcept {
auto ctx = ox::make_unique<Context>(tctx, params); auto ctx = ox::make_unique<Context>(tctx, params);
OX_RETURN_ERROR(initGfx(*ctx, params)); OX_RETURN_ERROR(initGfx(*ctx, params));
return ContextUPtr(ctx.release()); return ox::UPtr<Context>(ctx.release());
} }
keel::Context &keelCtx(Context &ctx) noexcept { keel::Context &keelCtx(Context &ctx) noexcept {

View File

@ -650,7 +650,7 @@ ox::Error loadSpriteTileSheet(
CompactTileSheet const&ts, CompactTileSheet const&ts,
bool loadDefaultPalette) noexcept { bool loadDefaultPalette) noexcept {
OX_REQUIRE(tsd, normalizeTileSheet(ts)); OX_REQUIRE(tsd, normalizeTileSheet(ts));
oxTracef("nostalgia.core.gfx.gl", "loadSpriteTexture: { w: {}, h: {} }", tsd.width, tsd.height); oxTracef("nostalgia.gfx.gl", "loadSpriteTexture: { w: {}, h: {} }", tsd.width, tsd.height);
ctx.spriteBlocks.tex = renderer::createTexture(tsd.width, tsd.height, tsd.pixels.data()); ctx.spriteBlocks.tex = renderer::createTexture(tsd.width, tsd.height, tsd.pixels.data());
if (loadDefaultPalette) { if (loadDefaultPalette) {
OX_RETURN_ERROR(loadSpritePalette(ctx, ts.defaultPalette)); OX_RETURN_ERROR(loadSpritePalette(ctx, ts.defaultPalette));
@ -673,7 +673,7 @@ void setBgTile(
int row, int row,
BgTile const&tile) noexcept { BgTile const&tile) noexcept {
oxTracef( oxTracef(
"nostalgia.core.gfx.setBgTile", "nostalgia.gfx.setBgTile",
"bgIdx: {}, column: {}, row: {}, tile: {}, palBank: {}", "bgIdx: {}, column: {}, row: {}, tile: {}, palBank: {}",
bgIdx, column, row, tile.tileIdx, tile.palBank); bgIdx, column, row, tile.tileIdx, tile.palBank);
const auto z = static_cast<uint_t>(bgIdx); const auto z = static_cast<uint_t>(bgIdx);

View File

@ -14,13 +14,13 @@ OX_MODEL_FWD_DECL(class TileSheetClipboard);
class TileSheetClipboard: public turbine::ClipboardObject<TileSheetClipboard> { class TileSheetClipboard: public turbine::ClipboardObject<TileSheetClipboard> {
public: public:
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.TileSheetClipboard"; static constexpr auto TypeName = "net.drinkingtea.nostalgia.gfx.studio.TileSheetClipboard";
static constexpr auto TypeVersion = 1; static constexpr auto TypeVersion = 1;
OX_MODEL_FRIEND(TileSheetClipboard); OX_MODEL_FRIEND(TileSheetClipboard);
struct Pixel { struct Pixel {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.TileSheetClipboard.Pixel"; static constexpr auto TypeName = "net.drinkingtea.nostalgia.gfx.studio.TileSheetClipboard.Pixel";
static constexpr auto TypeVersion = 1; static constexpr auto TypeVersion = 1;
uint16_t colorIdx = 0; uint16_t colorIdx = 0;
ox::Point pt; ox::Point pt;

View File

@ -16,7 +16,7 @@ namespace nostalgia::gfx {
namespace ig = studio::ig; namespace ig = studio::ig;
struct TileSheetEditorConfig { struct TileSheetEditorConfig {
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.TileSheetEditorConfig"; static constexpr auto TypeName = "net.drinkingtea.nostalgia.gfx.studio.TileSheetEditorConfig";
static constexpr auto TypeVersion = 1; static constexpr auto TypeVersion = 1;
TileSheet::SubSheetIdx activeSubsheet{}; TileSheet::SubSheetIdx activeSubsheet{};
}; };
@ -47,8 +47,8 @@ static ox::Vector<uint32_t> normalizePixelSizes(
static ox::Vector<uint32_t> normalizePixelArrangement( static ox::Vector<uint32_t> normalizePixelArrangement(
ox::Vector<uint32_t> const&inPixels, ox::Vector<uint32_t> const&inPixels,
int cols, int const cols,
int scale) { int const scale) {
auto const scalePt = ox::Point{scale, scale}; auto const scalePt = ox::Point{scale, scale};
auto const width = cols * TileWidth; auto const width = cols * TileWidth;
auto const height = static_cast<int>(inPixels.size()) / width; auto const height = static_cast<int>(inPixels.size()) / width;

View File

@ -15,7 +15,7 @@ namespace nostalgia::scene {
class SceneEditorView { class SceneEditorView {
private: private:
gfx::ContextUPtr m_cctx; ox::UPtr<gfx::Context> m_cctx;
SceneStatic const&m_sceneStatic; SceneStatic const&m_sceneStatic;
Scene m_scene; Scene m_scene;
glutils::FrameBuffer m_frameBuffer; glutils::FrameBuffer m_frameBuffer;

View File

@ -17,11 +17,7 @@ namespace turbine {
class Context; class Context;
struct ContextDeleter { void safeDelete(Context *p);
void operator()(Context *p) noexcept;
};
using ContextUPtr = ox::UPtr<Context, ContextDeleter>;
void shutdown(Context &ctx) noexcept; void shutdown(Context &ctx) noexcept;

View File

@ -16,9 +16,9 @@ namespace turbine {
using TimeMs = uint64_t; using TimeMs = uint64_t;
ox::Result<ContextUPtr> init(ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept; ox::Result<ox::UPtr<Context>> init(ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept;
ox::Result<ContextUPtr> init(ox::StringViewCR fsPath, ox::StringViewCR appName) noexcept; ox::Result<ox::UPtr<Context>> init(ox::StringViewCR fsPath, ox::StringViewCR appName) noexcept;
ox::Error run(Context &ctx) noexcept; ox::Error run(Context &ctx) noexcept;

View File

@ -6,8 +6,8 @@
namespace turbine { namespace turbine {
void ContextDeleter::operator()(Context *p) noexcept { void safeDelete(Context *p) {
ox::safeDelete(p); delete p;
} }
keel::Context const&keelCtx(Context const&ctx) noexcept { keel::Context const&keelCtx(Context const&ctx) noexcept {

View File

@ -58,7 +58,7 @@ OX_ALLOW_UNSAFE_BUFFERS_END
return ox::Error(1); return ox::Error(1);
} }
ox::Result<ContextUPtr> init( ox::Result<ox::UPtr<Context>> init(
ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept { ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept {
auto ctx = ox::make_unique<Context>(); auto ctx = ox::make_unique<Context>();
OX_RETURN_ERROR(keel::init(ctx->keelCtx, std::move(fs), appName)); OX_RETURN_ERROR(keel::init(ctx->keelCtx, std::move(fs), appName));
@ -68,7 +68,7 @@ ox::Result<ContextUPtr> init(
OX_RETURN_ERROR(initGfx(*ctx)); OX_RETURN_ERROR(initGfx(*ctx));
initTimer(); initTimer();
initIrq(); initIrq();
return ox::UPtr<turbine::Context, ContextDeleter>(std::move(ctx)); return ox::UPtr<Context>(std::move(ctx));
} }
void shutdown(Context&) noexcept { void shutdown(Context&) noexcept {

View File

@ -8,8 +8,8 @@
namespace turbine { namespace turbine {
void ContextDeleter::operator()(Context *p) noexcept { void safeDelete(Context *p) {
ox::safeDelete(p); delete p;
} }
keel::Context const&keelCtx(Context const&ctx) noexcept { keel::Context const&keelCtx(Context const&ctx) noexcept {

View File

@ -40,7 +40,7 @@ static void draw(GLFWwindow *window, int, int) noexcept {
draw(ctx); draw(ctx);
} }
ox::Result<ContextUPtr> init( ox::Result<ox::UPtr<Context>> init(
ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept { ox::UPtr<ox::FileSystem> &&fs, ox::StringViewCR appName) noexcept {
auto ctx = ox::make_unique<Context>(); auto ctx = ox::make_unique<Context>();
OX_RETURN_ERROR(keel::init(ctx->keelCtx, std::move(fs), appName)); OX_RETURN_ERROR(keel::init(ctx->keelCtx, std::move(fs), appName));
@ -51,10 +51,10 @@ ox::Result<ContextUPtr> init(
OX_RETURN_ERROR(initGfx(*ctx)); OX_RETURN_ERROR(initGfx(*ctx));
glfwSetWindowSizeCallback(ctx->window, draw); glfwSetWindowSizeCallback(ctx->window, draw);
ctx->mandatoryRefreshPeriodEnd = ticksMs(*ctx) + config::MandatoryRefreshPeriod; ctx->mandatoryRefreshPeriodEnd = ticksMs(*ctx) + config::MandatoryRefreshPeriod;
return ox::UPtr<Context, ContextDeleter>(ctx.release()); return ox::UPtr<Context>(ctx.release());
} }
static void tickFps(Context &ctx, uint64_t nowMs) noexcept { static void tickFps(Context &ctx, uint64_t const nowMs) noexcept {
++ctx.draws; ++ctx.draws;
if (ctx.draws >= 500) { if (ctx.draws >= 500) {
auto const duration = static_cast<double>(nowMs - ctx.prevFpsCheckTime) / 1000.0; auto const duration = static_cast<double>(nowMs - ctx.prevFpsCheckTime) / 1000.0;
@ -114,7 +114,7 @@ TimeMs ticksMs(Context const&ctx) noexcept {
return static_cast<TimeMs>(now) - ctx.startTime; return static_cast<TimeMs>(now) - ctx.startTime;
} }
bool buttonDown(Context const&ctx, Key key) noexcept { bool buttonDown(Context const&ctx, Key const key) noexcept {
return (ctx.keysDown >> static_cast<int>(key)) & 1; return (ctx.keysDown >> static_cast<int>(key)) & 1;
} }

View File

@ -8,7 +8,7 @@
namespace turbine { namespace turbine {
ox::Result<ContextUPtr> init(ox::StringViewCR fsPath, ox::StringViewCR appName) noexcept { ox::Result<ox::UPtr<Context>> init(ox::StringViewCR fsPath, ox::StringViewCR appName) noexcept {
OX_REQUIRE_M(fs, keel::loadRomFs(fsPath)); OX_REQUIRE_M(fs, keel::loadRomFs(fsPath));
return init(std::move(fs), appName); return init(std::move(fs), appName);
} }