[nostalgia] Make core::shutdown return void and add GBA implementation
This commit is contained in:
parent
6eb4070d97
commit
053d35b31c
@ -56,7 +56,7 @@ class Context {
|
|||||||
const ox::FileAddress &tilesheetPath,
|
const ox::FileAddress &tilesheetPath,
|
||||||
const ox::FileAddress &palettePath) noexcept;
|
const ox::FileAddress &palettePath) noexcept;
|
||||||
friend ox::Error run(Context *ctx) noexcept;
|
friend ox::Error run(Context *ctx) noexcept;
|
||||||
friend ox::Error shutdown(Context *ctx) noexcept;
|
friend void shutdown(Context *ctx) noexcept;
|
||||||
friend ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, const char *appName) noexcept;
|
friend ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, const char *appName) noexcept;
|
||||||
friend ox::String getClipboardText(Context *ctx) noexcept;
|
friend ox::String getClipboardText(Context *ctx) noexcept;
|
||||||
friend uint64_t ticksMs(Context *ctx) noexcept;
|
friend uint64_t ticksMs(Context *ctx) noexcept;
|
||||||
@ -82,6 +82,8 @@ class Context {
|
|||||||
AssetManager assetManager;
|
AssetManager assetManager;
|
||||||
int uninterruptedRefreshes = 3;
|
int uninterruptedRefreshes = 3;
|
||||||
ox::UniquePtr<BaseClipboardObject> clipboard;
|
ox::UniquePtr<BaseClipboardObject> clipboard;
|
||||||
|
#else
|
||||||
|
bool running = true;
|
||||||
#endif
|
#endif
|
||||||
protected:
|
protected:
|
||||||
#ifndef OX_BARE_METAL
|
#ifndef OX_BARE_METAL
|
||||||
|
@ -26,6 +26,6 @@ ox::Error run(Context *ctx) noexcept;
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
uint64_t ticksMs(Context *ctx) noexcept;
|
uint64_t ticksMs(Context *ctx) noexcept;
|
||||||
|
|
||||||
ox::Error shutdown(Context *ctx) noexcept;
|
void shutdown(Context *ctx) noexcept;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ UpdateHandler g_updateHandler = nullptr;
|
|||||||
|
|
||||||
ox::Error run(Context *ctx) noexcept {
|
ox::Error run(Context *ctx) noexcept {
|
||||||
g_wakeupTime = 0;
|
g_wakeupTime = 0;
|
||||||
while (1) {
|
while (ctx->running) {
|
||||||
if (g_wakeupTime <= g_timerMs && g_updateHandler) {
|
if (g_wakeupTime <= g_timerMs && g_updateHandler) {
|
||||||
auto sleepTime = g_updateHandler(ctx);
|
auto sleepTime = g_updateHandler(ctx);
|
||||||
if (sleepTime >= 0) {
|
if (sleepTime >= 0) {
|
||||||
|
@ -59,4 +59,8 @@ bool buttonDown(Context*, Key k) noexcept {
|
|||||||
return !(REG_GAMEPAD & (1 << static_cast<int>(k)));
|
return !(REG_GAMEPAD & (1 << static_cast<int>(k)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void shutdown(Context *ctx) noexcept {
|
||||||
|
ctx->running = false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -79,10 +79,9 @@ bool buttonDown(Context *ctx, Key key) noexcept {
|
|||||||
return (id->keysDown >> static_cast<int>(key)) & 1;
|
return (id->keysDown >> static_cast<int>(key)) & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ox::Error shutdown(Context *ctx) noexcept {
|
void shutdown(Context *ctx) noexcept {
|
||||||
const auto id = ctx->windowerData<GlfwImplData>();
|
const auto id = ctx->windowerData<GlfwImplData>();
|
||||||
glfwSetWindowShouldClose(id->window, true);
|
glfwSetWindowShouldClose(id->window, true);
|
||||||
return OxError(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ using namespace nostalgia;
|
|||||||
static unsigned spriteX = 72;
|
static unsigned spriteX = 72;
|
||||||
static unsigned spriteY = 64;
|
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)) {
|
if (core::buttonDown(ctx, core::GamePad_Right)) {
|
||||||
spriteX += 2;
|
spriteX += 2;
|
||||||
} else if (core::buttonDown(ctx, core::GamePad_Left)) {
|
} else if (core::buttonDown(ctx, core::GamePad_Left)) {
|
||||||
@ -28,6 +28,12 @@ static int eventHandler(core::Context *ctx) noexcept {
|
|||||||
return 16;
|
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<ox::FileSystem> fs) noexcept {
|
ox::Error run(ox::UniquePtr<ox::FileSystem> fs) noexcept {
|
||||||
oxRequireM(ctx, core::init(std::move(fs)));
|
oxRequireM(ctx, core::init(std::move(fs)));
|
||||||
constexpr auto TileSheetAddr = "/TileSheets/Charset.ng";
|
constexpr auto TileSheetAddr = "/TileSheets/Charset.ng";
|
||||||
@ -35,7 +41,8 @@ ox::Error run(ox::UniquePtr<ox::FileSystem> fs) noexcept {
|
|||||||
oxReturnError(core::loadSpriteTileSheet(ctx.get(), 0, TileSheetAddr, PaletteAddr));
|
oxReturnError(core::loadSpriteTileSheet(ctx.get(), 0, TileSheetAddr, PaletteAddr));
|
||||||
oxReturnError(core::initConsole(ctx.get()));
|
oxReturnError(core::initConsole(ctx.get()));
|
||||||
core::puts(ctx.get(), 10, 9, "DOPENESS!!!");
|
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());
|
return core::run(ctx.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ void StudioUI::handleKeyEvent(core::Key key, bool down) noexcept {
|
|||||||
m_taskRunner.add(new FileDialogManager(this, &StudioUI::openProject));
|
m_taskRunner.add(new FileDialogManager(this, &StudioUI::openProject));
|
||||||
break;
|
break;
|
||||||
case core::Key::Alpha_Q:
|
case core::Key::Alpha_Q:
|
||||||
oxIgnoreError(core::shutdown(m_ctx));
|
core::shutdown(m_ctx);
|
||||||
break;
|
break;
|
||||||
case core::Key::Alpha_S:
|
case core::Key::Alpha_S:
|
||||||
save();
|
save();
|
||||||
@ -120,7 +120,7 @@ void StudioUI::drawMenu() noexcept {
|
|||||||
m_acitveEditor->save();
|
m_acitveEditor->save();
|
||||||
}
|
}
|
||||||
if (ImGui::MenuItem("Quit", "Ctrl+Q")) {
|
if (ImGui::MenuItem("Quit", "Ctrl+Q")) {
|
||||||
oxIgnoreError(core::shutdown(m_ctx));
|
core::shutdown(m_ctx);
|
||||||
}
|
}
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user