From 53d04690f83ccdd89cc6f287e5450dc92d426c0b Mon Sep 17 00:00:00 2001 From: ske Date: Tue, 9 Jul 2024 19:37:39 -0300 Subject: [PATCH] Update bindings to the new API. (#193) * Fix bindings up until end of image.um * Convert more bindings * Convert ent.um * init collC to 0 * Fix Ent.getColl * Fix Ent.ysort * audio.um and window.um * Fix the remaining bindings * (style) dereference value parameter in definition --- lib/miniaudio | 2 +- lib/sokol | 2 +- lib/umka | 2 +- src/bindings.c | 900 +++++++++++++++++++++++++++---------------------- src/entity.c | 1 - src/staembed.c | 255 ++++++-------- umka/canvas.um | 11 +- umka/coll.um | 24 +- umka/ent.um | 17 +- umka/font.um | 6 +- umka/image.um | 31 +- umka/input.um | 78 ++--- umka/nav.um | 9 +- umka/rect.um | 8 +- umka/th.um | 34 +- umka/window.um | 29 +- 16 files changed, 720 insertions(+), 689 deletions(-) diff --git a/lib/miniaudio b/lib/miniaudio index 4a5b74be..b19cc09f 160000 --- a/lib/miniaudio +++ b/lib/miniaudio @@ -1 +1 @@ -Subproject commit 4a5b74bef029b3592c54b6048650ee5f972c1a48 +Subproject commit b19cc09fd06b80f370ca4385d260df7e31925b50 diff --git a/lib/sokol b/lib/sokol index ab110864..b1221d1f 160000 --- a/lib/sokol +++ b/lib/sokol @@ -1 +1 @@ -Subproject commit ab1108641067952916dfdc04dda22a2254e73933 +Subproject commit b1221d1f2bfc3cbb22f566cfa8f31b4073c287ae diff --git a/lib/umka b/lib/umka index e055fcda..f9ffb71b 160000 --- a/lib/umka +++ b/lib/umka @@ -1 +1 @@ -Subproject commit e055fcda66f0fb2abdcc9bb022873b99aceddf17 +Subproject commit f9ffb71b3da03dba60637f4a6c6ad5b9cd7e0ad8 diff --git a/src/bindings.c b/src/bindings.c index 1e345fa0..edd46b60 100644 --- a/src/bindings.c +++ b/src/bindings.c @@ -41,24 +41,28 @@ conv_path(char *path) return out; } +// fn umth_fopen(name: str, mode: str): std::File void umth_fopen(UmkaStackSlot *p, UmkaStackSlot *r) { - char *name = (char *)p[1].ptrVal; - const char *mode = (const char *)p[0].ptrVal; + char *name = (char *)umkaGetParam(p, 0)->ptrVal; + const char *mode = (const char *)umkaGetParam(p, 1)->ptrVal; char *path = conv_path(name); FILE *f = fopen(path, mode); free(path); - r->ptrVal = f; + + umkaGetResult(p, r)->ptrVal = f; } +// fn umth_th_getglobal(): ^struct{} void umth_th_getglobal(UmkaStackSlot *p, UmkaStackSlot *r) { - r->ptrVal = thg; + umkaGetResult(p, r)->ptrVal = thg; } +// fn umth_th_getfuncs(): ^struct{} void umth_th_getfuncs(UmkaStackSlot *p, UmkaStackSlot *r) { @@ -73,25 +77,28 @@ umth_th_getfuncs(UmkaStackSlot *p, UmkaStackSlot *r) #define THEXT(ret, name, ...) arr[idx++] = &name #include "thextdata.h" #undef THEXT - r->ptrVal = arr; + umkaGetResult(p, r)->ptrVal = arr; } /////////////////////////// // COLOUR -// fn umth_hsv2rgb_uint32((3) h, (2) s, (1) v, (0) a: th.fu): uint32 +// fn umth_hsv2rgb_uint32(h, s, v, a: th.fu): uint32 static void umth_hsv2rgb_uint32(UmkaStackSlot *p, UmkaStackSlot *r) { - r->uintVal = - th_color_hsv2rgb(p[3].real32Val, p[2].real32Val, p[1].real32Val, p[0].real32Val); + umkaGetResult(p, r)->uintVal = + th_color_hsv2rgb(umkaGetParam(p, 0)->real32Val, umkaGetParam(p, 1)->real32Val, + umkaGetParam(p, 2)->real32Val, umkaGetParam(p, 3)->real32Val); } -// fn umth_rgb_uint32((3) r, (2) g, (1) b, (0) a: th.fu): uint32 +// fn umth_rgb_uint32(r, g, b, a: th.fu): uint32 static void umth_rgb_uint32(UmkaStackSlot *p, UmkaStackSlot *r) { - r->uintVal = th_color_rgb(p[3].real32Val, p[2].real32Val, p[1].real32Val, p[0].real32Val); + umkaGetResult(p, r)->uintVal = + th_color_rgb(umkaGetParam(p, 0)->real32Val, umkaGetParam(p, 1)->real32Val, + umkaGetParam(p, 2)->real32Val, umkaGetParam(p, 3)->real32Val); } /////////////////////////// @@ -99,65 +106,66 @@ umth_rgb_uint32(UmkaStackSlot *p, UmkaStackSlot *r) extern th_em_placeholder th_em_placeholders[]; -// fn umth_placeholder_fetch((0) id: uint): ^struct{} +// fn umth_placeholder_fetch(id: uint): ^struct{} static void umth_placeholder_fetch(UmkaStackSlot *p, UmkaStackSlot *r) { - uint32_t id = p[0].intVal; + uint32_t id = umkaGetParam(p, 0)->uintVal; th_image *img = th_image_alloc(); th_image_from_data(img, th_em_placeholders[id].data, th_em_placeholders[id].dm); - r->ptrVal = img; + umkaGetResult(p, r)->ptrVal = img; } /////////////////////////// // FONT -// fn umth_font_load((3) out: ^Font, (2) path: str, (1) size: real, (0) filter: uint32): th.ErrCode +// fn umth_font_load(out: ^Font, path: str, size: real, filter: uint32): th::ErrCode static void umth_font_load(UmkaStackSlot *p, UmkaStackSlot *r) { - uint32_t filter = p[0].uintVal; - double size = p[1].real32Val; - char *path = conv_path(p[2].ptrVal); - th_font **ft = p[3].ptrVal; + th_font **ft = umkaGetParam(p, 0)->ptrVal; + char *path = conv_path(umkaGetParam(p, 1)->ptrVal); + double size = umkaGetParam(p, 2)->real32Val; + uint32_t filter = umkaGetParam(p, 3)->uintVal; - r->intVal = th_font_load(ft, path, size, filter); + umkaGetResult(p, r)->intVal = th_font_load(ft, path, size, filter); free(path); } -// fn umth_font_draw((5) font: Font, (4) s: str, (3) x: real, (2) y: real, (1) color: uint32, (0) -// scale: real) +// fn umth_font_draw(font: Font, s: str, x: real, y: real, color: uint32, scale: real) static void umth_font_draw(UmkaStackSlot *p, UmkaStackSlot *r) { - double scale = p[0].real32Val; - uint32_t color = p[1].uintVal; - double y = p[2].real32Val; - double x = p[3].real32Val; - const char *s = p[4].ptrVal; - th_font *font = p[5].ptrVal; + th_font *font = umkaGetParam(p, 0)->ptrVal; + const char *s = umkaGetParam(p, 1)->ptrVal; + double x = umkaGetParam(p, 2)->real32Val; + double y = umkaGetParam(p, 3)->real32Val; + uint32_t color = umkaGetParam(p, 4)->uintVal; + double scale = umkaGetParam(p, 5)->real32Val; th_font_draw(font, s, x, y, color, scale); } -// fn umth_font_measure((2) font: Font, (1) s: str, (0) o: ^th.Vf2) +// fn umth_font_measure(font: Font, s: str): th::Vf2 static void umth_font_measure(UmkaStackSlot *p, UmkaStackSlot *r) { - const char *s = p[1].ptrVal; - th_font *font = p[2].ptrVal; + th_font *font = umkaGetParam(p, 0)->ptrVal; + const char *s = umkaGetParam(p, 1)->ptrVal; - *((th_vf2 *)p[0].ptrVal) = th_font_measure(font, s); + *(th_vf2 *)umkaGetResult(p, r)->ptrVal = th_font_measure(font, s); } /////////////////////// // particles -void + +// fn umth_particles_draw(emitter: ^Particles, t: int) +static void umth_particles_draw(UmkaStackSlot *p, UmkaStackSlot *r) { - th_particles *emitter = (th_particles *)p[1].ptrVal; - int t = p[0].intVal; + th_particles *emitter = (th_particles *)umkaGetParam(p, 0)->ptrVal; + int t = umkaGetParam(p, 1)->intVal; th_particles_draw(emitter, t); } @@ -165,47 +173,53 @@ umth_particles_draw(UmkaStackSlot *p, UmkaStackSlot *r) /////////////////////// // tilemaps // draws a tilemap takes a rectangle as a camera and the tilemap itself + +// fn umth_tilemap_draw(t: ^Tilemap) void umth_tilemap_draw(UmkaStackSlot *p, UmkaStackSlot *r) { - th_tmap *t = (th_tmap *)p[0].ptrVal; + th_tmap *t = umkaGetParam(p, 0)->ptrVal; th_tmap_draw(t); } // checks, if tilemap collides with entity. // ent - entity to collide with, t - tilemap, x and y - pointers to ints used to return, where the // collision occured + +// fn umth_tilemap_getcoll(tc: ^th::Vf2, ic: ^th::Vf2, t: ^Tilemap, ent: ^Entity): int void umth_tilemap_getcoll(UmkaStackSlot *p, UmkaStackSlot *r) { - th_ent *ent = (th_ent *)p[0].ptrVal; - th_tmap *t = (th_tmap *)p[1].ptrVal; - th_vf2 *ic = (th_vf2 *)p[2].ptrVal; - th_vf2 *tc = (th_vf2 *)p[3].ptrVal; + th_vf2 *tc = umkaGetParam(p, 0)->ptrVal; + th_vf2 *ic = umkaGetParam(p, 1)->ptrVal; + th_tmap *t = umkaGetParam(p, 2)->ptrVal; + th_ent *ent = umkaGetParam(p, 3)->ptrVal; - r->intVal = th_coll_on_tilemap(ent, t, ic, tc); + umkaGetResult(p, r)->intVal = th_coll_on_tilemap(ent, t, ic, tc); } +// fn umth_tilemap_getcoll_line(b: th::Vf2, e: th::Vf2, t: ^Tilemap, ic: ^th::Vf2): int void umth_tilemap_getcoll_line(UmkaStackSlot *p, UmkaStackSlot *r) { - th_vf2 b = *(th_vf2 *)&p[3]; - th_vf2 e = *(th_vf2 *)&p[2]; - th_tmap *t = p[1].ptrVal; - th_vf2 *ic = p[0].ptrVal; + th_vf2 b = *(th_vf2 *)umkaGetParam(p, 0); + th_vf2 e = *(th_vf2 *)umkaGetParam(p, 1); + th_tmap *t = umkaGetParam(p, 2)->ptrVal; + th_vf2 *ic = umkaGetParam(p, 3)->ptrVal; - r->intVal = th_line_to_tilemap(b, e, t, ic); + umkaGetResult(p, r)->intVal = th_line_to_tilemap(b, e, t, ic); } +// fn umth_tilemap_autotile(tgt: ^th::uu, w, h: th::uu, src, cfg: ^th::uu, tile: th::uu) void umth_tilemap_autotile(UmkaStackSlot *p, UmkaStackSlot *r) { - uu tile = p[0].intVal; - uu *cfg = (uu *)p[1].ptrVal; - uu *src = (uu *)p[2].ptrVal; - uu h = p[3].intVal; - uu w = p[4].intVal; - uu *tgt = (uu *)p[5].ptrVal; + uu *tgt = umkaGetParam(p, 0)->ptrVal; + uu w = umkaGetParam(p, 1)->uintVal; + uu h = umkaGetParam(p, 2)->uintVal; + uu *src = umkaGetParam(p, 3)->ptrVal; + uu *cfg = umkaGetParam(p, 4)->ptrVal; + uu tile = umkaGetParam(p, 5)->uintVal; th_tmap_autotile(tgt, src, w, h, cfg, tile); } @@ -213,107 +227,114 @@ umth_tilemap_autotile(UmkaStackSlot *p, UmkaStackSlot *r) /////////////////////// // images // loads an image at respath + path + +// fn umth_image_load(ret: ^Image, path: str): th::ErrCode void umth_image_load(UmkaStackSlot *p, UmkaStackSlot *r) { - th_image **img = p[1].ptrVal; - char *path = (char *)p[0].ptrVal; + th_image **img = umkaGetParam(p, 0)->ptrVal; + char *path = conv_path(umkaGetParam(p, 1)->ptrVal); - char *pathcpy = conv_path(path); - r->intVal = th_load_image(img, pathcpy); - free(pathcpy); + umkaGetResult(p, r)->intVal = th_load_image(img, path); + free(path); } // flips image + +// fn umth_image_flipv(i: Image, f: bool) void umth_image_flipv(UmkaStackSlot *p, UmkaStackSlot *r) { - th_image *img = p[1].ptrVal; + th_image *img = umkaGetParam(p, 0)->ptrVal; if (!img) return; - img->flipv = p[0].intVal; + img->flipv = umkaGetParam(p, 1)->intVal; } // flips image + +// fn umth_image_fliph(i: Image, f: bool) void umth_image_fliph(UmkaStackSlot *p, UmkaStackSlot *r) { - th_image *img = p[1].ptrVal; + th_image *img = umkaGetParam(p, 0)->ptrVal; if (!img) return; - img->fliph = p[0].intVal; + img->fliph = umkaGetParam(p, 1)->intVal; } +// fn umth_image_get_dims(i: Image): th::Vf2 void umth_image_get_dims(UmkaStackSlot *p, UmkaStackSlot *r) { - th_image *img = p[0].ptrVal; + th_image *img = umkaGetParam(p, 0)->ptrVal; if (!img) return; - th_vf2 *out = (th_vf2 *)p[1].ptrVal; - - *out = img->dm; + *(th_vf2 *)umkaGetResult(p, r)->ptrVal = img->dm; } +// fn umth_image_crop(img: Image, tl, br: th::Vf2) void umth_image_crop(UmkaStackSlot *p, UmkaStackSlot *r) { - th_image *img = p[2].ptrVal; + th_image *img = umkaGetParam(p, 0)->ptrVal; if (!img) return; - th_vf2 tl = *(th_vf2 *)&p[1]; - th_vf2 br = *(th_vf2 *)&p[0]; + th_vf2 tl = *(th_vf2 *)umkaGetParam(p, 1); + th_vf2 br = *(th_vf2 *)umkaGetParam(p, 2); th_image_crop(img, tl, br); } +// fn umth_image_crop_quad(img: Image, q: th::Quad) void umth_image_crop_quad(UmkaStackSlot *p, UmkaStackSlot *r) { - th_image *img = p[1].ptrVal; + th_image *img = umkaGetParam(p, 0)->ptrVal; if (!img) return; - th_quad *q = p[0].ptrVal; - - img->crop = *q; + img->crop = *(th_quad *)umkaGetParam(p, 1); } +// fn umth_image_get_crop_quad(img: Image): th::Quad void umth_image_get_crop_quad(UmkaStackSlot *p, UmkaStackSlot *r) { - th_image *img = p[1].ptrVal; + th_image *img = umkaGetParam(p, 0)->ptrVal; if (!img) return; - th_quad *q = p[0].ptrVal; - *q = img->crop; + *(th_quad *)umkaGetResult(p, r)->ptrVal = img->crop; } // returns a pointer to an image from data + +// fn umth_image_from_data(ret: ^Image, data: ^uint32, dm: th::Vf2): th::ErrCode void umth_image_from_data(UmkaStackSlot *p, UmkaStackSlot *r) { - th_vf2 dm = *(th_vf2 *)&p[0]; - uint32_t *data = (uint32_t *)p[1].ptrVal; - th_image **ret = p[2].ptrVal; + th_image **ret = umkaGetParam(p, 0)->ptrVal; + uint32_t *data = umkaGetParam(p, 1)->ptrVal; + th_vf2 dm = *(th_vf2 *)umkaGetParam(p, 2); th_image *img = th_image_alloc(); if (!img) return; - r->intVal = th_image_from_data(img, data, dm); + umkaGetResult(p, r)->intVal = th_image_from_data(img, data, dm); *ret = img; } +// fn umth_image_copy(ret: ^Image, data: Image): th::ErrCode void umth_image_copy(UmkaStackSlot *p, UmkaStackSlot *r) { - th_image *img1 = p[0].ptrVal; - th_image **ret = p[1].ptrVal; + th_image **ret = umkaGetParam(p, 0)->ptrVal; + th_image *img1 = umkaGetParam(p, 1)->ptrVal; if (!img1) return; @@ -323,7 +344,7 @@ umth_image_copy(UmkaStackSlot *p, UmkaStackSlot *r) uint32_t *data = th_image_get_data(img1); - r->intVal = th_image_from_data(img2, data, img1->dm); + umkaGetResult(p, r)->intVal = th_image_from_data(img2, data, img1->dm); img2->flipv = img1->flipv; img2->fliph = img1->fliph; img2->crop = img1->crop; @@ -333,36 +354,39 @@ umth_image_copy(UmkaStackSlot *p, UmkaStackSlot *r) free(data); } +// fn umth_image_set_filter(data: Image, filter: int): th::ErrCode void umth_image_set_filter(UmkaStackSlot *p, UmkaStackSlot *r) { - th_image *img = p[1].ptrVal; + th_image *img = umkaGetParam(p, 0)->ptrVal; if (!img) return; - int filter = p[0].intVal; + int filter = umkaGetParam(p, 1)->intVal; - r->intVal = th_image_set_filter(img, filter); + umkaGetResult(p, r)->intVal = th_image_set_filter(img, filter); } +// fn umth_image_update_data(img: Image, data: ^uint32, dm: th::Vf2): th::ErrCode void umth_image_update_data(UmkaStackSlot *p, UmkaStackSlot *r) { - th_image *img = p[2].ptrVal; + th_image *img = umkaGetParam(p, 0)->ptrVal; if (!img) return; - uint32_t *data = p[1].ptrVal; - th_vf2 dm = *(th_vf2 *)&p[0]; + uint32_t *data = umkaGetParam(p, 1)->ptrVal; + th_vf2 dm = *(th_vf2 *)umkaGetParam(p, 2); - r->intVal = th_image_update_data(img, data, dm); + umkaGetResult(p, r)->intVal = th_image_update_data(img, data, dm); } +// fn umth_image_get_data(img: Image, data: ^uint32) void umth_image_get_data(UmkaStackSlot *p, UmkaStackSlot *r) { - th_image *img = p[1].ptrVal; + th_image *img = umkaGetParam(p, 0)->ptrVal; if (!img) return; - uint32_t *o = p[0].ptrVal; + uint32_t *o = umkaGetParam(p, 1)->ptrVal; uint32_t *data = th_image_get_data(img); memcpy(o, data, img->dm.w * img->dm.h * sizeof(uint32_t)); @@ -370,55 +394,70 @@ umth_image_get_data(UmkaStackSlot *p, UmkaStackSlot *r) free(data); } +// fn umth_image_render_target_begin(rt: RenderTarget): th::ErrCode void umth_image_render_target_begin(UmkaStackSlot *p, UmkaStackSlot *r) { - th_render_target *t = p[0].ptrVal; + th_render_target *t = umkaGetParam(p, 0)->ptrVal; if (!t) return; - r->intVal = th_image_set_as_render_target(t); + umkaGetResult(p, r)->intVal = th_image_set_as_render_target(t); } +// fn umth_image_render_target_end(rt: RenderTarget, wp: th::Vf2): th::ErrCode void umth_image_render_target_end(UmkaStackSlot *p, UmkaStackSlot *r) { - th_render_target *t = p[1].ptrVal; - th_vf2 wp = *(th_vf2 *)&p[0]; + th_render_target *t = umkaGetParam(p, 0)->ptrVal; + th_vf2 wp = *(th_vf2 *)umkaGetParam(p, 1); - r->intVal = th_image_remove_render_target(t, wp); + umkaGetResult(p, r)->intVal = th_image_remove_render_target(t, wp); } +// fn umth_image_draw(img: Image, t: th::Transform, color: uint32) void umth_image_draw(UmkaStackSlot *p, UmkaStackSlot *r) { - th_image_render_transformed( - (th_image *)p[2].ptrVal, *(th_transform *)p[1].ptrVal, (uint32_t)p[0].uintVal); + th_image *img = umkaGetParam(p, 0)->ptrVal; + if (!img) + return; + + th_transform t = *(th_transform *)umkaGetParam(p, 1); + uint32_t color = umkaGetParam(p, 2)->uintVal; + + th_image_render_transformed(img, t, color); } +// fn umth_image_draw_on_quad(img: Image, color: uint32, q: th::Quad) void umth_image_draw_on_quad(UmkaStackSlot *p, UmkaStackSlot *r) { - th_quad q; - q = *(th_quad *)&p[0]; - uint32_t filter = p[4].uintVal; - th_image *img = p[5].ptrVal; + th_image *img = umkaGetParam(p, 0)->ptrVal; + if (!img) + return; + + uint32_t filter = umkaGetParam(p, 1)->uintVal; + th_quad q = *(th_quad *)umkaGetParam(p, 2); th_blit_tex(img, q, filter); } +// fn umth_image_draw_nine_patch(img: Image, outer, inner, dest: rect::Rect, +// color: uint32, scale: real) void umth_image_draw_nine_patch(UmkaStackSlot *p, UmkaStackSlot *r) { - th_image *img = p[5].ptrVal; + th_image *img = umkaGetParam(p, 0)->ptrVal; if (!img) return; - th_rect outer = *(th_rect *)p[4].ptrVal, inner = *(th_rect *)p[3].ptrVal, - dest = *(th_rect *)p[2].ptrVal; + th_rect outer = *(th_rect *)umkaGetParam(p, 1); + th_rect inner = *(th_rect *)umkaGetParam(p, 2); + th_rect dest = *(th_rect *)umkaGetParam(p, 3); - uint32_t tint = p[1].uintVal; - fu scale = p[0].realVal; + uint32_t tint = umkaGetParam(p, 4)->uintVal; + fu scale = umkaGetParam(p, 5)->realVal; if (dest.w < 0) { dest.x += dest.w; @@ -471,72 +510,82 @@ umth_image_draw_nine_patch(UmkaStackSlot *p, UmkaStackSlot *r) } } +// fn umth_image_create_render_target(ret: ^RenderTarget, width: int, height: int, filter: int): +// th::ErrCode void umth_image_create_render_target(UmkaStackSlot *p, UmkaStackSlot *r) { - th_render_target **result = p[3].ptrVal; - int filter = p[0].intVal; - int height = p[1].intVal; - int width = p[2].intVal; + th_render_target **result = umkaGetParam(p, 0)->ptrVal; + int width = umkaGetParam(p, 1)->intVal; + int height = umkaGetParam(p, 2)->intVal; + int filter = umkaGetParam(p, 3)->intVal; - r->intVal = th_image_create_render_target(result, width, height, filter); + umkaGetResult(p, r)->intVal = th_image_create_render_target(result, width, height, filter); } +// fn umth_image_render_target_to_image(rt: RenderTarget): Image void umth_image_render_target_to_image(UmkaStackSlot *p, UmkaStackSlot *r) { - th_image **result = p[1].ptrVal; + th_render_target *rt = umkaGetParam(p, 0)->ptrVal; - *result = ((th_render_target *)p[0].ptrVal)->image; + *(th_image **)umkaGetResult(p, r)->ptrVal = rt->image; } /////////////////////// // input -// gets position of mouse cursor + +// fn umth_input_get_mouse(): th::Vf2 void umth_input_get_mouse(UmkaStackSlot *p, UmkaStackSlot *r) { - th_vf2 *out = (th_vf2 *)p[0].ptrVal; - out->x = (thg->mouse.x - thg->offset.x) / thg->scaling; - out->y = (thg->mouse.y - thg->offset.y) / thg->scaling; + th_vf2 out = {.x = (thg->mouse.x - thg->offset.x) / thg->scaling, + .y = (thg->mouse.y - thg->offset.y) / thg->scaling}; + + *(th_vf2 *)umkaGetResult(p, r)->ptrVal = out; } +// fn umth_input_is_pressed(key: Key): bool void umth_input_is_pressed(UmkaStackSlot *p, UmkaStackSlot *r) { - int keycode = p[0].intVal; + int keycode = umkaGetParam(p, 0)->intVal; - r->intVal = thg->pressed[keycode]; + umkaGetResult(p, r)->intVal = !!thg->pressed[keycode]; } +// fn umth_input_is_just_pressed(key: Key): bool void umth_input_is_just_pressed(UmkaStackSlot *p, UmkaStackSlot *r) { - int keycode = p[0].intVal; + int keycode = umkaGetParam(p, 0)->intVal; - r->intVal = thg->just_pressed[keycode]; + umkaGetResult(p, r)->intVal = !!thg->just_pressed[keycode]; } +// fn umth_input_is_pressed_repeat(key: Key): bool void umth_input_is_pressed_repeat(UmkaStackSlot *p, UmkaStackSlot *r) { - int keycode = p[0].intVal; + int keycode = umkaGetParam(p, 0)->intVal; - r->intVal = thg->press_repeat[keycode]; + umkaGetResult(p, r)->intVal = !!thg->press_repeat[keycode]; } +// fn umth_input_is_just_released(key: Key): bool void umth_input_is_just_released(UmkaStackSlot *p, UmkaStackSlot *r) { - int keycode = p[0].intVal; + int keycode = umkaGetParam(p, 0)->intVal; - r->intVal = thg->just_released[keycode]; + umkaGetResult(p, r)->intVal = !!thg->just_released[keycode]; } +// fn umth_input_clear*(code: Key) void umth_input_clear(UmkaStackSlot *p, UmkaStackSlot *r) { - int keycode = p[0].intVal; + int keycode = umkaGetParam(p, 0)->intVal; thg->just_pressed[keycode] = 0; thg->just_released[keycode] = 0; @@ -544,130 +593,146 @@ umth_input_clear(UmkaStackSlot *p, UmkaStackSlot *r) thg->press_repeat[keycode] = 0; } +// fn umth_input_get_str(): str void umth_input_get_str(UmkaStackSlot *p, UmkaStackSlot *r) { thg->input_string[thg->input_string_len] = 0; - r->ptrVal = umkaMakeStr(thg->umka, thg->input_string); + umkaGetResult(p, r)->ptrVal = umkaMakeStr(thg->umka, thg->input_string); } +// fn umth_input_get_mouse_delta(): th::Vf2 void umth_input_get_mouse_delta(UmkaStackSlot *p, UmkaStackSlot *r) { - th_vf2 *o = (th_vf2 *)p[0].ptrVal; - o->x = thg->mouse_delta.x / thg->scaling; - o->y = thg->mouse_delta.y / thg->scaling; + th_vf2 out = { + .x = thg->mouse_delta.x / thg->scaling, .y = thg->mouse_delta.y / thg->scaling}; + + *(th_vf2 *)umkaGetResult(p, r)->ptrVal = out; } +// fn umth_input_get_mouse_scroll(): th::Vf2 void umth_input_get_mouse_scroll(UmkaStackSlot *p, UmkaStackSlot *r) { - *(fu *)(p[0].ptrVal) = thg->mouse_wheel.y; - *(fu *)(p[1].ptrVal) = thg->mouse_wheel.x; + th_vf2 out = {.x = thg->mouse_wheel.x, .y = thg->mouse_wheel.y}; + + *(th_vf2 *)umkaGetResult(p, r)->ptrVal = out; } +// fn umth_input_gamepad_get_gamepads*(): [4]int void umth_input_gamepad_get_gamepads(UmkaStackSlot *p, UmkaStackSlot *r) { - ((int64_t *)p[0].ptrVal)[0] = thg->gamepad[0].connected ? 0 : -1; - ((int64_t *)p[0].ptrVal)[1] = thg->gamepad[1].connected ? 1 : -1; - ((int64_t *)p[0].ptrVal)[2] = thg->gamepad[2].connected ? 2 : -1; - ((int64_t *)p[0].ptrVal)[3] = thg->gamepad[3].connected ? 3 : -1; + int64_t states[4] = { + thg->gamepad[0].connected ? 0 : -1, + thg->gamepad[1].connected ? 1 : -1, + thg->gamepad[2].connected ? 2 : -1, + thg->gamepad[3].connected ? 3 : -1, + }; + + memcpy(umkaGetResult(p, r)->ptrVal, states, sizeof(states)); } +// fn umth_input_gamepad_get_gamepad*(): int void umth_input_gamepad_get_gamepad(UmkaStackSlot *p, UmkaStackSlot *r) { for (int i = 0; i < 4; i++) { if (thg->gamepad[i].connected) { - r->intVal = i; + umkaGetResult(p, r)->intVal = i; return; } } - r->intVal = -1; + umkaGetResult(p, r)->intVal = -1; } +// fn umth_input_gamepad_is_pressed(gamepad: int, button: GamepadButton): bool void umth_input_gamepad_is_pressed(UmkaStackSlot *p, UmkaStackSlot *r) { - int button = p[0].intVal; - int gamepad = p[1].intVal; + int gamepad = umkaGetParam(p, 0)->intVal; + int button = umkaGetParam(p, 1)->intVal; if (gamepad < 0 || gamepad >= 4) { - r->intVal = 0; + umkaGetResult(p, r)->intVal = 0; return; } - r->intVal = thg->gamepad[gamepad].buttons[button].pressed; + umkaGetResult(p, r)->intVal = thg->gamepad[gamepad].buttons[button].pressed; } +// fn umth_input_gamepad_is_just_pressed(gamepad: int, button: GamepadButton): bool void umth_input_gamepad_is_just_pressed(UmkaStackSlot *p, UmkaStackSlot *r) { - int button = p[0].intVal; - int gamepad = p[1].intVal; + int gamepad = umkaGetParam(p, 0)->intVal; + int button = umkaGetParam(p, 1)->intVal; if (gamepad < 0 || gamepad >= 4) { - r->intVal = 0; + umkaGetResult(p, r)->intVal = 0; return; } - r->intVal = thg->gamepad[gamepad].buttons[button].just_pressed; + umkaGetResult(p, r)->intVal = thg->gamepad[gamepad].buttons[button].just_pressed; } +// fn umth_input_gamepad_is_just_released(gamepad: int, button: GamepadButton): bool void umth_input_gamepad_is_just_released(UmkaStackSlot *p, UmkaStackSlot *r) { - int button = p[0].intVal; - int gamepad = p[1].intVal; + int gamepad = umkaGetParam(p, 0)->intVal; + int button = umkaGetParam(p, 1)->intVal; if (gamepad < 0 || gamepad >= 4) { - r->intVal = 0; + umkaGetResult(p, r)->intVal = 0; return; } - r->intVal = thg->gamepad[gamepad].buttons[button].just_released; + umkaGetResult(p, r)->intVal = thg->gamepad[gamepad].buttons[button].just_released; } +// fn umth_input_gamepad_pressure(gamepad: int, button: GamepadButton): th::fu void umth_input_gamepad_pressure(UmkaStackSlot *p, UmkaStackSlot *r) { - int button = p[0].intVal; - int gamepad = p[1].intVal; + int gamepad = umkaGetParam(p, 0)->intVal; + int button = umkaGetParam(p, 1)->intVal; if (gamepad < 0 || gamepad >= 4) { - r->realVal = 0; + umkaGetResult(p, r)->realVal = 0; return; } - r->realVal = thg->gamepad[gamepad].buttons[button].pressure; + umkaGetResult(p, r)->realVal = thg->gamepad[gamepad].buttons[button].pressure; } +// fn umth_input_gamepad_stick(gamepad: int, stick: GamepadStick): th::Vf2 void umth_input_gamepad_stick(UmkaStackSlot *p, UmkaStackSlot *r) { - th_vf2 *out = p[0].ptrVal; - int stick = p[1].intVal; - int gamepad = p[2].intVal; + int gamepad = umkaGetParam(p, 0)->intVal; + int stick = umkaGetParam(p, 1)->intVal; if (gamepad < 0 || gamepad >= 4) { - *out = (th_vf2){0}; + *(th_vf2 *)umkaGetResult(p, r)->ptrVal = (th_vf2){0}; return; } switch (stick) { - case 0: *out = thg->gamepad[gamepad].left_stick; break; - case 1: *out = thg->gamepad[gamepad].right_stick; break; + case 0: *(th_vf2 *)umkaGetResult(p, r)->ptrVal = thg->gamepad[gamepad].left_stick; break; + case 1: *(th_vf2 *)umkaGetResult(p, r)->ptrVal = thg->gamepad[gamepad].right_stick; break; } } +// fn umth_input_gamepad_rumble(gamepad: int, left, right: th::fu) void umth_input_gamepad_rumble(UmkaStackSlot *p, UmkaStackSlot *r) { - int gamepad = p[2].intVal; - float left = p[1].realVal; - float right = p[0].realVal; + int gamepad = umkaGetParam(p, 0)->intVal; + float left = umkaGetParam(p, 1)->realVal; + float right = umkaGetParam(p, 2)->realVal; if (gamepad < 0 || gamepad >= 4) { return; @@ -689,24 +754,42 @@ umth_input_gamepad_rumble(UmkaStackSlot *p, UmkaStackSlot *r) /////////////////////// // entities // draws an entity + +// fn umth_ent_draw(e: ^Ent) void umth_ent_draw(UmkaStackSlot *p, UmkaStackSlot *r) { - th_ent *e = (th_ent *)p[0].ptrVal; + th_ent *e = umkaGetParam(p, 0)->ptrVal; th_ent_draw(e); } +// fn umth_ent_getcoll(maxcolls: uint, e: ^Ent, s: ^[]^Ent, t: ^void): []Coll void umth_ent_getcoll(UmkaStackSlot *p, UmkaStackSlot *r) { - th_ent **scene = (th_ent **)p[0].ptrVal; - th_ent *e = (th_ent *)p[1].ptrVal; - int count = p[2].intVal; - uu maxColls = p[3].intVal; - uu *collC = (uu *)p[4].ptrVal; - th_coll *colls = (th_coll *)p[5].ptrVal; + size_t maxcolls = umkaGetParam(p, 0)->uintVal; + th_ent *e = umkaGetParam(p, 1)->ptrVal; + UmkaDynArray(th_ent *) *s = umkaGetParam(p, 2)->ptrVal; + void *t = umkaGetParam(p, 3)->ptrVal; + size_t count = umkaGetDynArrayLen(s); + if (maxcolls == 0) { + maxcolls = 1; + } + + if (maxcolls > count) { + maxcolls = count; + } - th_ent_getcoll(e, scene, count, collC, maxColls, colls); + th_coll *colls = malloc(sizeof(th_coll) * maxcolls); + + uu collC = 0; + th_ent_getcoll(e, s->data, count, &collC, maxcolls, colls); + + UmkaDynArray(th_coll) *result = umkaGetResult(p, r)->ptrVal; + umkaMakeDynArray(thg->umka, result, t, collC); + memcpy(result->data, colls, collC * sizeof(th_coll)); + + free(colls); } static int @@ -715,540 +798,568 @@ _th_ysort_test(const void *a, const void *b) return ((th_ent *)a)->t.pos.y - ((th_ent *)b)->t.pos.y; } +// fn umth_ent_ysort(ents: ^Ent, count: int) void umth_ent_ysort(UmkaStackSlot *p, UmkaStackSlot *r) { - th_ent *ents = (th_ent *)p[1].ptrVal; - int count = p[0].intVal; + th_ent *ents = (th_ent *)umkaGetParam(p, 0)->ptrVal; + int count = umkaGetParam(p, 1)->intVal; qsort(ents, count, sizeof(th_ent), _th_ysort_test); } /////////////////////// // audio + +// fn umth_sound_load(Sound: ^Sound, path: str, flags: LoadFlag): th::ErrCode void umth_sound_load(UmkaStackSlot *p, UmkaStackSlot *r) { - th_sound **out = p[2].ptrVal; - char *path = (char *)p[1].ptrVal; - uint32_t flags = p[0].intVal; + th_sound **out = umkaGetParam(p, 0)->ptrVal; + char *path = conv_path(umkaGetParam(p, 1)->ptrVal); + uint32_t flags = umkaGetParam(p, 2)->uintVal; - r->intVal = th_audio_load(out, path, flags); + umkaGetResult(p, r)->intVal = th_audio_load(out, path, flags); + free(path); } +// fn umth_sound_copy(out: ^Sound, s: Sound): th::ErrCode void umth_sound_copy(UmkaStackSlot *p, UmkaStackSlot *r) { - th_sound **out = p[1].ptrVal; - th_sound *s = p[0].ptrVal; + th_sound **out = umkaGetParam(p, 0)->ptrVal; + th_sound *s = umkaGetParam(p, 1)->ptrVal; - r->intVal = th_sound_copy(out, s); + umkaGetResult(p, r)->intVal = th_sound_copy(out, s); } +// fn umth_sound_is_playing(s: Sound): bool void umth_sound_is_playing(UmkaStackSlot *p, UmkaStackSlot *r) { - th_sound *s = p[0].ptrVal; + th_sound *s = umkaGetParam(p, 0)->ptrVal; - r->intVal = ma_sound_is_playing(&s->inst); + umkaGetResult(p, r)->intVal = ma_sound_is_playing(&s->inst); } +// fn umth_sound_play(s: Sound) void umth_sound_play(UmkaStackSlot *p, UmkaStackSlot *r) { - th_sound *s = p[0].ptrVal; + th_sound *s = umkaGetParam(p, 0)->ptrVal; ma_sound_start(&s->inst); } +// fn umth_sound_stop(s: Sound) +void +umth_sound_stop(UmkaStackSlot *p, UmkaStackSlot *r) +{ + th_sound *s = umkaGetParam(p, 0)->ptrVal; + + ma_sound_stop(&s->inst); +} + +// fn umth_sound_set_volume(s: Sound, vol: real32) void umth_sound_set_volume(UmkaStackSlot *p, UmkaStackSlot *r) { - th_sound *s = p[1].ptrVal; - float vol = p[0].real32Val; + th_sound *s = umkaGetParam(p, 0)->ptrVal; + float vol = umkaGetParam(p, 1)->real32Val; ma_sound_set_volume(&s->inst, vol); } +// fn umth_sound_set_pan(s: Sound, pan: real32) void umth_sound_set_pan(UmkaStackSlot *p, UmkaStackSlot *r) { - th_sound *s = p[1].ptrVal; - float pan = p[0].real32Val; + th_sound *s = umkaGetParam(p, 0)->ptrVal; + float pan = umkaGetParam(p, 1)->real32Val; ma_sound_set_pan(&s->inst, pan); } +// fn umth_sound_set_pitch(s: Sound, pitch: real32) void umth_sound_set_pitch(UmkaStackSlot *p, UmkaStackSlot *r) { - th_sound *s = p[1].ptrVal; - float pitch = p[0].real32Val; + th_sound *s = umkaGetParam(p, 0)->ptrVal; + float pitch = umkaGetParam(p, 1)->real32Val; ma_sound_set_pitch(&s->inst, pitch); } +// fn umth_sound_set_looping(s: Sound, looping: bool) void umth_sound_set_looping(UmkaStackSlot *p, UmkaStackSlot *r) { - th_sound *s = p[1].ptrVal; - int looping = p[0].intVal; + th_sound *s = umkaGetParam(p, 0)->ptrVal; + bool looping = umkaGetParam(p, 1)->intVal; ma_sound_set_looping(&s->inst, looping); } -void -umth_sound_stop(UmkaStackSlot *p, UmkaStackSlot *r) -{ - th_sound *s = p[0].ptrVal; - - ma_sound_stop(&s->inst); -} - +// fn umth_sound_seek_to_frame(s: Sound, frame: uint) void umth_sound_seek_to_frame(UmkaStackSlot *p, UmkaStackSlot *r) { - th_sound *s = p[1].ptrVal; - int frame = p[0].intVal; + th_sound *s = umkaGetParam(p, 0)->ptrVal; + uu frame = umkaGetParam(p, 1)->uintVal; ma_sound_seek_to_pcm_frame(&s->inst, frame); } +// fn umth_sound_frame_count(s: Sound): uint void umth_sound_frame_count(UmkaStackSlot *p, UmkaStackSlot *r) { - th_sound *s = p[0].ptrVal; + th_sound *s = umkaGetParam(p, 0)->ptrVal; + ma_uint64 frame = 0; - ma_sound_get_length_in_pcm_frames(&s->inst, (ma_uint64 *)&r->uintVal); + ma_sound_get_length_in_pcm_frames(&s->inst, &frame); + umkaGetResult(p, r)->uintVal = frame; } +// fn umth_sound_length_ms(s: Sound): uint void umth_sound_length_ms(UmkaStackSlot *p, UmkaStackSlot *r) { - th_sound *s = p[0].ptrVal; + th_sound *s = umkaGetParam(p, 0)->ptrVal; - float len; + float len = 0; ma_sound_get_length_in_seconds(&s->inst, &len); - r->intVal = len * 1000; + umkaGetResult(p, r)->intVal = len * 1000; } +// fn umth_sound_set_start_time_ms(s: Sound, t: uint) void umth_sound_set_start_time_ms(UmkaStackSlot *p, UmkaStackSlot *r) { - th_sound *s = p[1].ptrVal; - uint64_t t = p[0].uintVal; + th_sound *s = umkaGetParam(p, 0)->ptrVal; + ma_uint64 t = umkaGetParam(p, 1)->uintVal; ma_sound_set_start_time_in_milliseconds(&s->inst, t); } +// fn umth_sound_set_stop_time_ms(s: Sound, t: uint) void umth_sound_set_stop_time_ms(UmkaStackSlot *p, UmkaStackSlot *r) { - th_sound *s = p[1].ptrVal; - uint64_t t = p[0].uintVal; + th_sound *s = umkaGetParam(p, 0)->ptrVal; + ma_uint64 t = umkaGetParam(p, 1)->uintVal; ma_sound_set_stop_time_in_milliseconds(&s->inst, t); } /////////////////////// -// misc +// window +// fn umth_window_setup(title: str, w, h: int) void -umth_window_set_viewport_shift(UmkaStackSlot *p, UmkaStackSlot *r) -{ - thg->wp_offset = *(th_vf2 *)&p[0]; -} - -void -umth_window_get_viewport_shift(UmkaStackSlot *p, UmkaStackSlot *r) +umth_window_setup(UmkaStackSlot *p, UmkaStackSlot *r) { - th_vf2 *o = p[0].ptrVal; + char *title = umkaGetParam(p, 0)->ptrVal; + int w = umkaGetParam(p, 1)->intVal; + int h = umkaGetParam(p, 2)->intVal; - *o = thg->wp_offset; + th_window_setup(title, w, h); } +// fn umth_window_get_dimensions(w, h: ^int32) void -umth_window_set_clipboard(UmkaStackSlot *p, UmkaStackSlot *r) +umth_window_get_dimensions(UmkaStackSlot *p, UmkaStackSlot *r) { - char *str = p[0].ptrVal; - - if (str == NULL) { - return; - } + int32_t *w = (int32_t *)umkaGetParam(p, 0)->ptrVal; + int32_t *h = (int32_t *)umkaGetParam(p, 1)->ptrVal; - sapp_set_clipboard_string(str); + th_window_get_dimensions(w, h); } +// fn umth_window_set_viewport(dm: th::Vf2) void -umth_window_get_clipboard(UmkaStackSlot *p, UmkaStackSlot *r) +umth_window_set_viewport(UmkaStackSlot *p, UmkaStackSlot *r) { - char *str = p[0].ptrVal; - - const char *str2 = sapp_get_clipboard_string(); - strcpy(str, str2); + th_vf2 dm = *(th_vf2 *)umkaGetParam(p, 0); + th_calculate_scaling(dm.w, dm.h); } +// fn umth_window_is_dpi_enabled(): bool void -umth_window_get_fullscreen(UmkaStackSlot *p, UmkaStackSlot *r) +umth_window_is_dpi_enabled(UmkaStackSlot *p, UmkaStackSlot *r) { - r->uintVal = th_window_is_fullscreen(); + umkaGetResult(p, r)->intVal = thg->dpi_aware; } +// fn umth_window_get_dpi_scale(): th::fu void -umth_window_set_fullscreen(UmkaStackSlot *p, UmkaStackSlot *r) +umth_window_get_dpi_scale(UmkaStackSlot *p, UmkaStackSlot *r) { - th_window_set_fullscreen(p->uintVal); + umkaGetResult(p, r)->realVal = th_window_dpi_scale(); } +// 0 = other/unknown +// 1 = linux +// 2 = windows +// 3 = macos (unsupported currently) +// 4 = emscripten +// fn umth_window_get_platform_id(): th::Platform void -umth_window_is_dpi_enabled(UmkaStackSlot *p, UmkaStackSlot *r) +umth_window_get_platform_id(UmkaStackSlot *p, UmkaStackSlot *r) { - r->intVal = thg->dpi_aware; +#ifdef _WIN32 + umkaGetResult(p, r)->intVal = 2; +#elif __linux__ + umkaGetResult(p, r)->intVal = 1; +#elif defined(__EMSCRIPTEN__) + umkaGetResult(p, r)->intVal = 4; +#else + umkaGetResult(p, r)->intVal = 0; +#endif } +// fn umth_window_set_viewport_offset(s: th::Vf2) void -umth_window_get_dpi_scale(UmkaStackSlot *p, UmkaStackSlot *r) +umth_window_set_viewport_offset(UmkaStackSlot *p, UmkaStackSlot *r) { - r->realVal = th_window_dpi_scale(); + thg->wp_offset = *(th_vf2 *)umkaGetParam(p, 0); } +// fn umth_window_get_viewport_offset(): th::Vf2 void -umth_window_setup(UmkaStackSlot *p, UmkaStackSlot *r) +umth_window_get_viewport_offset(UmkaStackSlot *p, UmkaStackSlot *r) { - char *title = (char *)p[2].ptrVal; - int w = p[1].intVal; - int h = p[0].intVal; - - th_window_setup(title, w, h); + *(th_vf2 *)umkaGetResult(p, r)->ptrVal = thg->wp_offset; } +// fn umth_window_set_clipboard(s: str) void -umth_window_get_dimensions(UmkaStackSlot *p, UmkaStackSlot *r) +umth_window_set_clipboard(UmkaStackSlot *p, UmkaStackSlot *r) { - int *w = (int *)p[1].ptrVal; - int *h = (int *)p[0].ptrVal; + char *str = umkaGetParam(p, 0)->ptrVal; - th_window_get_dimensions(w, h); + if (str == NULL) { + return; + } + + sapp_set_clipboard_string(str); } -#ifdef _WIN32 -static double -time_now() +// fn umth_window_get_clipboard(): str +void +umth_window_get_clipboard(UmkaStackSlot *p, UmkaStackSlot *r) { - LARGE_INTEGER cnt, frq; - QueryPerformanceCounter(&cnt); - QueryPerformanceFrequency(&frq); - - return (double)cnt.QuadPart / (double)frq.QuadPart; + const char *clip = sapp_get_clipboard_string(); + umkaGetResult(p, r)->ptrVal = umkaMakeStr(thg->umka, clip); } -#endif +// fn umth_window_set_fullscreen(fullscreen: bool) void -umth_window_sleep(UmkaStackSlot *p, UmkaStackSlot *r) +umth_window_set_fullscreen(UmkaStackSlot *p, UmkaStackSlot *r) { - int ms = p[0].intVal; - -#ifdef _WIN32 - double sec = ms / 1000.0; - double time_start = time_now(); - double time = time_start; - while ((time - time_start) < sec) { - Sleep(0); - time = time_now(); - } -#else - usleep(ms * 1000); -#endif + th_window_set_fullscreen(umkaGetParam(p, 0)->uintVal); } -// fn umth_window_set_viewport(dm: th.Vf2) void -umth_window_set_viewport(UmkaStackSlot *p, UmkaStackSlot *r) +umth_window_get_fullscreen(UmkaStackSlot *p, UmkaStackSlot *r) { - th_vf2 dm = *(th_vf2 *)&p[0]; - th_calculate_scaling(dm.w, dm.h); + umkaGetResult(p, r)->uintVal = th_window_is_fullscreen(); } +// fn umth_window_set_dims(dm: th::Vf2) void umth_window_set_dims(UmkaStackSlot *p, UmkaStackSlot *r) { - th_vf2 dm = *(th_vf2 *)&p[0]; + th_vf2 dm = *(th_vf2 *)umkaGetParam(p, 0); th_window_set_dims(dm); } +// fn umth_window_set_icon(img: image::Image) void umth_window_set_icon(UmkaStackSlot *p, UmkaStackSlot *r) { - th_image *img = (th_image *)p[0].ptrVal; + th_image *img = (th_image *)umkaGetParam(p, 0)->ptrVal; th_window_set_icon(img); } +// fn umth_window_show_cursor(show: bool) void umth_window_show_cursor(UmkaStackSlot *p, UmkaStackSlot *r) { - bool show = p[0].intVal; - th_window_show_cursor(show); + th_window_show_cursor(umkaGetParam(p, 0)->uintVal); } +// fn umth_window_freeze_cursor(freeze: bool) void umth_window_freeze_cursor(UmkaStackSlot *p, UmkaStackSlot *r) { - bool freeze = p[0].intVal; - th_window_freeze_cursor(freeze); + th_window_freeze_cursor(umkaGetParam(p, 0)->uintVal); } +// fn umth_window_set_cursor(cursor: Cursor) void umth_window_set_cursor(UmkaStackSlot *p, UmkaStackSlot *r) { - int cursor = p[0].intVal; - th_window_set_cursor(cursor); + th_window_set_cursor(umkaGetParam(p, 0)->uintVal); } +// fn umth_window_request_exit() void umth_window_request_exit(UmkaStackSlot *p, UmkaStackSlot *r) { th_window_request_exit(); } +// fn umth_window_set_target_fps(fps: int) extern int *th_sapp_swap_interval; void umth_window_set_target_fps(UmkaStackSlot *p, UmkaStackSlot *r) { - int fps = p[0].intVal; + int fps = umkaGetParam(p, 0)->intVal; if (fps < 0) { fps = 0; } *th_sapp_swap_interval = fps; } -// 0 = other/unknown -// 1 = linux -// 2 = windows -// 3 = macos (unsupported currently) -// 4 = emscripten -void -umth_window_get_platform_id(UmkaStackSlot *p, UmkaStackSlot *r) -{ -#ifdef _WIN32 - r->intVal = 2; -#elif __linux__ - r->intVal = 1; -#elif defined(__EMSCRIPTEN__) - r->intVal = 4; -#else - r->intVal = 0; -#endif -} +/////////////////////// +// canvas -// draws text +// fn umth_canvas_draw_text(text: str, pos: th::Vf2, color: uint32, size: th::fu) void umth_canvas_draw_text(UmkaStackSlot *p, UmkaStackSlot *r) { - fu size = p[0].real32Val; - uint32_t color = (uint32_t)p[1].uintVal; - th_vf2 pos = *(th_vf2 *)&p[2]; - char *text = (char *)p[3].ptrVal; + char *text = umkaGetParam(p, 0)->ptrVal; + th_vf2 pos = *(th_vf2 *)umkaGetParam(p, 1); + uint32_t color = umkaGetParam(p, 2)->uintVal; + fu size = umkaGetParam(p, 3)->real32Val; th_canvas_text(text, color, pos, size); } +// fn umth_canvas_draw_rect(color: uint32, r: rect::Rect) void umth_canvas_draw_rect(UmkaStackSlot *p, UmkaStackSlot *r) { - uint32_t color = p[2].uintVal; - th_rect re = *(th_rect *)&p[0]; + uint32_t color = umkaGetParam(p, 0)->uintVal; + th_rect re = *(th_rect *)umkaGetParam(p, 1); th_canvas_rect(color, re); } +// fn umth_canvas_draw_line(color: uint32, b, e: th::Vf2, thickness: th::fu) void umth_canvas_draw_line(UmkaStackSlot *p, UmkaStackSlot *r) { - float thickness = p[0].real32Val; - th_vf2 e = *(th_vf2 *)&p[1]; - th_vf2 b = *(th_vf2 *)&p[2]; - uint32_t color = p[3].uintVal; + uint32_t color = umkaGetParam(p, 0)->uintVal; + th_vf2 b = *(th_vf2 *)umkaGetParam(p, 1); + th_vf2 e = *(th_vf2 *)umkaGetParam(p, 2); + float thickness = umkaGetParam(p, 3)->real32Val; th_canvas_line(color, b, e, thickness); } +// fn umth_canvas_draw_quad(color: uint32, q: th::Quad) void umth_canvas_draw_quad(UmkaStackSlot *p, UmkaStackSlot *r) { - uint32_t color = p[1].uintVal; - th_quad *q = p[0].ptrVal; + uint32_t color = umkaGetParam(p, 0)->uintVal; + th_quad *q = (th_quad *)umkaGetParam(p, 1); th_canvas_quad(q, color); } +// fn umth_canvas_begin_scissor_rect(r: rect::Rect) void umth_canvas_begin_scissor_rect(UmkaStackSlot *p, UmkaStackSlot *r) { - th_canvas_begin_scissor_rect( - (th_rect){p[3].realVal, p[2].realVal, p[1].realVal, p[0].realVal}); + th_canvas_begin_scissor_rect(*(th_rect *)umkaGetParam(p, 0)); } +// fn umth_canvas_end_scissor() void umth_canvas_end_scissor(UmkaStackSlot *p, UmkaStackSlot *r) { th_canvas_end_scissor(); } +// fn umth_transform_rect(r: Rect, t: th::Transform): th::Quad void -umth_transform_rect(UmkaStackSlot *p, UmkaStackSlot *_) +umth_transform_rect(UmkaStackSlot *p, UmkaStackSlot *r) { - th_quad *ret = p[2].ptrVal; - th_rect *r = p[1].ptrVal; - th_transform *t = p[0].ptrVal; + th_rect rc = *(th_rect *)umkaGetParam(p, 0); + th_transform t = *(th_transform *)umkaGetParam(p, 1); - th_transform_rect(ret, *t, *r); + th_transform_rect(umkaGetResult(p, r)->ptrVal, t, rc); } +// fn umth_transform_quad(q: Quad, t: Transform): Quad void umth_transform_quad(UmkaStackSlot *p, UmkaStackSlot *r) { - th_quad *q = p[1].ptrVal; - th_transform *t = p[0].ptrVal; + th_quad q = *(th_quad *)umkaGetParam(p, 0); + th_transform t = *(th_transform *)umkaGetParam(p, 1); + + th_transform_quad(&q, t); - th_transform_quad(q, *t); + *(th_quad *)umkaGetResult(p, r)->ptrVal = q; } +// fn umth_transform_vf2(v: Vf2, t: Transform): Vf2 void umth_transform_vf2(UmkaStackSlot *p, UmkaStackSlot *r) { - th_vf2 *v = p[1].ptrVal; - th_transform *t = p[0].ptrVal; + th_vf2 v = *(th_vf2 *)umkaGetParam(p, 0); + th_transform t = *(th_transform *)umkaGetParam(p, 1); - th_transform_vf2(v, *t); + th_transform_vf2(&v, t); + + *(th_vf2 *)umkaGetResult(p, r)->ptrVal = v; } +// fn umth_transform_transform(o, t: Transform): Transform void umth_transform_transform(UmkaStackSlot *p, UmkaStackSlot *r) { - th_transform *o = (th_transform *)p[1].ptrVal; - th_transform *t = p[0].ptrVal; - th_transform_transform(o, *t); + th_transform o = *(th_transform *)umkaGetParam(p, 0); + th_transform t = *(th_transform *)umkaGetParam(p, 1); + + th_transform_transform(&o, t); + + *(th_transform *)umkaGetResult(p, r)->ptrVal = o; } +// fn umth_quad_max(q: Quad): Vf2 void -umth_coll_line_to_line(UmkaStackSlot *p, UmkaStackSlot *r) +umth_quad_max(UmkaStackSlot *p, UmkaStackSlot *r) { - th_vf2 *b1 = p[4].ptrVal; - th_vf2 *e1 = p[3].ptrVal; - th_vf2 *b2 = p[2].ptrVal; - th_vf2 *e2 = p[1].ptrVal; - th_vf2 *ic = p[0].ptrVal; + th_quad q = *(th_quad *)umkaGetParam(p, 0); - r->intVal = th_line_to_line(*b1, *e1, *b2, *e2, ic); + *(th_vf2 *)umkaGetResult(p, r)->ptrVal = th_quad_max(q); } +// fn umth_quad_min(q: Quad): Vf2 void -umth_coll_point_to_quad(UmkaStackSlot *p, UmkaStackSlot *r) +umth_quad_min(UmkaStackSlot *p, UmkaStackSlot *r) { - th_vf2 *v = p[2].ptrVal; - th_quad *q = p[1].ptrVal; - th_vf2 *ic = p[0].ptrVal; + th_quad q = *(th_quad *)umkaGetParam(p, 0); - r->intVal = th_point_to_quad(*v, q, ic); + *(th_vf2 *)umkaGetResult(p, r)->ptrVal = th_quad_min(q); } +// TODO: This isn't in th.um right now, as it would create a cyclic dependency between rect.um and +// th.um +// fn umth_quad_bounding_box(q: Quad): Rect void -umth_coll_line_to_quad(UmkaStackSlot *p, UmkaStackSlot *r) +umth_quad_bounding_box(UmkaStackSlot *p, UmkaStackSlot *r) { - th_vf2 *b = p[4].ptrVal; - th_vf2 *e = p[3].ptrVal; - th_quad *q = p[2].ptrVal; - th_vf2 *ic1 = p[1].ptrVal; - th_vf2 *ic2 = p[0].ptrVal; + th_quad q = *(th_quad *)umkaGetParam(p, 0); - r->intVal = th_line_to_quad(*b, *e, q, ic1, ic2); + *(th_rect *)umkaGetResult(p, r)->ptrVal = th_quad_bounding_box(q); } +// fn umth_coll_line_to_line(b1, e1, b2, e2: th::Vf2, ic: ^th::Vf2): bool void -umth_coll_quad_to_quad(UmkaStackSlot *p, UmkaStackSlot *r) +umth_coll_line_to_line(UmkaStackSlot *p, UmkaStackSlot *r) { - th_quad *q1 = p[2].ptrVal; - th_quad *q2 = p[1].ptrVal; - th_vf2 *ic = p[0].ptrVal; + th_vf2 b1 = *(th_vf2 *)umkaGetParam(p, 0); + th_vf2 e1 = *(th_vf2 *)umkaGetParam(p, 1); + th_vf2 b2 = *(th_vf2 *)umkaGetParam(p, 2); + th_vf2 e2 = *(th_vf2 *)umkaGetParam(p, 3); + th_vf2 *ic = umkaGetParam(p, 4)->ptrVal; - r->intVal = th_quad_to_quad(q1, q2, ic); + umkaGetResult(p, r)->intVal = th_line_to_line(b1, e1, b2, e2, ic); } +// fn umth_coll_point_to_quad(v: th::Vf2, q: th::Quad, ic: ^th::Vf2): bool void -umth_coll_point_to_rect(UmkaStackSlot *p, UmkaStackSlot *r) +umth_coll_point_to_quad(UmkaStackSlot *p, UmkaStackSlot *r) { - th_vf2 v = *(th_vf2 *)&p[1]; - th_rect *re = p[0].ptrVal; + th_vf2 v = *(th_vf2 *)umkaGetParam(p, 0); + th_quad q = *(th_quad *)umkaGetParam(p, 1); + th_vf2 *ic = umkaGetParam(p, 2)->ptrVal; - r->intVal = th_coll_point_on_rect(v, re); + umkaGetResult(p, r)->intVal = th_point_to_quad(v, &q, ic); } +// fn umth_coll_line_to_quad(b, e: th::Vf2, q: th::Quad, ic1, ic2: ^th::Vf2): bool void -umth_coll_rect_to_rect(UmkaStackSlot *p, UmkaStackSlot *r) +umth_coll_line_to_quad(UmkaStackSlot *p, UmkaStackSlot *r) { - th_rect *r1 = p[1].ptrVal; - th_rect *r2 = p[0].ptrVal; + th_vf2 b = *(th_vf2 *)umkaGetParam(p, 0); + th_vf2 e = *(th_vf2 *)umkaGetParam(p, 1); + th_quad q = *(th_quad *)umkaGetParam(p, 2); + th_vf2 *ic1 = umkaGetParam(p, 3)->ptrVal; + th_vf2 *ic2 = umkaGetParam(p, 4)->ptrVal; - r->intVal = th_rect_to_rect(r1, r2); + umkaGetResult(p, r)->intVal = th_line_to_quad(b, e, &q, ic1, ic2); } +// fn umth_coll_quad_to_quad(q1, q2: th::Quad, ic: ^th::Vf2): bool void -umth_nav_mesh_add_quad(UmkaStackSlot *p, UmkaStackSlot *r) +umth_coll_quad_to_quad(UmkaStackSlot *p, UmkaStackSlot *r) { - th_navmesh *m = p[1].ptrVal; - th_quad *q = p[0].ptrVal; + th_quad q1 = *(th_quad *)umkaGetParam(p, 0); + th_quad q2 = *(th_quad *)umkaGetParam(p, 1); + th_vf2 *ic = umkaGetParam(p, 2)->ptrVal; - th_navmesh_add_quad(m, q); + umkaGetResult(p, r)->intVal = th_quad_to_quad(&q1, &q2, ic); } +// fn umth_coll_point_to_rect(p: th::Vf2, r: rect::Rect): bool void -umth_nav_mesh_nav(UmkaStackSlot *p, UmkaStackSlot *r) +umth_coll_point_to_rect(UmkaStackSlot *p, UmkaStackSlot *r) { - th_vf2s *cameFrom = p[4].ptrVal; - void *cameFromType = p[3].ptrVal; - th_navmesh *m = p[2].ptrVal; - th_vf2 p1 = *(th_vf2 *)&p[1]; - th_vf2 p2 = *(th_vf2 *)&p[0]; + th_vf2 v = *(th_vf2 *)umkaGetParam(p, 0); + th_rect rc = *(th_rect *)umkaGetParam(p, 1); - th_navmesh_nav(cameFrom, cameFromType, m, p1, p2); + umkaGetResult(p, r)->intVal = th_coll_point_on_rect(v, &rc); } +// fn umth_coll_rect_to_rect(r1, r2: rect::Rect): bool void -umth_quad_min(UmkaStackSlot *p, UmkaStackSlot *r) +umth_coll_rect_to_rect(UmkaStackSlot *p, UmkaStackSlot *r) { - th_vf2 *o = (th_vf2 *)p[1].ptrVal; - th_quad *q = (th_quad *)p[0].ptrVal; + th_rect r1 = *(th_rect *)umkaGetParam(p, 0); + th_rect r2 = *(th_rect *)umkaGetParam(p, 1); - *o = th_quad_min(*q); + umkaGetResult(p, r)->intVal = th_rect_to_rect(&r1, &r2); } +// fn umth_nav_mesh_add_quad(m: ^Mesh, q: th::Quad) void -umth_quad_max(UmkaStackSlot *p, UmkaStackSlot *r) +umth_nav_mesh_add_quad(UmkaStackSlot *p, UmkaStackSlot *r) { - th_vf2 *o = (th_vf2 *)p[1].ptrVal; - th_quad *q = (th_quad *)p[0].ptrVal; + th_navmesh *m = umkaGetParam(p, 0)->ptrVal; + th_quad q = *(th_quad *)umkaGetParam(p, 1); - *o = th_quad_max(*q); + th_navmesh_add_quad(m, &q); } +// fn umth_nav_mesh_nav(t: ^void, m: ^Mesh, p1, p2: th::Vf2): []th::Vf2 void -umth_quad_bounding_box(UmkaStackSlot *p, UmkaStackSlot *r) +umth_nav_mesh_nav(UmkaStackSlot *p, UmkaStackSlot *r) { - th_rect *o = (th_rect *)p[1].ptrVal; - th_quad *q = (th_quad *)p[0].ptrVal; + void *cameFromType = umkaGetParam(p, 0)->ptrVal; + th_navmesh *m = umkaGetParam(p, 1)->ptrVal; + th_vf2 p1 = *(th_vf2 *)umkaGetParam(p, 2); + th_vf2 p2 = *(th_vf2 *)umkaGetParam(p, 3); - *o = th_quad_bounding_box(*q); + th_vf2s *cameFrom = umkaGetResult(p, r)->ptrVal; + + th_navmesh_nav(cameFrom, cameFromType, m, p1, p2); } +// fn umth_atlas_pack(a: ^Atlas, images: ^[]image::Image, strategy: int): th::ErrCode void umth_atlas_pack(UmkaStackSlot *p, UmkaStackSlot *r) { - th_atlas *a = p[2].ptrVal; - UmkaDynArray(th_image *) *images = p[1].ptrVal; - th_atlas_pack_strategy strategy = p[0].intVal; + th_atlas *a = umkaGetParam(p, 0)->ptrVal; + UmkaDynArray(th_image *) *images = umkaGetParam(p, 1)->ptrVal; + th_atlas_pack_strategy strategy = umkaGetParam(p, 2)->intVal; - r->intVal = th_atlas_pack(a, images, strategy); + umkaGetResult(p, r)->intVal = th_atlas_pack(a, images, strategy); } void @@ -1344,8 +1455,8 @@ _th_umka_bind(void *umka) umkaAddFunc(umka, "umth_sound_set_stop_time_ms", &umth_sound_set_stop_time_ms); // window - umkaAddFunc(umka, "umth_window_set_viewport_shift", &umth_window_set_viewport_shift); - umkaAddFunc(umka, "umth_window_get_viewport_shift", &umth_window_get_viewport_shift); + umkaAddFunc(umka, "umth_window_set_viewport_offset", &umth_window_set_viewport_offset); + umkaAddFunc(umka, "umth_window_get_viewport_offset", &umth_window_get_viewport_offset); umkaAddFunc(umka, "umth_window_set_clipboard", &umth_window_set_clipboard); umkaAddFunc(umka, "umth_window_get_clipboard", &umth_window_get_clipboard); umkaAddFunc(umka, "umth_window_get_fullscreen", &umth_window_get_fullscreen); @@ -1354,7 +1465,6 @@ _th_umka_bind(void *umka) umkaAddFunc(umka, "umth_window_is_dpi_enabled", &umth_window_is_dpi_enabled); umkaAddFunc(umka, "umth_window_setup", &umth_window_setup); umkaAddFunc(umka, "umth_window_get_dimensions", &umth_window_get_dimensions); - umkaAddFunc(umka, "umth_window_sleep", &umth_window_sleep); umkaAddFunc(umka, "umth_window_set_viewport", &umth_window_set_viewport); umkaAddFunc(umka, "umth_window_set_dims", &umth_window_set_dims); umkaAddFunc(umka, "umth_window_set_icon", &umth_window_set_icon); diff --git a/src/entity.c b/src/entity.c index 230582ef..3ee148c2 100644 --- a/src/entity.c +++ b/src/entity.c @@ -33,7 +33,6 @@ th_ent_draw(th_ent *o) void th_ent_getcoll(th_ent *e, th_ent **scene, uu count, uu *collC, uu maxColls, th_coll *colls) { - for (int i = 0; i < count && *collC < maxColls; i++) { if (e == scene[i]) continue; diff --git a/src/staembed.c b/src/staembed.c index f4af1bb1..ca7f1ea0 100644 --- a/src/staembed.c +++ b/src/staembed.c @@ -458,8 +458,7 @@ const char *th_em_modulesrc[] = { "\treturn e\n" "}\n" "\n" -"fn umth_ent_getcoll(coll: ^Coll, collC: ^int, maxCount: th::uu, count: int32,\n" -"\te: ^Ent, s: ^^Ent)\n" +"fn umth_ent_getcoll(maxcolls: uint, e: ^Ent, s: ^[]^Ent, t: ^void): []Coll\n" "//~~fn Ent.getColl\n" "// Checks collisions of e with entities in s. Checks at max maxColl collisions.\n" "// If s contains e, the collision won\'t be returned.\n" @@ -469,19 +468,7 @@ const char *th_em_modulesrc[] = { "\t\treturn []Coll{}\n" "\t}\n" "\n" -"\tif maxColls > len(s) {\n" -"\t\tmaxColls = len(s)\n" -"\t}\n" -"\n" -"\tif maxColls == 0 {\n" -"\t\tmaxColls = 1\n" -"\t}\n" -"\n" -"\tcolls := make([]Coll, maxColls)\n" -"\tcount := 0\n" -"\tumth_ent_getcoll(&colls[0], &count, maxColls, len(s), e, &s[0])\n" -"\n" -"\treturn slice(colls, 0, count)\n" +"\treturn umth_ent_getcoll(maxColls, e, &s, typeptr([]Coll))\n" "}\n" "\n" "//~~fn Ent.animate\n" @@ -545,7 +532,7 @@ const char *th_em_modulesrc[] = { "\treturn th::__errFromCode(ec)\n" "}\n" "\n" -"fn umth_image_render_target_to_image(ret: ^Image, rt: RenderTarget)\n" +"fn umth_image_render_target_to_image(rt: RenderTarget): Image\n" "//~~fn RenderTarget.toImage\n" "// Returns the image of the render target. The resulting image has the same\n" "// lifetime as the base RenderTarget. If you need to use it past the lifetime\n" @@ -553,9 +540,7 @@ const char *th_em_modulesrc[] = { "// Do not call `setfilter` on the resulting image.\n" "fn (rt: ^RenderTarget) toImage*(): Image {\n" "//~~\n" -"\timg := Image{}\n" -"\tumth_image_render_target_to_image(&img, rt^)\n" -"\treturn img\n" +"\treturn umth_image_render_target_to_image(rt^)\n" "}\n" "\n" "fn umth_image_load(ret: ^Image, path: str): th::ErrCode\n" @@ -599,7 +584,7 @@ const char *th_em_modulesrc[] = { "\tumth_image_fliph(i^, flip)\n" "}\n" "\n" -"fn umth_image_draw(img: Image, t: ^th::Transform, color: uint32)\n" +"fn umth_image_draw(img: Image, t: th::Transform, color: uint32)\n" "//~~fn Image.draw\n" "// Draws the image in screen coordinates. It transforms it with t and\n" "// applies color as a color filter.\n" @@ -609,10 +594,10 @@ const char *th_em_modulesrc[] = { "\t\tth::__error(\"image is invalid\")\n" "\t}\n" "\n" -"\tumth_image_draw(i^, &t, color)\n" +"\tumth_image_draw(i^, t, color)\n" "}\n" "\n" -"fn umth_image_draw_nine_patch(img: Image, outer, inner, dest: ^rect::Rect,\n" +"fn umth_image_draw_nine_patch(img: Image, outer, inner, dest: rect::Rect,\n" "\tcolor: uint32, scale: real)\n" "//~~fn Image.drawNinepatch\n" "// Draws \"nine-patch\" image.\n" @@ -627,7 +612,7 @@ const char *th_em_modulesrc[] = { "\t\tth::__error(\"image is invalid\")\n" "\t}\n" "\n" -"\tumth_image_draw_nine_patch(i^, &outer, &inner, &dest, color, scale)\n" +"\tumth_image_draw_nine_patch(i^, outer, inner, dest, color, scale)\n" "}\n" "\n" "fn umth_image_draw_on_quad(img: Image, color: uint32, q: th::Quad)\n" @@ -643,7 +628,7 @@ const char *th_em_modulesrc[] = { "\tumth_image_draw_on_quad(i^, color, q)\n" "}\n" "\n" -"fn umth_image_get_dims(dm: ^th::Vf2, i: Image)\n" +"fn umth_image_get_dims(i: Image): th::Vf2\n" "//~~fn Image.getDims\n" "// Returns width and heigth.\n" "fn (i: ^Image) getDims*(): th::Vf2 {\n" @@ -652,10 +637,7 @@ const char *th_em_modulesrc[] = { "\t\tth::__error(\"image is invalid\")\n" "\t}\n" "\n" -"\tout := th::Vf2{}\n" -"\tumth_image_get_dims(&out, i^)\n" -"\n" -"\treturn out\n" +"\treturn umth_image_get_dims(i^)\n" "}\n" "\n" "fn umth_image_crop(img: Image, tl, br: th::Vf2)\n" @@ -695,7 +677,7 @@ const char *th_em_modulesrc[] = { "\tumth_image_crop(i^, r.getPos().div(dm), r.getEnd().div(dm))\n" "}\n" "\n" -"fn umth_image_crop_quad(img: Image, q: ^th::Quad)\n" +"fn umth_image_crop_quad(img: Image, q: th::Quad)\n" "//~~fn Image.cropQuad\n" "// Crop an image using a quad.\n" "fn (i: ^Image) cropQuad*(q: th::Quad) {\n" @@ -704,10 +686,10 @@ const char *th_em_modulesrc[] = { "\t\tth::__error(\"image is invalid\")\n" "\t}\n" "\n" -"\tumth_image_crop_quad(i^, &q)\n" +"\tumth_image_crop_quad(i^, q)\n" "}\n" "\n" -"fn umth_image_get_crop_quad(img: Image, q: ^th::Quad)\n" +"fn umth_image_get_crop_quad(img: Image): th::Quad\n" "//~~fn Image.getCropQuad\n" "// Crop an image using a quad.\n" "fn (i: ^Image) getCropQuad*(): th::Quad {\n" @@ -716,9 +698,7 @@ const char *th_em_modulesrc[] = { "\t\tth::__error(\"image is invalid\")\n" "\t}\n" "\n" -"\tvar (q: th::Quad)\n" -"\tumth_image_get_crop_quad(i^, &q)\n" -"\treturn q\n" +"\treturn umth_image_get_crop_quad(i^)\n" "}\n" "\n" "fn umth_image_from_data(ret: ^Image, data: ^uint32, dm: th::Vf2): th::ErrCode\n" @@ -986,82 +966,79 @@ const char *th_em_modulesrc[] = { "\treturn int(c);\n" "}\n" "\n" -"fn umth_input_get_mouse(out: ^th::Vf2)\n" +"fn umth_input_get_mouse(): th::Vf2\n" "//~~fn getMousePos\n" "// Returns the position of mouse cursor in relation to the screen.\n" "fn getMousePos*(): th::Vf2 {\n" -"\t//~~\n" -"\tout := th::Vf2{}\n" -"\tumth_input_get_mouse(&out)\n" -"\treturn out\n" +"//~~\n" +"\treturn umth_input_get_mouse()\n" "}\n" "\n" "//~~fn getGlobalMousePos\n" "// Returns the position of mouse cursor in relation to cam.\n" "fn getGlobalMousePos*(): th::Vf2 {\n" -"\t//~~\n" +"//~~\n" "\treturn getMousePos().add(window::getViewportOffset())\n" "}\n" "\n" -"fn umth_input_is_pressed(keycode: Key): int32\n" +"fn umth_input_is_pressed(key: Key): bool\n" "//~~fn isPressed\n" "// Returns true if key is pressed. Either use codes defined in the file above,\n" "// or pass lower case char/number.\n" "fn isPressed*(code: Key): bool {\n" -"\t//~~\n" -"\tval := bool(umth_input_is_pressed(code))\n" -"\treturn val\n" +"//~~\n" +"\treturn umth_input_is_pressed(code)\n" "}\n" "\n" "//~~fn isPressedc\n" "// Like `isPressed`, but you can pass char as the code.\n" "fn isPressedc*(code: char): bool {\n" -"\t//~~\n" +"//~~\n" "\treturn isPressed(Key(toupper(code)))\n" "}\n" "\n" -"fn umth_input_is_just_pressed(key: Key): int32\n" +"fn umth_input_is_just_pressed(key: Key): bool\n" "//~~fn isJustPressed\n" "// Returns, whether code was just pressed this loop.\n" "fn isJustPressed*(code: Key): bool {\n" -"\t//~~\n" -"\treturn bool(umth_input_is_just_pressed(code))\n" +"//~~\n" +"\treturn umth_input_is_just_pressed(code)\n" "}\n" "\n" "//~~fn isJustPressedc\n" "// Like `isJustPressed`, but you can pass char as the code.\n" "fn isJustPressedc*(code: char): bool {\n" -"\t//~~\n" +"//~~\n" "\treturn isJustPressed(Key(toupper(code)))\n" "}\n" "\n" -"fn umth_input_is_pressed_repeat(key: Key): int32\n" +"fn umth_input_is_pressed_repeat(key: Key): bool\n" "//~~fn isPressedRepeat\n" "// Returns, whether code was just pressed this loop, with key repeat.\n" "fn isPressedRepeat*(code: Key): bool {\n" -"\t//~~\n" -"\treturn bool(umth_input_is_pressed_repeat(code))\n" +"//~~\n" +"\treturn umth_input_is_pressed_repeat(code)\n" "}\n" "\n" "//~~fn isPressedRepeatc\n" "// Like `isPressedRepeat`, but you can pass char as the code.\n" "fn isPressedRepeatc*(code: char): bool {\n" -"\t//~~\n" +"//~~\n" "\treturn isPressedRepeat(Key(toupper(code)))\n" "}\n" "\n" -"\n" -"fn umth_input_is_just_released(key: Key): int32\n" +"fn umth_input_is_just_released(key: Key): bool\n" "//~~fn isJustReleased\n" "// Returns true if a key was just released.\n" "fn isJustReleased*(code: Key): bool {\n" -"\t//~~\n" -"\treturn bool(umth_input_is_just_released(code))\n" +"//~~\n" +"\treturn umth_input_is_just_released(code)\n" "}\n" +"\n" "//~~fn isJustReleasedc\n" "// Like `isJustReleased`, but you can pass char as the code.\n" "fn isJustReleasedc*(code: char): bool {\n" -"\t//~~\n" +"//~~\n" "\treturn isJustReleased(Key(toupper(code)))\n" "}\n" "\n" @@ -1069,14 +1046,14 @@ const char *th_em_modulesrc[] = { "//~~fn clear\n" "// Clears both the pressed and justPressed state of a code.\n" "fn clear*(code: Key) {\n" -"\t//~~\n" +"//~~\n" "\tumth_input_clear(code)\n" "}\n" "\n" "//~~fn clearc\n" "// Like `clear`, but you can pass char as the code.\n" "fn clearc*(code: char) {\n" -"\t//~~\n" +"//~~\n" "\tumth_input_clear(Key(toupper(code)))\n" "}\n" "\n" @@ -1084,39 +1061,34 @@ const char *th_em_modulesrc[] = { "//~~fn getStr\n" "// Returns a string entered by the user in the last cycle.\n" "fn getStr*(): str {\n" -"\t//~~\n" +"//~~\n" "\treturn umth_input_get_str()\n" "}\n" "\n" -"fn umth_input_get_mouse_delta(o: ^th::Vf2)\n" +"fn umth_input_get_mouse_delta(): th::Vf2\n" "//~~fn getMouseDelta\n" "// Returns the difference between mouse positions in the last cycle. Will work\n" "// even if `window.freezeCursor` is enabled.\n" "fn getMouseDelta*(): th::Vf2 {\n" -"\t//~~\n" -"\to := th::Vf2{}\n" -"\tumth_input_get_mouse_delta(&o)\n" -"\treturn o\n" +"//~~\n" +"\treturn umth_input_get_mouse_delta()\n" "}\n" "\n" -"fn umth_input_get_mouse_scroll(x, y: ^th::fu)\n" +"fn umth_input_get_mouse_scroll(): th::Vf2\n" "//~~fn getMouseScroll\n" "// Returns the scroll wheel value\n" "fn getMouseScroll*(): th::Vf2 {\n" -"\t//~~\n" -"\tvar x, y: th::fu\n" -"\tumth_input_get_mouse_scroll(&x, &y)\n" -"\treturn {x, y}\n" +"//~~\n" +"\treturn umth_input_get_mouse_scroll()\n" "}\n" "\n" -"fn umth_input_gamepad_get_gamepads*(out: ^[4]int)\n" +"fn umth_input_gamepad_get_gamepads*(): [4]int\n" "\n" "//~~fn gamepads\n" "// Returns a list of gamepads that are currently connected.\n" "fn gamepads*(): []Gamepad {\n" "//~~\n" -"\tvar gamepads: [4]int\n" -"\tumth_input_gamepad_get_gamepads(&gamepads)\n" +"\tgamepads := umth_input_gamepad_get_gamepads()\n" "\n" "\tresult := []Gamepad{}\n" "\n" @@ -1174,15 +1146,13 @@ const char *th_em_modulesrc[] = { "\treturn umth_input_gamepad_pressure(g.id, button)\n" "}\n" "\n" -"fn umth_input_gamepad_stick(gamepad: int, stick: GamepadStick, out: ^th::Vf2)\n" +"fn umth_input_gamepad_stick(gamepad: int, stick: GamepadStick): th::Vf2\n" "\n" "//~~fn stick\n" "// Returns the movement of the gamepad stick in the range [-1, 1] for each axis.\n" "fn (g: ^Gamepad) stick*(stick: GamepadStick): th::Vf2 {\n" "//~~\n" -"\tvar out: th::Vf2\n" -"\tumth_input_gamepad_stick(g.id, stick, &out)\n" -"\treturn out\n" +"\treturn umth_input_gamepad_stick(g.id, stick)\n" "}\n" "\n" "fn umth_input_gamepad_rumble(gamepad: int, left, right: th::fu)\n" @@ -1313,17 +1283,17 @@ const char *th_em_modulesrc[] = { " drawLine(color, {r.x+r.w, r.y}, {r.x+r.w, r.y+r.h}, thickness)\n" "}\n" "\n" -"fn umth_canvas_draw_quad(color: uint32, q: ^th::Quad)\n" +"fn umth_canvas_draw_quad(color: uint32, q: th::Quad)\n" "//~~fn drawQuad\n" "// Draws a convex quad.\n" "fn drawQuad*(color: uint32, q: th::Quad) {\n" "//~~\n" -"\tumth_canvas_draw_quad(color, &q)\n" +"\tumth_canvas_draw_quad(color, q)\n" "}\n" "\n" "var scissor: []rect::Rect\n" "\n" -"fn umth_canvas_begin_scissor_rect(x, y, w, h: real)\n" +"fn umth_canvas_begin_scissor_rect(r: rect::Rect)\n" "fn umth_canvas_end_scissor()\n" "\n" "fn rectDiff(a, b: rect::Rect): rect::Rect {\n" @@ -1352,7 +1322,7 @@ const char *th_em_modulesrc[] = { "\t\tdrawRectLines(th::red, r2, 0.1) \n" "\t}\n" "\t\n" -"\tumth_canvas_begin_scissor_rect(r2.x, r2.y, r2.w, r2.h)\n" +"\tumth_canvas_begin_scissor_rect(r2)\n" "}\n" "\n" "//~~fn endScissor\n" @@ -1363,15 +1333,13 @@ const char *th_em_modulesrc[] = { "\t\tscissor = delete(scissor, len(scissor) - 1)\n" "\t\tif len(scissor) > 0 {\n" "\t\t\tlast := scissor[len(scissor)-1]\n" -"\t\t\tumth_canvas_begin_scissor_rect(last.x, last.y, last.w, last.h)\n" +"\t\t\tumth_canvas_begin_scissor_rect(last)\n" "\t\t} else {\n" "\t\t\tumth_canvas_end_scissor();\n" "\t\t}\n" "\t}\n" -"\t\n" "}\n" "", -"\n" "import (\n" "\t\"th.um\"\n" ")\n" @@ -1422,7 +1390,7 @@ const char *th_em_modulesrc[] = { "\treturn {r.x+r.w, r.y+r.h}\n" "}\n" "\n" -"fn umth_transform_rect(ret: ^th::Quad, r: ^Rect, t: ^th::Transform)\n" +"fn umth_transform_rect(r: Rect, t: th::Transform): th::Quad\n" "//~~fn Rect.transformed\n" "// Transforms a rect into a quad.\n" "// Order:\n" @@ -1431,10 +1399,7 @@ const char *th_em_modulesrc[] = { "// \t3. position\n" "fn (r: ^Rect) transformed*(t: th::Transform): th::Quad {\n" "//~~\n" -"\tvar ret: th::Quad\n" -"\tumth_transform_rect(&ret, r, &t)\n" -"\n" -"\treturn ret\n" +"\treturn umth_transform_rect(r^, t)\n" "}\n" "\n" "//~~fn Rect.shrink\n" @@ -1679,11 +1644,11 @@ const char *th_em_modulesrc[] = { "}\n" "\n" "// 0 = other/unknown\n" -"// 2 = linux\n" -"// 3 = windows\n" -"// 4 = macos (unsupported currently)\n" -"// 5 = emscripten\n" -"fn umth_window_get_platform_id(): int\n" +"// 1 = linux\n" +"// 2 = windows\n" +"// 3 = macos (unsupported currently)\n" +"// 4 = emscripten\n" +"fn umth_window_get_platform_id(): th::Platform\n" "\n" "//~~fn setup\n" "// Sets up the engine and opens a window.\n" @@ -1692,7 +1657,7 @@ const char *th_em_modulesrc[] = { "\tw, h = width, height\n" "\tumth_window_setup(title, width, height)\n" "\n" -"\tth::platform = th::Platform(umth_window_get_platform_id())\n" +"\tth::platform = umth_window_get_platform_id()\n" "\n" "\taudio::__setup()\n" "\tplaceholders::__setup()\n" @@ -1848,33 +1813,28 @@ const char *th_em_modulesrc[] = { "\tumth_window_set_clipboard(s)\n" "}\n" "\n" -"fn umth_window_get_clipboard(s: ^char)\n" +"fn umth_window_get_clipboard(): str\n" "//~~fn getClipboard\n" "// Gets a string from the system clipboard.\n" "fn getClipboard*(): str {\n" "//~~\n" -"\tbuf := make([]char, 8192)\n" -"\tumth_window_get_clipboard(&buf[0])\n" -"\treturn str(buf)\n" +"\treturn umth_window_get_clipboard()\n" "}\n" "\n" -"fn umth_window_set_viewport_shift(s: th::Vf2)\n" +"fn umth_window_set_viewport_offset(s: th::Vf2)\n" "//~~fn setViewportOffset\n" "// Sets the offset of the viewport.\n" "fn setViewportOffset*(s: th::Vf2) {\n" "//~~\n" -"\tumth_window_set_viewport_shift(s)\n" +"\tumth_window_set_viewport_offset(s)\n" "}\n" "\n" -"fn umth_window_get_viewport_shift(s: ^th::Vf2)\n" +"fn umth_window_get_viewport_offset(): th::Vf2\n" "//~~fn getViewportOffset\n" "// Gets the offset of the viewport (as set by `setViewportShift`)\n" "fn getViewportOffset*(): th::Vf2 {\n" "//~~\n" -"\to := th::Vf2{}\n" -"\n" -"\tumth_window_get_viewport_shift(&o)\n" -"\treturn o\n" +"\treturn umth_window_get_viewport_offset()\n" "}\n" "", "//~~\n" @@ -2086,7 +2046,7 @@ const char *th_em_modulesrc[] = { "\tumth_font_draw(f^, text, pos.x, pos.y, color, scale)\n" "}\n" "\n" -"fn umth_font_measure(font: Font, s: str, o: ^th::Vf2)\n" +"fn umth_font_measure(font: Font, s: str): th::Vf2\n" "//~~fn Font.measure\n" "fn (f: ^Font) measure*(text: str): th::Vf2 {\n" "//~~\n" @@ -2095,9 +2055,7 @@ const char *th_em_modulesrc[] = { "\t\treturn {}\n" "\t}\n" "\n" -"\tvar size: th::Vf2\n" -"\tumth_font_measure(f^, text, &size)\n" -"\treturn size\n" +"\treturn umth_font_measure(f^, text)\n" "}\n" "", "//~~\n" @@ -2352,18 +2310,15 @@ const char *th_em_modulesrc[] = { "\treturn Transform{p: p, s: s, o: o, r: r}\n" "}\n" "\n" -"fn umth_transform_transform(o, t: ^Transform)\n" +"fn umth_transform_transform(o, t: Transform): Transform\n" "//~~fn Transform.transformed\n" "// Transforms a transform with another transform.\n" "fn (o: ^Transform) transformed*(t: Transform): Transform {\n" "//~~\n" -"\tret := o^\n" -"\tumth_transform_transform(&ret, &t)\n" -"\n" -"\treturn ret\n" +"\treturn umth_transform_transform(o^, t)\n" "}\n" "\n" -"fn umth_transform_vf2(v: ^Vf2, t: ^Transform)\n" +"fn umth_transform_vf2(v: Vf2, t: Transform): Vf2\n" "//~~fn Vf2.transformed\n" "// Transforms a vf2 to another vf2.\n" "// Order:\n" @@ -2374,33 +2329,36 @@ const char *th_em_modulesrc[] = { "// This allows conversion from a relative to an absolute vf2.\n" "fn (v: ^Vf2) transformed*(t: Transform): Vf2 {\n" "//~~\n" -"\tret := v^\n" -"\tumth_transform_vf2(&ret, &t)\n" -"\treturn ret\n" +"\treturn umth_transform_vf2(v^, t)\n" "}\n" "\n" "//~~type Quad\n" "type Quad* = [4]Vf2\n" "//~~\n" "\n" -"fn umth_quad_max(o: ^Vf2, q: ^Quad)\n" +"fn umth_transform_quad(q: Quad, t: Transform): Quad\n" +"\n" +"//~~fn Quad.transformed\n" +"// Transforms a quad with a transform.\n" +"fn (q: ^Quad) transformed*(t: Transform): Quad {\n" +"//~~\n" +"\treturn umth_transform_quad(q^, t)\n" +"}\n" +"\n" +"fn umth_quad_max(q: Quad): Vf2\n" "//~~fn Quad.getMax\n" "// Gets the maximum coordinate.\n" "fn (q: ^Quad) getMax*(): Vf2 {\n" "//~~\n" -"\to := Vf2{}\n" -"\tumth_quad_max(&o, q)\n" -"\treturn o\n" +"\treturn umth_quad_max(q^)\n" "}\n" "\n" -"fn umth_quad_min(o: ^Vf2, q: ^Quad)\n" +"fn umth_quad_min(q: Quad): Vf2\n" "//~~fn Quad.getMin\n" "// Gets the minimum coordinate.\n" "fn (q: ^Quad) getMin*(): Vf2 {\n" "//~~\n" -"\to := Vf2{}\n" -"\tumth_quad_min(&o, q)\n" -"\treturn o\n" +"\treturn umth_quad_min(q^)\n" "}\n" "\n" "//~~fn Quad.getDims\n" @@ -2865,52 +2823,52 @@ const char *th_em_modulesrc[] = { "\t\"rect.um\"\n" ")\n" "\n" -"fn umth_coll_line_to_line(b1, e1, b2, e2, ic: ^th::Vf2): bool\n" +"fn umth_coll_line_to_line(b1, e1, b2, e2: th::Vf2, ic: ^th::Vf2): bool\n" "//~~fn lineToLine\n" "// Checks for a collision between 2 lines specified by their end points.\n" "fn lineToLine*(b1, e1, b2, e2: th::Vf2, ic: ^th::Vf2): bool {\n" "//~~\n" -"\treturn umth_coll_line_to_line(&b1, &e1, &b2, &e2, ic)\n" +"\treturn umth_coll_line_to_line(b1, e1, b2, e2, ic)\n" "}\n" "\n" -"fn umth_coll_point_to_quad(p: ^th::Vf2, q: ^th::Quad, ic: ^th::Vf2): bool\n" +"fn umth_coll_point_to_quad(p: th::Vf2, q: th::Quad, ic: ^th::Vf2): bool\n" "//~~fn vf2ToQuad\n" "// Checks for a collision between a vf2 and a quad.\n" "fn vf2ToQuad*(p: th::Vf2, q: th::Quad, ic: ^th::Vf2): bool {\n" "//~~\n" -"\treturn umth_coll_point_to_quad(&p, &q, ic)\n" +"\treturn umth_coll_point_to_quad(p, q, ic)\n" "}\n" "\n" -"fn umth_coll_line_to_quad(b, e: ^th::Vf2, q: ^th::Quad, ic1, ic2: ^th::Vf2): bool\n" +"fn umth_coll_line_to_quad(b, e: th::Vf2, q: th::Quad, ic1, ic2: ^th::Vf2): bool\n" "//~~fn lineToQuad\n" "// Check for a collision between a line and quad edges.\n" "fn lineToQuad*(b, e: th::Vf2, q: th::Quad, ic1, ic2: ^th::Vf2): bool {\n" "//~~\n" -"\treturn umth_coll_line_to_quad(&b, &e, &q, ic1, ic2)\n" +"\treturn umth_coll_line_to_quad(b, e, q, ic1, ic2)\n" "}\n" "\n" -"fn umth_coll_quad_to_quad(q1, q2: ^th::Quad, ic: ^th::Vf2): bool\n" +"fn umth_coll_quad_to_quad(q1, q2: th::Quad, ic: ^th::Vf2): bool\n" "//~~fn quadToQuad\n" "// Check for a collision between two quads.\n" "fn quadToQuad*(q1, q2: th::Quad, ic: ^th::Vf2): bool {\n" "//~~\n" -"\treturn umth_coll_quad_to_quad(&q1, &q2, ic)\n" +"\treturn umth_coll_quad_to_quad(q1, q2, ic)\n" "}\n" "\n" -"fn umth_coll_point_to_rect(p: th::Vf2, r: ^rect::Rect): bool\n" +"fn umth_coll_point_to_rect(p: th::Vf2, r: rect::Rect): bool\n" "//~~fn vf2ToRect\n" "// Check for a collision between a vf2 and a rectangle.\n" "fn vf2ToRect*(p: th::Vf2, r: rect::Rect): bool {\n" "//~~\n" -"\treturn umth_coll_point_to_rect(p, &r)\n" +"\treturn umth_coll_point_to_rect(p, r)\n" "}\n" "\n" -"fn umth_coll_rect_to_rect(r1, r2: ^rect::Rect): bool\n" +"fn umth_coll_rect_to_rect(r1, r2: rect::Rect): bool\n" "//~~fn rectToRect\n" "// Check for a collision between two rects\n" "fn rectToRect*(r1, r2: rect::Rect): bool {\n" "//~~\n" -"\treturn umth_coll_rect_to_rect(&r1, &r2)\n" +"\treturn umth_coll_rect_to_rect(r1, r2)\n" "}\n" "\n" "", @@ -2991,15 +2949,15 @@ const char *th_em_modulesrc[] = { "\treturn m\n" "}\n" "\n" -"fn umth_nav_mesh_add_quad(m: ^Mesh, q: ^th::Quad)\n" +"fn umth_nav_mesh_add_quad(m: ^Mesh, q: th::Quad)\n" "//~~fn Mesh.addQuad\n" "// Sets mask\'s fields overlapping `q` to `false`.\n" "fn (m: ^Mesh) addQuad*(q: th::Quad) {\n" "//~~\n" -"\tumth_nav_mesh_add_quad(m, &q)\n" +"\tumth_nav_mesh_add_quad(m, q)\n" "}\n" "\n" -"fn umth_nav_mesh_nav(cameFrom: ^[]th::Vf2, cameFromType: ^void, m: ^Mesh, p1, p2: th::Vf2)\n" +"fn umth_nav_mesh_nav(t: ^void, m: ^Mesh, p1, p2: th::Vf2): []th::Vf2\n" "//~~fn Mesh.nav\n" "// Navigates between `p1` and `p2`. Returns the path as an array of `th.Vf2`s.\n" "// If it doesn\'t find any path, or one of the points is outside of the mask,\n" @@ -3010,8 +2968,7 @@ const char *th_em_modulesrc[] = { "\t\treturn {}\n" "\t}\n" "\n" -"\tvar cameFrom: []th::Vf2\n" -"\tumth_nav_mesh_nav(&cameFrom, typeptr([]th::Vf2), m, p1, p2)\n" +"\tcameFrom := umth_nav_mesh_nav(typeptr([]th::Vf2), m, p1, p2)\n" "\n" "\tpath := []th::Vf2{p2}\n" "\tp := p2\n" @@ -5800,6 +5757,14 @@ const char *th_em_moduledocs[] = { "\n" "---------\n" "\n" +"fn Quad.transformed\n" +"\n" +"fn (q: ^Quad) transformed*(t: Transform): Quad {\n" +"\n" +"Transforms a quad with a transform.\n" +"\n" +"---------\n" +"\n" "fn Quad.getMax\n" "\n" "fn (q: ^Quad) getMax*(): Vf2 {\n" diff --git a/umka/canvas.um b/umka/canvas.um index 950cdeb4..9f7f3b84 100644 --- a/umka/canvas.um +++ b/umka/canvas.um @@ -77,17 +77,17 @@ fn drawRectLines*(color: uint32, r: rect::Rect, thickness: real32 = 1.0) { drawLine(color, {r.x+r.w, r.y}, {r.x+r.w, r.y+r.h}, thickness) } -fn umth_canvas_draw_quad(color: uint32, q: ^th::Quad) +fn umth_canvas_draw_quad(color: uint32, q: th::Quad) //~~fn drawQuad // Draws a convex quad. fn drawQuad*(color: uint32, q: th::Quad) { //~~ - umth_canvas_draw_quad(color, &q) + umth_canvas_draw_quad(color, q) } var scissor: []rect::Rect -fn umth_canvas_begin_scissor_rect(x, y, w, h: real) +fn umth_canvas_begin_scissor_rect(r: rect::Rect) fn umth_canvas_end_scissor() fn rectDiff(a, b: rect::Rect): rect::Rect { @@ -116,7 +116,7 @@ fn beginScissorRect*(r: rect::Rect, debug: bool = false) { drawRectLines(th::red, r2, 0.1) } - umth_canvas_begin_scissor_rect(r2.x, r2.y, r2.w, r2.h) + umth_canvas_begin_scissor_rect(r2) } //~~fn endScissor @@ -127,10 +127,9 @@ fn endScissor*() { scissor = delete(scissor, len(scissor) - 1) if len(scissor) > 0 { last := scissor[len(scissor)-1] - umth_canvas_begin_scissor_rect(last.x, last.y, last.w, last.h) + umth_canvas_begin_scissor_rect(last) } else { umth_canvas_end_scissor(); } } - } diff --git a/umka/coll.um b/umka/coll.um index 0a68f66e..66f6d813 100644 --- a/umka/coll.um +++ b/umka/coll.um @@ -7,51 +7,51 @@ import ( "rect.um" ) -fn umth_coll_line_to_line(b1, e1, b2, e2, ic: ^th::Vf2): bool +fn umth_coll_line_to_line(b1, e1, b2, e2: th::Vf2, ic: ^th::Vf2): bool //~~fn lineToLine // Checks for a collision between 2 lines specified by their end points. fn lineToLine*(b1, e1, b2, e2: th::Vf2, ic: ^th::Vf2): bool { //~~ - return umth_coll_line_to_line(&b1, &e1, &b2, &e2, ic) + return umth_coll_line_to_line(b1, e1, b2, e2, ic) } -fn umth_coll_point_to_quad(p: ^th::Vf2, q: ^th::Quad, ic: ^th::Vf2): bool +fn umth_coll_point_to_quad(p: th::Vf2, q: th::Quad, ic: ^th::Vf2): bool //~~fn vf2ToQuad // Checks for a collision between a vf2 and a quad. fn vf2ToQuad*(p: th::Vf2, q: th::Quad, ic: ^th::Vf2): bool { //~~ - return umth_coll_point_to_quad(&p, &q, ic) + return umth_coll_point_to_quad(p, q, ic) } -fn umth_coll_line_to_quad(b, e: ^th::Vf2, q: ^th::Quad, ic1, ic2: ^th::Vf2): bool +fn umth_coll_line_to_quad(b, e: th::Vf2, q: th::Quad, ic1, ic2: ^th::Vf2): bool //~~fn lineToQuad // Check for a collision between a line and quad edges. fn lineToQuad*(b, e: th::Vf2, q: th::Quad, ic1, ic2: ^th::Vf2): bool { //~~ - return umth_coll_line_to_quad(&b, &e, &q, ic1, ic2) + return umth_coll_line_to_quad(b, e, q, ic1, ic2) } -fn umth_coll_quad_to_quad(q1, q2: ^th::Quad, ic: ^th::Vf2): bool +fn umth_coll_quad_to_quad(q1, q2: th::Quad, ic: ^th::Vf2): bool //~~fn quadToQuad // Check for a collision between two quads. fn quadToQuad*(q1, q2: th::Quad, ic: ^th::Vf2): bool { //~~ - return umth_coll_quad_to_quad(&q1, &q2, ic) + return umth_coll_quad_to_quad(q1, q2, ic) } -fn umth_coll_point_to_rect(p: th::Vf2, r: ^rect::Rect): bool +fn umth_coll_point_to_rect(p: th::Vf2, r: rect::Rect): bool //~~fn vf2ToRect // Check for a collision between a vf2 and a rectangle. fn vf2ToRect*(p: th::Vf2, r: rect::Rect): bool { //~~ - return umth_coll_point_to_rect(p, &r) + return umth_coll_point_to_rect(p, r) } -fn umth_coll_rect_to_rect(r1, r2: ^rect::Rect): bool +fn umth_coll_rect_to_rect(r1, r2: rect::Rect): bool //~~fn rectToRect // Check for a collision between two rects fn rectToRect*(r1, r2: rect::Rect): bool { //~~ - return umth_coll_rect_to_rect(&r1, &r2) + return umth_coll_rect_to_rect(r1, r2) } diff --git a/umka/ent.um b/umka/ent.um index fccf4a4f..3302c541 100644 --- a/umka/ent.um +++ b/umka/ent.um @@ -60,8 +60,7 @@ fn mk*(img: image::Image = image::Image{}, t: th::Transform = th::Transform{ s: return e } -fn umth_ent_getcoll(coll: ^Coll, collC: ^int, maxCount: th::uu, count: int32, - e: ^Ent, s: ^^Ent) +fn umth_ent_getcoll(maxcolls: uint, e: ^Ent, s: ^[]^Ent, t: ^void): []Coll //~~fn Ent.getColl // Checks collisions of e with entities in s. Checks at max maxColl collisions. // If s contains e, the collision won't be returned. @@ -71,19 +70,7 @@ fn (e: ^Ent) getColl*(s: []^Ent, maxColls: th::uu): []Coll { return []Coll{} } - if maxColls > len(s) { - maxColls = len(s) - } - - if maxColls == 0 { - maxColls = 1 - } - - colls := make([]Coll, maxColls) - count := 0 - umth_ent_getcoll(&colls[0], &count, maxColls, len(s), e, &s[0]) - - return slice(colls, 0, count) + return umth_ent_getcoll(maxColls, e, &s, typeptr([]Coll)) } //~~fn Ent.animate diff --git a/umka/font.um b/umka/font.um index f167f7f8..978cc870 100644 --- a/umka/font.um +++ b/umka/font.um @@ -43,7 +43,7 @@ fn (f: ^Font) draw*(text: str, pos: th::Vf2, color: uint32, scale: th::fu = 1.0) umth_font_draw(f^, text, pos.x, pos.y, color, scale) } -fn umth_font_measure(font: Font, s: str, o: ^th::Vf2) +fn umth_font_measure(font: Font, s: str): th::Vf2 //~~fn Font.measure fn (f: ^Font) measure*(text: str): th::Vf2 { //~~ @@ -52,7 +52,5 @@ fn (f: ^Font) measure*(text: str): th::Vf2 { return {} } - var size: th::Vf2 - umth_font_measure(f^, text, &size) - return size + return umth_font_measure(f^, text) } diff --git a/umka/image.um b/umka/image.um index b0554746..880c0ae5 100644 --- a/umka/image.um +++ b/umka/image.um @@ -46,7 +46,7 @@ fn (rt: ^RenderTarget) end*(wp: th::Vf2): std::Err { return th::__errFromCode(ec) } -fn umth_image_render_target_to_image(ret: ^Image, rt: RenderTarget) +fn umth_image_render_target_to_image(rt: RenderTarget): Image //~~fn RenderTarget.toImage // Returns the image of the render target. The resulting image has the same // lifetime as the base RenderTarget. If you need to use it past the lifetime @@ -54,9 +54,7 @@ fn umth_image_render_target_to_image(ret: ^Image, rt: RenderTarget) // Do not call `setfilter` on the resulting image. fn (rt: ^RenderTarget) toImage*(): Image { //~~ - img := Image{} - umth_image_render_target_to_image(&img, rt^) - return img + return umth_image_render_target_to_image(rt^) } fn umth_image_load(ret: ^Image, path: str): th::ErrCode @@ -100,7 +98,7 @@ fn (i: ^Image) fliph*(flip: bool) { umth_image_fliph(i^, flip) } -fn umth_image_draw(img: Image, t: ^th::Transform, color: uint32) +fn umth_image_draw(img: Image, t: th::Transform, color: uint32) //~~fn Image.draw // Draws the image in screen coordinates. It transforms it with t and // applies color as a color filter. @@ -110,10 +108,10 @@ fn (i: ^Image) draw*(t: th::Transform, color: uint32 = th::white) { th::__error("image is invalid") } - umth_image_draw(i^, &t, color) + umth_image_draw(i^, t, color) } -fn umth_image_draw_nine_patch(img: Image, outer, inner, dest: ^rect::Rect, +fn umth_image_draw_nine_patch(img: Image, outer, inner, dest: rect::Rect, color: uint32, scale: real) //~~fn Image.drawNinepatch // Draws "nine-patch" image. @@ -128,7 +126,7 @@ fn (i: ^Image) drawNinepatch*(outer, inner, dest: rect::Rect, color: uint32 = th th::__error("image is invalid") } - umth_image_draw_nine_patch(i^, &outer, &inner, &dest, color, scale) + umth_image_draw_nine_patch(i^, outer, inner, dest, color, scale) } fn umth_image_draw_on_quad(img: Image, color: uint32, q: th::Quad) @@ -144,7 +142,7 @@ fn (i: ^Image) drawOnQuad*(q: th::Quad, color: uint32 = th::white) { umth_image_draw_on_quad(i^, color, q) } -fn umth_image_get_dims(dm: ^th::Vf2, i: Image) +fn umth_image_get_dims(i: Image): th::Vf2 //~~fn Image.getDims // Returns width and heigth. fn (i: ^Image) getDims*(): th::Vf2 { @@ -153,10 +151,7 @@ fn (i: ^Image) getDims*(): th::Vf2 { th::__error("image is invalid") } - out := th::Vf2{} - umth_image_get_dims(&out, i^) - - return out + return umth_image_get_dims(i^) } fn umth_image_crop(img: Image, tl, br: th::Vf2) @@ -196,7 +191,7 @@ fn (i: ^Image) cropRect*(r: rect::Rect) { umth_image_crop(i^, r.getPos().div(dm), r.getEnd().div(dm)) } -fn umth_image_crop_quad(img: Image, q: ^th::Quad) +fn umth_image_crop_quad(img: Image, q: th::Quad) //~~fn Image.cropQuad // Crop an image using a quad. fn (i: ^Image) cropQuad*(q: th::Quad) { @@ -205,10 +200,10 @@ fn (i: ^Image) cropQuad*(q: th::Quad) { th::__error("image is invalid") } - umth_image_crop_quad(i^, &q) + umth_image_crop_quad(i^, q) } -fn umth_image_get_crop_quad(img: Image, q: ^th::Quad) +fn umth_image_get_crop_quad(img: Image): th::Quad //~~fn Image.getCropQuad // Crop an image using a quad. fn (i: ^Image) getCropQuad*(): th::Quad { @@ -217,9 +212,7 @@ fn (i: ^Image) getCropQuad*(): th::Quad { th::__error("image is invalid") } - var (q: th::Quad) - umth_image_get_crop_quad(i^, &q) - return q + return umth_image_get_crop_quad(i^) } fn umth_image_from_data(ret: ^Image, data: ^uint32, dm: th::Vf2): th::ErrCode diff --git a/umka/input.um b/umka/input.um index b4bbf682..8708d081 100644 --- a/umka/input.um +++ b/umka/input.um @@ -183,82 +183,79 @@ fn toupper(c: char): int { return int(c); } -fn umth_input_get_mouse(out: ^th::Vf2) +fn umth_input_get_mouse(): th::Vf2 //~~fn getMousePos // Returns the position of mouse cursor in relation to the screen. fn getMousePos*(): th::Vf2 { - //~~ - out := th::Vf2{} - umth_input_get_mouse(&out) - return out +//~~ + return umth_input_get_mouse() } //~~fn getGlobalMousePos // Returns the position of mouse cursor in relation to cam. fn getGlobalMousePos*(): th::Vf2 { - //~~ +//~~ return getMousePos().add(window::getViewportOffset()) } -fn umth_input_is_pressed(keycode: Key): int32 +fn umth_input_is_pressed(key: Key): bool //~~fn isPressed // Returns true if key is pressed. Either use codes defined in the file above, // or pass lower case char/number. fn isPressed*(code: Key): bool { - //~~ - val := bool(umth_input_is_pressed(code)) - return val +//~~ + return umth_input_is_pressed(code) } //~~fn isPressedc // Like `isPressed`, but you can pass char as the code. fn isPressedc*(code: char): bool { - //~~ +//~~ return isPressed(Key(toupper(code))) } -fn umth_input_is_just_pressed(key: Key): int32 +fn umth_input_is_just_pressed(key: Key): bool //~~fn isJustPressed // Returns, whether code was just pressed this loop. fn isJustPressed*(code: Key): bool { - //~~ - return bool(umth_input_is_just_pressed(code)) +//~~ + return umth_input_is_just_pressed(code) } //~~fn isJustPressedc // Like `isJustPressed`, but you can pass char as the code. fn isJustPressedc*(code: char): bool { - //~~ +//~~ return isJustPressed(Key(toupper(code))) } -fn umth_input_is_pressed_repeat(key: Key): int32 +fn umth_input_is_pressed_repeat(key: Key): bool //~~fn isPressedRepeat // Returns, whether code was just pressed this loop, with key repeat. fn isPressedRepeat*(code: Key): bool { - //~~ - return bool(umth_input_is_pressed_repeat(code)) +//~~ + return umth_input_is_pressed_repeat(code) } //~~fn isPressedRepeatc // Like `isPressedRepeat`, but you can pass char as the code. fn isPressedRepeatc*(code: char): bool { - //~~ +//~~ return isPressedRepeat(Key(toupper(code))) } - -fn umth_input_is_just_released(key: Key): int32 +fn umth_input_is_just_released(key: Key): bool //~~fn isJustReleased // Returns true if a key was just released. fn isJustReleased*(code: Key): bool { - //~~ - return bool(umth_input_is_just_released(code)) +//~~ + return umth_input_is_just_released(code) } + //~~fn isJustReleasedc // Like `isJustReleased`, but you can pass char as the code. fn isJustReleasedc*(code: char): bool { - //~~ +//~~ return isJustReleased(Key(toupper(code))) } @@ -266,14 +263,14 @@ fn umth_input_clear*(code: Key) //~~fn clear // Clears both the pressed and justPressed state of a code. fn clear*(code: Key) { - //~~ +//~~ umth_input_clear(code) } //~~fn clearc // Like `clear`, but you can pass char as the code. fn clearc*(code: char) { - //~~ +//~~ umth_input_clear(Key(toupper(code))) } @@ -281,39 +278,34 @@ fn umth_input_get_str(): str //~~fn getStr // Returns a string entered by the user in the last cycle. fn getStr*(): str { - //~~ +//~~ return umth_input_get_str() } -fn umth_input_get_mouse_delta(o: ^th::Vf2) +fn umth_input_get_mouse_delta(): th::Vf2 //~~fn getMouseDelta // Returns the difference between mouse positions in the last cycle. Will work // even if `window.freezeCursor` is enabled. fn getMouseDelta*(): th::Vf2 { - //~~ - o := th::Vf2{} - umth_input_get_mouse_delta(&o) - return o +//~~ + return umth_input_get_mouse_delta() } -fn umth_input_get_mouse_scroll(x, y: ^th::fu) +fn umth_input_get_mouse_scroll(): th::Vf2 //~~fn getMouseScroll // Returns the scroll wheel value fn getMouseScroll*(): th::Vf2 { - //~~ - var x, y: th::fu - umth_input_get_mouse_scroll(&x, &y) - return {x, y} +//~~ + return umth_input_get_mouse_scroll() } -fn umth_input_gamepad_get_gamepads*(out: ^[4]int) +fn umth_input_gamepad_get_gamepads*(): [4]int //~~fn gamepads // Returns a list of gamepads that are currently connected. fn gamepads*(): []Gamepad { //~~ - var gamepads: [4]int - umth_input_gamepad_get_gamepads(&gamepads) + gamepads := umth_input_gamepad_get_gamepads() result := []Gamepad{} @@ -371,15 +363,13 @@ fn (g: ^Gamepad) pressure*(button: GamepadButton): th::fu { return umth_input_gamepad_pressure(g.id, button) } -fn umth_input_gamepad_stick(gamepad: int, stick: GamepadStick, out: ^th::Vf2) +fn umth_input_gamepad_stick(gamepad: int, stick: GamepadStick): th::Vf2 //~~fn stick // Returns the movement of the gamepad stick in the range [-1, 1] for each axis. fn (g: ^Gamepad) stick*(stick: GamepadStick): th::Vf2 { //~~ - var out: th::Vf2 - umth_input_gamepad_stick(g.id, stick, &out) - return out + return umth_input_gamepad_stick(g.id, stick) } fn umth_input_gamepad_rumble(gamepad: int, left, right: th::fu) diff --git a/umka/nav.um b/umka/nav.um index 2002695f..86a11dd2 100644 --- a/umka/nav.um +++ b/umka/nav.um @@ -51,15 +51,15 @@ fn mk*(r: rect::Rect, s: th::fu): Mesh { return m } -fn umth_nav_mesh_add_quad(m: ^Mesh, q: ^th::Quad) +fn umth_nav_mesh_add_quad(m: ^Mesh, q: th::Quad) //~~fn Mesh.addQuad // Sets mask's fields overlapping `q` to `false`. fn (m: ^Mesh) addQuad*(q: th::Quad) { //~~ - umth_nav_mesh_add_quad(m, &q) + umth_nav_mesh_add_quad(m, q) } -fn umth_nav_mesh_nav(cameFrom: ^[]th::Vf2, cameFromType: ^void, m: ^Mesh, p1, p2: th::Vf2) +fn umth_nav_mesh_nav(t: ^void, m: ^Mesh, p1, p2: th::Vf2): []th::Vf2 //~~fn Mesh.nav // Navigates between `p1` and `p2`. Returns the path as an array of `th.Vf2`s. // If it doesn't find any path, or one of the points is outside of the mask, @@ -70,8 +70,7 @@ fn (m: ^Mesh) nav*(p1, p2: th::Vf2): []th::Vf2 { return {} } - var cameFrom: []th::Vf2 - umth_nav_mesh_nav(&cameFrom, typeptr([]th::Vf2), m, p1, p2) + cameFrom := umth_nav_mesh_nav(typeptr([]th::Vf2), m, p1, p2) path := []th::Vf2{p2} p := p2 diff --git a/umka/rect.um b/umka/rect.um index 1d37ef37..92a3e4e6 100644 --- a/umka/rect.um +++ b/umka/rect.um @@ -1,4 +1,3 @@ - import ( "th.um" ) @@ -49,7 +48,7 @@ fn (r: ^Rect) getEnd*(): th::Vf2 { return {r.x+r.w, r.y+r.h} } -fn umth_transform_rect(ret: ^th::Quad, r: ^Rect, t: ^th::Transform) +fn umth_transform_rect(r: Rect, t: th::Transform): th::Quad //~~fn Rect.transformed // Transforms a rect into a quad. // Order: @@ -58,10 +57,7 @@ fn umth_transform_rect(ret: ^th::Quad, r: ^Rect, t: ^th::Transform) // 3. position fn (r: ^Rect) transformed*(t: th::Transform): th::Quad { //~~ - var ret: th::Quad - umth_transform_rect(&ret, r, &t) - - return ret + return umth_transform_rect(r^, t) } //~~fn Rect.shrink diff --git a/umka/th.um b/umka/th.um index 0a760a4b..0cde16b5 100644 --- a/umka/th.um +++ b/umka/th.um @@ -250,18 +250,15 @@ fn mkTransform*(p: Vf2, s: Vf2 = Vf2{1, 1}, o: Vf2 = Vf2{0, 0}, r: fu = 0.0): Tr return Transform{p: p, s: s, o: o, r: r} } -fn umth_transform_transform(o, t: ^Transform) +fn umth_transform_transform(o, t: Transform): Transform //~~fn Transform.transformed // Transforms a transform with another transform. fn (o: ^Transform) transformed*(t: Transform): Transform { //~~ - ret := o^ - umth_transform_transform(&ret, &t) - - return ret + return umth_transform_transform(o^, t) } -fn umth_transform_vf2(v: ^Vf2, t: ^Transform) +fn umth_transform_vf2(v: Vf2, t: Transform): Vf2 //~~fn Vf2.transformed // Transforms a vf2 to another vf2. // Order: @@ -272,33 +269,36 @@ fn umth_transform_vf2(v: ^Vf2, t: ^Transform) // This allows conversion from a relative to an absolute vf2. fn (v: ^Vf2) transformed*(t: Transform): Vf2 { //~~ - ret := v^ - umth_transform_vf2(&ret, &t) - return ret + return umth_transform_vf2(v^, t) } //~~type Quad type Quad* = [4]Vf2 //~~ -fn umth_quad_max(o: ^Vf2, q: ^Quad) +fn umth_transform_quad(q: Quad, t: Transform): Quad + +//~~fn Quad.transformed +// Transforms a quad with a transform. +fn (q: ^Quad) transformed*(t: Transform): Quad { +//~~ + return umth_transform_quad(q^, t) +} + +fn umth_quad_max(q: Quad): Vf2 //~~fn Quad.getMax // Gets the maximum coordinate. fn (q: ^Quad) getMax*(): Vf2 { //~~ - o := Vf2{} - umth_quad_max(&o, q) - return o + return umth_quad_max(q^) } -fn umth_quad_min(o: ^Vf2, q: ^Quad) +fn umth_quad_min(q: Quad): Vf2 //~~fn Quad.getMin // Gets the minimum coordinate. fn (q: ^Quad) getMin*(): Vf2 { //~~ - o := Vf2{} - umth_quad_min(&o, q) - return o + return umth_quad_min(q^) } //~~fn Quad.getDims diff --git a/umka/window.um b/umka/window.um index 47374559..160f3a61 100644 --- a/umka/window.um +++ b/umka/window.um @@ -87,11 +87,11 @@ fn getDpiScaleFactor*(): th::fu { } // 0 = other/unknown -// 2 = linux -// 3 = windows -// 4 = macos (unsupported currently) -// 5 = emscripten -fn umth_window_get_platform_id(): int +// 1 = linux +// 2 = windows +// 3 = macos (unsupported currently) +// 4 = emscripten +fn umth_window_get_platform_id(): th::Platform //~~fn setup // Sets up the engine and opens a window. @@ -100,7 +100,7 @@ fn setup*(title: str = "tophat game", width: int = 400, height: int32 = 400) { w, h = width, height umth_window_setup(title, width, height) - th::platform = th::Platform(umth_window_get_platform_id()) + th::platform = umth_window_get_platform_id() audio::__setup() placeholders::__setup() @@ -256,31 +256,26 @@ fn setClipboard*(s: str) { umth_window_set_clipboard(s) } -fn umth_window_get_clipboard(s: ^char) +fn umth_window_get_clipboard(): str //~~fn getClipboard // Gets a string from the system clipboard. fn getClipboard*(): str { //~~ - buf := make([]char, 8192) - umth_window_get_clipboard(&buf[0]) - return str(buf) + return umth_window_get_clipboard() } -fn umth_window_set_viewport_shift(s: th::Vf2) +fn umth_window_set_viewport_offset(s: th::Vf2) //~~fn setViewportOffset // Sets the offset of the viewport. fn setViewportOffset*(s: th::Vf2) { //~~ - umth_window_set_viewport_shift(s) + umth_window_set_viewport_offset(s) } -fn umth_window_get_viewport_shift(s: ^th::Vf2) +fn umth_window_get_viewport_offset(): th::Vf2 //~~fn getViewportOffset // Gets the offset of the viewport (as set by `setViewportShift`) fn getViewportOffset*(): th::Vf2 { //~~ - o := th::Vf2{} - - umth_window_get_viewport_shift(&o) - return o + return umth_window_get_viewport_offset() }