summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-06-15 18:19:50 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-06-15 18:19:50 -0700
commit64a5b1747b41f8dcb1d8cf6e6108c386e2904585 (patch)
tree127587127e7b92b6eecf13afbc216e1e7ed67d1e
parentf89689ba9f198755a3f2ce05dec11b7ea185f374 (diff)
til_module_context: s/ticks/last_ticks/ in context
And just maintain it as the last ticks value after rendering with the context... A couple modules were already doing this manually in an ad-hoc fashion, just make it a general thing. Updated those modules to reflect the new situation Especially in a rkt world with modules::mixer doing fades, it becomes common to render the same context twice in the same frame for the blending. We need to prevent accelerated animations in such situations. For now let's just rely on ticks in a delta-T fashion to prevent animating the context when ticks is the same. modules::stars in particular needs this fixed up, upcoming commit
-rw-r--r--src/modules/plato/plato.c5
-rw-r--r--src/modules/roto/roto.c6
-rw-r--r--src/til.c1
-rw-r--r--src/til_module_context.c2
-rw-r--r--src/til_module_context.h2
5 files changed, 7 insertions, 9 deletions
diff --git a/src/modules/plato/plato.c b/src/modules/plato/plato.c
index f43eda3..a20137e 100644
--- a/src/modules/plato/plato.c
+++ b/src/modules/plato/plato.c
@@ -658,9 +658,8 @@ static void plato_render_fragment(til_module_context_t *context, til_stream_t *s
(void) til_stream_tap_context(stream, context, NULL, &ctxt->taps.orbit_rate);
(void) til_stream_tap_context(stream, context, NULL, &ctxt->taps.spin_rate);
- ctxt->r += (float)(ticks - context->ticks) * (*ctxt->orbit_rate * .001f);
- ctxt->rr += (float)(ticks - context->ticks) * (*ctxt->spin_rate * .001f);
- context->ticks = ticks;
+ ctxt->r += (float)(ticks - context->last_ticks) * (*ctxt->orbit_rate * .001f);
+ ctxt->rr += (float)(ticks - context->last_ticks) * (*ctxt->spin_rate * .001f);
til_fb_fragment_clear(fragment);
for (int i = 0; i < sizeof(polyhedra) / sizeof(*polyhedra); i++) {
diff --git a/src/modules/roto/roto.c b/src/modules/roto/roto.c
index 8564870..28e27e1 100644
--- a/src/modules/roto/roto.c
+++ b/src/modules/roto/roto.c
@@ -189,9 +189,9 @@ static void roto_prepare_frame(til_module_context_t *context, til_stream_t *stre
*res_frame_plan = (til_frame_plan_t){ .fragmenter = til_fragmenter_slice_per_cpu };
// This governs the rotation and color cycle.
- if (ticks != context->ticks) {
+ if (ticks != context->last_ticks) {
ctxt->r += FIXED_TO_INT(FIXED_MULT(FIXED_SIN(ctxt->rr), FIXED_NEW(16)));
- ctxt->rr += (ticks - context->ticks) >> 2;
+ ctxt->rr += (ticks - context->last_ticks) >> 2;
/* Vary the colors, this is just a mashup of sinusoidal rgb values. */
ctxt->palette[0].r = (FIXED_MULT(FIXED_COS(ctxt->rr), FIXED_NEW(127)) + FIXED_NEW(128));
@@ -201,8 +201,6 @@ static void roto_prepare_frame(til_module_context_t *context, til_stream_t *stre
ctxt->palette[1].r = (FIXED_MULT(FIXED_SIN(ctxt->rr / 2), FIXED_NEW(127)) + FIXED_NEW(128));
ctxt->palette[1].g = (FIXED_MULT(FIXED_COS(ctxt->rr / 2), FIXED_NEW(127)) + FIXED_NEW(128));
ctxt->palette[1].b = (FIXED_MULT(FIXED_SIN(ctxt->rr), FIXED_NEW(127)) + FIXED_NEW(128));
-
- context->ticks = ticks;
}
}
diff --git a/src/til.c b/src/til.c
index fec6b46..78838ef 100644
--- a/src/til.c
+++ b/src/til.c
@@ -395,6 +395,7 @@ static void module_render_fragment(til_module_context_t *context, til_stream_t *
void til_module_render(til_module_context_t *context, til_stream_t *stream, unsigned ticks, til_fb_fragment_t **fragment_ptr)
{
module_render_fragment(context, stream, til_threads, ticks, fragment_ptr);
+ context->last_ticks = ticks;
}
diff --git a/src/til_module_context.c b/src/til_module_context.c
index 092e3e1..8b13410 100644
--- a/src/til_module_context.c
+++ b/src/til_module_context.c
@@ -47,7 +47,7 @@ void * til_module_context_new(const til_module_t *module, size_t size, til_strea
module_context->module = module;
module_context->stream = stream;
module_context->seed = seed;
- module_context->ticks = ticks;
+ module_context->last_ticks = ticks;
module_context->n_cpus = n_cpus;
module_context->setup = til_setup_ref(setup);
module_context->refcount = 1;
diff --git a/src/til_module_context.h b/src/til_module_context.h
index 05f77ab..e4c0bca 100644
--- a/src/til_module_context.h
+++ b/src/til_module_context.h
@@ -10,7 +10,7 @@ struct til_module_context_t {
const til_module_t *module;
til_stream_t *stream; /* optional stream this context is part of (module_contexts are discoverable @setup->path when part of a stream) */
unsigned seed;
- unsigned ticks;
+ unsigned last_ticks; /* this gets updated after every render finishes, starts as the ticks supplied @ context create */
unsigned n_cpus;
til_setup_t *setup; /* Baked setup this context was made from, reffed by context.
* Always present as it provides the path, which is generally derived from a settings instance.
© All Rights Reserved