From 193a27ce44726234d2d33837147a46ead3eb94a1 Mon Sep 17 00:00:00 2001 From: skejeton Date: Sat, 13 Jul 2024 10:21:44 -0300 Subject: [PATCH] Update Umka version --- lib/umka | 2 +- src/main.c | 20 ++++++++++++++------ src/tophat.h | 12 ++++++++++-- src/window.c | 14 ++++++-------- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/lib/umka b/lib/umka index f9ffb71..eca0f48 160000 --- a/lib/umka +++ b/lib/umka @@ -1 +1 @@ -Subproject commit f9ffb71b3da03dba60637f4a6c6ad5b9cd7e0ad8 +Subproject commit eca0f483512bef77362eb8ea70ad93ef9fc29b8d diff --git a/src/main.c b/src/main.c index a388516..1818795 100644 --- a/src/main.c +++ b/src/main.c @@ -100,14 +100,22 @@ th_init(const char *scriptpath, const char *script_src) exit(0); } - thg->umth_frame_callback = umkaGetFunc(thg->umka, "window.um", "umth_frame_callback"); - thg->umth_destroy_callback = umkaGetFunc(thg->umka, "window.um", "umth_destroy_callback"); + thg->umka_init.addr = umkaGetFunc( + thg->umka, "tophat_main.um", "__th_init", &thg->umka_init.p, &thg->umka_init.r); + thg->umka_frame.addr = umkaGetFunc( + thg->umka, "window.um", "umth_frame_callback", &thg->umka_frame.p, &thg->umka_frame.r); + thg->umka_destroy.addr = umkaGetFunc(thg->umka, "window.um", "umth_destroy_callback", + &thg->umka_destroy.p, &thg->umka_destroy.r); + + if (thg->umka_init.addr == -1) { + th_error("Internal error: umka_init == -1"); + } - if (thg->umth_frame_callback == -1) { + if (thg->umka_frame.addr == -1) { th_error("Internal error: umth_frame_callback == -1"); } - if (thg->umth_destroy_callback == -1) { + if (thg->umka_destroy.addr == -1) { th_error("Internal error: umth_destroy_callback == -1"); } @@ -131,9 +139,9 @@ th_deinit() } } - UmkaStackSlot s; if (umkaAlive(thg->umka)) - umkaCall(thg->umka, thg->umth_destroy_callback, 0, &s, &s); + umkaCall( + thg->umka, thg->umka_destroy.addr, thg->umka_destroy.p, thg->umka_destroy.r); if (umkaAlive(thg->umka)) umkaRun(thg->umka); diff --git a/src/tophat.h b/src/tophat.h index 344be13..3a917f7 100644 --- a/src/tophat.h +++ b/src/tophat.h @@ -273,6 +273,13 @@ typedef struct float rumble_right; } th_generic_gamepad; +typedef struct +{ + int addr; + UmkaStackSlot *p; + UmkaStackSlot *r; +} th_umka_func; + // struct holding all tophat's global variables. typedef struct { @@ -333,8 +340,9 @@ typedef struct float dpi_scale_factor; - int umth_destroy_callback; - int umth_frame_callback; + th_umka_func umka_init; + th_umka_func umka_destroy; + th_umka_func umka_frame; ma_engine audio_engine; } th_global; diff --git a/src/window.c b/src/window.c index 068295a..ed9944e 100644 --- a/src/window.c +++ b/src/window.c @@ -64,11 +64,9 @@ init(void) th_canvas_init(); th_image_init(); - UmkaStackSlot s; - if (umkaAlive(thg->umka)) { - int code = umkaCall( - thg->umka, umkaGetFunc(thg->umka, "tophat_main.um", "__th_init"), 0, &s, &s); + int code = + umkaCall(thg->umka, thg->umka_init.addr, thg->umka_init.p, thg->umka_init.r); if (!umkaAlive(thg->umka)) { th_print_umka_error_and_quit(code); } @@ -97,11 +95,11 @@ frame(void) th_window_get_dimensions(&window_width, &window_height); thg->target_size = (th_vf2){.w = window_width, .h = window_height}; - UmkaStackSlot s; - if (thg->umka && umkaAlive(thg->umka) && thg->umth_frame_callback != -1) { - s.realVal = sapp_frame_duration(); + if (thg->umka && umkaAlive(thg->umka)) { + umkaGetParam(thg->umka_frame.p, 0)->realVal = sapp_frame_duration(); - int code = umkaCall(thg->umka, thg->umth_frame_callback, 1, &s, &s); + int code = + umkaCall(thg->umka, thg->umka_frame.addr, thg->umka_frame.p, thg->umka_frame.r); if (!umkaAlive(thg->umka)) { th_print_umka_error_and_quit(code); }