[nostalgia/core] Add Context parameter to event_handler

This commit is contained in:
Gary Talent 2020-07-28 19:10:36 -05:00
parent 80f98802b6
commit 0d405ec88a
3 changed files with 4 additions and 4 deletions

View File

@ -16,7 +16,7 @@
namespace nostalgia::core { namespace nostalgia::core {
using event_handler = int(*)(void); using event_handler = int(*)(Context*);
[[nodiscard]] ox::Error init(Context *ctx); [[nodiscard]] ox::Error init(Context *ctx);

View File

@ -21,11 +21,11 @@ extern volatile gba_timer_t g_timerMs;
gba_timer_t g_wakeupTime; gba_timer_t g_wakeupTime;
event_handler g_eventHandler = nullptr; event_handler g_eventHandler = nullptr;
ox::Error run(Context*) { ox::Error run(Context *ctx) {
g_wakeupTime = 0; g_wakeupTime = 0;
while (1) { while (1) {
if (g_wakeupTime <= g_timerMs && g_eventHandler) { if (g_wakeupTime <= g_timerMs && g_eventHandler) {
auto sleepTime = g_eventHandler(); auto sleepTime = g_eventHandler(ctx);
if (sleepTime >= 0) { if (sleepTime >= 0) {
g_wakeupTime = g_timerMs + static_cast<unsigned>(sleepTime); g_wakeupTime = g_timerMs + static_cast<unsigned>(sleepTime);
} else { } else {

View File

@ -17,7 +17,7 @@ using namespace nostalgia;
static unsigned spriteX = 72; static unsigned spriteX = 72;
static unsigned spriteY = 64; static unsigned spriteY = 64;
static int mainLoop() { static int mainLoop(core::Context*) {
if (core::buttonDown(core::GamePad_Right)) { if (core::buttonDown(core::GamePad_Right)) {
spriteX += 2; spriteX += 2;
} else if (core::buttonDown(core::GamePad_Left)) { } else if (core::buttonDown(core::GamePad_Left)) {