From 942131dc41905ee14b6bfbc3182282c73694be4d Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Wed, 13 Dec 2023 19:20:47 -0800 Subject: modules/flow: trivial optimization Small micro optimization avoiding bounds check for respawned elements, plus comment fixup. --- src/modules/flow/flow.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/modules/flow/flow.c b/src/modules/flow/flow.c index 34159e3..c9b94e4 100644 --- a/src/modules/flow/flow.c +++ b/src/modules/flow/flow.c @@ -236,10 +236,8 @@ static void flow_render_fragment(til_module_context_t *context, til_stream_t *st ff_data_t d; e->lifetime -= .1f; - if (e->lifetime <= 0.0f) - *e = rand_element(&ctxt->til_module_context.seed); - - if (e->position_b.x < -1.f || e->position_b.x > 1.f || + if (e->lifetime <= 0.0f || + e->position_b.x < -1.f || e->position_b.x > 1.f || e->position_b.y < -1.f || e->position_b.y > 1.f || e->position_b.z < 0.f || e->position_b.z > 1.f) *e = rand_element(&ctxt->til_module_context.seed); @@ -259,7 +257,7 @@ static void flow_render_fragment(til_module_context_t *context, til_stream_t *st /* Compute the final position now for the next go-round. * The second pass can't just write it back willy-nilly while racing with others, * despite doing the same thing iteratively as it draws n_iters pixels. Hence - * this position_b becomes position_a situation above. + * the position_b becomes position_a situation above. */ d.direction = v3f_mult_scalar(&d.direction, (float)ctxt->n_iters); e->position_b = v3f_add(&pos, &d.direction); -- cgit v1.2.1