[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:
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;

View File

@ -20,7 +20,7 @@ namespace nostalgia::core {
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;

View File

@ -40,10 +40,10 @@ static void initTimer() noexcept {
REG_IE = REG_IE | Int_timer0;
}
ox::Result<Context> init(ox::FileSystem *fs) noexcept {
Context ctx;
ctx.rom = fs;
oxReturnError(initGfx(&ctx));
ox::Result<ox::UniquePtr<Context>> init(ox::FileSystem *fs) noexcept {
auto ctx = ox::make_unique<Context>();
ctx->rom = fs;
oxReturnError(initGfx(ctx.get()));
initTimer();
initIrq();
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 {
Context ctx;
ctx.rom = fs;
ox::Result<ox::UniquePtr<Context>> init(ox::FileSystem *fs) noexcept {
auto ctx = ox::make_unique<Context>();
ctx->rom = fs;
const auto id = new GlfwImplData;
ctx.setWindowerData(id);
ctx->setWindowerData(id);
using namespace std::chrono;
id->startTime = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
glfwInit();
oxReturnError(initGfx(&ctx));
oxReturnError(initGfx(ctx.get()));
glfwSetKeyCallback(id->window, handleGlfwKeyEvent);
return ctx;
}

View File

@ -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);
}