Skip to content

Commit

Permalink
Update Umka version
Browse files Browse the repository at this point in the history
  • Loading branch information
skejeton committed Jul 13, 2024
1 parent 3de9ed3 commit 193a27c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
20 changes: 14 additions & 6 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand All @@ -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);

Expand Down
12 changes: 10 additions & 2 deletions src/tophat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 6 additions & 8 deletions src/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 193a27c

Please sign in to comment.