diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2020-09-11 00:48:13 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2020-09-11 01:05:40 -0700 |
commit | 85127285bff6983665275fe14d3c2b80b36a872a (patch) | |
tree | 0215b33ee3b1101b9300d790f15914fa4e2bfcdf /src/modules/sparkler/particle.h | |
parent | a9f489265c1ebbc67a3f675d1a79a2254345b489 (diff) |
module/sparkler: implement some BSP drawing settings
This commit adds a few settings for visualizing the octree BSP:
show_bsp_leafs (on/off):
Draw wireframe cubes around octree leaf nodes
show_bsp_leafs_min_depth (0,4,6,8,10):
Set minimum octree depth for leaf nodes displayed
show_bsp_matches (on/off):
Draw lines connecting BSP search matches
show_bsp_matches_affected_only (on/off):
Limit drawn BSP search matches to only matches actually
affected by the simulation
The code implementing this stuff is a bit crufty, fb_fragment_t
had to be pulled down to the sim ops for example and whether that
actually results in drawing occurring during the sim phase
depends on the config used and how the particle implementations
react to the config... it's just gross. This matters because the
caller used to know only the draw phase touched fb_fragment_t,
and because of that the fragment was zeroed after sim and before
draw in parallel. But now the caller needs to know if the config
would make sim do some drawing, and do the fragment zeroing
before sim instead, and skip the zero before draw to not lose
what sim drew. It's icky, but I'll leave it for now, at least
it's isolated to the sparkler.
Diffstat (limited to 'src/modules/sparkler/particle.h')
-rw-r--r-- | src/modules/sparkler/particle.h | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/modules/sparkler/particle.h b/src/modules/sparkler/particle.h index c63024d..a5999ee 100644 --- a/src/modules/sparkler/particle.h +++ b/src/modules/sparkler/particle.h @@ -22,13 +22,14 @@ typedef enum particle_status_t { typedef struct particle_t particle_t; typedef struct particles_t particles_t; +typedef struct particles_conf_t particles_conf_t; typedef struct particle_ops_t { unsigned context_size; /* size of the particle context (0 for none) */ - int (*init)(particles_t *, particle_t *); /* initialize the particle, called after allocating context (optional) */ - void (*cleanup)(particles_t *, particle_t *); /* cleanup function, called before freeing context (optional) */ - particle_status_t (*sim)(particles_t *, particle_t *); /* simulate the particle for another cycle (required) */ - void (*draw)(particles_t *, particle_t *, int, int, fb_fragment_t *); /* draw the particle, 3d->2d projection has been done already (optional) */ + int (*init)(particles_t *, const particles_conf_t *, particle_t *); /* initialize the particle, called after allocating context (optional) */ + void (*cleanup)(particles_t *, const particles_conf_t *, particle_t *); /* cleanup function, called before freeing context (optional) */ + particle_status_t (*sim)(particles_t *, const particles_conf_t *, particle_t *, fb_fragment_t *); /* simulate the particle for another cycle (required) */ + void (*draw)(particles_t *, const particles_conf_t *, particle_t *, int, int, fb_fragment_t *); /* draw the particle, 3d->2d projection has been done already (optional) */ } particle_ops_t; struct particle_t { @@ -47,34 +48,38 @@ struct particle_t { #define INHERIT_PROPS NULL -static inline int particle_init(particles_t *particles, particle_t *p) { +static inline int particle_init(particles_t *particles, const particles_conf_t *conf, particle_t *p) { if (p->ops->init) { - return p->ops->init(particles, p); + return p->ops->init(particles, conf, p); } return 1; } -static inline void particle_cleanup(particles_t *particles, particle_t *p) { +static inline void particle_cleanup(particles_t *particles, const particles_conf_t *conf, particle_t *p) { if (p->ops->cleanup) { - p->ops->cleanup(particles, p); + p->ops->cleanup(particles, conf, p); } } -static inline particle_status_t particle_sim(particles_t *particles, particle_t *p) { - return p->ops->sim(particles, p); +/* XXX: fragment is supplied to ops->sim() only for debugging/overlay purposes, if particles_conf_t.show_bsp_matches for + * example is true, then sim may draw into fragment, and the callers shouldn't zero the fragment between sim and draw but + * instead should zero it before sim. It's kind of janky, not a fan. + */ +static inline particle_status_t particle_sim(particles_t *particles, const particles_conf_t *conf, particle_t *p, fb_fragment_t *f) { + return p->ops->sim(particles, conf, p, f); } -static inline void particle_draw(particles_t *particles, particle_t *p, int x, int y, fb_fragment_t *f) { +static inline void particle_draw(particles_t *particles, const particles_conf_t *conf, particle_t *p, int x, int y, fb_fragment_t *f) { if (p->ops->draw) { - p->ops->draw(particles, p, x, y, f); + p->ops->draw(particles, conf, p, x, y, f); } } -void particle_convert(particles_t *particles, particle_t *p, particle_props_t *props, particle_ops_t *ops); +void particle_convert(particles_t *particles, const particles_conf_t *conf, particle_t *p, particle_props_t *props, particle_ops_t *ops); #endif |