From 1299c8667b44058ce35b20e3d86c5ae1d5ee0995 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Thu, 14 Nov 2019 23:26:00 -0800 Subject: rtv: add some snow between module switches This uses the newly added snow module as a transition between modules --- src/modules/rtv/rtv.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/modules/rtv') diff --git a/src/modules/rtv/rtv.c b/src/modules/rtv/rtv.c index da6ae52..8848e82 100644 --- a/src/modules/rtv/rtv.c +++ b/src/modules/rtv/rtv.c @@ -24,15 +24,18 @@ * same thing over and over. */ +#define RTV_SNOW_DURATION_SECS 1 #define RTV_DURATION_SECS 15 typedef struct rtv_context_t { const rototiller_module_t **modules; size_t n_modules; - time_t last_switch; + time_t next_switch; const rototiller_module_t *module; void *module_ctxt; + + const rototiller_module_t *snow_module; } rtv_context_t; static void setup_next_module(rtv_context_t *ctxt); @@ -68,15 +71,22 @@ static void setup_next_module(rtv_context_t *ctxt) ctxt->module_ctxt = NULL; } - do { - i = rand() % ctxt->n_modules; - } while (ctxt->modules[i] == &rtv_module || ctxt->modules[i] == ctxt->module); + if (ctxt->module != ctxt->snow_module) { + ctxt->module = ctxt->snow_module; + ctxt->next_switch = time(NULL) + RTV_SNOW_DURATION_SECS; + } else { + do { + i = rand() % ctxt->n_modules; + } while (ctxt->modules[i] == &rtv_module || + ctxt->modules[i] == ctxt->module || + ctxt->modules[i] == ctxt->snow_module); + + ctxt->module = ctxt->modules[i]; + ctxt->next_switch = time(NULL) + RTV_DURATION_SECS; + } - ctxt->module = ctxt->modules[i]; if (ctxt->module->create_context) ctxt->module_ctxt = ctxt->module->create_context(); - - ctxt->last_switch = time(NULL); } @@ -84,6 +94,7 @@ static void * rtv_create_context(void) { rtv_context_t *ctxt = calloc(1, sizeof(rtv_context_t)); + ctxt->snow_module = rototiller_lookup_module("snow"); rototiller_get_modules(&ctxt->modules, &ctxt->n_modules); setup_next_module(ctxt); @@ -101,7 +112,7 @@ static void rtv_prepare_frame(void *context, unsigned n_cpus, fb_fragment_t *fra { rtv_context_t *ctxt = context; - if (!ctxt->last_switch || time(NULL) - ctxt->last_switch > RTV_DURATION_SECS) + if (time(NULL) >= ctxt->next_switch) setup_next_module(ctxt); rototiller_module_render(ctxt->module, ctxt->module_ctxt, fragment); -- cgit v1.2.1