summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-05-11 12:51:00 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-05-11 15:19:25 -0700
commit0d9aa593e68f33da8ea71a04b930bb6093dbaccb (patch)
tree679fd3c55385e597176b51a7d4b4c297680ad341 /src
parentdede4eca3e2fca76f297b5f5b901434cb99eafb0 (diff)
modules/*: stop storing setup by value in contexts
With setup refcounting and a reference bound to the context, we should just dereference the single instance. The way setups are used it just as a read-only thing to affect context behavior... Note I've left the module-type-specific setup pointer despite it duplicating the setup pointer in the module_context. This is just a convenience thing so the accessors don't have to cast the general til_setup_t* to my_module_setup_t* everywhere.
Diffstat (limited to 'src')
-rw-r--r--src/modules/blinds/blinds.c12
-rw-r--r--src/modules/checkers/checkers.c38
-rw-r--r--src/modules/drizzle/drizzle.c8
-rw-r--r--src/modules/flui2d/flui2d.c14
-rw-r--r--src/modules/moire/moire.c8
-rw-r--r--src/modules/shapes/shapes.c20
-rw-r--r--src/modules/sparkler/sparkler.c8
-rw-r--r--src/modules/strobe/strobe.c6
-rw-r--r--src/modules/swarm/swarm.c6
-rw-r--r--src/modules/voronoi/voronoi.c18
10 files changed, 69 insertions, 69 deletions
diff --git a/src/modules/blinds/blinds.c b/src/modules/blinds/blinds.c
index 12de39f..0494cd1 100644
--- a/src/modules/blinds/blinds.c
+++ b/src/modules/blinds/blinds.c
@@ -38,7 +38,7 @@ typedef struct blinds_context_t {
} vars;
float *t, *step, *count;
- blinds_setup_t setup;
+ blinds_setup_t *setup;
} blinds_context_t;
@@ -54,7 +54,7 @@ static til_module_context_t * blinds_create_context(const til_module_t *module,
ctxt->taps.step = til_tap_init_float(ctxt, &ctxt->step, 1, &ctxt->vars.step, "step");
ctxt->taps.count = til_tap_init_float(ctxt, &ctxt->count, 1, &ctxt->vars.count, "count");
- ctxt->setup = *(blinds_setup_t *)setup;
+ ctxt->setup = (blinds_setup_t *)setup;
return &ctxt->til_module_context;
}
@@ -104,17 +104,17 @@ static void blinds_render_fragment(til_module_context_t *context, til_stream_t *
*ctxt->step = .1f;
if (!til_stream_tap_context(stream, context, NULL, &ctxt->taps.count))
- *ctxt->count = ctxt->setup.count;
+ *ctxt->count = ctxt->setup->count;
til_fb_fragment_clear(fragment);
for (t = *ctxt->t, blind = 0; blind < (unsigned)*ctxt->count; blind++, t += *ctxt->step) {
- switch (ctxt->setup.orientation) {
+ switch (ctxt->setup->orientation) {
case BLINDS_ORIENTATION_HORIZONTAL:
- draw_blind_horizontal(fragment, blind, ctxt->setup.count, 1.f - fabsf(cosf(t)));
+ draw_blind_horizontal(fragment, blind, ctxt->setup->count, 1.f - fabsf(cosf(t)));
break;
case BLINDS_ORIENTATION_VERTICAL:
- draw_blind_vertical(fragment, blind, ctxt->setup.count, 1.f - fabsf(cosf(t)));
+ draw_blind_vertical(fragment, blind, ctxt->setup->count, 1.f - fabsf(cosf(t)));
break;
}
}
diff --git a/src/modules/checkers/checkers.c b/src/modules/checkers/checkers.c
index 5ff33da..84dd067 100644
--- a/src/modules/checkers/checkers.c
+++ b/src/modules/checkers/checkers.c
@@ -65,7 +65,7 @@ typedef struct checkers_setup_t {
typedef struct checkers_context_t {
til_module_context_t til_module_context;
- checkers_setup_t setup;
+ checkers_setup_t *setup;
til_module_context_t *fill_module_contexts[];
} checkers_context_t;
@@ -82,10 +82,10 @@ static til_module_context_t * checkers_create_context(const til_module_t *module
if (!ctxt)
return NULL;
- ctxt->setup = *(checkers_setup_t *)setup;
+ ctxt->setup = (checkers_setup_t *)setup;
- if (ctxt->setup.fill_module) {
- const til_module_t *module = ctxt->setup.fill_module;
+ if (ctxt->setup->fill_module) {
+ const til_module_t *module = ctxt->setup->fill_module;
til_setup_t *module_setup = NULL;
(void) til_module_randomize_setup(module, seed, &module_setup, NULL);
@@ -109,7 +109,7 @@ static void checkers_destroy_context(til_module_context_t *context)
{
checkers_context_t *ctxt = (checkers_context_t *)context;
- if (ctxt->setup.fill_module) {
+ if (ctxt->setup->fill_module) {
for (unsigned i = 0; i < context->n_cpus; i++)
til_module_context_free(ctxt->fill_module_contexts[i]);
}
@@ -211,7 +211,7 @@ static int checkers_fragmenter(til_module_context_t *context, const til_fb_fragm
{
checkers_context_t *ctxt = (checkers_context_t *)context;
- return checkers_fragment_tile_single(fragment, ctxt->setup.size, number, res_fragment);
+ return checkers_fragment_tile_single(fragment, ctxt->setup->size, number, res_fragment);
}
@@ -228,7 +228,7 @@ static void checkers_prepare_frame(til_module_context_t *context, til_stream_t *
* is actually *the* reason til_frame_plan_t.cpu_affinity got implemented, before this there
* wasn't even a til_frame_plan_t container; a bare til_fragmenter_t was returned.
*/
- *res_frame_plan = (til_frame_plan_t){ .fragmenter = checkers_fragmenter, .cpu_affinity = !!ctxt->setup.fill_module };
+ *res_frame_plan = (til_frame_plan_t){ .fragmenter = checkers_fragmenter, .cpu_affinity = !!ctxt->setup->fill_module };
}
@@ -248,16 +248,16 @@ static void checkers_render_fragment(til_module_context_t *context, til_stream_t
checkers_context_t *ctxt = (checkers_context_t *)context;
til_fb_fragment_t *fragment = *fragment_ptr;
- uint32_t color = ctxt->setup.color, flags = 0;
- checkers_fill_t fill = ctxt->setup.fill;
+ uint32_t color = ctxt->setup->color, flags = 0;
+ checkers_fill_t fill = ctxt->setup->fill;
int state;
- switch (ctxt->setup.pattern) {
+ switch (ctxt->setup->pattern) {
case CHECKERS_PATTERN_CHECKERED: {
unsigned tiles_per_row, row, col;
- tiles_per_row = fragment->frame_width / ctxt->setup.size;
- if (tiles_per_row * ctxt->setup.size < fragment->frame_width)
+ tiles_per_row = fragment->frame_width / ctxt->setup->size;
+ if (tiles_per_row * ctxt->setup->size < fragment->frame_width)
tiles_per_row++;
row = fragment->number / tiles_per_row;
@@ -271,27 +271,27 @@ static void checkers_render_fragment(til_module_context_t *context, til_stream_t
}
/* now that state has been determined, set the frame size */
- fragment->frame_width = ctxt->setup.size;
- fragment->frame_height = ctxt->setup.size;
+ fragment->frame_width = ctxt->setup->size;
+ fragment->frame_height = ctxt->setup->size;
- switch (ctxt->setup.dynamics) {
+ switch (ctxt->setup->dynamics) {
case CHECKERS_DYNAMICS_ODD:
break;
case CHECKERS_DYNAMICS_EVEN:
state = ~state & 0x1;
break;
case CHECKERS_DYNAMICS_ALTERNATING:
- state ^= ((unsigned)((float)ticks * ctxt->setup.rate) & 0x1);
+ state ^= ((unsigned)((float)ticks * ctxt->setup->rate) & 0x1);
break;
case CHECKERS_DYNAMICS_RANDOM: /* note: the big multiply here is just to get up out of the low bits */
- state &= hash(fragment->number * 0x61C88647 + (unsigned)((float)ticks * ctxt->setup.rate)) & 0x1;
+ state &= hash(fragment->number * 0x61C88647 + (unsigned)((float)ticks * ctxt->setup->rate)) & 0x1;
break;
}
if (fill == CHECKERS_FILL_RANDOM || fill == CHECKERS_FILL_MIXED)
fill = rand_r(&ctxt->til_module_context.seed) % CHECKERS_FILL_RANDOM; /* TODO: mixed should have a setting for controlling the ratios */
- switch (ctxt->setup.fill) {
+ switch (ctxt->setup->fill) {
case CHECKERS_FILL_SAMPLED:
if (fragment->cleared)
color = til_fb_fragment_get_pixel_unchecked(fragment, fragment->x + (fragment->width >> 1), fragment->y + (fragment->height >> 1));
@@ -307,7 +307,7 @@ static void checkers_render_fragment(til_module_context_t *context, til_stream_t
if (!state)
til_fb_fragment_clear(fragment);
else {
- if (!ctxt->setup.fill_module)
+ if (!ctxt->setup->fill_module)
til_fb_fragment_fill(fragment, flags, color);
else {
/* TODO: we need a way to send down color and flags, and use the module render as a brush of sorts */
diff --git a/src/modules/drizzle/drizzle.c b/src/modules/drizzle/drizzle.c
index 7558ea7..f60aa6e 100644
--- a/src/modules/drizzle/drizzle.c
+++ b/src/modules/drizzle/drizzle.c
@@ -65,7 +65,7 @@ typedef struct drizzle_context_t {
float *viscosity, *rainfall;
til_fb_fragment_t *snapshot;
puddle_t *puddle;
- drizzle_setup_t setup;
+ drizzle_setup_t *setup;
} drizzle_context_t;
@@ -108,7 +108,7 @@ static til_module_context_t * drizzle_create_context(const til_module_t *module,
ctxt->taps.viscosity = til_tap_init_float(ctxt, &ctxt->viscosity, 1, &ctxt->vars.viscosity, "viscosity");
ctxt->taps.rainfall = til_tap_init_float(ctxt, &ctxt->rainfall, 1, &ctxt->vars.rainfall, "rainfall");
- ctxt->setup = *(drizzle_setup_t *)setup;
+ ctxt->setup = (drizzle_setup_t *)setup;
return &ctxt->til_module_context;
}
@@ -128,7 +128,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;
+ *ctxt->viscosity = ctxt->setup->viscosity;
if (!til_stream_tap_context(stream, context, NULL, &ctxt->taps.rainfall))
*ctxt->rainfall = RAINFALL_CNT;
@@ -292,7 +292,7 @@ static void drizzle_render_fragment(til_module_context_t *context, til_stream_t
return;
}
- switch (ctxt->setup.style) {
+ switch (ctxt->setup->style) {
case DRIZZLE_STYLE_MASK:
coord.y = yf * (float)fragment->y;
for (int y = fragment->y; y < fragment->y + fragment->height; y++) {
diff --git a/src/modules/flui2d/flui2d.c b/src/modules/flui2d/flui2d.c
index 44a4123..d3a36a6 100644
--- a/src/modules/flui2d/flui2d.c
+++ b/src/modules/flui2d/flui2d.c
@@ -190,7 +190,7 @@ typedef struct flui2d_setup_t {
typedef struct flui2d_context_t {
til_module_context_t til_module_context;
- flui2d_setup_t setup;
+ flui2d_setup_t *setup;
struct {
til_tap_t viscosity, diffusion, decay;
@@ -263,7 +263,7 @@ static til_module_context_t * flui2d_create_context(const til_module_t *module,
gamma_init(1.4f);
}
- ctxt->setup = *((flui2d_setup_t *)setup);
+ ctxt->setup = (flui2d_setup_t *)setup;
ctxt->taps.viscosity = til_tap_init_float(ctxt, &ctxt->viscosity, 1, &ctxt->vars.viscosity, "viscosity");
ctxt->taps.diffusion = til_tap_init_float(ctxt, &ctxt->diffusion, 1, &ctxt->vars.diffusion, "diffusion");
@@ -284,13 +284,13 @@ 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;
+ *ctxt->viscosity = ctxt->setup->viscosity;
if (!til_stream_tap_context(stream, context, NULL, &ctxt->taps.diffusion))
- *ctxt->diffusion = ctxt->setup.diffusion;
+ *ctxt->diffusion = ctxt->setup->diffusion;
if (!til_stream_tap_context(stream, context, NULL, &ctxt->taps.decay))
- *ctxt->decay = ctxt->setup.decay;
+ *ctxt->decay = ctxt->setup->decay;
/* 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.
@@ -299,7 +299,7 @@ static void flui2d_prepare_frame(til_module_context_t *context, til_stream_t *st
ctxt->fluid.diff = *ctxt->diffusion;
ctxt->fluid.decay = *ctxt->decay;
- switch (ctxt->setup.emitters) {
+ switch (ctxt->setup->emitters) {
case FLUI2D_EMITTERS_FIGURE8: {
int x = (cos(r) * .4f + .5f) * (float)ROOT; /* figure eight pattern for the added densities */
int y = (sin(r * 2.f) * .4f + .5f) * (float)ROOT;
@@ -321,7 +321,7 @@ static void flui2d_prepare_frame(til_module_context_t *context, til_stream_t *st
#define FLUI2D_CLOCKGRID_SIZE (ROOT>>4)
#define FLUI2D_CLOCKGRID_STEP (ROOT/FLUI2D_CLOCKGRID_SIZE)
for (int y = FLUI2D_CLOCKGRID_STEP; y < ROOT; y += FLUI2D_CLOCKGRID_STEP) {
- for (int x = FLUI2D_CLOCKGRID_STEP; x < ROOT; x += FLUI2D_CLOCKGRID_STEP, r += ctxt->setup.clockstep * M_PI * 2) {
+ for (int x = FLUI2D_CLOCKGRID_STEP; x < ROOT; x += FLUI2D_CLOCKGRID_STEP, r += ctxt->setup->clockstep * M_PI * 2) {
ctxt->fluid.dens_prev_r[IX(x, y)] = .5f + cos(r) * .5f;
ctxt->fluid.dens_prev_g[IX(x, y)] = .5f + sin(r) * .5f;
diff --git a/src/modules/moire/moire.c b/src/modules/moire/moire.c
index 2c992d6..eb4c10b 100644
--- a/src/modules/moire/moire.c
+++ b/src/modules/moire/moire.c
@@ -38,7 +38,7 @@ typedef struct moire_center_t {
typedef struct moire_context_t {
til_module_context_t til_module_context;
- moire_setup_t setup;
+ moire_setup_t *setup;
moire_center_t centers[];
} moire_context_t;
@@ -50,7 +50,7 @@ static til_module_context_t * moire_create_context(const til_module_t *module, t
if (!ctxt)
return NULL;
- ctxt->setup = *(moire_setup_t *)setup;
+ ctxt->setup = (moire_setup_t *)setup;
for (unsigned i = 0; i < ((moire_setup_t *)setup)->n_centers; i++) {
ctxt->centers[i].seed = rand_r(&seed) * (1.f / (float)RAND_MAX) * 2 * M_PI;
@@ -69,7 +69,7 @@ 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 };
- for (unsigned i = 0; i < ctxt->setup.n_centers; i++) {
+ 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);
}
@@ -93,7 +93,7 @@ static void moire_render_fragment(til_module_context_t *context, til_stream_t *s
for (int x = fragment->x; x < fragment->x + fragment->width; x++, cx += xf) {
int filled = 0;
- for (unsigned i = 0; i < ctxt->setup.n_centers; i++) {
+ for (unsigned i = 0; i < ctxt->setup->n_centers; i++) {
float dx, dy;
dx = cx - ctxt->centers[i].x;
diff --git a/src/modules/shapes/shapes.c b/src/modules/shapes/shapes.c
index ff25267..47e4b8b 100644
--- a/src/modules/shapes/shapes.c
+++ b/src/modules/shapes/shapes.c
@@ -89,7 +89,7 @@ typedef struct shapes_setup_t {
typedef struct shapes_context_t {
til_module_context_t til_module_context;
- shapes_setup_t setup;
+ shapes_setup_t *setup;
} shapes_context_t;
@@ -101,7 +101,7 @@ static til_module_context_t * shapes_create_context(const til_module_t *module,
if (!ctxt)
return NULL;
- ctxt->setup = *(shapes_setup_t *)setup;
+ ctxt->setup = (shapes_setup_t *)setup;
return &ctxt->til_module_context;
}
@@ -112,7 +112,7 @@ static void shapes_render_fragment(til_module_context_t *context, til_stream_t *
shapes_context_t *ctxt = (shapes_context_t *)context;
til_fb_fragment_t *fragment = *fragment_ptr;
- unsigned size = MIN(fragment->frame_width, fragment->frame_height) * ctxt->setup.scale;
+ unsigned size = MIN(fragment->frame_width, fragment->frame_height) * ctxt->setup->scale;
unsigned xoff = (fragment->frame_width - size) >> 1;
unsigned yoff = (fragment->frame_height - size) >> 1;
@@ -141,7 +141,7 @@ static void shapes_render_fragment(til_module_context_t *context, til_stream_t *
/* eventually these should probably get broken out into functions,
* but it's not too unwieldy for now.
*/
- switch (ctxt->setup.type) {
+ switch (ctxt->setup->type) {
case SHAPES_TYPE_CIRCLE: {
unsigned yskip = (fragment->y > yoff ? (fragment->y - yoff) : 0);
unsigned xskip = (fragment->x > xoff ? (fragment->x - xoff) : 0);
@@ -158,7 +158,7 @@ static void shapes_render_fragment(til_module_context_t *context, til_stream_t *
for (unsigned x = MAX(fragment->x, xoff); x < xoff + size; x++, X++, XX += s) {
float rad = atan2f(YY, XX);
- if (Y*Y+X*X < r_sq * (1.f - fabsf(cosf(ctxt->setup.n_pinches * rad + (float)ticks * ctxt->setup.pinch_spin * SHAPES_SPIN_BASE)) * ctxt->setup.pinch))
+ if (Y*Y+X*X < r_sq * (1.f - fabsf(cosf(ctxt->setup->n_pinches * rad + (float)ticks * ctxt->setup->pinch_spin * SHAPES_SPIN_BASE)) * ctxt->setup->pinch))
til_fb_fragment_put_pixel_checked(fragment, TIL_FB_DRAW_FLAG_TEXTURABLE, x, y, 0xffffffff); /* TODO: stop relying on checked for clipping */
else if (!fragment->cleared)
til_fb_fragment_put_pixel_checked(fragment, 0, x, y, 0x0);
@@ -179,9 +179,9 @@ static void shapes_render_fragment(til_module_context_t *context, til_stream_t *
XX = -1.f + xskip * s;
for (unsigned x = MAX(fragment->x, xoff); x < xoff + size; x++, XX += s) {
float rad = atan2f(YY, XX);
- float r = cosf((float)ctxt->setup.n_points * (rad + (float)ticks * ctxt->setup.spin * SHAPES_SPIN_BASE)) * .5f + .5f;
+ float r = cosf((float)ctxt->setup->n_points * (rad + (float)ticks * ctxt->setup->spin * SHAPES_SPIN_BASE)) * .5f + .5f;
- r *= 1.f - fabsf(cosf(ctxt->setup.n_pinches * rad + (float)ticks * ctxt->setup.pinch_spin * SHAPES_SPIN_BASE)) * ctxt->setup.pinch;
+ r *= 1.f - fabsf(cosf(ctxt->setup->n_pinches * rad + (float)ticks * ctxt->setup->pinch_spin * SHAPES_SPIN_BASE)) * ctxt->setup->pinch;
if (XX * XX + YY * YY < r * r)
til_fb_fragment_put_pixel_checked(fragment, TIL_FB_DRAW_FLAG_TEXTURABLE, x, y, 0xffffffff); /* stop relying on checked for clipping */
@@ -209,7 +209,7 @@ static void shapes_render_fragment(til_module_context_t *context, til_stream_t *
for (unsigned x = MAX(fragment->x, xoff); x < xoff + size; x++, X++, XX += s) {
float rad = atan2f(YY, XX);
- if (abs(Y) + abs(X) < r * (1.f - fabsf(cosf(ctxt->setup.n_pinches * rad + (float)ticks * ctxt->setup.pinch_spin * SHAPES_SPIN_BASE)) * ctxt->setup.pinch))
+ if (abs(Y) + abs(X) < r * (1.f - fabsf(cosf(ctxt->setup->n_pinches * rad + (float)ticks * ctxt->setup->pinch_spin * SHAPES_SPIN_BASE)) * ctxt->setup->pinch))
til_fb_fragment_put_pixel_checked(fragment, TIL_FB_DRAW_FLAG_TEXTURABLE, x, y, 0xffffffff);
else if (!fragment->cleared)
til_fb_fragment_put_pixel_checked(fragment, 0, x, y, 0x0);
@@ -230,10 +230,10 @@ static void shapes_render_fragment(til_module_context_t *context, til_stream_t *
XX = -1.f + xskip * s;
for (unsigned x = MAX(fragment->x, xoff); x < xoff + size; x++, XX += s) {
float rad = atan2f(YY, XX);
- float r = (M_2_PI * asinf(sinf((float)ctxt->setup.n_points * (rad + (float)ticks * ctxt->setup.spin * SHAPES_SPIN_BASE)) * .5f + .5f)) * .5f + .5f;
+ float r = (M_2_PI * asinf(sinf((float)ctxt->setup->n_points * (rad + (float)ticks * ctxt->setup->spin * SHAPES_SPIN_BASE)) * .5f + .5f)) * .5f + .5f;
/* ^^^^^^^^^^^^^^^^^^^ approximates a triangle wave */
- r *= 1.f - fabsf(cosf(ctxt->setup.n_pinches * rad + (float)ticks * ctxt->setup.pinch_spin * SHAPES_SPIN_BASE)) * ctxt->setup.pinch;
+ r *= 1.f - fabsf(cosf(ctxt->setup->n_pinches * rad + (float)ticks * ctxt->setup->pinch_spin * SHAPES_SPIN_BASE)) * ctxt->setup->pinch;
if (XX * XX + YY * YY < r * r)
til_fb_fragment_put_pixel_checked(fragment, TIL_FB_DRAW_FLAG_TEXTURABLE, x, y, 0xffffffff);
diff --git a/src/modules/sparkler/sparkler.c b/src/modules/sparkler/sparkler.c
index f35852a..3f3c681 100644
--- a/src/modules/sparkler/sparkler.c
+++ b/src/modules/sparkler/sparkler.c
@@ -28,7 +28,7 @@ typedef struct sparkler_setup_t {
typedef struct sparkler_context_t {
til_module_context_t til_module_context;
particles_t *particles;
- sparkler_setup_t setup;
+ sparkler_setup_t *setup;
} sparkler_context_t;
extern particle_ops_t simple_ops;
@@ -41,7 +41,7 @@ static til_module_context_t * sparkler_create_context(const til_module_t *module
if (!ctxt)
return NULL;
- ctxt->setup = *(sparkler_setup_t *)setup;
+ ctxt->setup = (sparkler_setup_t *)setup;
ctxt->particles = particles_new(&(particles_conf_t){
.show_bsp_leafs = ((sparkler_setup_t *)setup)->show_bsp_leafs,
@@ -77,7 +77,7 @@ static void sparkler_prepare_frame(til_module_context_t *context, til_stream_t *
*res_frame_plan = (til_frame_plan_t){ .fragmenter = til_fragmenter_slice_per_cpu };
- if (ctxt->setup.show_bsp_matches)
+ if (ctxt->setup->show_bsp_matches)
til_fb_fragment_clear(fragment);
particles_sim(ctxt->particles, fragment);
@@ -92,7 +92,7 @@ static void sparkler_render_fragment(til_module_context_t *context, til_stream_t
sparkler_context_t *ctxt = (sparkler_context_t *)context;
til_fb_fragment_t *fragment = *fragment_ptr;
- if (!ctxt->setup.show_bsp_matches)
+ if (!ctxt->setup->show_bsp_matches)
til_fb_fragment_clear(fragment);
particles_draw(ctxt->particles, fragment);
diff --git a/src/modules/strobe/strobe.c b/src/modules/strobe/strobe.c
index 634a46b..495b95b 100644
--- a/src/modules/strobe/strobe.c
+++ b/src/modules/strobe/strobe.c
@@ -28,7 +28,7 @@ typedef struct strobe_setup_t {
typedef struct strobe_context_t {
til_module_context_t til_module_context;
- strobe_setup_t setup;
+ strobe_setup_t *setup;
unsigned ticks;
unsigned flash:1;
unsigned flash_ready:1;
@@ -43,7 +43,7 @@ static til_module_context_t * strobe_create_context(const til_module_t *module,
if (!ctxt)
return NULL;
- ctxt->setup = *(strobe_setup_t *)setup;
+ ctxt->setup = (strobe_setup_t *)setup;
ctxt->ticks = ticks;
return &ctxt->til_module_context;
@@ -56,7 +56,7 @@ static void strobe_prepare_frame(til_module_context_t *context, til_stream_t *st
*res_frame_plan = (til_frame_plan_t){ .fragmenter = til_fragmenter_slice_per_cpu };
- if (ctxt->flash_ready && (ticks - ctxt->ticks >= (unsigned)(ctxt->setup.period * 1000.f))){
+ if (ctxt->flash_ready && (ticks - ctxt->ticks >= (unsigned)(ctxt->setup->period * 1000.f))){
ctxt->flash = 1;
ctxt->flash_ready = 0;
} else {
diff --git a/src/modules/swarm/swarm.c b/src/modules/swarm/swarm.c
index d7f1614..78acc38 100644
--- a/src/modules/swarm/swarm.c
+++ b/src/modules/swarm/swarm.c
@@ -57,7 +57,7 @@ typedef struct swarm_context_t {
til_module_context_t til_module_context;
v3f_t color;
float ztweak;
- swarm_setup_t setup;
+ swarm_setup_t *setup;
boid_t boids[];
} swarm_context_t;
@@ -185,7 +185,7 @@ static til_module_context_t * swarm_create_context(const til_module_t *module, t
if (!ctxt)
return NULL;
- ctxt->setup = *(swarm_setup_t *)setup;
+ ctxt->setup = (swarm_setup_t *)setup;
for (unsigned i = 0; i < SWARM_SIZE; i++)
boid_randomize(&ctxt->boids[i], &seed);
@@ -403,7 +403,7 @@ static void swarm_render_fragment(til_module_context_t *context, til_stream_t *s
til_fb_fragment_clear(fragment);
- switch (ctxt->setup.draw_style) {
+ switch (ctxt->setup->draw_style) {
case SWARM_DRAW_STYLE_POINTS:
return swarm_draw_as_points(ctxt, fragment);
case SWARM_DRAW_STYLE_LINES:
diff --git a/src/modules/voronoi/voronoi.c b/src/modules/voronoi/voronoi.c
index 0248b08..5e40142 100644
--- a/src/modules/voronoi/voronoi.c
+++ b/src/modules/voronoi/voronoi.c
@@ -45,7 +45,7 @@ typedef struct voronoi_distances_t {
typedef struct voronoi_context_t {
til_module_context_t til_module_context;
unsigned seed;
- voronoi_setup_t setup;
+ voronoi_setup_t *setup;
voronoi_distances_t distances;
voronoi_cell_t cells[];
} voronoi_context_t;
@@ -60,7 +60,7 @@ static void voronoi_randomize(voronoi_context_t *ctxt)
{
float inv_rand_max= 1.f / (float)RAND_MAX;
- for (size_t i = 0; i < ctxt->setup.n_cells; i++) {
+ for (size_t i = 0; i < ctxt->setup->n_cells; i++) {
voronoi_cell_t *p = &ctxt->cells[i];
p->origin.x = ((float)rand_r(&ctxt->seed) * inv_rand_max) * 2.f - 1.f;
@@ -81,7 +81,7 @@ static til_module_context_t * voronoi_create_context(const til_module_t *module,
if (!ctxt)
return NULL;
- ctxt->setup = *(voronoi_setup_t *)setup;
+ ctxt->setup = (voronoi_setup_t *)setup;
ctxt->seed = seed;
voronoi_randomize(ctxt);
@@ -210,7 +210,7 @@ static void voronoi_calculate_distances(voronoi_context_t *ctxt)
#if 0
/* naive inefficient brute-force but correct algorithm */
- for (size_t i = 0; i < ctxt->setup.n_cells; i++) {
+ for (size_t i = 0; i < ctxt->setup->n_cells; i++) {
voronoi_distance_t *d = ctxt->distances.buf;
v2f_t dp = {};
@@ -233,7 +233,7 @@ static void voronoi_calculate_distances(voronoi_context_t *ctxt)
/* An attempt at implementing https://en.wikipedia.org/wiki/Jump_flooding_algorithm */
/* first assign the obvious zero-distance cell origins */
- for (size_t i = 0; i < ctxt->setup.n_cells; i++) {
+ for (size_t i = 0; i < ctxt->setup->n_cells; i++) {
voronoi_cell_t *c = &ctxt->cells[i];
size_t idx;
voronoi_distance_t *d;
@@ -246,7 +246,7 @@ static void voronoi_calculate_distances(voronoi_context_t *ctxt)
}
/* now for every distance sample neighbors */
- if (ctxt->setup.dirty) {
+ if (ctxt->setup->dirty) {
for (size_t step = 2; step <= MAX(ctxt->distances.width, ctxt->distances.height); step *= 2)
voronoi_jumpfill_pass(ctxt, &ds, step);
} else {
@@ -259,7 +259,7 @@ static void voronoi_calculate_distances(voronoi_context_t *ctxt)
static void voronoi_sample_colors(voronoi_context_t *ctxt, til_fb_fragment_t *fragment)
{
- for (size_t i = 0; i < ctxt->setup.n_cells; i++) {
+ for (size_t i = 0; i < ctxt->setup->n_cells; i++) {
voronoi_cell_t *p = &ctxt->cells[i];
int x, y;
@@ -288,13 +288,13 @@ static void voronoi_prepare_frame(til_module_context_t *context, til_stream_t *s
ctxt->distances.size = fragment->frame_width * fragment->frame_height;
ctxt->distances.buf = malloc(sizeof(voronoi_distance_t) * ctxt->distances.size);
- if (!ctxt->setup.randomize)
+ if (!ctxt->setup->randomize)
voronoi_calculate_distances(ctxt);
}
/* TODO: explore moving voronoi_calculate_distances() into render_fragment (threaded) */
- if (ctxt->setup.randomize) {
+ if (ctxt->setup->randomize) {
voronoi_randomize(ctxt);
voronoi_calculate_distances(ctxt);
}
© All Rights Reserved