From 0d9aa593e68f33da8ea71a04b930bb6093dbaccb Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Thu, 11 May 2023 12:51:00 -0700 Subject: 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. --- src/modules/flui2d/flui2d.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/modules/flui2d') 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; -- cgit v1.2.1