particle fix

This commit is contained in:
John Alanbrook 2024-01-03 14:38:17 +00:00
parent dbf4b668bb
commit 4a4711e38f
8 changed files with 23 additions and 23 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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 */

View file

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