Prototype updates

This commit is contained in:
John Alanbrook 2023-01-09 13:21:45 +00:00
parent e24eef6c8f
commit a2c9d1163a
4 changed files with 29 additions and 1 deletions

View file

@ -66,5 +66,5 @@ void engine_init()
phys2d_init(); phys2d_init();
YughInfo("Starting sound ..."); YughInfo("Starting sound ...");
sound_init(); // sound_init();
} }

View file

@ -313,6 +313,14 @@ s7_pointer s7_register(s7_scheme *sc, s7_pointer args) {
return sym; 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 s7_set_pawn(s7_scheme *sc, s7_pointer args) {
s7_pointer pawn = s7_car(args); s7_pointer pawn = s7_car(args);
set_pawn(pawn); set_pawn(pawn);
@ -585,6 +593,7 @@ void ffi_load() {
S7_FUNC(sound_cmd, 2); S7_FUNC(sound_cmd, 2);
S7_FUNC(gui_hook, 1); S7_FUNC(gui_hook, 1);
S7_FUNC(register, 2); S7_FUNC(register, 2);
S7_FUNC(obregister, 3);
S7_FUNC(set_pawn, 1); S7_FUNC(set_pawn, 1);
S7_FUNC(set_body, 3); S7_FUNC(set_body, 3);
S7_FUNC(phys_cmd, 3); S7_FUNC(phys_cmd, 3);

View file

@ -132,13 +132,31 @@ s7_pointer *updates;
s7_pointer *guis; s7_pointer *guis;
s7_pointer *physics; s7_pointer *physics;
struct obupdate {
s7_pointer obj;
s7_pointer sym;
};
struct obupdate *obupdates = NULL;
void register_update(s7_pointer sym) { void register_update(s7_pointer sym) {
arrput(updates, 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) { void call_updates(double dt) {
for (int i = 0; i < arrlen(updates); i++) for (int i = 0; i < arrlen(updates); i++)
s7_call(s7, updates[i], s7_cons(s7, s7_make_real(s7, dt), s7_nil(s7))); 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) { void register_gui(s7_pointer sym) {

View file

@ -19,6 +19,7 @@ int script_has_sym(s7_pointer sym);
void script_eval_w_env(const char *s, s7_pointer env); void script_eval_w_env(const char *s, s7_pointer env);
void register_update(s7_pointer sym); void register_update(s7_pointer sym);
void register_obupdate(s7_pointer obj, s7_pointer sym);
void call_updates(double dt); void call_updates(double dt);
void register_gui(s7_pointer sym); void register_gui(s7_pointer sym);