Add Nuke radio buttons; fixed edge memory leak

This commit is contained in:
John Alanbrook 2023-02-23 23:03:58 +00:00
parent d1c87b38ac
commit 8e0c4948a6
6 changed files with 25 additions and 21 deletions

View file

@ -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);
}

View file

@ -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);

View file

@ -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;

View file

@ -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) {

View file

@ -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);

View file

@ -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);