dsp node js objects

This commit is contained in:
John Alanbrook 2023-11-29 13:32:32 +00:00
parent f47b6ece21
commit 7e7514f5d7
6 changed files with 61 additions and 1 deletions

View file

@ -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++) {

View file

@ -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;

View file

@ -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()));

View file

@ -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);
}

View file

@ -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;

View file

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