javasrcript update & phys update
This commit is contained in:
parent
3baec775a8
commit
469b955d97
|
@ -153,14 +153,19 @@ duk_ret_t duk_sys_cmd(duk_context *duk) {
|
||||||
|
|
||||||
duk_ret_t duk_register(duk_context *duk) {
|
duk_ret_t duk_register(duk_context *duk) {
|
||||||
int cmd = duk_to_int(duk, 0);
|
int cmd = duk_to_int(duk, 0);
|
||||||
void *obj = duk_get_pointer(duk, 1);
|
void *obj = duk_get_heapptr(duk, 1);
|
||||||
void *fn = duk_get_pointer(duk, 2);
|
void *fn = duk_get_heapptr(duk, 2);
|
||||||
|
|
||||||
|
switch (cmd) {
|
||||||
|
case 0:
|
||||||
|
register_update(obj, fn);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
register_physics(obj, fn);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Test a call ... */
|
|
||||||
duk_push_pointer(duk, fn);
|
|
||||||
duk_push_pointer(duk, obj);
|
|
||||||
duk_call_method(duk, 0);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,39 +111,27 @@ void script_call_sym_args(void *sym, void *args)
|
||||||
//s7_call(s7, sym, s7_cons(s7, args, s7_nil(s7)));
|
//s7_call(s7, sym, s7_cons(s7, args, s7_nil(s7)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void **updates;
|
|
||||||
void **guis;
|
|
||||||
void **physics;
|
|
||||||
|
|
||||||
struct obupdate {
|
struct obupdate {
|
||||||
void *obj;
|
void *obj;
|
||||||
void *sym;
|
void *sym;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct obupdate *obupdates = NULL;
|
struct obupdate *updates = NULL;
|
||||||
|
struct obupdate *physics = NULL;
|
||||||
|
void **guis = NULL;
|
||||||
|
|
||||||
void register_update(void *sym) {
|
void register_update(void *obj, void *sym) {
|
||||||
arrput(updates, sym);
|
|
||||||
}
|
|
||||||
|
|
||||||
void register_obupdate(void *obj, void *sym) {
|
|
||||||
struct obupdate ob = {obj, sym};
|
struct obupdate ob = {obj, sym};
|
||||||
arrput(obupdates, ob);
|
arrput(updates, ob);
|
||||||
}
|
}
|
||||||
|
|
||||||
void call_updates(double dt) {
|
void call_updates(double dt) {
|
||||||
for (int i = 0; i < arrlen(updates); i++) {
|
for (int i = 0; i < arrlen(updates); i++) {
|
||||||
duk_push_heapptr(duk, updates[i]);
|
duk_push_heapptr(duk, updates[i].obj);
|
||||||
|
duk_push_heapptr(duk, updates[i].sym);
|
||||||
duk_push_number(duk, dt);
|
duk_push_number(duk, dt);
|
||||||
duk_call(duk, 1);
|
duk_call_prop(duk, -3, 1);
|
||||||
}
|
duk_pop_2(duk);
|
||||||
|
|
||||||
for (int i = 0; i < arrlen(obupdates); i++) {
|
|
||||||
duk_push_heapptr(duk, obupdates[i].sym);
|
|
||||||
duk_push_heapptr(duk, obupdates[i].obj);
|
|
||||||
duk_push_number(duk, dt);
|
|
||||||
duk_call_method(duk, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,14 +144,17 @@ void call_gui() {
|
||||||
script_call_sym(guis[i]);
|
script_call_sym(guis[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void register_physics(void *sym) {
|
void register_physics(void *obj, void *sym) {
|
||||||
arrput(physics, sym);
|
struct obupdate ob = {obj, sym};
|
||||||
|
arrput(physics, ob);
|
||||||
}
|
}
|
||||||
|
|
||||||
void call_physics(double dt) {
|
void call_physics(double dt) {
|
||||||
for (int i = 0; i < arrlen(physics); i++) {
|
for (int i = 0; i < arrlen(physics); i++) {
|
||||||
duk_push_pointer(duk, physics[i]);
|
duk_push_heapptr(duk, physics[i].obj);
|
||||||
|
duk_push_heapptr(duk, physics[i].sym);
|
||||||
duk_push_number(duk, dt);
|
duk_push_number(duk, dt);
|
||||||
duk_call(duk, 1);
|
duk_call_prop(duk, -3, 1);
|
||||||
|
duk_pop_2(duk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,14 +18,13 @@ void script_call_sym_args(void *sym, void *args);
|
||||||
int script_has_sym(void *sym);
|
int script_has_sym(void *sym);
|
||||||
void script_eval_w_env(const char *s, void *env);
|
void script_eval_w_env(const char *s, void *env);
|
||||||
|
|
||||||
void register_update(void *sym);
|
void register_update(void *obj, void *sym);
|
||||||
void register_obupdate(void *obj, void *sym);
|
|
||||||
void call_updates(double dt);
|
void call_updates(double dt);
|
||||||
|
|
||||||
void register_gui(void *sym);
|
void register_gui(void *sym);
|
||||||
void call_gui();
|
void call_gui();
|
||||||
|
|
||||||
void register_physics(void *sym);
|
void register_physics(void *obj, void *sym);
|
||||||
void call_physics(double dt);
|
void call_physics(double dt);
|
||||||
|
|
||||||
duk_idx_t vec2duk(cpVect v);
|
duk_idx_t vec2duk(cpVect v);
|
||||||
|
|
Loading…
Reference in a new issue