summaryrefslogtreecommitdiff
path: root/src/modules/moire
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-08-31 21:22:51 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-08-31 21:24:06 -0700
commitc1118d5daed415f49cc4bb9bfba07801fa9a1481 (patch)
tree08883b8f8504a9e5cd618d3c98b7083e3d846f39 /src/modules/moire
parent677d64caa8f18b1081ee9a9387902ee760762c38 (diff)
modules/moire: tap n_rings
This has a nice side effect of being able to have no rings at all via 0. Note it would be potentially interesting to tap n_centers, but that's substantially more complicated as those have allocated state per-center. Maybe the centers= setting could be treated as a max, then the tap could vary within that limit.
Diffstat (limited to 'src/modules/moire')
-rw-r--r--src/modules/moire/moire.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/src/modules/moire/moire.c b/src/modules/moire/moire.c
index d9a985e..118b519 100644
--- a/src/modules/moire/moire.c
+++ b/src/modules/moire/moire.c
@@ -22,6 +22,8 @@
#include "til.h"
#include "til_fb.h"
#include "til_module_context.h"
+#include "til_stream.h"
+#include "til_tap.h"
#define MOIRE_DEFAULT_CENTERS 2
#define MOIRE_DEFAULT_RINGS 20
@@ -41,9 +43,33 @@ typedef struct moire_center_t {
typedef struct moire_context_t {
til_module_context_t til_module_context;
moire_setup_t *setup;
+
+ struct {
+ til_tap_t n_rings;
+ } taps;
+
+ struct {
+ float n_rings;
+ } vars;
+
+ float *n_rings;
+
moire_center_t centers[];
} moire_context_t;
+
+static void moire_update_taps(moire_context_t *ctxt, til_stream_t *stream, unsigned ticks)
+{
+ if (!til_stream_tap_context(stream, &ctxt->til_module_context, NULL, &ctxt->taps.n_rings))
+ *ctxt->n_rings = ctxt->setup->n_rings;
+ else
+ ctxt->vars.n_rings = *ctxt->n_rings;
+
+ if (ctxt->vars.n_rings <= 0.f)
+ ctxt->vars.n_rings = 0.f;
+}
+
+
static til_module_context_t * moire_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup)
{
moire_context_t *ctxt;
@@ -61,6 +87,9 @@ static til_module_context_t * moire_create_context(const til_module_t *module, t
ctxt->centers[i].y = sinf(ctxt->centers[i].seed + (float)ticks * .001f * ctxt->centers[i].dir);
}
+ ctxt->taps.n_rings = til_tap_init_float(ctxt, &ctxt->n_rings, 1, &ctxt->vars.n_rings, "n_rings");
+ moire_update_taps(ctxt, stream, ticks);
+
return &ctxt->til_module_context;
}
@@ -71,6 +100,8 @@ static void moire_prepare_frame(til_module_context_t *context, til_stream_t *str
*res_frame_plan = (til_frame_plan_t){ .fragmenter = til_fragmenter_slice_per_cpu_x16 };
+ moire_update_taps(ctxt, stream, ticks);
+
for (unsigned i = 0; i < ctxt->setup->n_centers; i++) {
ctxt->centers[i].x = cosf(ctxt->centers[i].seed + (float)ticks * .001f * ctxt->centers[i].dir);
ctxt->centers[i].y = sinf(ctxt->centers[i].seed + (float)ticks * .001f * ctxt->centers[i].dir);
@@ -87,7 +118,7 @@ static void moire_render_fragment(til_module_context_t *context, til_stream_t *s
float yf = 2.f / (float)fragment->frame_height;
unsigned n_centers = ctxt->setup->n_centers;
moire_center_t *centers = ctxt->centers;
- float n_rings = ctxt->setup->n_rings;
+ float n_rings = rintf(ctxt->vars.n_rings);
float cx, cy;
/* TODO: optimize */
© All Rights Reserved