summaryrefslogtreecommitdiff
path: root/src/modules/sparkler/particles.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@gnugeneration.com>2023-08-30 13:45:07 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-08-30 13:49:54 -0700
commit20d097ab1fe8ef5b62f4169f4353cc0074c27e4b (patch)
tree412f1069b7a3fa3953df02b54302bbdca3ddf6fb /src/modules/sparkler/particles.c
parenta634b2df74222be85a03b1895ee10135822031c3 (diff)
sparkler: parameterize particles
Having everything in fixed defines severely constrains the diversity of particle behaviors and appearances. This commit has been sitting around bitrotting since 2017, but now that there's all this settings infra. and randomizing via rtv, it seems worth landing, so I've rebased and am merging to prevent a bitrot->rebase recurrence. As-is, this commit ~minimally establishes a somewhat streamlined parameterizing mechanism w/X-Macro patterns, while wiring up a few of the obvious use cases surrounding xplode/burst, colorizing the default sparkler explosions while at it. It appears that when I first hacked this up I did some experimentation with parameters as well, so there are some tweaks to the behavior as opposed to a strict conversion of the fixed defines to parameters. They seem minor enough to just leave be. Plus a few minor optimizations like converting divides to multiplies were in there. Future commits can now wire up settings to choose from parameter presets for different sparklers...
Diffstat (limited to 'src/modules/sparkler/particles.c')
-rw-r--r--src/modules/sparkler/particles.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/modules/sparkler/particles.c b/src/modules/sparkler/particles.c
index f6adf13..8fc93a2 100644
--- a/src/modules/sparkler/particles.c
+++ b/src/modules/sparkler/particles.c
@@ -1,4 +1,5 @@
#include <assert.h>
+#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -128,7 +129,7 @@ static void particles_reap_particle(particles_t *particles, _particle_t *particl
/* add a particle to the specified list */
-static inline int _particles_add_particle(particles_t *particles, list_head_t *list, particle_props_t *props, particle_ops_t *ops)
+static inline int _particles_add_particle(particles_t *particles, list_head_t *list, particle_props_t *props, particle_ops_t *ops, unsigned n_params, va_list ap)
{
_particle_t *p;
@@ -158,7 +159,7 @@ static inline int _particles_add_particle(particles_t *particles, list_head_t *l
p->public.ctxt = p->context;
}
- if (!particle_init(particles, &particles->conf, &p->public)) {
+ if (!particle_init(particles, &particles->conf, &p->public, n_params, ap)) {
/* XXX FIXME this shouldn't be normal, we don't want to allocate
* particles that cannot be initialized. the rockets today set a cap
* by failing initialization, that's silly. */
@@ -175,36 +176,49 @@ static inline int _particles_add_particle(particles_t *particles, list_head_t *l
/* add a new "top-level" particle of the specified props and ops taking from the provided parts list */
-int particles_add_particle(particles_t *particles, particle_props_t *props, particle_ops_t *ops)
+int particles_add_particle(particles_t *particles, particle_props_t *props, particle_ops_t *ops, unsigned n_params, ...)
{
+ int ret;
+ va_list ap;
+
assert(particles);
- return _particles_add_particle(particles, &particles->active, props, ops);
+ va_start(ap, n_params);
+ ret = _particles_add_particle(particles, &particles->active, props, ops, n_params, ap);
+ va_end(ap);
+
+ return ret;
}
/* spawn a new child particle from a parent, initializing it via inheritance if desired */
-void particles_spawn_particle(particles_t *particles, particle_t *parent, particle_props_t *props, particle_ops_t *ops)
+void particles_spawn_particle(particles_t *particles, particle_t *parent, particle_props_t *props, particle_ops_t *ops, unsigned n_params, ...)
{
+ va_list ap;
_particle_t *p = container_of(parent, _particle_t, public);
assert(particles);
assert(parent);
- _particles_add_particle(particles, &p->children, props ? props : parent->props, ops ? ops : parent->ops);
+ va_start(ap, n_params);
+ _particles_add_particle(particles, &p->children, props ? props : parent->props, ops ? ops : parent->ops, n_params, ap);
+ va_end(ap);
}
/* plural version of particle_add(); adds multiple "top-level" particles of uniform props and ops */
-void particles_add_particles(particles_t *particles, particle_props_t *props, particle_ops_t *ops, int num)
+void particles_add_particles(particles_t *particles, particle_props_t *props, particle_ops_t *ops, unsigned num, unsigned n_params, ...)
{
+ va_list ap;
int i;
assert(particles);
+ va_start(ap, n_params);
for (i = 0; i < num; i++) {
- _particles_add_particle(particles, &particles->active, props, ops);
+ _particles_add_particle(particles, &particles->active, props, ops, n_params, ap);
}
+ va_end(ap);
}
© All Rights Reserved