diff --git a/src/nostalgia/core/context.hpp b/src/nostalgia/core/context.hpp index 1f1af2bf..3513fd90 100644 --- a/src/nostalgia/core/context.hpp +++ b/src/nostalgia/core/context.hpp @@ -24,12 +24,21 @@ class Drawer { class Context { public: ox::FileSystem *rom = nullptr; - ox::Vector drawer; + ox::Vector drawers; private: void *m_windowerData = nullptr; void *m_rendererData = nullptr; public: + constexpr Context() noexcept = default; + + constexpr Context(const Context &&other) noexcept { + rom = ox::move(other.rom); + drawers = ox::move(other.drawers); + m_windowerData = ox::move(other.m_windowerData); + m_rendererData = ox::move(other.m_rendererData); + } + constexpr void setWindowerData(void *windowerData) noexcept { m_windowerData = windowerData; } diff --git a/src/nostalgia/core/core.hpp b/src/nostalgia/core/core.hpp index fe624f60..8ee5f6c1 100644 --- a/src/nostalgia/core/core.hpp +++ b/src/nostalgia/core/core.hpp @@ -20,7 +20,7 @@ namespace nostalgia::core { using event_handler = int(*)(Context*); -ox::Error init(Context *ctx) noexcept; +ox::Result init(ox::FileSystem *fs) noexcept; ox::Error run(Context *ctx) noexcept; diff --git a/src/nostalgia/core/gba/core.cpp b/src/nostalgia/core/gba/core.cpp index 52773b56..3c242cc4 100644 --- a/src/nostalgia/core/gba/core.cpp +++ b/src/nostalgia/core/gba/core.cpp @@ -40,11 +40,13 @@ static void initTimer() noexcept { REG_IE = REG_IE | Int_timer0; } -ox::Error init(Context *ctx) noexcept { - oxReturnError(initGfx(ctx)); +ox::Result init(ox::FileSystem *fs) noexcept { + Context ctx; + ctx.rom = fs; + oxReturnError(initGfx(&ctx)); initTimer(); initIrq(); - return OxError(0); + return ctx; } void setEventHandler(Context*, event_handler h) noexcept { diff --git a/src/nostalgia/core/gba/gfx.cpp b/src/nostalgia/core/gba/gfx.cpp index 8454d7a4..caf046a3 100644 --- a/src/nostalgia/core/gba/gfx.cpp +++ b/src/nostalgia/core/gba/gfx.cpp @@ -100,6 +100,9 @@ ox::Error shutdownGfx(Context*) noexcept { return OxError(0); } +void setWindowTitle(Context*, const char*) noexcept { +} + int getScreenWidth(Context*) noexcept { return 240; } diff --git a/src/nostalgia/core/gfx.cpp b/src/nostalgia/core/gfx.cpp index 01912e8c..f47d4062 100644 --- a/src/nostalgia/core/gfx.cpp +++ b/src/nostalgia/core/gfx.cpp @@ -142,13 +142,13 @@ char charMap[128] = { }; void addCustomDrawer(Context *ctx, Drawer *cd) noexcept { - ctx->drawer.emplace_back(cd); + ctx->drawers.emplace_back(cd); } void removeCustomDrawer(Context *ctx, Drawer *cd) noexcept { - for (auto i = 0u; i < ctx->drawer.size(); ++i) { - if (ctx->drawer[i] == cd) { - oxIgnoreError(ctx->drawer.erase(i)); + for (auto i = 0u; i < ctx->drawers.size(); ++i) { + if (ctx->drawers[i] == cd) { + oxIgnoreError(ctx->drawers.erase(i)); break; } } diff --git a/src/nostalgia/core/gfx.hpp b/src/nostalgia/core/gfx.hpp index b416c168..dc91f745 100644 --- a/src/nostalgia/core/gfx.hpp +++ b/src/nostalgia/core/gfx.hpp @@ -80,6 +80,8 @@ void addCustomDrawer(Context *ctx, Drawer *cd) noexcept; void removeCustomDrawer(Context *ctx, Drawer *cd) noexcept; +void setWindowTitle(Context *ctx, const char *title) noexcept; + [[nodiscard]] int getScreenWidth(Context *ctx) noexcept; diff --git a/src/nostalgia/core/glfw/core.cpp b/src/nostalgia/core/glfw/core.cpp index 1302a759..d27a7e95 100644 --- a/src/nostalgia/core/glfw/core.cpp +++ b/src/nostalgia/core/glfw/core.cpp @@ -37,15 +37,17 @@ static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int } } -ox::Error init(Context *ctx) noexcept { +ox::Result init(ox::FileSystem *fs) noexcept { + Context ctx; + ctx.rom = fs; const auto id = new GlfwImplData; - ctx->setWindowerData(id); + ctx.setWindowerData(id); using namespace std::chrono; id->startTime = duration_cast(system_clock::now().time_since_epoch()).count(); glfwInit(); - oxReturnError(initGfx(ctx)); + oxReturnError(initGfx(&ctx)); glfwSetKeyCallback(id->window, handleGlfwKeyEvent); - return OxError(0); + return ctx; } ox::Error run(Context *ctx) noexcept { diff --git a/src/nostalgia/core/glfw/gfx.cpp b/src/nostalgia/core/glfw/gfx.cpp index f0690726..6c1cbb62 100644 --- a/src/nostalgia/core/glfw/gfx.cpp +++ b/src/nostalgia/core/glfw/gfx.cpp @@ -57,6 +57,11 @@ ox::Error shutdownGfx(Context *ctx) noexcept { return OxError(0); } +void setWindowTitle(Context *ctx, const char *title) noexcept { + const auto id = ctx->windowerData(); + glfwSetWindowTitle(id->window, title); +} + int getScreenWidth(Context *ctx) noexcept { auto id = ctx->windowerData(); int w = 0, h = 0; diff --git a/src/nostalgia/core/userland/gfx_opengl.cpp b/src/nostalgia/core/userland/gfx_opengl.cpp index 84a1f762..7ff13d0d 100644 --- a/src/nostalgia/core/userland/gfx_opengl.cpp +++ b/src/nostalgia/core/userland/gfx_opengl.cpp @@ -278,7 +278,7 @@ void draw(Context *ctx) noexcept { renderer::drawBackgrounds(id); //bool showDemo = true; //ImGui::ShowDemoWindow(&showDemo); - for (const auto cd : ctx->drawer) { + for (const auto cd : ctx->drawers) { cd->draw(ctx); } if constexpr(config::ImGuiEnabled) { diff --git a/src/nostalgia/player/app.cpp b/src/nostalgia/player/app.cpp index 784812c8..754be2c9 100644 --- a/src/nostalgia/player/app.cpp +++ b/src/nostalgia/player/app.cpp @@ -33,9 +33,7 @@ static int eventHandler(core::Context *ctx) noexcept { } ox::Error run(ox::FileSystem *fs) noexcept { - core::Context ctx; - ctx.rom = fs; - oxReturnError(core::init(&ctx)); + oxRequireM(ctx, core::init(fs)); constexpr auto TileSheetAddr = "/TileSheets/Charset.ng"; constexpr auto PaletteAddr = "/Palettes/Charset.npal"; oxReturnError(core::loadSpriteTileSheet(&ctx, 0, TileSheetAddr, PaletteAddr));