[nostalgia/core] Rename event handler to update handler
This commit is contained in:
parent
8e660f6b15
commit
2223fe7863
@ -67,7 +67,7 @@ class Context {
|
||||
friend void setBgStatus(Context *ctx, uint32_t status) noexcept;
|
||||
friend void setBgStatus(Context *ctx, unsigned bg, bool status) 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 setWindowTitle(Context *ctx, const char *title) noexcept;
|
||||
|
||||
|
@ -8,10 +8,10 @@ namespace nostalgia::core {
|
||||
|
||||
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
|
||||
// sleep time is a minimum of ~16 milliseconds.
|
||||
void setEventHandler(Context *ctx, event_handler) noexcept;
|
||||
void setUpdateHandler(Context *ctx, UpdateHandler) noexcept;
|
||||
|
||||
}
|
||||
|
@ -16,13 +16,13 @@ namespace nostalgia::core {
|
||||
|
||||
extern volatile gba_timer_t g_timerMs;
|
||||
gba_timer_t g_wakeupTime;
|
||||
event_handler g_eventHandler = nullptr;
|
||||
UpdateHandler g_updateHandler = nullptr;
|
||||
|
||||
ox::Error run(Context *ctx) noexcept {
|
||||
g_wakeupTime = 0;
|
||||
while (1) {
|
||||
if (g_wakeupTime <= g_timerMs && g_eventHandler) {
|
||||
auto sleepTime = g_eventHandler(ctx);
|
||||
if (g_wakeupTime <= g_timerMs && g_updateHandler) {
|
||||
auto sleepTime = g_updateHandler(ctx);
|
||||
if (sleepTime >= 0) {
|
||||
g_wakeupTime = g_timerMs + static_cast<unsigned>(sleepTime);
|
||||
} else {
|
||||
|
@ -20,7 +20,7 @@ constexpr int NanoSecond = 1000000000;
|
||||
constexpr int MilliSecond = 1000;
|
||||
constexpr int TicksMs59ns = 65535 - (NanoSecond / MilliSecond) / 59.59;
|
||||
|
||||
extern event_handler g_eventHandler;
|
||||
extern UpdateHandler g_updateHandler;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void setEventHandler(Context*, event_handler h) noexcept {
|
||||
g_eventHandler = h;
|
||||
void setUpdateHandler(Context*, UpdateHandler h) noexcept {
|
||||
g_updateHandler = h;
|
||||
}
|
||||
|
||||
uint64_t ticksMs(Context*) noexcept {
|
||||
|
@ -62,7 +62,7 @@ ox::Error run(Context *ctx) noexcept {
|
||||
return OxError(0);
|
||||
}
|
||||
|
||||
void setEventHandler(Context *ctx, event_handler h) noexcept {
|
||||
void setUpdateHandler(Context *ctx, UpdateHandler h) noexcept {
|
||||
const auto id = ctx->windowerData<GlfwImplData>();
|
||||
id->eventHandler = h;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace nostalgia::core {
|
||||
struct GlfwImplData {
|
||||
struct GLFWwindow *window = nullptr;
|
||||
int64_t startTime = 0;
|
||||
event_handler eventHandler = nullptr;
|
||||
UpdateHandler eventHandler = nullptr;
|
||||
uint64_t wakeupTime = 0;
|
||||
};
|
||||
|
||||
|
@ -11,7 +11,7 @@ ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem>, const cha
|
||||
return OxError(1);
|
||||
}
|
||||
|
||||
void setEventHandler(Context*, event_handler) noexcept {
|
||||
void setUpdateHandler(Context*, UpdateHandler) noexcept {
|
||||
}
|
||||
|
||||
uint64_t ticksMs(Context*) noexcept {
|
||||
|
@ -35,7 +35,7 @@ ox::Error run(ox::UniquePtr<ox::FileSystem> fs) noexcept {
|
||||
oxReturnError(core::loadSpriteTileSheet(ctx.get(), 0, TileSheetAddr, PaletteAddr));
|
||||
oxReturnError(core::initConsole(ctx.get()));
|
||||
core::puts(ctx.get(), 10, 9, "DOPENESS!!!");
|
||||
core::setEventHandler(ctx.get(), eventHandler);
|
||||
core::setUpdateHandler(ctx.get(), eventHandler);
|
||||
return core::run(ctx.get());
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ static int eventHandler(core::Context *ctx) noexcept {
|
||||
static ox::Error run(ox::UniquePtr<ox::FileSystem> fs) noexcept {
|
||||
oxRequireM(ctx, core::init(std::move(fs), "NostalgiaStudio"));
|
||||
core::setWindowTitle(ctx.get(), "Nostalgia Studio");
|
||||
core::setEventHandler(ctx.get(), eventHandler);
|
||||
core::setUpdateHandler(ctx.get(), eventHandler);
|
||||
core::setConstantRefresh(ctx.get(), false);
|
||||
studio::StudioContext studioCtx;
|
||||
core::setApplicationData(ctx.get(), &studioCtx);
|
||||
|
Loading…
Reference in New Issue
Block a user