From b38db01c835fa222aa11ace3a2d84095fe2c3f83 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Wed, 20 Jul 2022 21:06:31 -0700 Subject: modules/sparkler: s/rand/rand_r/ and wire up seed This is a little contorted but not too bad. The input to particles_new() is just a const conf struct, so instead of passing in the seed value for particles_t to contain, a pointer to where the seed lives is passed in via the conf. This requires the caller to persist a seed somewhere outside the particles instance, but at least in rototiller we already have that conveniently in til_module_context_t. --- src/modules/sparkler/simple.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/modules/sparkler/simple.c') diff --git a/src/modules/sparkler/simple.c b/src/modules/sparkler/simple.c index 78e415b..3bc3076 100644 --- a/src/modules/sparkler/simple.c +++ b/src/modules/sparkler/simple.c @@ -28,8 +28,8 @@ static int simple_init(particles_t *particles, const particles_conf_t *conf, par { simple_ctxt_t *ctxt = p->ctxt; - ctxt->decay_rate = rand_within_range(SIMPLE_MIN_DECAY_RATE, SIMPLE_MAX_DECAY_RATE); - ctxt->lifetime = ctxt->longevity = rand_within_range(SIMPLE_MIN_LIFETIME, SIMPLE_MAX_LIFETIME); + ctxt->decay_rate = rand_within_range(conf->seedp, SIMPLE_MIN_DECAY_RATE, SIMPLE_MAX_DECAY_RATE); + ctxt->lifetime = ctxt->longevity = rand_within_range(conf->seedp, SIMPLE_MIN_LIFETIME, SIMPLE_MAX_LIFETIME); if (!p->props->of_use) { /* everything starts from the bottom center */ @@ -38,12 +38,12 @@ static int simple_init(particles_t *particles, const particles_conf_t *conf, par p->props->position.z = 0; /* TODO: direction random-ish within the range of a narrow upward facing cone */ - p->props->direction.x = (float)(rand_within_range(0, 6) - 3) * .1f; - p->props->direction.y = 1.0f + (float)(rand_within_range(0, 6) - 3) * .1f; - p->props->direction.z = (float)(rand_within_range(0, 6) - 3) * .1f; + p->props->direction.x = (float)(rand_within_range(conf->seedp, 0, 6) - 3) * .1f; + p->props->direction.y = 1.0f + (float)(rand_within_range(conf->seedp, 0, 6) - 3) * .1f; + p->props->direction.z = (float)(rand_within_range(conf->seedp, 0, 6) - 3) * .1f; p->props->direction = v3f_normalize(&p->props->direction); - p->props->velocity = (float)rand_within_range(300, 800) / 100000.0; + p->props->velocity = (float)rand_within_range(conf->seedp, 300, 800) / 100000.0; p->props->drag = 0.03; p->props->mass = 0.3; @@ -70,7 +70,7 @@ static particle_status_t simple_sim(particles_t *particles, const particles_conf /* create particles inheriting our type based on some silly conditions, with some tweaks to their direction */ if (ctxt->longevity == 42 || (ctxt->longevity > 500 && !(ctxt->longevity % 50))) { - int i, num = rand_within_range(SIMPLE_MIN_SPAWN, SIMPLE_MAX_SPAWN); + int i, num = rand_within_range(conf->seedp, SIMPLE_MIN_SPAWN, SIMPLE_MAX_SPAWN); for (i = 0; i < num; i++) { particle_props_t props = *p->props; @@ -78,14 +78,14 @@ static particle_status_t simple_sim(particles_t *particles, const particles_conf if (i == (SIMPLE_MAX_SPAWN - 2)) { ops = &rocket_ops; - props.velocity = (float)rand_within_range(60, 100) / 1000000.0; + props.velocity = (float)rand_within_range(conf->seedp, 60, 100) / 1000000.0; } else { - props.velocity = (float)rand_within_range(30, 100) / 10000.0; + props.velocity = (float)rand_within_range(conf->seedp, 30, 100) / 10000.0; } - props.direction.x += (float)(rand_within_range(0, 315 * 2) - 315) / 100.0; - props.direction.y += (float)(rand_within_range(0, 315 * 2) - 315) / 100.0; - props.direction.z += (float)(rand_within_range(0, 315 * 2) - 315) / 100.0; + props.direction.x += (float)(rand_within_range(conf->seedp, 0, 315 * 2) - 315) / 100.0; + props.direction.y += (float)(rand_within_range(conf->seedp, 0, 315 * 2) - 315) / 100.0; + props.direction.z += (float)(rand_within_range(conf->seedp, 0, 315 * 2) - 315) / 100.0; props.direction = v3f_normalize(&props.direction); particles_spawn_particle(particles, p, &props, ops); // XXX -- cgit v1.2.1