particle fix
This commit is contained in:
parent
dbf4b668bb
commit
4a4711e38f
4
Makefile
4
Makefile
|
@ -138,9 +138,9 @@ else
|
||||||
ifeq ($(UNAME), Darwin)
|
ifeq ($(UNAME), Darwin)
|
||||||
OS := macos
|
OS := macos
|
||||||
CPPFLAGS += -arch $(ARCH)
|
CPPFLAGS += -arch $(ARCH)
|
||||||
CFLAGS += -x objective-c
|
CFLAGS += -x objective-c# -fopenmp=libomp
|
||||||
CXXFLAGS += -std=c++11
|
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
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
|
@ -625,9 +625,9 @@ static cpBool handle_collision(cpArbiter *arb, int type) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CTYPE_SEP:
|
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);
|
duk_call_phys_cb(norm1, go->cbs.separate, go2, arb);
|
||||||
|
*/
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -189,12 +189,19 @@ void rm_body_shapes(cpBody *body, cpShape *shape, void *data) {
|
||||||
cpShapeFree(shape);
|
cpShapeFree(shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void rm_body_constraints(cpBody *body, cpConstraint *constraint, void *data)
|
||||||
|
{
|
||||||
|
cpSpaceRemoveConstraint(space, constraint);
|
||||||
|
cpConstraintFree(constraint);
|
||||||
|
}
|
||||||
|
|
||||||
gameobject **go_toclean = NULL;
|
gameobject **go_toclean = NULL;
|
||||||
|
|
||||||
/* Free this gameobject */
|
/* Free this gameobject */
|
||||||
void gameobject_clean(gameobject *go) {
|
void gameobject_clean(gameobject *go) {
|
||||||
arrfree(go->shape_cbs);
|
arrfree(go->shape_cbs);
|
||||||
cpBodyEachShape(go->body, rm_body_shapes, NULL);
|
cpBodyEachShape(go->body, rm_body_shapes, NULL);
|
||||||
|
cpBodyEachConstraint(go->body, rm_body_constraints, NULL);
|
||||||
cpSpaceRemoveBody(space, go->body);
|
cpSpaceRemoveBody(space, go->body);
|
||||||
cpBodyFree(go->body);
|
cpBodyFree(go->body);
|
||||||
go->body = NULL;
|
go->body = NULL;
|
||||||
|
|
|
@ -186,13 +186,12 @@ void register_gamepad(struct callee c) {
|
||||||
|
|
||||||
void input_dropped_files(int n)
|
void input_dropped_files(int n)
|
||||||
{
|
{
|
||||||
|
|
||||||
JSValue argv[4];
|
JSValue argv[4];
|
||||||
argv[0] = jstr("emacs");
|
argv[0] = jstr("emacs");
|
||||||
argv[1] = jstr("drop");
|
argv[1] = jstr("drop");
|
||||||
argv[2] = jstr("pressed");
|
argv[2] = jstr("pressed");
|
||||||
char *path = rebase_path(sapp_get_dropped_file_path(0));
|
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);
|
script_callee(pawn_callee, 4, argv);
|
||||||
JS_FreeValue(js,argv[3]);
|
JS_FreeValue(js,argv[3]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "2dphysics.h"
|
#include "2dphysics.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "simplex.h"
|
#include "simplex.h"
|
||||||
|
#include "pthread.h"
|
||||||
|
|
||||||
static emitter **emitters;
|
static emitter **emitters;
|
||||||
|
|
||||||
|
@ -13,7 +14,7 @@ static sg_pipeline par_pipe;
|
||||||
static sg_bindings par_bind;
|
static sg_bindings par_bind;
|
||||||
static int draw_count;
|
static int draw_count;
|
||||||
|
|
||||||
#define MAX_PARTICLES 500000
|
#define MAX_PARTICLES 1000000
|
||||||
|
|
||||||
struct par_vert {
|
struct par_vert {
|
||||||
HMM_Vec2 pos;
|
HMM_Vec2 pos;
|
||||||
|
@ -145,6 +146,8 @@ void emitters_draw()
|
||||||
for (int i = 0; i < arrlen(emitters); i++) {
|
for (int i = 0; i < arrlen(emitters); i++) {
|
||||||
emitter *e = emitters[i];
|
emitter *e = emitters[i];
|
||||||
par_bind.fs.images[0] = e->texture->id;
|
par_bind.fs.images[0] = e->texture->id;
|
||||||
|
|
||||||
|
#pragma omp parallel for
|
||||||
for (int j = 0; j < arrlen(e->particles); j++) {
|
for (int j = 0; j < arrlen(e->particles); j++) {
|
||||||
particle *p = &e->particles[j];
|
particle *p = &e->particles[j];
|
||||||
pv[j].pos = p->pos.xy;
|
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].scale = HMM_ScaleV2(tex_get_dimensions(e->texture), p->scale);
|
||||||
pv[j].color = vec2rgba(p->color);
|
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)});
|
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);
|
draw_count += arrlen(e->particles);
|
||||||
}
|
}
|
||||||
|
@ -163,6 +167,7 @@ void emitters_draw()
|
||||||
}
|
}
|
||||||
|
|
||||||
void emitter_step(emitter *e, double dt) {
|
void emitter_step(emitter *e, double dt) {
|
||||||
|
#pragma omp parallel for
|
||||||
for (int i = arrlen(e->particles)-1; i >= 0; i--) {
|
for (int i = arrlen(e->particles)-1; i >= 0; i--) {
|
||||||
particle p = e->particles[i];
|
particle p = e->particles[i];
|
||||||
if (e->gravity)
|
if (e->gravity)
|
||||||
|
@ -179,11 +184,11 @@ void emitter_step(emitter *e, double dt) {
|
||||||
p.scale = e->scale;
|
p.scale = e->scale;
|
||||||
e->particles[i] = p;
|
e->particles[i] = p;
|
||||||
|
|
||||||
if (p.life <= 0)
|
// if (p.life <= 0)
|
||||||
arrdelswap(e->particles,i);
|
// arrdelswap(e->particles,i);
|
||||||
|
|
||||||
if (query_point(p.pos.xy))
|
// if (query_point(p.pos.xy))
|
||||||
arrdelswap(e->particles,i);
|
// arrdelswap(e->particles,i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!e->on) return;
|
if (!e->on) return;
|
||||||
|
|
|
@ -43,7 +43,6 @@ static struct cdb game_cdb;
|
||||||
void resources_init() {
|
void resources_init() {
|
||||||
DATA_PATH = malloc(MAXPATH);
|
DATA_PATH = malloc(MAXPATH);
|
||||||
getcwd(DATA_PATH, MAXPATH);
|
getcwd(DATA_PATH, MAXPATH);
|
||||||
strncat(DATA_PATH, "/", MAXPATH);
|
|
||||||
|
|
||||||
if (!PREF_PATH)
|
if (!PREF_PATH)
|
||||||
PREF_PATH = strdup("./tmp/");
|
PREF_PATH = strdup("./tmp/");
|
||||||
|
@ -51,7 +50,6 @@ void resources_init() {
|
||||||
int fd = open("test.cdb", O_RDONLY);
|
int fd = open("test.cdb", O_RDONLY);
|
||||||
cdb_init(&game_cdb, fd);
|
cdb_init(&game_cdb, fd);
|
||||||
cdb_initf(&corecdb, core_cdb, core_cdb_len);
|
cdb_initf(&corecdb, core_cdb, core_cdb_len);
|
||||||
printf("%s\n", DATA_PATH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *get_filename_from_path(char *path, int extension) {
|
char *get_filename_from_path(char *path, int extension) {
|
||||||
|
@ -185,12 +183,6 @@ FILE *path_open(const char *tag, const char *fmt, ...) {
|
||||||
return f;
|
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)
|
void *cdb_slurp(struct cdb *cdb, const char *file, size_t *size)
|
||||||
{
|
{
|
||||||
unsigned vlen, vpos;
|
unsigned vlen, vpos;
|
||||||
|
|
|
@ -14,7 +14,6 @@ char *get_directory_from_path(char *path);
|
||||||
char *str_replace_ext(const char *s, const char *newext);
|
char *str_replace_ext(const char *s, const char *newext);
|
||||||
FILE *res_open(char *path, const char *tag);
|
FILE *res_open(char *path, const char *tag);
|
||||||
FILE *path_open(const char *tag, const char *fmt, ...);
|
FILE *path_open(const char *tag, const char *fmt, ...);
|
||||||
char *make_path(const char *file);
|
|
||||||
char **ls(const char *path);
|
char **ls(const char *path);
|
||||||
int cp(const char *p1, const char *p2);
|
int cp(const char *p1, const char *p2);
|
||||||
char *rebase_path(const char *path); /* given a global path, rebase to the local structure */
|
char *rebase_path(const char *path); /* given a global path, rebase to the local structure */
|
||||||
|
|
|
@ -108,8 +108,6 @@ void c_init() {
|
||||||
script_evalf("Game.init();");
|
script_evalf("Game.init();");
|
||||||
|
|
||||||
particle_init();
|
particle_init();
|
||||||
|
|
||||||
YughWarn("simplex %.17lf", Noise3D(3.14,42,7.001));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int frame_fps() { return 1.0/sapp_frame_duration(); }
|
int frame_fps() { return 1.0/sapp_frame_duration(); }
|
||||||
|
@ -286,7 +284,7 @@ int main(int argc, char **argv) {
|
||||||
signal(SIGSEGV, seghandle);
|
signal(SIGSEGV, seghandle);
|
||||||
signal(SIGABRT, seghandle);
|
signal(SIGABRT, seghandle);
|
||||||
signal(SIGFPE, seghandle);
|
signal(SIGFPE, seghandle);
|
||||||
signal(SIGBUS, seghandle);
|
// signal(SIGBUS, seghandle);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue