diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/modules/drizzle/drizzle.c | 18 | ||||
-rw-r--r-- | src/modules/flui2d/flui2d.c | 24 | ||||
-rw-r--r-- | src/modules/meta2d/meta2d.c | 18 | ||||
-rw-r--r-- | src/modules/plato/plato.c | 14 | ||||
-rw-r--r-- | src/modules/stars/stars.c | 61 |
5 files changed, 87 insertions, 48 deletions
diff --git a/src/modules/drizzle/drizzle.c b/src/modules/drizzle/drizzle.c index 9ca58f7..54ca204 100644 --- a/src/modules/drizzle/drizzle.c +++ b/src/modules/drizzle/drizzle.c @@ -91,6 +91,16 @@ static inline uint32_t color_to_uint32(v3f_t color) { } +static void drizzle_update_taps(drizzle_context_t *ctxt, til_stream_t *stream, unsigned ticks) +{ + if (!til_stream_tap_context(stream, &ctxt->til_module_context, NULL, &ctxt->taps.viscosity)) + *ctxt->viscosity = ctxt->setup->viscosity; + + if (!til_stream_tap_context(stream, &ctxt->til_module_context, NULL, &ctxt->taps.rainfall)) + *ctxt->rainfall = RAINFALL_CNT; +} + + static til_module_context_t * drizzle_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { drizzle_context_t *ctxt; @@ -110,6 +120,8 @@ static til_module_context_t * drizzle_create_context(const til_module_t *module, ctxt->setup = (drizzle_setup_t *)setup; + drizzle_update_taps(ctxt, stream, ticks); + return &ctxt->til_module_context; } @@ -127,11 +139,7 @@ static void drizzle_prepare_frame(til_module_context_t *context, til_stream_t *s { drizzle_context_t *ctxt = (drizzle_context_t *)context; - if (!til_stream_tap_context(stream, context, NULL, &ctxt->taps.viscosity)) - *ctxt->viscosity = ctxt->setup->viscosity; - - if (!til_stream_tap_context(stream, context, NULL, &ctxt->taps.rainfall)) - *ctxt->rainfall = RAINFALL_CNT; + drizzle_update_taps(ctxt, stream, ticks); *res_frame_plan = (til_frame_plan_t){ .fragmenter = til_fragmenter_slice_per_cpu_x16 }; diff --git a/src/modules/flui2d/flui2d.c b/src/modules/flui2d/flui2d.c index bfa36fb..40307a2 100644 --- a/src/modules/flui2d/flui2d.c +++ b/src/modules/flui2d/flui2d.c @@ -249,6 +249,19 @@ static void gamma_init(float gamma) } +static void flui2d_update_taps(flui2d_context_t *ctxt, til_stream_t *stream, unsigned ticks) +{ + if (!til_stream_tap_context(stream, &ctxt->til_module_context, NULL, &ctxt->taps.viscosity)) + *ctxt->viscosity = ctxt->setup->viscosity; + + if (!til_stream_tap_context(stream, &ctxt->til_module_context, NULL, &ctxt->taps.diffusion)) + *ctxt->diffusion = ctxt->setup->diffusion; + + if (!til_stream_tap_context(stream, &ctxt->til_module_context, NULL, &ctxt->taps.decay)) + *ctxt->decay = ctxt->setup->decay; +} + + static til_module_context_t * flui2d_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { static int initialized; @@ -269,6 +282,8 @@ static til_module_context_t * flui2d_create_context(const til_module_t *module, ctxt->taps.diffusion = til_tap_init_float(ctxt, &ctxt->diffusion, 1, &ctxt->vars.diffusion, "diffusion"); ctxt->taps.decay = til_tap_init_float(ctxt, &ctxt->decay, 1, &ctxt->vars.decay, "decay"); + flui2d_update_taps(ctxt, stream, ticks); + return &ctxt->til_module_context; } @@ -283,14 +298,7 @@ static void flui2d_prepare_frame(til_module_context_t *context, til_stream_t *st *res_frame_plan = (til_frame_plan_t){ .fragmenter = til_fragmenter_tile64 }; - if (!til_stream_tap_context(stream, context, NULL, &ctxt->taps.viscosity)) - *ctxt->viscosity = ctxt->setup->viscosity; - - if (!til_stream_tap_context(stream, context, NULL, &ctxt->taps.diffusion)) - *ctxt->diffusion = ctxt->setup->diffusion; - - if (!til_stream_tap_context(stream, context, NULL, &ctxt->taps.decay)) - *ctxt->decay = ctxt->setup->decay; + flui2d_update_taps(ctxt, stream, ticks); /* this duplication of visc/diff/decay is silly, it's just a product of this * module being written as a flui2d_t class in-situ but distinct from the module. diff --git a/src/modules/meta2d/meta2d.c b/src/modules/meta2d/meta2d.c index 0cf7101..ee3b952 100644 --- a/src/modules/meta2d/meta2d.c +++ b/src/modules/meta2d/meta2d.c @@ -80,6 +80,16 @@ static inline uint32_t color_to_uint32(v3f_t color) { } +static void meta2d_update_taps(meta2d_context_t *ctxt, til_stream_t *stream, unsigned ticks) +{ + if (!til_stream_tap_context(stream, &ctxt->til_module_context, NULL, &ctxt->taps.min_t)) + *ctxt->min_t = .7f; + + if (!til_stream_tap_context(stream, &ctxt->til_module_context, NULL, &ctxt->taps.max_t)) + *ctxt->max_t = .8f; +} + + static til_module_context_t * meta2d_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { meta2d_context_t *ctxt; @@ -103,6 +113,8 @@ static til_module_context_t * meta2d_create_context(const til_module_t *module, ctxt->taps.min_t = til_tap_init_float(ctxt, &ctxt->min_t, 1, &ctxt->vars.min_t, "min_t"); ctxt->taps.max_t = til_tap_init_float(ctxt, &ctxt->max_t, 1, &ctxt->vars.max_t, "max_t"); + meta2d_update_taps(ctxt, stream, ticks); + return &ctxt->til_module_context; } @@ -123,11 +135,7 @@ static void meta2d_prepare_frame(til_module_context_t *context, til_stream_t *st *res_frame_plan = (til_frame_plan_t){ .fragmenter = til_fragmenter_slice_per_cpu_x16 }; - if (!til_stream_tap_context(stream, context, NULL, &ctxt->taps.min_t)) - *ctxt->min_t = .7f; - - if (!til_stream_tap_context(stream, context, NULL, &ctxt->taps.max_t)) - *ctxt->max_t = .8f; + meta2d_update_taps(ctxt, stream, ticks); /* move the balls around */ for (int i = 0; i < META2D_NUM_BALLS; i++) { diff --git a/src/modules/plato/plato.c b/src/modules/plato/plato.c index 89661c3..617d882 100644 --- a/src/modules/plato/plato.c +++ b/src/modules/plato/plato.c @@ -632,6 +632,14 @@ static void draw_polyhedron(const polyhedron_t *polyhedron, m4f_t *transform, ti } +static void plato_update_taps(plato_context_t *ctxt, til_stream_t *stream, unsigned ticks) +{ + /* since we don't automate the rates ourselves, we don't care about the tap return values */ + (void) til_stream_tap_context(stream, &ctxt->til_module_context, NULL, &ctxt->taps.orbit_rate); + (void) til_stream_tap_context(stream, &ctxt->til_module_context, NULL, &ctxt->taps.spin_rate); +} + + static til_module_context_t * plato_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { plato_context_t *ctxt; @@ -645,6 +653,8 @@ static til_module_context_t * plato_create_context(const til_module_t *module, t ctxt->taps.spin_rate = til_tap_init_float(ctxt, &ctxt->spin_rate, 1, &ctxt->setup.spin_rate, "spin_rate"); ctxt->taps.orbit_rate = til_tap_init_float(ctxt, &ctxt->orbit_rate, 1, &ctxt->setup.orbit_rate, "orbit_rate"); + plato_update_taps(ctxt, stream, ticks); + return &ctxt->til_module_context; } @@ -654,9 +664,7 @@ static void plato_render_fragment(til_module_context_t *context, til_stream_t *s plato_context_t *ctxt = (plato_context_t *)context; til_fb_fragment_t *fragment = *fragment_ptr; - /* since we don't automate the rates ourselves, we don't care about the tap return values */ - (void) til_stream_tap_context(stream, context, NULL, &ctxt->taps.orbit_rate); - (void) til_stream_tap_context(stream, context, NULL, &ctxt->taps.spin_rate); + plato_update_taps(ctxt, stream, ticks); ctxt->r += (float)(ticks - context->last_ticks) * (*ctxt->orbit_rate * .001f); ctxt->rr += (float)(ticks - context->last_ticks) * (*ctxt->spin_rate * .001f); diff --git a/src/modules/stars/stars.c b/src/modules/stars/stars.c index fff6792..bff3d8f 100644 --- a/src/modules/stars/stars.c +++ b/src/modules/stars/stars.c @@ -66,6 +66,36 @@ float get_random_unit_coord(unsigned *seed) { } +static void stars_update_taps(stars_context_t *ctxt, til_stream_t *stream, float dt) +{ + if (!til_stream_tap_context(stream, &ctxt->til_module_context, NULL, &ctxt->taps.rot_angle)) + *ctxt->rot_angle += (*ctxt->rot_rate * dt); + + if (!til_stream_tap_context(stream, &ctxt->til_module_context, NULL, &ctxt->taps.rot_rate)) { + // handle rotation parameters + if(*ctxt->rot_angle>M_PI_4) + *ctxt->rot_rate = *ctxt->rot_rate - (ctxt->rot_adj * dt); + else + *ctxt->rot_rate = *ctxt->rot_rate + (ctxt->rot_adj * dt); + } + + /* there's no automation of offset_angle */ + (void) til_stream_tap_context(stream, &ctxt->til_module_context, NULL, &ctxt->taps.offset_angle); + + // handle offset parameters + if (!til_stream_tap_context(stream, &ctxt->til_module_context, NULL, &ctxt->taps.offset_x)) { + float tmp_x = (*ctxt->offset_x*cosf(*ctxt->offset_angle * dt))- + (*ctxt->offset_y*sinf(*ctxt->offset_angle * dt)); + *ctxt->offset_x = tmp_x; + } + + if (!til_stream_tap_context(stream, &ctxt->til_module_context, NULL, &ctxt->taps.offset_y)) { + float tmp_y = (*ctxt->offset_x*sinf(*ctxt->offset_angle * dt))+ + (*ctxt->offset_y*cosf(*ctxt->offset_angle * dt)); + *ctxt->offset_y = tmp_y; + } +} + static til_module_context_t * stars_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { stars_context_t *ctxt; @@ -101,6 +131,9 @@ static til_module_context_t * stars_create_context(const til_module_t *module, t ctxt->points = p_ptr; } } + + stars_update_taps(ctxt, stream, 0.f); + return &ctxt->til_module_context; } @@ -218,33 +251,7 @@ static void stars_render_fragment(til_module_context_t *context, til_stream_t *s ctxt->points = tmp_ptr; } - if (!til_stream_tap_context(stream, context, NULL, &ctxt->taps.rot_angle)) - *ctxt->rot_angle += (*ctxt->rot_rate * dt); - - if (!til_stream_tap_context(stream, context, NULL, &ctxt->taps.rot_rate)) { - // handle rotation parameters - if(*ctxt->rot_angle>M_PI_4) - *ctxt->rot_rate = *ctxt->rot_rate - (ctxt->rot_adj * dt); - else - *ctxt->rot_rate = *ctxt->rot_rate + (ctxt->rot_adj * dt); - } - - /* there's no automation of offset_angle */ - (void) til_stream_tap_context(stream, context, NULL, &ctxt->taps.offset_angle); - - // handle offset parameters - if (!til_stream_tap_context(stream, context, NULL, &ctxt->taps.offset_x)) { - float tmp_x = (*ctxt->offset_x*cosf(*ctxt->offset_angle * dt))- - (*ctxt->offset_y*sinf(*ctxt->offset_angle * dt)); - *ctxt->offset_x = tmp_x; - } - - if (!til_stream_tap_context(stream, context, NULL, &ctxt->taps.offset_y)) { - float tmp_y = (*ctxt->offset_x*sinf(*ctxt->offset_angle * dt))+ - (*ctxt->offset_y*cosf(*ctxt->offset_angle * dt)); - *ctxt->offset_y = tmp_y; - } - + stars_update_taps(ctxt, stream, dt); } } |