diff options
Diffstat (limited to 'src/modules/sparkler/xplode.c')
-rw-r--r-- | src/modules/sparkler/xplode.c | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/src/modules/sparkler/xplode.c b/src/modules/sparkler/xplode.c index 1534369..bf50a10 100644 --- a/src/modules/sparkler/xplode.c +++ b/src/modules/sparkler/xplode.c @@ -1,3 +1,4 @@ +#include <stdarg.h> #include <stdlib.h> #include "til_fb.h" @@ -5,31 +6,38 @@ #include "helpers.h" #include "particle.h" #include "particles.h" +#include "xplode.h" -/* a "xplode" particle type, emitted by rockets in large numbers at the end of their lifetime */ -#define XPLODE_MAX_DECAY_RATE 10 -#define XPLODE_MIN_DECAY_RATE 5 -#define XPLODE_MAX_LIFETIME 150 -#define XPLODE_MIN_LIFETIME 5 +/* a "xplode" particle type, emitted by rockets in large numbers at the end of their duration */ extern particle_ops_t spark_ops; particle_ops_t xplode_ops; typedef struct _xplode_ctxt_t { - int decay_rate; - int longevity; - int lifetime; +#define PARAMS_DECLARE_STRUCT +#include "xplode_params.def" + int remaining; } xplode_ctxt_t; -static int xplode_init(particles_t *particles, const particles_conf_t *conf, particle_t *p) +static int xplode_init(particles_t *particles, const particles_conf_t *conf, particle_t *p, unsigned n_params, va_list params) { xplode_ctxt_t *ctxt = p->ctxt; - ctxt->decay_rate = rand_within_range(conf->seedp, XPLODE_MIN_DECAY_RATE, XPLODE_MAX_DECAY_RATE); - ctxt->lifetime = ctxt->longevity = rand_within_range(conf->seedp, XPLODE_MIN_LIFETIME, XPLODE_MAX_LIFETIME); +#define PARAMS_ASSIGN_DEFAULTS +#include "xplode_params.def" - p->props->drag = 10.9; + for (; n_params; n_params--) { + switch (va_arg(params, xplode_param_t)) { +#define PARAMS_IMPLEMENT_SWITCH +#include "xplode_params.def" + default: + return 0; + } + } + + ctxt->remaining = ctxt->duration; + p->props->drag = 10.5; p->props->mass = 0.3; p->props->virtual = 0; @@ -41,17 +49,17 @@ static particle_status_t xplode_sim(particles_t *particles, const particles_conf { xplode_ctxt_t *ctxt = p->ctxt; - if (!ctxt->longevity || (ctxt->longevity -= ctxt->decay_rate) <= 0) { - ctxt->longevity = 0; + if (!ctxt->remaining || (ctxt->remaining -= ctxt->decay_rate) <= 0) { + ctxt->remaining = 0; return PARTICLE_DEAD; } /* litter some small sparks behind the explosion particle */ - if (!(ctxt->lifetime % 30)) { + if (!(ctxt->duration % 30)) { particle_props_t props = *p->props; - props.velocity = (float)rand_within_range(conf->seedp, 10, 50) / 10000.0; - particles_spawn_particle(particles, p, &props, &xplode_ops); + props.velocity = (float)rand_within_range(conf->seedp, 10, 50) * .0001; + particles_spawn_particle(particles, p, &props, &xplode_ops, 1, XPLODE_PARAM_COLOR_UINT, ctxt->color); } return PARTICLE_ALIVE; @@ -63,13 +71,14 @@ static void xplode_draw(particles_t *particles, const particles_conf_t *conf, pa xplode_ctxt_t *ctxt = p->ctxt; uint32_t color; - if (!should_draw_expire_if_oob(particles, p, x, y, f, &ctxt->longevity)) + if (!should_draw_expire_if_oob(particles, p, x, y, f, &ctxt->remaining)) return; - if (ctxt->longevity == ctxt->lifetime) { + if (ctxt->remaining == ctxt->duration) { + /* always start with a white flash */ color = makergb(0xff, 0xff, 0xa0, 1.0); } else { - color = makergb(0xff, 0xff, 0x00, ((float)ctxt->longevity / ctxt->lifetime)); + color = makergb((ctxt->color & 0xff0000) >> 16, (ctxt->color & 0xff00) >> 8, ctxt->color & 0xff, ((float)ctxt->remaining / ctxt->duration)); } til_fb_fragment_put_pixel_unchecked(f, 0, x, y, color); |