From 4a4711e38f6499ff96bbb74232d2f41458cb126a Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Wed, 3 Jan 2024 14:38:17 +0000 Subject: [PATCH] particle fix --- Makefile | 4 ++-- source/engine/2dphysics.c | 4 ++-- source/engine/gameobject.c | 7 +++++++ source/engine/input.c | 3 +-- source/engine/particle.c | 15 ++++++++++----- source/engine/resources.c | 8 -------- source/engine/resources.h | 1 - source/engine/yugine.c | 4 +--- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index b02d5f5..6db7c16 100755 --- a/Makefile +++ b/Makefile @@ -138,9 +138,9 @@ else ifeq ($(UNAME), Darwin) OS := macos CPPFLAGS += -arch $(ARCH) - CFLAGS += -x objective-c + CFLAGS += -x objective-c# -fopenmp=libomp CXXFLAGS += -std=c++11 - LDFLAGS += -framework Cocoa -framework QuartzCore -framework AudioToolbox -framework Metal -framework MetalKit + LDFLAGS += -framework Cocoa -framework QuartzCore -framework AudioToolbox -framework Metal -framework MetalKit# -fopenmp=libomp endif endif diff --git a/source/engine/2dphysics.c b/source/engine/2dphysics.c index ef66abe..b963cb7 100644 --- a/source/engine/2dphysics.c +++ b/source/engine/2dphysics.c @@ -625,9 +625,9 @@ static cpBool handle_collision(cpArbiter *arb, int type) { break; case CTYPE_SEP: - if (JS_IsObject(go->cbs.separate.obj)) +/* if (JS_IsObject(go->cbs.separate.obj)) duk_call_phys_cb(norm1, go->cbs.separate, go2, arb); - +*/ break; } diff --git a/source/engine/gameobject.c b/source/engine/gameobject.c index 101aad2..98143a8 100644 --- a/source/engine/gameobject.c +++ b/source/engine/gameobject.c @@ -189,12 +189,19 @@ void rm_body_shapes(cpBody *body, cpShape *shape, void *data) { cpShapeFree(shape); } +void rm_body_constraints(cpBody *body, cpConstraint *constraint, void *data) +{ + cpSpaceRemoveConstraint(space, constraint); + cpConstraintFree(constraint); +} + gameobject **go_toclean = NULL; /* Free this gameobject */ void gameobject_clean(gameobject *go) { arrfree(go->shape_cbs); cpBodyEachShape(go->body, rm_body_shapes, NULL); + cpBodyEachConstraint(go->body, rm_body_constraints, NULL); cpSpaceRemoveBody(space, go->body); cpBodyFree(go->body); go->body = NULL; diff --git a/source/engine/input.c b/source/engine/input.c index e296fab..ce9fba2 100644 --- a/source/engine/input.c +++ b/source/engine/input.c @@ -186,13 +186,12 @@ void register_gamepad(struct callee c) { void input_dropped_files(int n) { - JSValue argv[4]; argv[0] = jstr("emacs"); argv[1] = jstr("drop"); argv[2] = jstr("pressed"); char *path = rebase_path(sapp_get_dropped_file_path(0)); - argv[3] = str2js(path); + argv[3] = str2js(path+1); script_callee(pawn_callee, 4, argv); JS_FreeValue(js,argv[3]); } diff --git a/source/engine/particle.c b/source/engine/particle.c index 351806e..cc196a6 100644 --- a/source/engine/particle.c +++ b/source/engine/particle.c @@ -5,6 +5,7 @@ #include "2dphysics.h" #include "log.h" #include "simplex.h" +#include "pthread.h" static emitter **emitters; @@ -13,7 +14,7 @@ static sg_pipeline par_pipe; static sg_bindings par_bind; static int draw_count; -#define MAX_PARTICLES 500000 +#define MAX_PARTICLES 1000000 struct par_vert { HMM_Vec2 pos; @@ -145,6 +146,8 @@ void emitters_draw() for (int i = 0; i < arrlen(emitters); i++) { emitter *e = emitters[i]; par_bind.fs.images[0] = e->texture->id; + + #pragma omp parallel for for (int j = 0; j < arrlen(e->particles); j++) { particle *p = &e->particles[j]; pv[j].pos = p->pos.xy; @@ -152,6 +155,7 @@ void emitters_draw() pv[j].scale = HMM_ScaleV2(tex_get_dimensions(e->texture), p->scale); pv[j].color = vec2rgba(p->color); } + sg_append_buffer(par_bind.vertex_buffers[0], &(sg_range){.ptr=&pv, .size=sizeof(struct par_vert)*arrlen(e->particles)}); draw_count += arrlen(e->particles); } @@ -163,6 +167,7 @@ void emitters_draw() } void emitter_step(emitter *e, double dt) { + #pragma omp parallel for for (int i = arrlen(e->particles)-1; i >= 0; i--) { particle p = e->particles[i]; if (e->gravity) @@ -179,11 +184,11 @@ void emitter_step(emitter *e, double dt) { p.scale = e->scale; e->particles[i] = p; - if (p.life <= 0) - arrdelswap(e->particles,i); +// if (p.life <= 0) +// arrdelswap(e->particles,i); - if (query_point(p.pos.xy)) - arrdelswap(e->particles,i); +// if (query_point(p.pos.xy)) +// arrdelswap(e->particles,i); } if (!e->on) return; diff --git a/source/engine/resources.c b/source/engine/resources.c index 90efb7e..61d9c43 100644 --- a/source/engine/resources.c +++ b/source/engine/resources.c @@ -43,7 +43,6 @@ static struct cdb game_cdb; void resources_init() { DATA_PATH = malloc(MAXPATH); getcwd(DATA_PATH, MAXPATH); - strncat(DATA_PATH, "/", MAXPATH); if (!PREF_PATH) PREF_PATH = strdup("./tmp/"); @@ -51,7 +50,6 @@ void resources_init() { int fd = open("test.cdb", O_RDONLY); cdb_init(&game_cdb, fd); cdb_initf(&corecdb, core_cdb, core_cdb_len); - printf("%s\n", DATA_PATH); } char *get_filename_from_path(char *path, int extension) { @@ -185,12 +183,6 @@ FILE *path_open(const char *tag, const char *fmt, ...) { return f; } -char *make_path(const char *file) { - strncpy(pathbuf, DATA_PATH, MAXPATH); - strncat(pathbuf, file, MAXPATH); - return pathbuf; -} - void *cdb_slurp(struct cdb *cdb, const char *file, size_t *size) { unsigned vlen, vpos; diff --git a/source/engine/resources.h b/source/engine/resources.h index 2067237..4a61b8e 100644 --- a/source/engine/resources.h +++ b/source/engine/resources.h @@ -14,7 +14,6 @@ char *get_directory_from_path(char *path); char *str_replace_ext(const char *s, const char *newext); FILE *res_open(char *path, const char *tag); FILE *path_open(const char *tag, const char *fmt, ...); -char *make_path(const char *file); char **ls(const char *path); int cp(const char *p1, const char *p2); char *rebase_path(const char *path); /* given a global path, rebase to the local structure */ diff --git a/source/engine/yugine.c b/source/engine/yugine.c index 3c6c630..85f54b3 100644 --- a/source/engine/yugine.c +++ b/source/engine/yugine.c @@ -108,8 +108,6 @@ void c_init() { script_evalf("Game.init();"); particle_init(); - - YughWarn("simplex %.17lf", Noise3D(3.14,42,7.001)); } int frame_fps() { return 1.0/sapp_frame_duration(); } @@ -286,7 +284,7 @@ int main(int argc, char **argv) { signal(SIGSEGV, seghandle); signal(SIGABRT, seghandle); signal(SIGFPE, seghandle); - signal(SIGBUS, seghandle); +// signal(SIGBUS, seghandle); #endif