[nostalgia/core] Rename event handler to update handler

This commit is contained in:
Gary Talent 2022-03-19 20:11:53 -05:00
parent 8e660f6b15
commit 2223fe7863
9 changed files with 14 additions and 14 deletions

View File

@ -67,7 +67,7 @@ class Context {
friend void setBgStatus(Context *ctx, uint32_t status) noexcept; friend void setBgStatus(Context *ctx, uint32_t status) noexcept;
friend void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept; friend void setBgStatus(Context *ctx, unsigned bg, bool status) noexcept;
friend void setClipboardText(Context *ctx, const ox::String &text) noexcept; friend void setClipboardText(Context *ctx, const ox::String &text) noexcept;
friend void setEventHandler(Context *ctx, event_handler h) noexcept; friend void setUpdateHandler(Context *ctx, UpdateHandler h) noexcept;
friend void setTile(Context *ctx, int layer, int column, int row, uint8_t tile) noexcept; friend void setTile(Context *ctx, int layer, int column, int row, uint8_t tile) noexcept;
friend void setWindowTitle(Context *ctx, const char *title) noexcept; friend void setWindowTitle(Context *ctx, const char *title) noexcept;

View File

@ -8,10 +8,10 @@ namespace nostalgia::core {
class Context; class Context;
using event_handler = int(*)(Context*); using UpdateHandler = int(*)(Context*);
// Sets event handler that sleeps for the time given in the return value. The // Sets event handler that sleeps for the time given in the return value. The
// sleep time is a minimum of ~16 milliseconds. // sleep time is a minimum of ~16 milliseconds.
void setEventHandler(Context *ctx, event_handler) noexcept; void setUpdateHandler(Context *ctx, UpdateHandler) noexcept;
} }

View File

@ -16,13 +16,13 @@ namespace nostalgia::core {
extern volatile gba_timer_t g_timerMs; extern volatile gba_timer_t g_timerMs;
gba_timer_t g_wakeupTime; gba_timer_t g_wakeupTime;
event_handler g_eventHandler = nullptr; 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 (1) {
if (g_wakeupTime <= g_timerMs && g_eventHandler) { if (g_wakeupTime <= g_timerMs && g_updateHandler) {
auto sleepTime = g_eventHandler(ctx); auto sleepTime = g_updateHandler(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

@ -20,7 +20,7 @@ constexpr int NanoSecond = 1000000000;
constexpr int MilliSecond = 1000; constexpr int MilliSecond = 1000;
constexpr int TicksMs59ns = 65535 - (NanoSecond / MilliSecond) / 59.59; constexpr int TicksMs59ns = 65535 - (NanoSecond / MilliSecond) / 59.59;
extern event_handler g_eventHandler; extern UpdateHandler g_updateHandler;
extern volatile gba_timer_t g_timerMs; extern volatile gba_timer_t g_timerMs;
@ -47,8 +47,8 @@ ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, const
return ctx; return ctx;
} }
void setEventHandler(Context*, event_handler h) noexcept { void setUpdateHandler(Context*, UpdateHandler h) noexcept {
g_eventHandler = h; g_updateHandler = h;
} }
uint64_t ticksMs(Context*) noexcept { uint64_t ticksMs(Context*) noexcept {

View File

@ -62,7 +62,7 @@ ox::Error run(Context *ctx) noexcept {
return OxError(0); return OxError(0);
} }
void setEventHandler(Context *ctx, event_handler h) noexcept { void setUpdateHandler(Context *ctx, UpdateHandler h) noexcept {
const auto id = ctx->windowerData<GlfwImplData>(); const auto id = ctx->windowerData<GlfwImplData>();
id->eventHandler = h; id->eventHandler = h;
} }

View File

@ -11,7 +11,7 @@ namespace nostalgia::core {
struct GlfwImplData { struct GlfwImplData {
struct GLFWwindow *window = nullptr; struct GLFWwindow *window = nullptr;
int64_t startTime = 0; int64_t startTime = 0;
event_handler eventHandler = nullptr; UpdateHandler eventHandler = nullptr;
uint64_t wakeupTime = 0; uint64_t wakeupTime = 0;
}; };

View File

@ -11,7 +11,7 @@ ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem>, const cha
return OxError(1); return OxError(1);
} }
void setEventHandler(Context*, event_handler) noexcept { void setUpdateHandler(Context*, UpdateHandler) noexcept {
} }
uint64_t ticksMs(Context*) noexcept { uint64_t ticksMs(Context*) noexcept {

View File

@ -35,7 +35,7 @@ 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::setEventHandler(ctx.get(), eventHandler); core::setUpdateHandler(ctx.get(), eventHandler);
return core::run(ctx.get()); return core::run(ctx.get());
} }

View File

@ -33,7 +33,7 @@ static int eventHandler(core::Context *ctx) noexcept {
static ox::Error run(ox::UniquePtr<ox::FileSystem> fs) noexcept { static ox::Error run(ox::UniquePtr<ox::FileSystem> fs) noexcept {
oxRequireM(ctx, core::init(std::move(fs), "NostalgiaStudio")); oxRequireM(ctx, core::init(std::move(fs), "NostalgiaStudio"));
core::setWindowTitle(ctx.get(), "Nostalgia Studio"); core::setWindowTitle(ctx.get(), "Nostalgia Studio");
core::setEventHandler(ctx.get(), eventHandler); core::setUpdateHandler(ctx.get(), eventHandler);
core::setConstantRefresh(ctx.get(), false); core::setConstantRefresh(ctx.get(), false);
studio::StudioContext studioCtx; studio::StudioContext studioCtx;
core::setApplicationData(ctx.get(), &studioCtx); core::setApplicationData(ctx.get(), &studioCtx);