From 41cebff5fc95de619063ccf92733a8f5ec1f16b0 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 13 Feb 2022 02:21:38 -0600 Subject: [PATCH] [nostalgia/core] Add Context buttonDown function --- src/nostalgia/core/gba/core.cpp | 2 +- src/nostalgia/core/glfw/core.cpp | 5 +---- src/nostalgia/core/input.hpp | 4 +++- src/nostalgia/player/app.cpp | 8 ++++---- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/nostalgia/core/gba/core.cpp b/src/nostalgia/core/gba/core.cpp index 8ad054f5..a2969a74 100644 --- a/src/nostalgia/core/gba/core.cpp +++ b/src/nostalgia/core/gba/core.cpp @@ -55,7 +55,7 @@ uint64_t ticksMs(Context*) noexcept { return g_timerMs; } -bool buttonDown(Key k) noexcept { +bool buttonDown(Context*, Key k) noexcept { return !(REG_GAMEPAD & k); } diff --git a/src/nostalgia/core/glfw/core.cpp b/src/nostalgia/core/glfw/core.cpp index 6564ef8c..f017bfeb 100644 --- a/src/nostalgia/core/glfw/core.cpp +++ b/src/nostalgia/core/glfw/core.cpp @@ -13,8 +13,6 @@ namespace nostalgia::core { -void draw(Context *ctx) noexcept; - ox::Result> init(ox::UniquePtr fs, const char *appName) noexcept { auto ctx = ox::make_unique(); ctx->rom = std::move(fs); @@ -72,7 +70,7 @@ uint64_t ticksMs(Context *ctx) noexcept { return static_cast(now - id->startTime); } -bool buttonDown(Key) noexcept { +bool buttonDown(Context*, Key) noexcept { return false; } @@ -82,5 +80,4 @@ ox::Error shutdown(Context *ctx) noexcept { return OxError(0); } - } diff --git a/src/nostalgia/core/input.hpp b/src/nostalgia/core/input.hpp index 9a507004..e80afb56 100644 --- a/src/nostalgia/core/input.hpp +++ b/src/nostalgia/core/input.hpp @@ -20,7 +20,9 @@ enum Key { GamePad_L = 512, }; +class Context; + [[nodiscard]] -bool buttonDown(Key) noexcept; +bool buttonDown(Context *ctx, Key) noexcept; } diff --git a/src/nostalgia/player/app.cpp b/src/nostalgia/player/app.cpp index fff3524b..63ab0854 100644 --- a/src/nostalgia/player/app.cpp +++ b/src/nostalgia/player/app.cpp @@ -10,14 +10,14 @@ static unsigned spriteX = 72; static unsigned spriteY = 64; static int eventHandler(core::Context *ctx) noexcept { - if (core::buttonDown(core::GamePad_Right)) { + if (core::buttonDown(ctx, core::GamePad_Right)) { spriteX += 2; - } else if (core::buttonDown(core::GamePad_Left)) { + } else if (core::buttonDown(ctx, core::GamePad_Left)) { spriteX -= 2; } - if (core::buttonDown(core::GamePad_Down)) { + if (core::buttonDown(ctx, core::GamePad_Down)) { spriteY += 2; - } else if (core::buttonDown(core::GamePad_Up)) { + } else if (core::buttonDown(ctx, core::GamePad_Up)) { spriteY -= 2; } constexpr auto s = "nostalgia";