diff --git a/src/nostalgia/core/context.hpp b/src/nostalgia/core/context.hpp index a5c6b747..24776dc6 100644 --- a/src/nostalgia/core/context.hpp +++ b/src/nostalgia/core/context.hpp @@ -56,7 +56,7 @@ class Context { const ox::FileAddress &tilesheetPath, const ox::FileAddress &palettePath) noexcept; friend ox::Error run(Context *ctx) noexcept; - friend ox::Error shutdown(Context *ctx) noexcept; + friend void shutdown(Context *ctx) noexcept; friend ox::Result> init(ox::UniquePtr fs, const char *appName) noexcept; friend ox::String getClipboardText(Context *ctx) noexcept; friend uint64_t ticksMs(Context *ctx) noexcept; @@ -82,6 +82,8 @@ class Context { AssetManager assetManager; int uninterruptedRefreshes = 3; ox::UniquePtr clipboard; +#else + bool running = true; #endif protected: #ifndef OX_BARE_METAL diff --git a/src/nostalgia/core/core.hpp b/src/nostalgia/core/core.hpp index 5c2cca97..baa1f849 100644 --- a/src/nostalgia/core/core.hpp +++ b/src/nostalgia/core/core.hpp @@ -26,6 +26,6 @@ ox::Error run(Context *ctx) noexcept; [[nodiscard]] uint64_t ticksMs(Context *ctx) noexcept; -ox::Error shutdown(Context *ctx) noexcept; +void shutdown(Context *ctx) noexcept; } diff --git a/src/nostalgia/core/gba/core.arm.cpp b/src/nostalgia/core/gba/core.arm.cpp index ebd36528..7ee1e217 100644 --- a/src/nostalgia/core/gba/core.arm.cpp +++ b/src/nostalgia/core/gba/core.arm.cpp @@ -20,7 +20,7 @@ UpdateHandler g_updateHandler = nullptr; ox::Error run(Context *ctx) noexcept { g_wakeupTime = 0; - while (1) { + while (ctx->running) { if (g_wakeupTime <= g_timerMs && g_updateHandler) { auto sleepTime = g_updateHandler(ctx); if (sleepTime >= 0) { diff --git a/src/nostalgia/core/gba/core.cpp b/src/nostalgia/core/gba/core.cpp index ba32b646..1192e3be 100644 --- a/src/nostalgia/core/gba/core.cpp +++ b/src/nostalgia/core/gba/core.cpp @@ -59,4 +59,8 @@ bool buttonDown(Context*, Key k) noexcept { return !(REG_GAMEPAD & (1 << static_cast(k))); } +void shutdown(Context *ctx) noexcept { + ctx->running = false; +} + } diff --git a/src/nostalgia/core/glfw/core.cpp b/src/nostalgia/core/glfw/core.cpp index 276d8b9a..590c98b9 100644 --- a/src/nostalgia/core/glfw/core.cpp +++ b/src/nostalgia/core/glfw/core.cpp @@ -79,10 +79,9 @@ bool buttonDown(Context *ctx, Key key) noexcept { return (id->keysDown >> static_cast(key)) & 1; } -ox::Error shutdown(Context *ctx) noexcept { +void shutdown(Context *ctx) noexcept { const auto id = ctx->windowerData(); glfwSetWindowShouldClose(id->window, true); - return OxError(0); } } diff --git a/src/nostalgia/player/app.cpp b/src/nostalgia/player/app.cpp index eeb5ff70..487740a0 100644 --- a/src/nostalgia/player/app.cpp +++ b/src/nostalgia/player/app.cpp @@ -9,7 +9,7 @@ using namespace nostalgia; static unsigned spriteX = 72; static unsigned spriteY = 64; -static int eventHandler(core::Context *ctx) noexcept { +static int updateHandler(core::Context *ctx) noexcept { if (core::buttonDown(ctx, core::GamePad_Right)) { spriteX += 2; } else if (core::buttonDown(ctx, core::GamePad_Left)) { @@ -28,6 +28,12 @@ static int eventHandler(core::Context *ctx) noexcept { return 16; } +static void keyEventHandler(core::Context *ctx, core::Key key, bool down) noexcept { + if (down && key == core::Key::Alpha_Q) { + core::shutdown(ctx); + } +} + ox::Error run(ox::UniquePtr fs) noexcept { oxRequireM(ctx, core::init(std::move(fs))); constexpr auto TileSheetAddr = "/TileSheets/Charset.ng"; @@ -35,7 +41,8 @@ ox::Error run(ox::UniquePtr fs) noexcept { oxReturnError(core::loadSpriteTileSheet(ctx.get(), 0, TileSheetAddr, PaletteAddr)); oxReturnError(core::initConsole(ctx.get())); core::puts(ctx.get(), 10, 9, "DOPENESS!!!"); - core::setUpdateHandler(ctx.get(), eventHandler); + core::setUpdateHandler(ctx.get(), updateHandler); + core::setKeyEventHandler(ctx.get(), keyEventHandler); return core::run(ctx.get()); } diff --git a/src/nostalgia/studio/studioapp.cpp b/src/nostalgia/studio/studioapp.cpp index c235c9f3..61631b6e 100644 --- a/src/nostalgia/studio/studioapp.cpp +++ b/src/nostalgia/studio/studioapp.cpp @@ -70,7 +70,7 @@ void StudioUI::handleKeyEvent(core::Key key, bool down) noexcept { m_taskRunner.add(new FileDialogManager(this, &StudioUI::openProject)); break; case core::Key::Alpha_Q: - oxIgnoreError(core::shutdown(m_ctx)); + core::shutdown(m_ctx); break; case core::Key::Alpha_S: save(); @@ -120,7 +120,7 @@ void StudioUI::drawMenu() noexcept { m_acitveEditor->save(); } if (ImGui::MenuItem("Quit", "Ctrl+Q")) { - oxIgnoreError(core::shutdown(m_ctx)); + core::shutdown(m_ctx); } ImGui::EndMenu(); }