diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2022-07-17 22:52:00 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2022-07-18 01:06:05 -0700 |
commit | af21b876efde47274a36d8a13d2c7503034227d0 (patch) | |
tree | 131358787058f953270fa388cc46e77389e9ddfd /src/modules/compose | |
parent | 209b11f99c801141b79802cd6c23a2b568286f75 (diff) |
til: wire seed up to til randomizers
til_setting_desc_t.random() and til_module_randomize_setup() now
take seeds.
Note they are not taking a pointer to a shared seed, but instead
receive the seed by value.
If a caller wishes the seed to evolve on every invocation into
these functions, it should simply insert a rand_r(&seed) in
producing the supplied seed value.
Within a given randomizer, the seed evolves when appropriate.
But isolating the effects by default seems appropriate, so
callers can easily have determinism within their respective scope
regardless of how much nested random use occurs.
Diffstat (limited to 'src/modules/compose')
-rw-r--r-- | src/modules/compose/compose.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/modules/compose/compose.c b/src/modules/compose/compose.c index bd34405..ed0ed1c 100644 --- a/src/modules/compose/compose.c +++ b/src/modules/compose/compose.c @@ -86,7 +86,7 @@ static til_module_context_t * compose_create_context(unsigned seed, unsigned tic til_setup_t *layer_setup = NULL; layer_module = til_lookup_module(((compose_setup_t *)setup)->layers[i]); - (void) til_module_randomize_setup(layer_module, &layer_setup, NULL); + (void) til_module_randomize_setup(layer_module, rand_r(&seed), &layer_setup, NULL); ctxt->layers[i].module = layer_module; (void) til_module_create_context(layer_module, rand_r(&seed), ticks, 0, layer_setup, &ctxt->layers[i].module_ctxt); @@ -99,7 +99,7 @@ static til_module_context_t * compose_create_context(unsigned seed, unsigned tic til_setup_t *texture_setup = NULL; ctxt->texture.module = til_lookup_module(((compose_setup_t *)setup)->texture); - (void) til_module_randomize_setup(ctxt->texture.module, &texture_setup, NULL); + (void) til_module_randomize_setup(ctxt->texture.module, rand_r(&seed), &texture_setup, NULL); (void) til_module_create_context(ctxt->texture.module, rand_r(&seed), ticks, 0, texture_setup, &ctxt->texture.module_ctxt); til_setup_free(texture_setup); @@ -165,7 +165,7 @@ static void compose_prepare_frame(til_module_context_t *context, unsigned ticks, /* return a randomized valid layers= setting */ -static char * compose_random_layers_setting(void) +static char * compose_random_layers_setting(unsigned seed) { size_t n_modules, n_rand_overlays, n_overlayable = 0, base_idx; char *layers = NULL; @@ -178,7 +178,7 @@ static char * compose_random_layers_setting(void) n_overlayable++; } - base_idx = rand() % (n_modules - n_overlayable); + base_idx = rand_r(&seed) % (n_modules - n_overlayable); for (size_t i = 0, j = 0; !layers && i < n_modules; i++) { if (modules[i]->flags & TIL_MODULE_OVERLAYABLE) continue; @@ -192,9 +192,9 @@ static char * compose_random_layers_setting(void) * sometimes interesting. Maybe another module flag is necessary for indicating * manifold-appropriate overlays. */ - n_rand_overlays = 1 + (rand() % (n_overlayable - 1)); + n_rand_overlays = 1 + (rand_r(&seed) % (n_overlayable - 1)); for (size_t n = 0; n < n_rand_overlays; n++) { - size_t rand_idx = rand() % n_overlayable; + size_t rand_idx = rand_r(&seed) % n_overlayable; for (size_t i = 0, j = 0; i < n_modules; i++) { if (!(modules[i]->flags & TIL_MODULE_OVERLAYABLE)) |