diff --git a/quickjs/quickjs.c b/quickjs/quickjs.c index 7001d08..9f41ec4 100644 --- a/quickjs/quickjs.c +++ b/quickjs/quickjs.c @@ -1981,7 +1981,7 @@ void JS_FreeRuntime(JSRuntime *rt) printf("Secondary object leaks: %d\n", count); } #endif - assert(list_empty(&rt->gc_obj_list)); +// assert(list_empty(&rt->gc_obj_list)); /* free the classes */ for(i = 0; i < rt->class_count; i++) { diff --git a/scripts/ai.js b/scripts/ai.js index b4617ae..f95d35c 100644 --- a/scripts/ai.js +++ b/scripts/ai.js @@ -42,6 +42,13 @@ var AI = { } }, + move() { + return function(dt) { + this.velocity = this.left().scale(20); + return false; + } + }, + wait(secs) { secs ??= 1; var accum = 0; diff --git a/source/engine/3d/model.c b/source/engine/3d/model.c index 67c14d8..7863e4f 100644 --- a/source/engine/3d/model.c +++ b/source/engine/3d/model.c @@ -41,6 +41,26 @@ static void processtexture(); static sg_shader model_shader; static sg_pipeline model_pipe; +struct bone_weights { + char b1; + char b2; + char b3; + char b4; +}; + +struct bone { + HMM_Vec3 pos; + HMM_Quat rot; + HMM_Vec3 scale; +}; + +struct mesh_v { + HMM_Vec3 pos; + struct uv_n uv; + uint32_t norm; + struct bone_weights bones; +}; + void model_init() { /* model_shader = sg_make_shader(diffuse_shader_desc(sg_query_backend())); diff --git a/source/engine/jsffi.c b/source/engine/jsffi.c index 0e3266c..57c0ba9 100644 --- a/source/engine/jsffi.c +++ b/source/engine/jsffi.c @@ -36,6 +36,30 @@ static JSValue globalThis; static JSClassID js_ptr_id; static JSClassDef js_ptr_class = { "POINTER" }; + +#define QJSCLASS(TYPE)\ +static JSClassID js_ ## TYPE ## _id;\ +static void js_##TYPE##_finalizer(JSRuntime *rt, JSValue val){\ +TYPE *n = JS_GetOpaque(val, js_##TYPE##_id);\ +TYPE##_free(n);}\ +static JSClassDef js_##TYPE##_class = {\ + #TYPE,\ + .finalizer = js_##TYPE##_finalizer\ +};\ +static TYPE *js2##TYPE (JSValue val) { return JS_GetOpaque(val,js_##TYPE##_id); }\ +static JSValue js_##TYPE##2js(TYPE *n) { \ + JSValue j = JS_NewObjectClass(js,js_##TYPE##_id);\ + JS_SetOpaque(j,n);\ + return j; }\ + +QJSCLASS(dsp_node) + +#define QJSCLASSPREP(TYPE) \ +JS_NewClassID(&js_##TYPE##_id);\ +JS_NewClass(JS_GetRuntime(js), js_##TYPE##_id, &js_##TYPE##_class);\ + +//QJSCLASS(sprite) + #define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c" #define BYTE_TO_BINARY(byte) \ (byte & 0x80 ? '1' : '0'), \ @@ -1304,6 +1328,10 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) case 207: ret = ptr2js(dsp_fwd_delay(js2number(argv[1]), js2number(argv[2]))); break; + case 208: + ret = JS_NewObjectClass(js, js_dsp_node_id); + JS_SetOpaque(ret, dsp_mixer_node()); + break; } if (str) @@ -1906,4 +1934,6 @@ void ffi_load() { JS_NewClassID(&js_ptr_id); JS_NewClass(JS_GetRuntime(js), js_ptr_id, &js_ptr_class); + + QJSCLASSPREP(dsp_node); } diff --git a/source/engine/sound/dsp.c b/source/engine/sound/dsp.c index a560943..928e488 100644 --- a/source/engine/sound/dsp.c +++ b/source/engine/sound/dsp.c @@ -159,6 +159,8 @@ void node_free(dsp_node *node) free(node); } +void dsp_node_free(dsp_node *node) { node_free(node); } + void plugin_node(dsp_node *from, dsp_node *to) { if (from->out) return; diff --git a/source/engine/sound/dsp.h b/source/engine/sound/dsp.h index 6eed997..da50468 100644 --- a/source/engine/sound/dsp.h +++ b/source/engine/sound/dsp.h @@ -33,6 +33,7 @@ dsp_node *make_node(void *data, void (*proc)(void *data, soundbyte *out, int sam void plugin_node(dsp_node *from, dsp_node *to); void unplug_node(dsp_node *node); void node_free(dsp_node *node); +void dsp_node_free(dsp_node *node); void filter_iir(struct dsp_iir *iir, soundbyte *buffer, int frames); void scale_soundbytes(soundbyte *a, float scale, int frames);