[nostalgia/core] Make Context never move

This commit is contained in:
Gary Talent 2021-07-18 16:11:23 -05:00
parent 70fd56ce0b
commit bed8c35218
5 changed files with 19 additions and 22 deletions

View File

@ -32,12 +32,9 @@ class Context {
public: public:
constexpr Context() noexcept = default; constexpr Context() noexcept = default;
constexpr Context(const Context &&other) noexcept { Context(Context &other) noexcept = delete;
rom = ox::move(other.rom); Context(const Context &other) noexcept = delete;
drawers = ox::move(other.drawers); Context(const Context &&other) noexcept = delete;
m_windowerData = ox::move(other.m_windowerData);
m_rendererData = ox::move(other.m_rendererData);
}
constexpr void setWindowerData(void *windowerData) noexcept { constexpr void setWindowerData(void *windowerData) noexcept {
m_windowerData = windowerData; m_windowerData = windowerData;

View File

@ -20,7 +20,7 @@ namespace nostalgia::core {
using event_handler = int(*)(Context*); using event_handler = int(*)(Context*);
ox::Result<Context> init(ox::FileSystem *fs) noexcept; ox::Result<ox::UniquePtr<Context>> init(ox::FileSystem *fs) noexcept;
ox::Error run(Context *ctx) noexcept; ox::Error run(Context *ctx) noexcept;

View File

@ -40,10 +40,10 @@ static void initTimer() noexcept {
REG_IE = REG_IE | Int_timer0; REG_IE = REG_IE | Int_timer0;
} }
ox::Result<Context> init(ox::FileSystem *fs) noexcept { ox::Result<ox::UniquePtr<Context>> init(ox::FileSystem *fs) noexcept {
Context ctx; auto ctx = ox::make_unique<Context>();
ctx.rom = fs; ctx->rom = fs;
oxReturnError(initGfx(&ctx)); oxReturnError(initGfx(ctx.get()));
initTimer(); initTimer();
initIrq(); initIrq();
return ctx; return ctx;

View File

@ -37,15 +37,15 @@ static void handleGlfwKeyEvent(GLFWwindow *window, int key, int, int action, int
} }
} }
ox::Result<Context> init(ox::FileSystem *fs) noexcept { ox::Result<ox::UniquePtr<Context>> init(ox::FileSystem *fs) noexcept {
Context ctx; auto ctx = ox::make_unique<Context>();
ctx.rom = fs; ctx->rom = fs;
const auto id = new GlfwImplData; const auto id = new GlfwImplData;
ctx.setWindowerData(id); ctx->setWindowerData(id);
using namespace std::chrono; using namespace std::chrono;
id->startTime = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count(); id->startTime = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
glfwInit(); glfwInit();
oxReturnError(initGfx(&ctx)); oxReturnError(initGfx(ctx.get()));
glfwSetKeyCallback(id->window, handleGlfwKeyEvent); glfwSetKeyCallback(id->window, handleGlfwKeyEvent);
return ctx; return ctx;
} }

View File

@ -36,12 +36,12 @@ ox::Error run(ox::FileSystem *fs) noexcept {
oxRequireM(ctx, core::init(fs)); oxRequireM(ctx, core::init(fs));
constexpr auto TileSheetAddr = "/TileSheets/Charset.ng"; constexpr auto TileSheetAddr = "/TileSheets/Charset.ng";
constexpr auto PaletteAddr = "/Palettes/Charset.npal"; constexpr auto PaletteAddr = "/Palettes/Charset.npal";
oxReturnError(core::loadSpriteTileSheet(&ctx, 0, TileSheetAddr, PaletteAddr)); oxReturnError(core::loadSpriteTileSheet(ctx.get(), 0, TileSheetAddr, PaletteAddr));
oxReturnError(core::initConsole(&ctx)); oxReturnError(core::initConsole(ctx.get()));
core::puts(&ctx, 10, 9, "DOPENESS!!!"); core::puts(ctx.get(), 10, 9, "DOPENESS!!!");
core::setEventHandler(&ctx, eventHandler); core::setEventHandler(ctx.get(), eventHandler);
oxReturnError(core::run(&ctx)); oxReturnError(core::run(ctx.get()));
oxReturnError(core::shutdownGfx(&ctx)); oxReturnError(core::shutdownGfx(ctx.get()));
return OxError(0); return OxError(0);
} }