From a2c9d1163a31425003c208b6d7644bdab260f2dd Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Mon, 9 Jan 2023 13:21:45 +0000 Subject: [PATCH] Prototype updates --- source/engine/engine.c | 2 +- source/engine/mrbffi.c | 9 +++++++++ source/engine/script.c | 18 ++++++++++++++++++ source/engine/script.h | 1 + 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/source/engine/engine.c b/source/engine/engine.c index 5270b90..7f56383 100644 --- a/source/engine/engine.c +++ b/source/engine/engine.c @@ -66,5 +66,5 @@ void engine_init() phys2d_init(); YughInfo("Starting sound ..."); - sound_init(); +// sound_init(); } diff --git a/source/engine/mrbffi.c b/source/engine/mrbffi.c index 6164482..1e27a7a 100644 --- a/source/engine/mrbffi.c +++ b/source/engine/mrbffi.c @@ -313,6 +313,14 @@ s7_pointer s7_register(s7_scheme *sc, s7_pointer args) { return sym; } +s7_pointer s7_obregister(s7_scheme *sc, s7_pointer args) { + int cmd = s7_integer(s7_car(args)); + s7_pointer sym = s7_cadr(args); + s7_pointer env = s7_caddr(args); + + register_obupdate(env, sym); +} + s7_pointer s7_set_pawn(s7_scheme *sc, s7_pointer args) { s7_pointer pawn = s7_car(args); set_pawn(pawn); @@ -585,6 +593,7 @@ void ffi_load() { S7_FUNC(sound_cmd, 2); S7_FUNC(gui_hook, 1); S7_FUNC(register, 2); + S7_FUNC(obregister, 3); S7_FUNC(set_pawn, 1); S7_FUNC(set_body, 3); S7_FUNC(phys_cmd, 3); diff --git a/source/engine/script.c b/source/engine/script.c index 142b717..b25db81 100644 --- a/source/engine/script.c +++ b/source/engine/script.c @@ -132,13 +132,31 @@ s7_pointer *updates; s7_pointer *guis; s7_pointer *physics; +struct obupdate { + s7_pointer obj; + s7_pointer sym; +}; + +struct obupdate *obupdates = NULL; + void register_update(s7_pointer sym) { arrput(updates, sym); } +void register_obupdate(s7_pointer obj, s7_pointer sym) { + struct obupdate ob = {obj, sym}; + arrput(obupdates, ob); +} + void call_updates(double dt) { for (int i = 0; i < arrlen(updates); i++) s7_call(s7, updates[i], s7_cons(s7, s7_make_real(s7, dt), s7_nil(s7))); + + for (int i = 0; i < arrlen(obupdates); i++) { + s7_set_curlet(s7, obupdates[i].obj); + s7_call(s7, obupdates[i].sym, s7_cons(s7, s7_make_real(s7, dt), s7_nil(s7))); + } + } void register_gui(s7_pointer sym) { diff --git a/source/engine/script.h b/source/engine/script.h index a693cdc..65ec98c 100644 --- a/source/engine/script.h +++ b/source/engine/script.h @@ -19,6 +19,7 @@ int script_has_sym(s7_pointer sym); void script_eval_w_env(const char *s, s7_pointer env); void register_update(s7_pointer sym); +void register_obupdate(s7_pointer obj, s7_pointer sym); void call_updates(double dt); void register_gui(s7_pointer sym);