circle and sprites work with saves
This commit is contained in:
@@ -201,6 +201,7 @@ struct phys2d_circle *Make2DCircle(int go) {
|
||||
new->shape.shape = cpSpaceAddShape(space, cpCircleShapeNew(id2go(go)->body, new->radius, cpvzero));
|
||||
new->shape.debugdraw = phys2d_dbgdrawcircle;
|
||||
new->shape.moi = phys2d_circle_moi;
|
||||
new->shape.apply = phys2d_applycircle;
|
||||
init_phys2dshape(&new->shape, go, new);
|
||||
|
||||
return new;
|
||||
|
||||
@@ -21,13 +21,13 @@ extern struct rgba kinematic_color;
|
||||
extern struct rgba static_color;
|
||||
extern struct rgba sleep_color;
|
||||
|
||||
|
||||
struct phys2d_shape {
|
||||
cpShape *shape;
|
||||
int go;
|
||||
void *data;
|
||||
void (*debugdraw)(void *data);
|
||||
float (*moi)(void *data, float mass);
|
||||
void (*apply)(void *data);
|
||||
};
|
||||
|
||||
/* Circles are the fastest collier type */
|
||||
|
||||
@@ -707,6 +707,7 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||
|
||||
case 36:
|
||||
id2go(js2int(argv[1]))->scale = js2number(argv[2]);
|
||||
gameobject_apply(id2go(js2int(argv[1])));
|
||||
cpSpaceReindexShapesForBody(space, id2go(js2int(argv[1]))->body);
|
||||
return JS_NULL;
|
||||
|
||||
|
||||
@@ -95,6 +95,10 @@ void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go) {
|
||||
filter.categories = CP_ALL_CATEGORIES;//1<<go->layer;
|
||||
filter.mask = CP_ALL_CATEGORIES;//category_masks[go->layer];
|
||||
cpShapeSetFilter(shape, filter);
|
||||
|
||||
struct phys2d_shape *ape = cpShapeGetUserData(shape);
|
||||
if (ape)
|
||||
ape->apply(ape->data);
|
||||
}
|
||||
|
||||
void go_shape_moi(cpBody *body, cpShape *shape, struct gameobject *go) {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include "font.h"
|
||||
|
||||
@@ -248,8 +249,34 @@ char *slurp_text(const char *filename, size_t *size)
|
||||
return retstr;
|
||||
}
|
||||
|
||||
void rek_mkdir(char *path) {
|
||||
char *sep = strrchr(path, '/');
|
||||
if(sep != NULL) {
|
||||
*sep = 0;
|
||||
rek_mkdir(path);
|
||||
*sep = '/';
|
||||
}
|
||||
#if defined __WIN32
|
||||
if(mkdir(path) && errno != EEXIST)
|
||||
#else
|
||||
if (mkdir(path, 0777) && errno != EEXIST)
|
||||
#endif
|
||||
printf("error while trying to create '%s'\n%m\n", path);
|
||||
}
|
||||
|
||||
FILE *fopen_mkdir(char *path, char *mode) {
|
||||
char *sep = strrchr(path, '/');
|
||||
if(sep) {
|
||||
char *path0 = strdup(path);
|
||||
path0[ sep - path ] = 0;
|
||||
rek_mkdir(path0);
|
||||
free(path0);
|
||||
}
|
||||
return fopen(path,mode);
|
||||
}
|
||||
|
||||
int slurp_write(const char *txt, const char *filename) {
|
||||
FILE *f = fopen(filename, "w");
|
||||
FILE *f = fopen_mkdir(filename, "w");
|
||||
if (!f) return 1;
|
||||
|
||||
fputs(txt, f);
|
||||
|
||||
Reference in New Issue
Block a user