diff --git a/scripts/components.js b/scripts/components.js index c232e6f..40884ff 100644 --- a/scripts/components.js +++ b/scripts/components.js @@ -477,7 +477,7 @@ component.edge2d = Object.copy(collider2d, { } if (this.hollow) { - var hpoints = inflate_cpv(spoints, spoints.length, this.hollowt); + var hpoints = vector.inflate(spoints, this.hollowt); if (hpoints.length === spoints.length) return spoints; var arr1 = hpoints.filter(function(x,i) { return i % 2 === 0; }); var arr2 = hpoints.filter(function(x,i) { return i % 2 !== 0; }); diff --git a/scripts/engine.js b/scripts/engine.js index 78909cd..167aa2e 100644 --- a/scripts/engine.js +++ b/scripts/engine.js @@ -70,7 +70,7 @@ function use(file) var c = io.slurp(file); var script = `(function() { ${c} })();`; - use.files[file] = os.eval_env(file,global,script); + use.files[file] = os.eval_env(file,script,global); return use.files[file]; } @@ -90,7 +90,7 @@ function eval_env(script, env, file) file ??= "SCRIPT"; console.spam(`eval ${file}`); script = `(function() { ${script}; }).call(this);\n`; - return os.eval_env(file,env,script); + return os.eval_env(file,script,env); } global.check_registers = function(obj) @@ -147,8 +147,7 @@ global.mixin("scripts/render.js"); global.mixin("scripts/debug.js"); var frame_t = profile.secs(profile.now()); -var updateMS = 1/60; -var physMS = 1/60; +var phys_step = 1/60; var sim = { mode: "play", @@ -185,10 +184,10 @@ function process() physlag += dt; - while (physlag > physMS) { - physlag -= physMS; - prosperon.phys2d_step(physMS*timescale); - prosperon.physupdate(physMS*timescale); + while (physlag > phys_step) { + physlag -= phys_step; + prosperon.phys2d_step(phys_step*timescale); + prosperon.physupdate(phys_step*timescale); } prosperon.window_render(); diff --git a/source/engine/2dphysics.c b/source/engine/2dphysics.c index a993de3..9e5b179 100644 --- a/source/engine/2dphysics.c +++ b/source/engine/2dphysics.c @@ -287,9 +287,8 @@ float phys2d_circle_moi(struct phys2d_circle *c) { return cpMomentForCircle(m, 0, cpCircleShapeGetRadius(c->shape.shape), cpCircleShapeGetOffset(c->shape.shape)); } -void phys2d_circledel(struct phys2d_circle *c) { - phys2d_shape_del(&c->shape); -} +void phys2d_circledel(struct phys2d_circle *c) { phys2d_shape_del(&c->shape); } +void circle2d_free(circle2d *c) { phys2d_circledel(c); } void phys2d_dbgdrawcpcirc(cpShape *c) { HMM_Vec2 pos = mat_t_pos(t_go2world(shape2go(c)), (HMM_Vec2)cpCircleShapeGetOffset(c)); diff --git a/source/engine/2dphysics.h b/source/engine/2dphysics.h index c42a1e6..dc6567f 100644 --- a/source/engine/2dphysics.h +++ b/source/engine/2dphysics.h @@ -47,6 +47,8 @@ struct phys2d_circle { struct phys2d_shape shape; }; +typedef struct phys2d_circle circle2d; + /* A convex polygon; defined as the convex hull around the given set of points */ struct phys2d_poly { HMM_Vec2 *points; @@ -66,6 +68,7 @@ struct phys2d_edge { struct phys2d_circle *Make2DCircle(gameobject *go); void phys2d_circledel(struct phys2d_circle *c); +void circle2d_free(circle2d *c); void phys2d_applycircle(struct phys2d_circle *circle); void phys2d_dbgdrawcircle(struct phys2d_circle *circle); float phys2d_circle_moi(struct phys2d_circle *c); diff --git a/source/engine/jsffi.c b/source/engine/jsffi.c index cb48116..7db5b4e 100644 --- a/source/engine/jsffi.c +++ b/source/engine/jsffi.c @@ -1,7 +1,6 @@ #include "jsffi.h" #include "script.h" - #include "debugdraw.h" #include "font.h" #include "gameobject.h" @@ -46,7 +45,11 @@ static JSValue globalThis; static JSClassID js_ptr_id; static JSClassDef js_ptr_class = { "POINTER" }; -JSValue str2js(const char *c) { return JS_NewString(js, c); } +JSValue str2js(const char *c) { + if (!c) return JS_UNDEFINED; + return JS_NewString(js, c); +} + const char *js2str(JSValue v) { return JS_ToCString(js, v); } @@ -55,21 +58,72 @@ const char *js2str(JSValue v) { #define MIST_FUNC_DEF(TYPE, FN, LEN) MIST_CFUNC_DEF(#FN, LEN, js_##TYPE##_##FN) -#define MIST_FN_STR(NAME) MIST_CFUNC_DEF(#NAME, 1, js_##NAME) +#define GETFN(ID, ENTRY, TYPE) JSC_CCALL(ID##_##ENTRY, return TYPE##2js(js2##ID (this)->ENTRY)) + +#define JSC_SCALL(NAME, FN) JSC_CCALL(NAME, \ + const char *str = js2str(argv[0]); \ + FN ; \ + JS_FreeCString(js,str); \ +) \ + +#define JSC_SSCALL(NAME, FN) JSC_CCALL(NAME, \ + const char *str = js2str(argv[0]); \ + const char *str2 = js2str(argv[1]); \ + FN ; \ + JS_FreeCString(js,str2); \ + JS_FreeCString(js,str); \ +) \ #define MIST_CGETSET_DEF(name, fgetter, fsetter) { name, JS_PROP_CONFIGURABLE | JS_PROP_ENUMERABLE, JS_DEF_CGETSET, 0, .u = { .getset = { .get = { .getter = fgetter }, .set = { .setter = fsetter } } } } -#define CGETSET_ADD(ID, ENTRY) MIST_CGETSET_DEF(#ENTRY, ID##_get_##ENTRY, ID##_set_##ENTRY) - -#define GGETSET_ADD(ENTRY) +#define CGETSET_ADD(ID, ENTRY) MIST_CGETSET_DEF(#ENTRY, js_##ID##_get_##ENTRY, js_##ID##_set_##ENTRY) #define JSC_CCALL(NAME, FN) JSValue js_##NAME (JSContext *js, JSValue this, int argc, JSValue *argv) { \ + JSValue ret = JS_UNDEFINED; \ + {FN;} \ + return ret; \ +} \ + +#define GETSETPAIR(ID, ENTRY, TYPE, FN) \ +JSValue js_##ID##_set_##ENTRY (JSContext *js, JSValue this, JSValue val) { \ + js2##ID (this)->ENTRY = js2##TYPE (val); \ {FN;} \ return JS_UNDEFINED; \ } \ +\ +JSValue js_##ID##_get_##ENTRY (JSContext *js, JSValue this) { \ + return TYPE##2js(js2##ID (this)->ENTRY); \ +} \ -#define JSC_RET(NAME, FN) JSValue js_##NAME (JSContext *js, JSValue this, int argc, JSValue *argv) { \ - FN; } \ +/* support functions for these macros when they involve a JSValue */ +JSValue js2JSValue(JSValue v) { return v; } +JSValue JSValue2js(JSValue v) { return v; } + +#define JSC_GETSET(ID, ENTRY, TYPE) GETSETPAIR( ID , ENTRY , TYPE , ; ) +#define JSC_GETSET_APPLY(ID, ENTRY, TYPE) GETSETPAIR(ID, ENTRY, TYPE, ID##_apply(js2##ID (this));) +#define JSC_GETSET_HOOK(ID, ENTRY) GETSETPAIR(ID, ENTRY, JSValue, ;) + +#define JSC_GETSET_GLOBAL(ENTRY, TYPE) \ +JSValue js_global_set_##ENTRY (JSContext *js, JSValue this, JSValue val) { \ + ENTRY = js2##TYPE (val); \ + return JS_UNDEFINED; \ +} \ +\ +JSValue js_global_get_##ENTRY (JSContext *js, JSValue this) { \ + return TYPE##2js(ENTRY); \ +} \ + +#define JSC_GETSET_BODY(ENTRY, CPENTRY, TYPE) \ +JSValue js_gameobject_set_##ENTRY (JSContext *js, JSValue this, JSValue val) { \ + cpBody *b = js2gameobject(this)->body; \ + cpBodySet##CPENTRY (b, js2##TYPE (val)); \ + return JS_UNDEFINED; \ +} \ +\ +JSValue js_gameobject_get_##ENTRY (JSContext *js, JSValue this) { \ + cpBody *b = js2gameobject(this)->body; \ + return TYPE##2js (cpBodyGet##CPENTRY (b)); \ +} \ #define QJSCLASS(TYPE)\ static JSClassID js_ ## TYPE ## _id;\ @@ -88,6 +142,22 @@ static JSValue TYPE##2js(TYPE *n) { \ JS_SetOpaque(j,n);\ return j; }\ +#define QJSGLOBALCLASS(NAME) \ +JSValue NAME = JS_NewObject(js); \ +JS_SetPropertyFunctionList(js, NAME, js_##NAME##_funcs, countof(js_##NAME##_funcs)); \ +JS_SetPropertyStr(js, globalThis, #NAME, NAME); \ + +#define QJSCLASSPREP(TYPE) \ +JS_NewClassID(&js_##TYPE##_id);\ +JS_NewClass(JS_GetRuntime(js), js_##TYPE##_id, &js_##TYPE##_class);\ + +/* Defines a class and uses its function list as its prototype */ +#define QJSCLASSPREP_FUNCS(TYPE) \ +QJSCLASSPREP(TYPE); \ +JSValue TYPE##_proto = JS_NewObject(js); \ +JS_SetPropertyFunctionList(js, TYPE##_proto, js_##TYPE##_funcs, countof(js_##TYPE##_funcs)); \ +JS_SetClassProto(js, js_##TYPE##_id, TYPE##_proto); \ + QJSCLASS(gameobject) QJSCLASS(emitter) QJSCLASS(dsp_node) @@ -122,22 +192,6 @@ static JSValue constraint2js(constraint *c) static JSValue sound_proto; sound *js2sound(JSValue v) { return js2dsp_node(v)->data; } -#define QJSGLOBALCLASS(NAME) \ -JSValue NAME = JS_NewObject(js); \ -JS_SetPropertyFunctionList(js, NAME, js_##NAME##_funcs, countof(js_##NAME##_funcs)); \ -JS_SetPropertyStr(js, globalThis, #NAME, NAME); \ - -#define QJSCLASSPREP(TYPE) \ -JS_NewClassID(&js_##TYPE##_id);\ -JS_NewClass(JS_GetRuntime(js), js_##TYPE##_id, &js_##TYPE##_class);\ - -/* Defines a class and uses its function list as its prototype */ -#define QJSCLASSPREP_FUNCS(TYPE) \ -QJSCLASSPREP(TYPE); \ -JSValue TYPE##_proto = JS_NewObject(js); \ -JS_SetPropertyFunctionList(js, TYPE##_proto, js_##TYPE##_funcs, countof(js_##TYPE##_funcs)); \ -JS_SetClassProto(js, js_##TYPE##_id, TYPE##_proto); \ - #define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c" #define BYTE_TO_BINARY(byte) \ (byte & 0x80 ? '1' : '0'), \ @@ -149,8 +203,8 @@ JS_SetClassProto(js, js_##TYPE##_id, TYPE##_proto); \ (byte & 0x02 ? '1' : '0'), \ (byte & 0x01 ? '1' : '0') -int js2bool(JSValue v) { return JS_ToBool(js, v); } -JSValue bool2js(int b) { return JS_NewBool(js,b); } +int js2boolean(JSValue v) { return JS_ToBool(js, v); } +JSValue boolean2js(int b) { return JS_NewBool(js,b); } void js_setprop_num(JSValue obj, uint32_t i, JSValue v) { JS_SetPropertyUint32(js, obj, i, v); } @@ -179,7 +233,6 @@ JSValue js_getpropstr(JSValue v, const char *str) static inline cpBody *js2body(JSValue v) { return js2gameobject(v)->body; } - JSValue strarr2js(char **c) { JSValue arr = JS_NewArray(js); @@ -254,7 +307,7 @@ char *js_do_nota_decode(JSValue *tmp, char *nota) nota = nota_read_sym(&b, nota); if (b == NOTA_NULL) *tmp = JS_UNDEFINED; else - *tmp = bool2js(b); + *tmp = boolean2js(b); break; default: case NOTA_FLOAT: @@ -401,7 +454,7 @@ cpBitmask js2bitmask(JSValue v) { int len = js_arrlen(v); for (int i = 0; i < len; i++) { - int val = JS_ToBool(js, js_getpropidx( v, i)); + int val = js2boolean(js_getpropidx( v, i)); if (!val) continue; mask |= 1 << i; @@ -434,7 +487,7 @@ HMM_Vec2 *jsfloat2vec(JSValue v) JSValue bitmask2js(cpBitmask mask) { JSValue arr = JS_NewArray(js); for (int i = 0; i < 11; i++) - js_setprop_num(arr,i,JS_NewBool(js,mask & 1 << i)); + js_setprop_num(arr,i,boolean2js(mask & 1 << i)); return arr; } @@ -585,7 +638,7 @@ void gameobject_add_shape_collider(gameobject *go, JSValue fn, struct phys2d_sha arrpush(go->shape_cbs, shapecb); } -struct phys2d_circle *js2circle2d(JSValue v) { return js2ptr(v); } +circle2d *js2circle2d(JSValue v) { return js2ptr(v); } JSC_CCALL(circle2d_set_radius, js2circle2d(argv[0])->radius = js2number(argv[1])) JSC_CCALL(circle2d_get_radius, return number2js(js2circle2d(argv[0])->radius)) @@ -614,53 +667,11 @@ static const JSCFunctionListEntry js_poly2d_funcs[] = { MIST_FUNC_DEF(poly2d, setverts, 2), }; -#define GETSET_PAIR(ID, ENTRY, TYPE) \ -JSValue ID##_set_##ENTRY (JSContext *js, JSValue this, JSValue val) { \ - js2##ID (this)->ENTRY = js2##TYPE (val); \ - return JS_UNDEFINED; \ -} \ -\ -JSValue ID##_get_##ENTRY (JSContext *js, JSValue this) { \ - return TYPE##2js(js2##ID (this)->ENTRY); \ -} \ - -#define GETSET_PAIR_APPLY(ID, ENTRY, TYPE) \ -JSValue ID##_set_##ENTRY (JSContext *js, JSValue this, JSValue val) { \ - ID *id = js2##ID (this); \ - id->ENTRY = js2##TYPE (val); \ - ID##_apply(id); \ - return JS_UNDEFINED; \ -} \ -\ -JSValue ID##_get_##ENTRY (JSContext *js, JSValue this) { \ - return TYPE##2js(js2##ID (this)->ENTRY); \ -} \ - -#define GETSET_PAIR_HOOK(ID, ENTRY) \ -JSValue ID##_set_##ENTRY (JSContext *js, JSValue this, JSValue val) { \ - ID *n = js2##ID (this); \ - n->ENTRY = val; \ - return JS_UNDEFINED; \ -} \ -\ -JSValue ID##_get_##ENTRY (JSContext *js, JSValue this) { \ - ID *n = js2##ID (this); \ - return n->ENTRY; \ -} \ - - -#define DEF_FN_STR(NAME) JSValue js_##NAME (JSContext *js, JSValue this, int argc, JSValue *argv) { \ - char *str = js2str(argv[0]); \ - NAME (str); \ - JS_FreeCString(js,str); \ - return JS_UNDEFINED; \ -} \ - -GETSET_PAIR(warp_gravity, strength, number) -GETSET_PAIR(warp_gravity, decay, number) -GETSET_PAIR(warp_gravity, spherical, bool) -GETSET_PAIR(warp_gravity, mask, bitmask) -GETSET_PAIR(warp_gravity, planar_force, vec3) +JSC_GETSET(warp_gravity, strength, number) +JSC_GETSET(warp_gravity, decay, number) +JSC_GETSET(warp_gravity, spherical, boolean) +JSC_GETSET(warp_gravity, mask, bitmask) +JSC_GETSET(warp_gravity, planar_force, vec3) static const JSCFunctionListEntry js_warp_gravity_funcs [] = { CGETSET_ADD(warp_gravity, strength), @@ -670,64 +681,43 @@ static const JSCFunctionListEntry js_warp_gravity_funcs [] = { CGETSET_ADD(warp_gravity, planar_force), }; -GETSET_PAIR(warp_damp, damp, vec3) +JSC_GETSET(warp_damp, damp, vec3) static const JSCFunctionListEntry js_warp_damp_funcs [] = { CGETSET_ADD(warp_damp, damp) }; JSC_CCALL(drawmodel_draw, draw_drawmodel(js2drawmodel(this))) -JSC_CCALL(drawmodel_path, - char *s = js2str(argv[0]); - js2drawmodel(this)->model = GetExistingModel(s); - JS_FreeCString(js,s); -) +JSC_SCALL(drawmodel_path, js2drawmodel(this)->model = GetExistingModel(str)) static const JSCFunctionListEntry js_drawmodel_funcs[] = { MIST_FUNC_DEF(drawmodel, draw, 0), MIST_FUNC_DEF(drawmodel, path, 1) }; -GETSET_PAIR(emitter, life, number) -GETSET_PAIR(emitter, life_var, number) -GETSET_PAIR(emitter, speed, number) -GETSET_PAIR(emitter, variation, number) -GETSET_PAIR(emitter, divergence, number) -GETSET_PAIR(emitter, scale, number) -GETSET_PAIR(emitter, scale_var, number) -GETSET_PAIR(emitter, grow_for, number) -GETSET_PAIR(emitter, shrink_for, number) -GETSET_PAIR(emitter, max, number) -GETSET_PAIR(emitter, explosiveness, number) -GETSET_PAIR(emitter, go, gameobject) -GETSET_PAIR(emitter, bounce, number) -GETSET_PAIR(emitter, collision_mask, bitmask) -GETSET_PAIR(emitter, die_after_collision, bool) -GETSET_PAIR(emitter, persist, number) -GETSET_PAIR(emitter, persist_var, number) -GETSET_PAIR(emitter, warp_mask, bitmask) -GETSET_PAIR(emitter, texture, texture) +JSC_GETSET(emitter, life, number) +JSC_GETSET(emitter, life_var, number) +JSC_GETSET(emitter, speed, number) +JSC_GETSET(emitter, variation, number) +JSC_GETSET(emitter, divergence, number) +JSC_GETSET(emitter, scale, number) +JSC_GETSET(emitter, scale_var, number) +JSC_GETSET(emitter, grow_for, number) +JSC_GETSET(emitter, shrink_for, number) +JSC_GETSET(emitter, max, number) +JSC_GETSET(emitter, explosiveness, number) +JSC_GETSET(emitter, go, gameobject) +JSC_GETSET(emitter, bounce, number) +JSC_GETSET(emitter, collision_mask, bitmask) +JSC_GETSET(emitter, die_after_collision, boolean) +JSC_GETSET(emitter, persist, number) +JSC_GETSET(emitter, persist_var, number) +JSC_GETSET(emitter, warp_mask, bitmask) +JSC_GETSET(emitter, texture, texture) -JSValue js_emitter_start (JSContext *js, JSValue this, int argc, JSValue *argv) -{ - emitter *n = js2emitter(this); - start_emitter(n); - return JS_UNDEFINED; -} - -JSValue js_emitter_stop(JSContext *js, JSValue this, int argc, JSValue *argv) -{ - emitter *n = js2emitter(this); - stop_emitter(n); - return JS_UNDEFINED; -} - -JSValue js_emitter_emit(JSContext *js, JSValue this, int argc, JSValue *argv) -{ - emitter *n = js2emitter(this); - emitter_emit(n, js2number(argv[0])); - return JS_UNDEFINED; -} +JSC_CCALL(emitter_start, start_emitter(js2emitter(this))) +JSC_CCALL(emitter_stop, stop_emitter(js2emitter(this))) +JSC_CCALL(emitter_emit, emitter_emit(js2emitter(this), js2number(argv[0]))) JSValue js_os_cwd(JSContext *js, JSValue this, int argc, JSValue *argv) { @@ -741,14 +731,7 @@ JSValue js_os_cwd(JSContext *js, JSValue this, int argc, JSValue *argv) return str2js(cwd); } -JSValue js_os_env(JSContext *js, JSValue this, int argc, JSValue *argv) -{ - char *str = js2str(argv[0]); - JSValue ret = JS_UNDEFINED; - if (getenv(str)) ret = str2js(getenv(str)); - JS_FreeCString(js,str); - return ret; -} +JSC_SCALL(os_env, ret = str2js(getenv(str))) JSValue js_os_sys(JSContext *js, JSValue this, int argc, JSValue *argv) { @@ -765,26 +748,12 @@ JSValue js_os_sys(JSContext *js, JSValue this, int argc, JSValue *argv) JSC_CCALL(os_quit, quit();) JSC_CCALL(os_reindex_static, cpSpaceReindexStatic(space)); JSC_CCALL(os_gc, script_gc()); -JSC_CCALL(os_eval_env, - char *s1 = js2str(argv[0]); - char *s2 = js2str(argv[2]); - JSValue ret = eval_script_env(s1, argv[1], s2); - JS_FreeCString(js,s1); - JS_FreeCString(js,s2); - return ret; -) +JSC_SSCALL(os_eval_env, ret = eval_script_env(str, argv[2], str2)) -#define RETUN return JS_UNDEFINED - -JSValue js_os_capture(JSContext *js, JSValue this, int argc, JSValue *argv) { - char *str = js2str(argv[0]); - capture_screen(js2number(argv[1]), js2number(argv[2]), js2number(argv[4]), js2number(argv[5]), str); - JS_FreeCString(js,str); - RETUN; -} +JSC_SCALL(os_capture, capture_screen(js2number(argv[1]), js2number(argv[2]), js2number(argv[4]), js2number(argv[5]), str)) JSC_CCALL(os_sprite, - if (js2bool(argv[0])) return JS_GetClassProto(js,js_sprite_id); + if (js2boolean(argv[0])) return JS_GetClassProto(js,js_sprite_id); return sprite2js(sprite_make()); ) @@ -872,26 +841,9 @@ JSC_CCALL(render_flush_hud, debug_flush(&hudproj); debug_flush(&hudproj); sprite JSC_CCALL(render_pass, debug_nextpass()) JSC_CCALL(render_end_pass, sg_end_pass()) JSC_CCALL(render_commit, sg_commit(); debug_newframe();) -JSC_CCALL(render_text_size, - char *s = js2str(argv[0]); - JSValue ret = bb2js(text_bb(s, js2number(argv[1]), js2number(argv[2]), 1)); - JS_FreeCString(js,s); - return ret; -) -JSC_CCALL(render_gif_times, - char *s = js2str(argv[0]); - JSValue ret = ints2js(gif_delays(s)); - JS_FreeCString(js,s); - return ret; -) - -JSC_CCALL(render_gif_frames, - char *s = js2str(argv[0]); - JSValue ret = number2js(gif_nframes(s)); - JS_FreeCString(js,s); - return ret; -) - +JSC_SCALL(render_text_size, ret = bb2js(text_bb(str, js2number(argv[1]), js2number(argv[2]), 1))) +JSC_SCALL(render_gif_times, ret = ints2js(gif_delays(str))) +JSC_SCALL(render_gif_frames, ret = number2js(gif_nframes(str))) JSC_CCALL(render_cam_body, set_cam_body(js2gameobject(argv[0])->body)) JSC_CCALL(render_add_zoom, add_zoom(js2number(argv[0]))) JSC_CCALL(render_get_zoom, return number2js(cam_zoom())) @@ -945,19 +897,18 @@ JSC_CCALL(gui_img, t.pos = js2vec2(argv[1]); t.scale = js2vec2(argv[2]); t.angle = js2number(argv[3]); - gui_draw_img(img, t, js2bool(argv[4]), js2vec2(argv[5]), 1.0, js2color(argv[6])); + gui_draw_img(img, t, js2boolean(argv[4]), js2vec2(argv[5]), 1.0, js2color(argv[6])); JS_FreeCString(js, img); ) - -DEF_FN_STR(font_set) +JSC_SCALL(gui_font_set, font_set(str)) static const JSCFunctionListEntry js_gui_funcs[] = { MIST_FUNC_DEF(gui, flush, 0), MIST_FUNC_DEF(gui, scissor, 4), MIST_FUNC_DEF(gui, text, 6), MIST_FUNC_DEF(gui, img, 7), - MIST_FN_STR(font_set), + MIST_FUNC_DEF(gui, font_set,1) }; JSC_CCALL(spline_catmull, @@ -989,17 +940,25 @@ static const JSCFunctionListEntry js_spline_funcs[] = { JSValue js_vector_dot(JSContext *js, JSValue this, int argc, JSValue *argv) { return number2js(HMM_DotV2(js2vec2(argv[0]), js2vec2(argv[1]))) ; }; -JSC_RET(vector_project, return vec22js(HMM_ProjV2(js2vec2(argv[0]), js2vec2(argv[1])));) +JSC_CCALL(vector_project, return vec22js(HMM_ProjV2(js2vec2(argv[0]), js2vec2(argv[1])))) + +JSC_CCALL(vector_inflate, + HMM_Vec2 *p = js2cpvec2arr(argv[0]); + double d = js2number(argv[1]); + HMM_Vec2 *infl = inflatepoints(p,d, js_arrlen(argv[0])); + ret = vecarr2js(infl, arrlen(infl)); + arrfree(infl); + arrfree(p); +) static const JSCFunctionListEntry js_vector_funcs[] = { MIST_FUNC_DEF(vector,dot,2), MIST_FUNC_DEF(vector,project,2), + MIST_FUNC_DEF(vector, inflate, 2) }; -JSValue js_game_engine_start(JSContext *js, JSValue this, int argc, JSValue *argv) { - engine_start(argv[0],argv[1]); - RETUN; -} +JSC_CCALL(game_engine_start, engine_start(argv[0],argv[1])) + JSValue js_game_object_count(JSContext *js, JSValue this) { return number2js(go_count()); } static const JSCFunctionListEntry js_game_funcs[] = { @@ -1007,31 +966,20 @@ static const JSCFunctionListEntry js_game_funcs[] = { MIST_FUNC_DEF(game, object_count, 0) }; -JSC_CCALL(input_show_keyboard, sapp_show_keyboard(js2bool(argv[0]))) -JSValue js_input_keyboard_shown(JSContext *js, JSValue this) { return bool2js(sapp_keyboard_shown()); } +JSC_CCALL(input_show_keyboard, sapp_show_keyboard(js2boolean(argv[0]))) +JSValue js_input_keyboard_shown(JSContext *js, JSValue this) { return boolean2js(sapp_keyboard_shown()); } JSC_CCALL(input_mouse_mode, set_mouse_mode(js2number(argv[0]))) JSC_CCALL(input_mouse_cursor, sapp_set_mouse_cursor(js2number(argv[0]))) - -DEF_FN_STR(cursor_img) +JSC_SCALL(input_cursor_img, cursor_img(str)) static const JSCFunctionListEntry js_input_funcs[] = { MIST_FUNC_DEF(input, show_keyboard, 1), MIST_FUNC_DEF(input, keyboard_shown, 0), MIST_FUNC_DEF(input, mouse_mode, 1), MIST_FUNC_DEF(input, mouse_cursor, 1), - MIST_FN_STR(cursor_img) + MIST_FUNC_DEF(input, cursor_img, 1) }; -#define GETSET_GLOBAL(ENTRY, TYPE) \ -JSValue global_set_##ENTRY (JSContext *js, JSValue this, JSValue val) { \ - ENTRY = js2##TYPE (val); \ - return JS_UNDEFINED; \ -} \ -\ -JSValue global_get_##ENTRY (JSContext *js, JSValue this) { \ - return TYPE##2js(ENTRY); \ -} \ - JSC_CCALL(prosperon_emitters_step, emitters_step(js2number(argv[0]))) JSC_CCALL(prosperon_phys2d_step, phys2d_update(js2number(argv[0]))) JSC_CCALL(prosperon_window_render, openglRender(&mainwin)) @@ -1042,15 +990,15 @@ static const JSCFunctionListEntry js_prosperon_funcs[] = { MIST_FUNC_DEF(prosperon, window_render, 0) }; -JSValue js_time_now(JSContext *js, JSValue this) { +JSC_CCALL(time_now, struct timeval ct; gettimeofday(&ct, NULL); return number2js((double)ct.tv_sec+(double)(ct.tv_usec/1000000.0)); -} +) JSValue js_time_computer_dst(JSContext *js, JSValue this) { time_t t = time(NULL); - return bool2js(localtime(&t)->tm_isdst); + return boolean2js(localtime(&t)->tm_isdst); } JSValue js_time_computer_zone(JSContext *js, JSValue this) { @@ -1066,13 +1014,7 @@ static const JSCFunctionListEntry js_time_funcs[] = { MIST_FUNC_DEF(time, computer_zone, 0) }; -JSValue js_console_print(JSContext *js, JSValue this, int argc, JSValue *argv) -{ - char *s = JS_ToCString(js,argv[0]); - log_print(s); - JS_FreeCString(js,s); - return JS_UNDEFINED; -} +JSC_SCALL(console_print, log_print(str)) JSValue js_console_rec(JSContext *js, JSValue this, int argc, JSValue *argv) { @@ -1089,7 +1031,7 @@ JSValue js_console_rec(JSContext *js, JSValue this, int argc, JSValue *argv) return JS_UNDEFINED; } -GETSET_GLOBAL(stdout_lvl, number) +JSC_GETSET_GLOBAL(stdout_lvl, number) static const JSCFunctionListEntry js_console_funcs[] = { MIST_FUNC_DEF(console,print,1), @@ -1097,70 +1039,19 @@ static const JSCFunctionListEntry js_console_funcs[] = { CGETSET_ADD(global, stdout_lvl) }; -JSValue js_profile_now(JSContext *js, JSValue this) { return number2js(stm_now()); } +JSC_CCALL(profile_now, return number2js(stm_now())) static const JSCFunctionListEntry js_profile_funcs[] = { MIST_FUNC_DEF(profile,now,0), }; -JSValue js_io_exists(JSContext *js, JSValue this, int argc, JSValue *argv) -{ - char *file = JS_ToCString(js, argv[0]); - JSValue ret = JS_NewBool(js, fexists(file)); - JS_FreeCString(js,file); - return ret; -} - -JSValue js_io_ls(JSContext *js, JSValue this, int argc, JSValue *argv) -{ - return strarr2js(ls(".")); -} - -JSValue js_io_cp(JSContext *js, JSValue this, int argc, JSValue *argv) -{ - char *f1, *f2; - f1 = JS_ToCString(js, argv[0]); - f2 = JS_ToCString(js, argv[1]); - JSValue ret = number2js(cp(f1,f2)); - JS_FreeCString(js,f1); - JS_FreeCString(js,f2); - return ret; -} - -JSValue js_io_mv(JSContext *js, JSValue this, int argc, JSValue *argv) -{ - char *f1, *f2; - f1 = JS_ToCString(js, argv[0]); - f2 = JS_ToCString(js, argv[1]); - JSValue ret = number2js(rename(f1,f2)); - JS_FreeCString(js,f1); - JS_FreeCString(js,f2); - return ret; -} - -JSValue js_io_chdir(JSContext *js, JSValue this, int argc, JSValue *argv) -{ - char *path = JS_ToCString(js, argv[0]); - JSValue ret = number2js(chdir(path)); - JS_FreeCString(js,path); - return ret; -} - -JSValue js_io_rm(JSContext *js, JSValue this, int argc, JSValue *argv) -{ - char *file = JS_ToCString(js, argv[0]); - JSValue ret = number2js(remove(file)); - JS_FreeCString(js,file); - return JS_UNDEFINED; -} - -JSValue js_io_mkdir(JSContext *js, JSValue this, int argc, JSValue *argv) -{ - char *f = js2str(argv[0]); - JSValue ret = number2js(mkdir(f,0777)); - JS_FreeCString(js,f); - return ret; -} +JSC_SCALL(io_exists, ret = boolean2js(fexists(str))) +JSC_CCALL(io_ls, return strarr2js(ls("."))) +JSC_SSCALL(io_cp, ret = number2js(cp(str,str2))) +JSC_SSCALL(io_mv, ret = number2js(rename(str,str2))) +JSC_SCALL(io_chdir, ret = number2js(chdir(str))) +JSC_SCALL(io_rm, ret = number2js(remove(str))) +JSC_SCALL(io_mkdir, ret = number2js(mkdir(str,0777))) JSValue js_io_slurpbytes(JSContext *js, JSValue this, int argc, JSValue *argv) { @@ -1192,7 +1083,7 @@ JSValue js_io_slurpwrite(JSContext *js, JSValue this, int argc, JSValue *argv) { char *f = js2str(argv[0]); size_t len; - char *data; + const char *data; JSValue ret; if (JS_IsString(argv[1])) { data = JS_ToCStringLen(js, &len, argv[1]); @@ -1214,7 +1105,7 @@ JSValue js_io_chmod(JSContext *js, JSValue this, int argc, JSValue *argv) return JS_UNDEFINED; } -DEF_FN_STR(save_qoa) +JSC_SCALL(io_save_qoa, save_qoa(str)) JSValue js_io_compile(JSContext *js, JSValue this, int argc, JSValue *argv) { size_t len; @@ -1236,7 +1127,7 @@ JSValue js_io_run_bytecode(JSContext *js, JSValue this, int argc, JSValue *argv) return ret; } -DEF_FN_STR(pack_engine) +JSC_SCALL(io_pack_engine, pack_engine(str)) static const JSCFunctionListEntry js_io_funcs[] = { MIST_FUNC_DEF(io, exists,1), @@ -1250,24 +1141,23 @@ static const JSCFunctionListEntry js_io_funcs[] = { MIST_FUNC_DEF(io, slurp, 1), MIST_FUNC_DEF(io, slurpbytes, 1), MIST_FUNC_DEF(io, slurpwrite, 2), - MIST_FN_STR(save_qoa), - MIST_FN_STR(pack_engine) + MIST_FUNC_DEF(io, save_qoa,1), + MIST_FUNC_DEF(io, pack_engine, 1) }; -JSValue js_debug_draw_gameobject(JSContext *js, JSValue this, int argc, JSValue *argv) { gameobject_draw_debug(js2gameobject(argv[0])); RETUN; } +JSC_CCALL(debug_draw_gameobject, gameobject_draw_debug(js2gameobject(argv[0]));) static const JSCFunctionListEntry js_debug_funcs[] = { MIST_FUNC_DEF(debug, draw_gameobject, 1) }; -JSValue js_physics_sgscale(JSContext *js, JSValue this, int argc, JSValue *argv) { +JSC_CCALL(physics_sgscale, js2gameobject(argv[0])->scale.xy = js2vec2(argv[1]); gameobject_apply(js2gameobject(argv[0])); cpSpaceReindexShapesForBody(space, js2gameobject(argv[0])->body); - RETUN; -} +) -JSValue js_physics_set_cat_mask(JSContext *js, JSValue this, int argc, JSValue *argv) { set_cat_mask(js2number(argv[0]), js2bitmask(argv[1])); RETUN; } +JSC_CCALL(physics_set_cat_mask, set_cat_mask(js2number(argv[0]), js2bitmask(argv[1]))) JSC_CCALL(physics_box_query, int *ids = phys2d_query_box(js2vec2(argv[0]), js2vec2(argv[1])); @@ -1353,23 +1243,13 @@ static const JSCFunctionListEntry js_emitter_funcs[] = { CGETSET_ADD(emitter, texture), }; -GETSET_PAIR(dsp_node, pass, bool) -GETSET_PAIR(dsp_node, off, bool) -GETSET_PAIR(dsp_node, gain, number) -GETSET_PAIR(dsp_node, pan, number) +JSC_GETSET(dsp_node, pass, boolean) +JSC_GETSET(dsp_node, off, boolean) +JSC_GETSET(dsp_node, gain, number) +JSC_GETSET(dsp_node, pan, number) -JSValue js_dsp_node_plugin(JSContext *js, JSValue this, int argc, JSValue *argv) -{ - plugin_node(js2dsp_node(this), js2dsp_node(argv[0])); - return JS_DupValue(js,this); -} - -JSValue js_dsp_node_unplug(JSContext *js, JSValue this, int argc, JSValue *argv) -{ - JS_FreeValue(js,this); - unplug_node(js2dsp_node(this)); - return JS_UNDEFINED; -} +JSC_CCALL(dsp_node_plugin, plugin_node(js2dsp_node(this), js2dsp_node(argv[0]))) +JSC_CCALL(dsp_node_unplug, unplug_node(js2dsp_node(this))) static const JSCFunctionListEntry js_dsp_node_funcs[] = { CGETSET_ADD(dsp_node, pass), @@ -1380,10 +1260,10 @@ static const JSCFunctionListEntry js_dsp_node_funcs[] = { MIST_FUNC_DEF(dsp_node, unplug, 0), }; -GETSET_PAIR(sound, loop, bool) -GETSET_PAIR(sound, timescale, number) -GETSET_PAIR(sound, frame, number) -GETSET_PAIR_HOOK(sound, hook) +JSC_GETSET(sound, loop, boolean) +JSC_GETSET(sound, timescale, number) +JSC_GETSET(sound, frame, number) +JSC_GETSET_HOOK(sound, hook) JSC_CCALL(sound_frames, return number2js(js2sound(this)->data->frames)) static const JSCFunctionListEntry js_sound_funcs[] = { @@ -1394,8 +1274,8 @@ static const JSCFunctionListEntry js_sound_funcs[] = { MIST_FUNC_DEF(sound, frames, 0), }; -static JSValue window_get_size(JSContext *js, JSValue this) { return vec22js(js2window(this)->size); } -static JSValue window_set_size(JSContext *js, JSValue this, JSValue v) { +static JSValue js_window_get_size(JSContext *js, JSValue this) { return vec22js(js2window(this)->size); } +static JSValue js_window_set_size(JSContext *js, JSValue this, JSValue v) { window *w = js2window(this); if (!w->start) w->size = js2vec2(v); @@ -1403,21 +1283,12 @@ static JSValue window_set_size(JSContext *js, JSValue this, JSValue v) { return JS_UNDEFINED; } -GETSET_PAIR_APPLY(window, rendersize, vec2) -GETSET_PAIR(window, mode, number) +JSC_GETSET_APPLY(window, rendersize, vec2) +JSC_GETSET(window, mode, number) +static JSValue js_window_get_fullscreen(JSContext *js, JSValue this) { return boolean2js(js2window(this)->fullscreen); } +static JSValue js_window_set_fullscreen(JSContext *js, JSValue this, JSValue v) { window_setfullscreen(js2window(this), js2boolean(v)); } -static JSValue window_get_fullscreen(JSContext *js, JSValue this) -{ - return number2js(js2window(this)->fullscreen); -} - -static JSValue window_set_fullscreen(JSContext *js, JSValue this, JSValue v) -{ - window_setfullscreen(js2window(this), js2bool(v)); - return JS_UNDEFINED; -} - -static JSValue window_set_title(JSContext *js, JSValue this, JSValue v) +static JSValue js_window_set_title(JSContext *js, JSValue this, JSValue v) { window *w = js2window(this); if (w->title) JS_FreeCString(js, w->title); @@ -1426,21 +1297,9 @@ static JSValue window_set_title(JSContext *js, JSValue this, JSValue v) sapp_set_window_title(w->title); return JS_UNDEFINED; } - -static JSValue window_get_title(JSContext *js, JSValue this, JSValue v) -{ - if (!js2window(this)->title) return JS_UNDEFINED; - return str2js(js2window(this)->title); -} - -DEF_FN_STR(set_icon) - -JSValue js_window_icon(JSContext *js, JSValue this, int argc, JSValue *argv) { - char *str = js2str(argv[0]); - set_icon(str); - JS_FreeCString(js,str); - RETUN; -} +JSC_CCALL(window_get_title, return str2js(js2window(this)->title)) +JSC_SCALL(window_set_icon, set_icon(str)) +JSC_SCALL(window_icon, set_icon(str)) static const JSCFunctionListEntry js_window_funcs[] = { CGETSET_ADD(window, size), @@ -1448,59 +1307,36 @@ static const JSCFunctionListEntry js_window_funcs[] = { CGETSET_ADD(window, mode), CGETSET_ADD(window, fullscreen), CGETSET_ADD(window, title), - MIST_FN_STR(set_icon), + MIST_FUNC_DEF(window, set_icon, 1) }; -#define GETSET_PAIR_BODY(ID, ENTRY, TYPE) \ -JSValue ID##_set_##ENTRY (JSContext *js, JSValue this, JSValue val) { \ - js2##ID (this)->ENTRY = js2##TYPE (val); \ - ID##_apply(js2##ID (this)); \ - return JS_UNDEFINED; \ -} \ -\ -JSValue ID##_get_##ENTRY (JSContext *js, JSValue this) { \ - return TYPE##2js(js2##ID (this)->ENTRY); \ -} \ - -#define BODY_GETSET(ENTRY, CPENTRY, TYPE) \ -JSValue gameobject_set_##ENTRY (JSContext *js, JSValue this, JSValue val) { \ - cpBody *b = js2gameobject(this)->body; \ - cpBodySet##CPENTRY (b, js2##TYPE (val)); \ - return JS_UNDEFINED; \ -} \ -\ -JSValue gameobject_get_##ENTRY (JSContext *js, JSValue this) { \ - cpBody *b = js2gameobject(this)->body; \ - return TYPE##2js (cpBodyGet##CPENTRY (b)); \ -} \ - -BODY_GETSET(pos, Position, cvec2) -BODY_GETSET(angle, Angle, number) -GETSET_PAIR(gameobject, scale, vec3) -BODY_GETSET(velocity, Velocity, cvec2) -BODY_GETSET(angularvelocity, AngularVelocity, number) -BODY_GETSET(moi, Moment, number) -//BODY_GETSET(phys, Type, number) -GETSET_PAIR(gameobject, phys, number) -BODY_GETSET(torque, Torque, number) +JSC_GETSET_BODY(pos, Position, cvec2) +JSC_GETSET_BODY(angle, Angle, number) +JSC_GETSET(gameobject, scale, vec3) +JSC_GETSET_BODY(velocity, Velocity, cvec2) +JSC_GETSET_BODY(angularvelocity, AngularVelocity, number) +JSC_GETSET_BODY(moi, Moment, number) +//JSC_GETSET_BODY(phys, Type, number) +JSC_GETSET(gameobject, phys, number) +JSC_GETSET_BODY(torque, Torque, number) JSC_CCALL(gameobject_impulse, cpBodyApplyImpulseAtWorldPoint(js2gameobject(this)->body, js2vec2(argv[0]).cp, cpBodyGetPosition(js2gameobject(this)->body))) JSC_CCALL(gameobject_force, cpBodyApplyForceAtWorldPoint(js2gameobject(this)->body, js2vec2(argv[0]).cp, cpBodyGetPosition(js2gameobject(this)->body))) JSC_CCALL(gameobject_force_local, cpBodyApplyForceAtLocalPoint(js2gameobject(this)->body, js2vec2(argv[0]).cp, js2vec2(argv[1]).cp)) -JSC_CCALL(gameobject_in_air, return bool2js(phys2d_in_air(js2gameobject(this)->body))) +JSC_CCALL(gameobject_in_air, return boolean2js(phys2d_in_air(js2gameobject(this)->body))) JSC_CCALL(gameobject_world2this, return vec22js(world2go(js2gameobject(this), js2vec2(argv[0])))) JSC_CCALL(gameobject_this2world, return vec22js(go2world(js2gameobject(this), js2vec2(argv[0])))) JSC_CCALL(gameobject_dir_world2this, return vec22js(mat_t_dir(t_world2go(js2gameobject(this)), js2vec2(argv[0])))) JSC_CCALL(gameobject_dir_this2world, return vec22js(mat_t_dir(t_go2world(js2gameobject(this)), js2vec2(argv[0])))) -GETSET_PAIR_BODY(gameobject, f, number) -GETSET_PAIR_BODY(gameobject, e, number) -GETSET_PAIR_BODY(gameobject, mass, number) -GETSET_PAIR(gameobject, damping, number) -GETSET_PAIR(gameobject, timescale, number) -GETSET_PAIR(gameobject, maxvelocity, number) -GETSET_PAIR(gameobject, maxangularvelocity, number) -GETSET_PAIR_BODY(gameobject, layer, number) -GETSET_PAIR(gameobject, warp_filter, bitmask) -GETSET_PAIR(gameobject, drawlayer, number) +JSC_GETSET_APPLY(gameobject, f, number) +JSC_GETSET_APPLY(gameobject, e, number) +JSC_GETSET_APPLY(gameobject, mass, number) +JSC_GETSET(gameobject, damping, number) +JSC_GETSET(gameobject, timescale, number) +JSC_GETSET(gameobject, maxvelocity, number) +JSC_GETSET(gameobject, maxangularvelocity, number) +JSC_GETSET_APPLY(gameobject, layer, number) +JSC_GETSET(gameobject, warp_filter, bitmask) +JSC_GETSET(gameobject, drawlayer, number) JSC_CCALL(gameobject_setref, js2gameobject(this)->ref = argv[0]); static const JSCFunctionListEntry js_gameobject_funcs[] = { @@ -1570,33 +1406,16 @@ JSC_CCALL(dspsound_lpf, return dsp_node2js(dsp_lpf(js2number(argv[0])))) JSC_CCALL(dspsound_hpf, return dsp_node2js(dsp_hpf(js2number(argv[0])))) JSC_CCALL(dspsound_delay, return dsp_node2js(dsp_delay(js2number(argv[0]), js2number(argv[1])))) JSC_CCALL(dspsound_fwd_delay, return dsp_node2js(dsp_fwd_delay(js2number(argv[0]), js2number(argv[1])))) -JSC_CCALL(dspsound_source, - char *s = js2str(argv[0]); - JSValue ret = dsp_node2js(dsp_source(s)); - JS_FreeCString(js,s); +JSC_SCALL(dspsound_source, + ret = dsp_node2js(dsp_source(str)); JS_SetPrototype(js, ret, sound_proto); - return ret; ) JSC_CCALL(dspsound_mix, return dsp_node2js(make_node(NULL,NULL,NULL))) JSC_CCALL(dspsound_master, return dsp_node2js(masterbus)) -JSC_CCALL(dspsound_plugin_node, plugin_node(js2dsp_node(argv[0]), js2dsp_node(argv[1]))) +JSC_CCALL(dspsound_plugin_node, plugin_node(js2dsp_node(argv[0]), js2dsp_node(argv[1]));) JSC_CCALL(dspsound_samplerate, return number2js(SAMPLERATE)) -JSC_CCALL(dspsound_mod, - char *s = js2str(argv[0]); - JSValue ret = dsp_node2js(dsp_mod(s)); - JS_FreeCString(js,s); - return ret; -) -JSC_CCALL(dspsound_midi, - char *s1; - char *s2; - s1 = js2str(argv[0]); - s2 = js2str(argv[1]); - JSValue ret = dsp_node2js(dsp_midi(s1, make_soundfont(s2))); - JS_FreeCString(js,s1); - JS_FreeCString(js,s2); - return ret; -) +JSC_SCALL(dspsound_mod, ret = dsp_node2js(dsp_mod(str))) +JSC_SSCALL(dspsound_midi, ret = dsp_node2js(dsp_midi(str, make_soundfont(str2)))) static const JSCFunctionListEntry js_dspsound_funcs[] = { MIST_FUNC_DEF(dspsound, noise, 0), @@ -1620,9 +1439,9 @@ static const JSCFunctionListEntry js_dspsound_funcs[] = { MIST_FUNC_DEF(dspsound, mod, 1) }; -JSC_CCALL(pshape_set_sensor, shape_set_sensor(js2ptr(argv[0]), js2bool(argv[1]))) +JSC_CCALL(pshape_set_sensor, shape_set_sensor(js2ptr(argv[0]), js2boolean(argv[1]))) JSC_CCALL(pshape_get_sensor, shape_get_sensor(js2ptr(argv[0]))) -JSC_CCALL(pshape_set_enabled, shape_enabled(js2ptr(argv[0]), js2bool(argv[1]))) +JSC_CCALL(pshape_set_enabled, shape_enabled(js2ptr(argv[0]), js2boolean(argv[1]))) JSC_CCALL(pshape_get_enabled, shape_is_enabled(js2ptr(argv[0]))) static const JSCFunctionListEntry js_pshape_funcs[] = { @@ -1632,16 +1451,16 @@ static const JSCFunctionListEntry js_pshape_funcs[] = { MIST_FUNC_DEF(pshape, get_enabled, 1) }; -GETSET_PAIR(sprite, color, color) -GETSET_PAIR(sprite, emissive, color) -GETSET_PAIR(sprite, enabled, bool) -GETSET_PAIR(sprite, parallax, number) -GETSET_PAIR(sprite, tex, texture) -GETSET_PAIR(sprite, pos, vec2) -GETSET_PAIR(sprite, scale, vec2) -GETSET_PAIR(sprite, angle, number) -GETSET_PAIR(sprite, frame, rect) -GETSET_PAIR(sprite,go,gameobject) +JSC_GETSET(sprite, color, color) +JSC_GETSET(sprite, emissive, color) +JSC_GETSET(sprite, enabled, boolean) +JSC_GETSET(sprite, parallax, number) +JSC_GETSET(sprite, tex, texture) +JSC_GETSET(sprite, pos, vec2) +JSC_GETSET(sprite, scale, vec2) +JSC_GETSET(sprite, angle, number) +JSC_GETSET(sprite, frame, rect) +JSC_GETSET(sprite,go,gameobject) static const JSCFunctionListEntry js_sprite_funcs[] = { CGETSET_ADD(sprite,pos), @@ -1656,23 +1475,10 @@ static const JSCFunctionListEntry js_sprite_funcs[] = { CGETSET_ADD(sprite,go) }; -#define GETFN(ID, ENTRY, TYPE) \ -JSValue js_##ID##_##ENTRY (JSContext *js, JSValue this, JSValue val) {\ - return TYPE##2js(js2##ID (this)->ENTRY); \ -} \ - GETFN(texture,width,number) GETFN(texture,height,number) -JSValue js_texture_path(JSContext *js, JSValue this, JSValue val) -{ - return str2js(tex_get_path(js2texture(this))); -} -JSValue js_texture_find(JSContext *js, JSValue this, int argc, JSValue *argv) { - char *str = js2str(argv[0]); - JSValue ret = texture2js(texture_from_file(str)); - JS_FreeCString(js,str); - return ret; -} +JSC_CCALL(texture_path, return str2js(tex_get_path(js2texture(this)))) +JSC_SCALL(texture_find, ret = texture2js(texture_from_file(str))) static const JSCFunctionListEntry js_texture_funcs[] = { MIST_FUNC_DEF(texture, width, 0), @@ -1682,20 +1488,20 @@ static const JSCFunctionListEntry js_texture_funcs[] = { // MIST_FUNC_DEF(texture, dimensions, 1), }; -JSValue constraint_set_max_force (JSContext *js, JSValue this, JSValue val) { +JSValue js_constraint_set_max_force (JSContext *js, JSValue this, JSValue val) { cpConstraintSetMaxForce(js2constraint(this)->c, js2number(val)); return JS_UNDEFINED; } -JSValue constraint_get_max_force(JSContext *js, JSValue this) { return number2js(cpConstraintGetMaxForce(js2constraint(this)->c)); +JSValue js_constraint_get_max_force(JSContext *js, JSValue this) { return number2js(cpConstraintGetMaxForce(js2constraint(this)->c)); } -JSValue constraint_set_collide (JSContext *js, JSValue this, JSValue val) { - cpConstraintSetCollideBodies(js2constraint(this)->c, js2bool(val)); +JSValue js_constraint_set_collide (JSContext *js, JSValue this, JSValue val) { + cpConstraintSetCollideBodies(js2constraint(this)->c, js2boolean(val)); return JS_UNDEFINED; } -JSValue constraint_get_collide(JSContext *js, JSValue this) { return bool2js(cpConstraintGetCollideBodies(js2constraint(this)->c)); +JSValue js_constraint_get_collide(JSContext *js, JSValue this) { return boolean2js(cpConstraintGetCollideBodies(js2constraint(this)->c)); } static const JSCFunctionListEntry js_constraint_funcs[] = { @@ -1719,18 +1525,6 @@ static const JSCFunctionListEntry js_edge2d_funcs[] = { MIST_FUNC_DEF(edge2d, get_thickness, 1), }; -JSValue duk_inflate_cpv(JSContext *js, JSValue this, int argc, JSValue *argv) { - HMM_Vec2 *points = js2cpvec2arr(argv[0]); - int n = js2number(argv[1]); - double d = js2number(argv[2]); - HMM_Vec2 *infl = inflatepoints(points,d,n); - JSValue arr = vecarr2js(infl,arrlen(infl)); - - arrfree(infl); - arrfree(points); - return arr; -} - const char *STRTEST = "TEST STRING"; JSC_CCALL(performance_barecall,) @@ -1789,8 +1583,6 @@ static const JSCFunctionListEntry js_nota_funcs[] = { void ffi_load() { globalThis = JS_GetGlobalObject(js); - DUK_FUNC(inflate_cpv, 3) - QJSCLASSPREP(ptr); QJSCLASSPREP_FUNCS(gameobject); QJSCLASSPREP_FUNCS(dsp_node);