From bed8c352188ee12a8d22ded76c2ae5ddadb9763a Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 18 Jul 2021 16:11:23 -0500 Subject: [PATCH] [nostalgia/core] Make Context never move --- src/nostalgia/core/context.hpp | 9 +++------ src/nostalgia/core/core.hpp | 2 +- src/nostalgia/core/gba/core.cpp | 8 ++++---- src/nostalgia/core/glfw/core.cpp | 10 +++++----- src/nostalgia/player/app.cpp | 12 ++++++------ 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/nostalgia/core/context.hpp b/src/nostalgia/core/context.hpp index 3513fd90..10cf3843 100644 --- a/src/nostalgia/core/context.hpp +++ b/src/nostalgia/core/context.hpp @@ -32,12 +32,9 @@ class Context { 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); - } + Context(Context &other) noexcept = delete; + Context(const Context &other) noexcept = delete; + Context(const Context &&other) noexcept = delete; constexpr void setWindowerData(void *windowerData) noexcept { m_windowerData = windowerData; diff --git a/src/nostalgia/core/core.hpp b/src/nostalgia/core/core.hpp index 8ee5f6c1..c861ca76 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::Result init(ox::FileSystem *fs) 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 3c242cc4..17e16891 100644 --- a/src/nostalgia/core/gba/core.cpp +++ b/src/nostalgia/core/gba/core.cpp @@ -40,10 +40,10 @@ static void initTimer() noexcept { REG_IE = REG_IE | Int_timer0; } -ox::Result init(ox::FileSystem *fs) noexcept { - Context ctx; - ctx.rom = fs; - oxReturnError(initGfx(&ctx)); +ox::Result> init(ox::FileSystem *fs) noexcept { + auto ctx = ox::make_unique(); + ctx->rom = fs; + oxReturnError(initGfx(ctx.get())); initTimer(); initIrq(); return ctx; diff --git a/src/nostalgia/core/glfw/core.cpp b/src/nostalgia/core/glfw/core.cpp index d27a7e95..fa3a0393 100644 --- a/src/nostalgia/core/glfw/core.cpp +++ b/src/nostalgia/core/glfw/core.cpp @@ -37,15 +37,15 @@ static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int } } -ox::Result init(ox::FileSystem *fs) noexcept { - Context ctx; - ctx.rom = fs; +ox::Result> init(ox::FileSystem *fs) noexcept { + auto ctx = ox::make_unique(); + 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.get())); glfwSetKeyCallback(id->window, handleGlfwKeyEvent); return ctx; } diff --git a/src/nostalgia/player/app.cpp b/src/nostalgia/player/app.cpp index 754be2c9..6f6aac05 100644 --- a/src/nostalgia/player/app.cpp +++ b/src/nostalgia/player/app.cpp @@ -36,12 +36,12 @@ ox::Error run(ox::FileSystem *fs) noexcept { oxRequireM(ctx, core::init(fs)); constexpr auto TileSheetAddr = "/TileSheets/Charset.ng"; constexpr auto PaletteAddr = "/Palettes/Charset.npal"; - oxReturnError(core::loadSpriteTileSheet(&ctx, 0, TileSheetAddr, PaletteAddr)); - oxReturnError(core::initConsole(&ctx)); - core::puts(&ctx, 10, 9, "DOPENESS!!!"); - core::setEventHandler(&ctx, eventHandler); - oxReturnError(core::run(&ctx)); - oxReturnError(core::shutdownGfx(&ctx)); + oxReturnError(core::loadSpriteTileSheet(ctx.get(), 0, TileSheetAddr, PaletteAddr)); + oxReturnError(core::initConsole(ctx.get())); + core::puts(ctx.get(), 10, 9, "DOPENESS!!!"); + core::setEventHandler(ctx.get(), eventHandler); + oxReturnError(core::run(ctx.get())); + oxReturnError(core::shutdownGfx(ctx.get())); return OxError(0); }