From 8e0c4948a63e885e7e708a81646ffe0e79d65113 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Thu, 23 Feb 2023 23:03:58 +0000 Subject: [PATCH] Add Nuke radio buttons; fixed edge memory leak --- source/engine/2dphysics.c | 4 +++- source/engine/2dphysics.h | 5 ++--- source/engine/ffi.c | 20 +++++++++++++------- source/engine/gameobject.c | 5 +---- source/engine/script.h | 2 ++ source/engine/yugine.c | 10 ++++------ 6 files changed, 25 insertions(+), 21 deletions(-) diff --git a/source/engine/2dphysics.c b/source/engine/2dphysics.c index fcf4054..8158b1d 100644 --- a/source/engine/2dphysics.c +++ b/source/engine/2dphysics.c @@ -409,6 +409,7 @@ struct phys2d_edge *Make2DEdge(int go) new->shape.go = go; new->shape.data = new; new->shape.debugdraw = phys2d_dbgdrawedge; + new->shape.shape = NULL; phys2d_applyedge(new); return new; @@ -439,6 +440,7 @@ void phys2d_edge_rmvert(struct phys2d_edge *edge, int index) if (index == 0) { cpSpaceRemoveShape(space, edge->shapes[index]); + cpShapeFree(edge->shapes[index]); arrdel(edge->shapes, index); phys2d_applyedge(edge); return; @@ -449,6 +451,7 @@ void phys2d_edge_rmvert(struct phys2d_edge *edge, int index) } cpSpaceRemoveShape(space, edge->shapes[index-1]); + cpShapeFree(edge->shapes[index-1]); arrdel(edge->shapes, index-1); phys2d_applyedge(edge); @@ -597,7 +600,6 @@ static cpBool script_phys_cb_begin(cpArbiter *arb, cpSpace *space, void *data) { struct gameobject *go = id2go(g1); for (int i = 0; i < arrlen(go->shape_cbs); i++) { - if (go->shape_cbs[i].shape != shape1) continue; duk_call_phys_cb(arb, go->shape_cbs[i].cbs.begin, g2); } diff --git a/source/engine/2dphysics.h b/source/engine/2dphysics.h index 6a804d4..7d12577 100644 --- a/source/engine/2dphysics.h +++ b/source/engine/2dphysics.h @@ -68,13 +68,11 @@ struct phys2d_circle *Make2DCircle(int go); void phys2d_circledel(struct phys2d_circle *c); void phys2d_applycircle(struct phys2d_circle *circle); void phys2d_dbgdrawcircle(struct phys2d_circle *circle); -void circle_gui(struct phys2d_circle *circle); struct phys2d_box *Make2DBox(int go); void phys2d_boxdel(struct phys2d_box *box); void phys2d_applybox(struct phys2d_box *box); void phys2d_dbgdrawbox(struct phys2d_box *box); -void box_gui(struct phys2d_box *box); struct phys2d_poly *Make2DPoly(int go); void phys2d_polydel(struct phys2d_poly *poly); @@ -90,10 +88,11 @@ void phys2d_dbgdrawedge(struct phys2d_edge *edge); void phys2d_edgeaddvert(struct phys2d_edge *edge); void phys2d_edge_rmvert(struct phys2d_edge *edge, int index); -void edge_gui(struct phys2d_edge *edge); void phys2d_edge_setvert(struct phys2d_edge *edge, int index, cpVect val); void phys2d_edge_clearverts(struct phys2d_edge *edge); void phys2d_edge_addverts(struct phys2d_edge *edge, cpVect *verts); +void phys2d_edge_set_sensor(struct phys2d_edge *edge, int sensor); +void phys2d_edge_set_enabled(struct phys2d_edge *edge, int enabled); void phys2d_init(); void phys2d_update(float deltaT); diff --git a/source/engine/ffi.c b/source/engine/ffi.c index 37ddeb9..116842c 100644 --- a/source/engine/ffi.c +++ b/source/engine/ffi.c @@ -238,6 +238,12 @@ duk_ret_t duk_nuke(duk_context *duk) case 8: nuke_img(duk_to_string(duk, 1)); break; + + case 9: + editint = duk_to_int(duk,2); + nuke_radio_btn(duk_to_string(duk,1), &editint, duk_to_int(duk, 3)); + duk_push_int(duk, editint); + return 1; } return 0; @@ -991,9 +997,9 @@ duk_ret_t duk_make_box2d(duk_context *duk) { phys2d_applybox(box); int idx = duk_push_object(duk); - duk_push_pointer(duk, &box->shape); - duk_put_prop_string(duk, idx, "id"); duk_push_pointer(duk, box); + duk_put_prop_string(duk, idx, "id"); + duk_push_pointer(duk, &box->shape); duk_put_prop_string(duk, idx, "shape"); return 1; @@ -1040,9 +1046,9 @@ duk_ret_t duk_make_circle2d(duk_context *duk) { phys2d_applycircle(circle); int idx = duk_push_object(duk); - duk_push_pointer(duk, &circle->shape); - duk_put_prop_string(duk, idx, "id"); duk_push_pointer(duk, circle); + duk_put_prop_string(duk, idx, "id"); + duk_push_pointer(duk, &circle->shape); duk_put_prop_string(duk, idx, "shape"); return 1; @@ -1117,10 +1123,10 @@ duk_ret_t duk_make_edge2d(duk_context *duk) phys2d_edge_setvert(edge, i, points[i]); } - int idx = duk_push_object(duk); - duk_push_pointer(duk, &edge->shape); - duk_put_prop_string(duk, idx, "id"); + int idx = duk_push_object(duk); duk_push_pointer(duk, edge); + duk_put_prop_string(duk, idx, "id"); + duk_push_pointer(duk, &edge->shape); duk_put_prop_string(duk, idx, "shape"); return 1; diff --git a/source/engine/gameobject.c b/source/engine/gameobject.c index c7b9256..1248a70 100644 --- a/source/engine/gameobject.c +++ b/source/engine/gameobject.c @@ -97,8 +97,6 @@ void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go) cpShapeSetElasticity(shape, go->e); cpShapeSetSensor(shape, go->sensor); cpShapeSetCollisionType(shape, go2id(go)); - if (go->sensor) - YughInfo("Enabled a sensor ..."); // cpShapeSetFilter(shape, go->filter); } @@ -276,8 +274,7 @@ void gameobject_rotate(struct gameobject *go, float as) void gameobject_setangle(struct gameobject *go, float angle) { cpBodySetAngle(go->body, angle); - - phys2d_reindex_body(go->body); + phys2d_reindex_body(go->body); } void gameobject_setpos(struct gameobject *go, cpVect vec) { diff --git a/source/engine/script.h b/source/engine/script.h index 956b902..49d893c 100644 --- a/source/engine/script.h +++ b/source/engine/script.h @@ -18,6 +18,8 @@ int script_dofile(const char *file); void script_update(double dt); void script_draw(); +void duk_run_err(); + void script_editor(); void script_call(const char *f); void script_call_sym(void *sym); diff --git a/source/engine/yugine.c b/source/engine/yugine.c index 674769d..906adba 100644 --- a/source/engine/yugine.c +++ b/source/engine/yugine.c @@ -109,7 +109,7 @@ int main(int argc, char **args) { case 'v': printf("Yugine version %s, %s build.\n", VER, INFO); - printf("Copyright 2022 odplot productions LLC.\n"); + printf("Copyright 2022-2023 odplot productions LLC.\n"); exit(1); break; @@ -117,6 +117,7 @@ int main(int argc, char **args) { printf("-l Set log file\n"); printf("-play Launch engine in play mode instead of editor mode\n"); printf("-v Display engine info\n"); + printf("-c Redirect logging to console\n"); exit(0); break; @@ -147,14 +148,11 @@ int main(int argc, char **args) { log_cat(sysinfo); pclose(sysinfo); } - - signal(SIGSEGV, seghandle); - + signal(SIGABRT, seghandle); + signal(SIGFPE, seghandle); #endif - - FILE *gameinfo = NULL; gameinfo = fopen("game.info", "w"); fprintf(gameinfo, "Yugine v. %s, sys %s.", VER, INFO);