From 09036d075dd8d18585077bdac26f87199b336166 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Mon, 2 Jan 2023 23:43:07 +0000 Subject: [PATCH] SEXP asset files --- source/engine/mrbffi.c | 63 ++++++++++++++++++++++++++++++++++++++++ source/engine/registry.c | 4 +++ source/engine/registry.h | 5 ++++ source/engine/yugine.c | 7 +---- 4 files changed, 73 insertions(+), 6 deletions(-) diff --git a/source/engine/mrbffi.c b/source/engine/mrbffi.c index 2a68b22..2ed29a5 100644 --- a/source/engine/mrbffi.c +++ b/source/engine/mrbffi.c @@ -486,6 +486,64 @@ s7_pointer s7_anim_cmd(s7_scheme *sc, s7_pointer args) { return args; } +s7_pointer s7_make_gameobject(s7_scheme *sc, s7_pointer args) { + int g = MakeGameobject(); + struct gameobject *go = get_gameobject_from_id(g); + + go->scale = s7_real(s7_car(args)); + go->bodytype = s7_integer(s7_cadr(args)); + go->mass = s7_real(s7_caddr(args)); + go->f = s7_real(s7_cadddr(args)); + go->e = s7_real(s7_list_ref(sc, args, 4)); + + return s7_make_integer(sc, g); +} + +s7_pointer s7_make_sprite(s7_scheme *sc, s7_pointer args) { + int go = s7_integer(s7_car(args)); + const char *path = s7_string(s7_cadr(args)); + cpVect pos = s7tovec2(sc, s7_caddr(args)); + + YughInfo("Using gameid %d.", go); + + struct sprite *sp = make_sprite(get_gameobject_from_id(go)); + + sprite_loadtex(sp, path); + sp->pos[0] = pos.x; + sp->pos[1] = pos.y; + + return args; +} + +s7_pointer s7_make_box2d(s7_scheme *sc, s7_pointer args) { + int go = s7_integer(s7_car(args)); + cpVect size = s7tovec2(sc, s7_cadr(args)); + cpVect offset = s7tovec2(sc, s7_caddr(args)); + + struct phys2d_box *box = Make2DBox(get_gameobject_from_id(go)); + box->w = size.x; + box->h = size.y; + box->offset[0] = offset.x; + box->offset[1] = offset.y; + + phys2d_boxinit(box, get_gameobject_from_id(go)); + + return args; +} + +s7_pointer s7_make_circ2d(s7_scheme *sc, s7_pointer args) { + int go = s7_integer(s7_car(args)); + double radius = s7_real(s7_cadr(args)); + cpVect offset = s7tovec2(sc, s7_caddr(args)); + + struct phys2d_circle *circle = Make2DCircle(get_gameobject_from_id(go)); + circle->radius = radius; + circle->offset[0] = offset.x; + circle->offset[1] = offset.y; + + phys2d_applycircle(circle); +} + #define S7_FUNC(NAME, ARGS) s7_define_function(s7, #NAME, s7_ ##NAME, ARGS, 0, 0, "") void ffi_load() { @@ -526,5 +584,10 @@ void ffi_load() { S7_FUNC(anim, 2); S7_FUNC(anim_cmd, 3); + + S7_FUNC(make_gameobject, 5); + S7_FUNC(make_sprite, 3); + S7_FUNC(make_box2d, 3); + S7_FUNC(make_circ2d, 3); } diff --git a/source/engine/registry.c b/source/engine/registry.c index cb36e08..a1ea3ec 100644 --- a/source/engine/registry.c +++ b/source/engine/registry.c @@ -74,3 +74,7 @@ void comp_draw_debug(struct component *c) { void comp_draw_gui(struct component *c) { c->draw_gui(c->data); } + +void c_draw_debug(struct compref *c) { + c->ref->draw_debug(c->data); +} \ No newline at end of file diff --git a/source/engine/registry.h b/source/engine/registry.h index b2257dc..3813399 100644 --- a/source/engine/registry.h +++ b/source/engine/registry.h @@ -8,6 +8,11 @@ struct gameobject; +struct compref { + void *data; + struct component *ref; +}; + struct component { const char *name; void *(*make)(struct gameobject * go); /* Called to create the component */ diff --git a/source/engine/yugine.c b/source/engine/yugine.c index 33e6ed6..2622fad 100644 --- a/source/engine/yugine.c +++ b/source/engine/yugine.c @@ -156,13 +156,8 @@ int main(int argc, char **args) { JSON_Object *ro = json_value_get_object(rv); json_object_set_string(ro, "name", "yugine"); json_object_set_number(ro, "age", 30); - char *serialized = json_serialize_to_string_pretty(rv); - - FILE *json = fopen("test.json", "w"); - fputs(serialized, json); - json_free_serialized_string(serialized); + char *serialized = json_serialize_to_file(rv, "test2.json"); json_value_free(rv); - fclose(json); const GLFWvidmode *vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());