diff options
32 files changed, 83 insertions, 148 deletions
@@ -399,7 +399,6 @@ int main(int argc, const char *argv[]) &rototiller.start_tv, rototiller.ticks_offset), 0, - "", setup.module_setup, &rototiller.module_context)) < 0, "unable to create module context: %s", strerror(-r)); diff --git a/src/modules/blinds/blinds.c b/src/modules/blinds/blinds.c index 39b439f..529cdaa 100644 --- a/src/modules/blinds/blinds.c +++ b/src/modules/blinds/blinds.c @@ -42,11 +42,11 @@ typedef struct blinds_context_t { } blinds_context_t; -static til_module_context_t * blinds_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * blinds_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { blinds_context_t *ctxt; - ctxt = til_module_context_new(module, sizeof(blinds_context_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(blinds_context_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/checkers/checkers.c b/src/modules/checkers/checkers.c index be83f9e..36b20f8 100644 --- a/src/modules/checkers/checkers.c +++ b/src/modules/checkers/checkers.c @@ -71,7 +71,7 @@ typedef struct checkers_context_t { } checkers_context_t; -static til_module_context_t * checkers_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * checkers_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { size_t size = sizeof(checkers_context_t); checkers_context_t *ctxt; @@ -79,7 +79,7 @@ static til_module_context_t * checkers_create_context(const til_module_t *module if (((checkers_setup_t *)setup)->fill_module) size += sizeof(til_module_context_t *) * n_cpus; - ctxt = til_module_context_new(module, size, stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, size, stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; @@ -87,17 +87,10 @@ static til_module_context_t * checkers_create_context(const til_module_t *module if (ctxt->setup->fill_module) { const til_module_t *module = ctxt->setup->fill_module; - size_t fill_module_path_len = snprintf(NULL, 0, "%s/fill_module", path) + 1; /* FIXME TODO: revisit path construction, see big comment in modules/compose FIXME TODO */ - char *fill_module_path = calloc(1, fill_module_path_len); - - if (!fill_module_path) - return til_module_context_free(&ctxt->til_module_context); - - snprintf(fill_module_path, fill_module_path_len, "%s/fill_module", path); /* since checkers is already threaded, create an n_cpus=1 context per-cpu */ for (unsigned i = 0; i < n_cpus; i++) /* TODO: errors */ - (void) til_module_create_context(module, stream, seed, ticks, 1, fill_module_path, ctxt->setup->fill_module_setup, &ctxt->fill_module_contexts[i]); + (void) til_module_create_context(module, stream, seed, ticks, 1, ctxt->setup->fill_module_setup, &ctxt->fill_module_contexts[i]); /* FIXME TODO ^^^ sharing the fill_module_path across the per-cpu contexts aliases them _across_threads_ no less, this needs attention/thought FIXME TODO */ /* but the problem with just doing something like suffixing the cpu # to give each context a unique path per-cpu is then the taps/pipes would all be * unique on a per-cpu basis. That's _very_ undesirable in terms of sequencing the pipes by name, we don't want sequencing tracks per-cpu and that's @@ -111,7 +104,6 @@ static til_module_context_t * checkers_create_context(const til_module_t *module * just roll with the punches and share the first instance of tap variables then all the others just get left alone. FIXME TODO FIXME TODO */ - free(fill_module_path); /* XXX: it would be interesting to support various patterns/layouts by varying the seed, but this will require * more complex context allocation strategies while also maintaining the per-cpu allocation. */ diff --git a/src/modules/compose/compose.c b/src/modules/compose/compose.c index 78a5fe1..f41b838 100644 --- a/src/modules/compose/compose.c +++ b/src/modules/compose/compose.c @@ -51,7 +51,7 @@ typedef struct compose_setup_t { compose_setup_layer_t layers[]; } compose_setup_t; -static til_module_context_t * compose_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup); +static til_module_context_t * compose_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup); static void compose_destroy_context(til_module_context_t *context); static void compose_render_fragment(til_module_context_t *context, til_stream_t *stream, unsigned ticks, unsigned cpu, til_fb_fragment_t **fragment_ptr); static int compose_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup); @@ -67,64 +67,30 @@ til_module_t compose_module = { }; -static til_module_context_t * compose_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * compose_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { compose_setup_t *s = (compose_setup_t *)setup; - size_t layers_path_len; - char *layers_path; compose_context_t *ctxt; assert(setup); - ctxt = til_module_context_new(module, sizeof(compose_context_t) + s->n_layers * sizeof(compose_layer_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(compose_context_t) + s->n_layers * sizeof(compose_layer_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; - layers_path_len = snprintf(NULL, 0, "%s/%s", path, "layers") + 1; - layers_path = calloc(1, layers_path_len); - /* FIXME TODO: path allocation/construction needs revisiting something fierce: - * 1. Layers can have the same module recur, using compose/layers/$modname will just collide. - * 2. We don't want to be ad-hoc constructing these things like this, but I'm deliberately leaving it ridiculous for now. - * 3. Giving the til_setup_t a settings-instance-derived path might Just Fix Everything and eliminate the need for passing around a path altogether: - * - * In scenarios like layers the settings code already generate instance labels in an enumerated array subscript fashion, so the path would be: - * compose/layers/layers[N] - * - * Some things need to change before that happens though, for starters always creating and supplying a til_setup_t to modules even ones without - * a .setup() method would be necessary. Also there isn't a trivial way to take an arbitrary settings instance anywhere in the heirarchy and - * ask til_settings to generate its path - there are no parent pointers going up the tree to construct it in reverse, and the instances don't - * get a full path copy placed into them at creation time, only the label. The label could be changed to an absolute path though, which would - * really be fine since these things don't move around the heirarchy, they just stay where they were created. - */ - if (!layers_path) - return til_module_context_free(&ctxt->til_module_context); - - snprintf(layers_path, layers_path_len, "%s/%s", path, "layers"); - for (size_t i = 0; i < s->n_layers; i++) { const til_module_t *layer_module; layer_module = til_lookup_module(((compose_setup_t *)setup)->layers[i].module); ctxt->layers[i].module = layer_module; - (void) til_module_create_context(layer_module, stream, rand_r(&seed), ticks, n_cpus, layers_path, s->layers[i].setup, &ctxt->layers[i].module_ctxt); /* TODO: errors */ + (void) til_module_create_context(layer_module, stream, rand_r(&seed), ticks, n_cpus, s->layers[i].setup, &ctxt->layers[i].module_ctxt); /* TODO: errors */ ctxt->n_layers++; } - free(layers_path); - if (((compose_setup_t *)setup)->texture.module) { - size_t texture_path_len = snprintf(NULL, 0, "%s/%s", path, "texture") + 1; - char *texture_path = calloc(1, texture_path_len); - - if (!texture_path) - return til_module_context_free(&ctxt->til_module_context); - - snprintf(texture_path, texture_path_len, "%s/%s", path, "texture"); - ctxt->texture.module = til_lookup_module(((compose_setup_t *)setup)->texture.module); - (void) til_module_create_context(ctxt->texture.module, stream, rand_r(&seed), ticks, n_cpus, texture_path, s->texture.setup, &ctxt->texture.module_ctxt); /* TODO: errors */ - free(texture_path); + (void) til_module_create_context(ctxt->texture.module, stream, rand_r(&seed), ticks, n_cpus, s->texture.setup, &ctxt->texture.module_ctxt); /* TODO: errors */ } return &ctxt->til_module_context; diff --git a/src/modules/drizzle/drizzle.c b/src/modules/drizzle/drizzle.c index 844a19a..83ba334 100644 --- a/src/modules/drizzle/drizzle.c +++ b/src/modules/drizzle/drizzle.c @@ -91,11 +91,11 @@ static inline uint32_t color_to_uint32(v3f_t color) { } -static til_module_context_t * drizzle_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * drizzle_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { drizzle_context_t *ctxt; - ctxt = til_module_context_new(module, sizeof(drizzle_context_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(drizzle_context_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/flui2d/flui2d.c b/src/modules/flui2d/flui2d.c index 41baaac..09869b3 100644 --- a/src/modules/flui2d/flui2d.c +++ b/src/modules/flui2d/flui2d.c @@ -249,12 +249,12 @@ static void gamma_init(float gamma) } -static til_module_context_t * flui2d_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * flui2d_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { static int initialized; flui2d_context_t *ctxt; - ctxt = til_module_context_new(module, sizeof(flui2d_context_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(flui2d_context_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/julia/julia.c b/src/modules/julia/julia.c index 3428490..e5ce433 100644 --- a/src/modules/julia/julia.c +++ b/src/modules/julia/julia.c @@ -67,11 +67,11 @@ static uint32_t colors[] = { }; -static til_module_context_t * julia_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * julia_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { julia_context_t *ctxt; - ctxt = til_module_context_new(module, sizeof(julia_context_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(julia_context_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/meta2d/meta2d.c b/src/modules/meta2d/meta2d.c index c4fd9f8..804e4fc 100644 --- a/src/modules/meta2d/meta2d.c +++ b/src/modules/meta2d/meta2d.c @@ -80,11 +80,11 @@ static inline uint32_t color_to_uint32(v3f_t color) { } -static til_module_context_t * meta2d_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * meta2d_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { meta2d_context_t *ctxt; - ctxt = til_module_context_new(module, sizeof(meta2d_context_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(meta2d_context_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/moire/moire.c b/src/modules/moire/moire.c index e75a5df..f8907af 100644 --- a/src/modules/moire/moire.c +++ b/src/modules/moire/moire.c @@ -42,11 +42,11 @@ typedef struct moire_context_t { moire_center_t centers[]; } moire_context_t; -static til_module_context_t * moire_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +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; - ctxt = til_module_context_new(module, sizeof(moire_context_t) + ((moire_setup_t *)setup)->n_centers * sizeof(moire_center_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(moire_context_t) + ((moire_setup_t *)setup)->n_centers * sizeof(moire_center_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/montage/montage.c b/src/modules/montage/montage.c index 78d40e2..301f323 100644 --- a/src/modules/montage/montage.c +++ b/src/modules/montage/montage.c @@ -16,7 +16,7 @@ typedef struct montage_context_t { size_t n_modules; } montage_context_t; -static til_module_context_t * montage_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup); +static til_module_context_t * montage_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup); static void montage_destroy_context(til_module_context_t *context); static void montage_prepare_frame(til_module_context_t *context, til_stream_t *stream, unsigned ticks, til_fb_fragment_t **fragment_ptr, til_frame_plan_t *res_frame_plan); static void montage_render_fragment(til_module_context_t *context, til_stream_t *stream, unsigned ticks, unsigned cpu, til_fb_fragment_t **fragment_ptr); @@ -32,13 +32,13 @@ til_module_t montage_module = { }; -static til_module_context_t * montage_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * montage_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { const til_module_t **modules, *rtv_module, *compose_module; size_t n_modules; montage_context_t *ctxt; - ctxt = til_module_context_new(module, sizeof(montage_context_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(montage_context_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; @@ -93,7 +93,7 @@ static til_module_context_t * montage_create_context(const til_module_t *module, (void) til_module_randomize_setup(module, rand_r(&seed), &setup, NULL); /* FIXME errors */ - (void) til_module_create_context(module, stream, rand_r(&seed), ticks, 1, path, setup, &ctxt->contexts[i]); + (void) til_module_create_context(module, stream, rand_r(&seed), ticks, 1, setup, &ctxt->contexts[i]); til_setup_free(setup); } diff --git a/src/modules/pixbounce/pixbounce.c b/src/modules/pixbounce/pixbounce.c index 4589b60..fcc3c5b 100644 --- a/src/modules/pixbounce/pixbounce.c +++ b/src/modules/pixbounce/pixbounce.c @@ -235,11 +235,11 @@ static uint32_t pick_color(unsigned *seedp) return makergb(rand_r(seedp)%256, rand_r(seedp)%256, rand_r(seedp)%256, 1); } -static til_module_context_t * pixbounce_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * pixbounce_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { pixbounce_context_t *ctxt; - ctxt = til_module_context_new(module, sizeof(pixbounce_context_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(pixbounce_context_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/plasma/plasma.c b/src/modules/plasma/plasma.c index e23599a..473574a 100644 --- a/src/modules/plasma/plasma.c +++ b/src/modules/plasma/plasma.c @@ -53,7 +53,7 @@ static void init_plasma(int32_t *costab, int32_t *sintab) } -static til_module_context_t * plasma_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * plasma_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { static int initialized; plasma_context_t *ctxt; @@ -64,7 +64,7 @@ static til_module_context_t * plasma_create_context(const til_module_t *module, init_plasma(costab, sintab); } - ctxt = til_module_context_new(module, sizeof(plasma_context_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(plasma_context_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/plato/plato.c b/src/modules/plato/plato.c index 52e653a..5551268 100644 --- a/src/modules/plato/plato.c +++ b/src/modules/plato/plato.c @@ -630,11 +630,11 @@ static void draw_polyhedron(const polyhedron_t *polyhedron, m4f_t *transform, ti } -static til_module_context_t * plato_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * plato_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { plato_context_t *ctxt; - ctxt = til_module_context_new(module, sizeof(plato_context_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(plato_context_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/ray/ray.c b/src/modules/ray/ray.c index 911fe1d..9ed023d 100644 --- a/src/modules/ray/ray.c +++ b/src/modules/ray/ray.c @@ -132,11 +132,11 @@ typedef struct ray_context_t { } ray_context_t; -static til_module_context_t * ray_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * ray_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { ray_context_t *ctxt; - ctxt = til_module_context_new(module, sizeof(ray_context_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(ray_context_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/rkt/rkt.c b/src/modules/rkt/rkt.c index 6bd4ddd..e76070a 100644 --- a/src/modules/rkt/rkt.c +++ b/src/modules/rkt/rkt.c @@ -47,16 +47,16 @@ typedef struct rkt_setup_t { } rkt_setup_t; -static til_module_context_t * rkt_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * rkt_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { - rkt_context_t *ctxt; + rkt_context_t *ctxt; const til_module_t *seq_module; seq_module = til_lookup_module(((rkt_setup_t *)setup)->seq_module_name); if (!seq_module) return NULL; - ctxt = til_module_context_new(module, sizeof(rkt_context_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(rkt_context_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; @@ -77,7 +77,7 @@ static til_module_context_t * rkt_create_context(const til_module_t *module, til (void) til_module_randomize_setup(ctxt->seq_module, rand_r(&seed), &module_setup, NULL); - (void) til_module_create_context(ctxt->seq_module, stream, rand_r(&seed), ticks, 0, path, module_setup, &ctxt->seq_module_ctxt); + (void) til_module_create_context(ctxt->seq_module, stream, rand_r(&seed), ticks, 0, module_setup, &ctxt->seq_module_ctxt); til_setup_free(module_setup); } diff --git a/src/modules/roto/roto.c b/src/modules/roto/roto.c index 1838f62..322b967 100644 --- a/src/modules/roto/roto.c +++ b/src/modules/roto/roto.c @@ -62,7 +62,7 @@ static void init_roto(uint8_t texture[256][256], int32_t *costab, int32_t *sinta } -static til_module_context_t * roto_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * roto_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { static int initialized; roto_context_t *ctxt; @@ -73,7 +73,7 @@ static til_module_context_t * roto_create_context(const til_module_t *module, ti init_roto(texture, costab, sintab); } - ctxt = til_module_context_new(module, sizeof(roto_context_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(roto_context_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/rtv/rtv.c b/src/modules/rtv/rtv.c index a2bc3c9..c3555c5 100644 --- a/src/modules/rtv/rtv.c +++ b/src/modules/rtv/rtv.c @@ -67,7 +67,7 @@ typedef struct rtv_setup_t { } rtv_setup_t; static void setup_next_channel(rtv_context_t *ctxt, unsigned ticks); -static til_module_context_t * rtv_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup); +static til_module_context_t * rtv_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup); static void rtv_destroy_context(til_module_context_t *context); static void rtv_render_fragment(til_module_context_t *context, til_stream_t *stream, unsigned ticks, unsigned cpu, til_fb_fragment_t **fragment_ptr); static void rtv_finish_frame(til_module_context_t *context, til_stream_t *stream, unsigned ticks, til_fb_fragment_t **fragment_ptr); @@ -195,7 +195,7 @@ static void setup_next_channel(rtv_context_t *ctxt, unsigned ticks) } if (!ctxt->channel->module_ctxt) - (void) til_module_create_context(ctxt->channel->module, ctxt->til_module_context.stream, rand_r(&ctxt->til_module_context.seed), ticks, ctxt->til_module_context.n_cpus, ctxt->til_module_context.path, ctxt->channel->module_setup, &ctxt->channel->module_ctxt); + (void) til_module_create_context(ctxt->channel->module, ctxt->til_module_context.stream, rand_r(&ctxt->til_module_context.seed), ticks, ctxt->til_module_context.n_cpus, ctxt->channel->module_setup, &ctxt->channel->module_ctxt); ctxt->channel->last_on_time = now; } @@ -227,7 +227,7 @@ static int rtv_should_skip_module(const rtv_setup_t *setup, const til_module_t * } -static til_module_context_t * rtv_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * rtv_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { rtv_context_t *ctxt; const til_module_t **modules; @@ -241,7 +241,7 @@ static til_module_context_t * rtv_create_context(const til_module_t *module, til n_channels++; } - ctxt = til_module_context_new(module, sizeof(rtv_context_t) + n_channels * sizeof(rtv_channel_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(rtv_context_t) + n_channels * sizeof(rtv_channel_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; @@ -257,7 +257,7 @@ static til_module_context_t * rtv_create_context(const til_module_t *module, til ((rtv_setup_t *)setup)->snow_module_setup = NULL; ctxt->snow_channel.module = til_lookup_module(((rtv_setup_t *)setup)->snow_module_name); - (void) til_module_create_context(ctxt->snow_channel.module, stream, rand_r(&seed), ticks, n_cpus, path, ctxt->snow_channel.module_setup, &ctxt->snow_channel.module_ctxt); + (void) til_module_create_context(ctxt->snow_channel.module, stream, rand_r(&seed), ticks, n_cpus, ctxt->snow_channel.module_setup, &ctxt->snow_channel.module_ctxt); } ctxt->log_channels = ((rtv_setup_t *)setup)->log_channels; diff --git a/src/modules/shapes/shapes.c b/src/modules/shapes/shapes.c index ab836a0..e7a0b56 100644 --- a/src/modules/shapes/shapes.c +++ b/src/modules/shapes/shapes.c @@ -93,11 +93,11 @@ typedef struct shapes_context_t { } shapes_context_t; -static til_module_context_t * shapes_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * shapes_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { shapes_context_t *ctxt; - ctxt = til_module_context_new(module, sizeof(shapes_context_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(shapes_context_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/snow/snow.c b/src/modules/snow/snow.c index 7ffd3af..1640ff2 100644 --- a/src/modules/snow/snow.c +++ b/src/modules/snow/snow.c @@ -22,11 +22,11 @@ typedef struct snow_context_t { } snow_context_t; -static til_module_context_t * snow_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * snow_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { snow_context_t *ctxt; - ctxt = til_module_context_new(module, sizeof(snow_context_t) + n_cpus * sizeof(snow_seed_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(snow_context_t) + n_cpus * sizeof(snow_seed_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/sparkler/sparkler.c b/src/modules/sparkler/sparkler.c index b6ffd01..8cd1bf9 100644 --- a/src/modules/sparkler/sparkler.c +++ b/src/modules/sparkler/sparkler.c @@ -33,11 +33,11 @@ typedef struct sparkler_context_t { extern particle_ops_t simple_ops; -static til_module_context_t * sparkler_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * sparkler_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { sparkler_context_t *ctxt; - ctxt = til_module_context_new(module, sizeof(sparkler_context_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(sparkler_context_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/spiro/spiro.c b/src/modules/spiro/spiro.c index 3fa8f7e..ef9e7b6 100644 --- a/src/modules/spiro/spiro.c +++ b/src/modules/spiro/spiro.c @@ -31,12 +31,12 @@ typedef struct spiro_context_t { } spiro_context_t; -static til_module_context_t * spiro_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * spiro_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { spiro_context_t *ctxt; float z; - ctxt = til_module_context_new(module, sizeof(spiro_context_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(spiro_context_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/stars/stars.c b/src/modules/stars/stars.c index 6d5f3c0..033794b 100644 --- a/src/modules/stars/stars.c +++ b/src/modules/stars/stars.c @@ -66,13 +66,13 @@ float get_random_unit_coord(unsigned *seed) { } -static til_module_context_t * stars_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * stars_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { stars_context_t *ctxt; float z; struct points* p_ptr = NULL; - ctxt = til_module_context_new(module, sizeof(stars_context_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(stars_context_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/strobe/strobe.c b/src/modules/strobe/strobe.c index 9f6b04a..a8d4237 100644 --- a/src/modules/strobe/strobe.c +++ b/src/modules/strobe/strobe.c @@ -35,11 +35,11 @@ typedef struct strobe_context_t { } strobe_context_t; -static til_module_context_t * strobe_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * strobe_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { strobe_context_t *ctxt; - ctxt = til_module_context_new(module, sizeof(strobe_context_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(strobe_context_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/submit/submit.c b/src/modules/submit/submit.c index c50b67c..a3f7b25 100644 --- a/src/modules/submit/submit.c +++ b/src/modules/submit/submit.c @@ -265,11 +265,11 @@ static void setup_grid(submit_context_t *ctxt) } -static til_module_context_t * submit_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * submit_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { submit_context_t *ctxt; - ctxt = til_module_context_new(module, sizeof(submit_context_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(submit_context_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/swab/swab.c b/src/modules/swab/swab.c index bff6f6b..9b7043c 100644 --- a/src/modules/swab/swab.c +++ b/src/modules/swab/swab.c @@ -66,11 +66,11 @@ static inline uint32_t color_to_uint32(color_t color) { } -static til_module_context_t * swab_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * swab_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { swab_context_t *ctxt; - ctxt = til_module_context_new(module, sizeof(swab_context_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(swab_context_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/swarm/swarm.c b/src/modules/swarm/swarm.c index 4a21260..8e2d853 100644 --- a/src/modules/swarm/swarm.c +++ b/src/modules/swarm/swarm.c @@ -177,11 +177,11 @@ static inline uint32_t color_to_uint32(v3f_t color) { } -static til_module_context_t * swarm_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * swarm_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { swarm_context_t *ctxt; - ctxt = til_module_context_new(module, sizeof(swarm_context_t) + sizeof(*(ctxt->boids)) * SWARM_SIZE, stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(swarm_context_t) + sizeof(*(ctxt->boids)) * SWARM_SIZE, stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; diff --git a/src/modules/voronoi/voronoi.c b/src/modules/voronoi/voronoi.c index 45333b0..b2eff94 100644 --- a/src/modules/voronoi/voronoi.c +++ b/src/modules/voronoi/voronoi.c @@ -89,11 +89,11 @@ static void voronoi_randomize(voronoi_context_t *ctxt, int do_colors) } -static til_module_context_t * voronoi_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +static til_module_context_t * voronoi_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { voronoi_context_t *ctxt; - ctxt = til_module_context_new(module, sizeof(voronoi_context_t) + ((voronoi_setup_t *)setup)->n_cells * sizeof(voronoi_cell_t), stream, seed, ticks, n_cpus, path, setup); + ctxt = til_module_context_new(module, sizeof(voronoi_context_t) + ((voronoi_setup_t *)setup)->n_cells * sizeof(voronoi_cell_t), stream, seed, ticks, n_cpus, setup); if (!ctxt) return NULL; @@ -225,35 +225,21 @@ void til_module_render(til_module_context_t *context, til_stream_t *stream, unsi * the purpose of explicitly constraining rendering parallelization to less than n_threads, * if n_cpus is specified > n_threads it won't increase n_threads... */ -int til_module_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, const char *parent_path, til_setup_t *setup, til_module_context_t **res_context) +int til_module_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup, til_module_context_t **res_context) { til_module_context_t *context; - char *path; assert(module); - assert(parent_path); - assert(setup || !module->setup); /* if a module provides a .setup() method, it can assume a provided setup */ + assert(setup); /* we *always* want a setup, even if the module has no setup() method - for the path */ assert(res_context); - { - size_t path_len; - - /* TODO: when til_setup_t learns to name settings blocks, this would be where to override module->name with the setup-specified name */ - path_len = strlen(parent_path) + 1 + strlen(module->name) + 1; - path = calloc(1, path_len); - if (!path) - return -ENOMEM; - - snprintf(path, path_len, "%s/%s", parent_path, module->name); - } - if (!n_cpus) n_cpus = til_threads_num_threads(til_threads); if (!module->create_context) - context = til_module_context_new(module, sizeof(til_module_context_t), stream, seed, ticks, n_cpus, path, setup); + context = til_module_context_new(module, sizeof(til_module_context_t), stream, seed, ticks, n_cpus, setup); else - context = module->create_context(module, stream, seed, ticks, n_cpus, path, setup); + context = module->create_context(module, stream, seed, ticks, n_cpus, setup); if (!context) return -ENOMEM; @@ -25,7 +25,7 @@ typedef struct til_stream_t til_stream_t; #define TIL_MODULE_EXPERIMENTAL 4u /* module is buggy / unfinished */ struct til_module_t { - til_module_context_t * (*create_context)(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup); + til_module_context_t * (*create_context)(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup); void (*destroy_context)(til_module_context_t *context); /* destroy gets stream in context, but the render-related functions should always use the passed-in stream so it can potentially change */ void (*prepare_frame)(til_module_context_t *context, til_stream_t *stream, unsigned ticks, til_fb_fragment_t **fragment_ptr, til_frame_plan_t *res_frame_plan); void (*render_fragment)(til_module_context_t *context, til_stream_t *stream, unsigned ticks, unsigned cpu, til_fb_fragment_t **fragment_ptr); @@ -43,7 +43,7 @@ void til_shutdown(void); const til_module_t * til_lookup_module(const char *name); void til_get_modules(const til_module_t ***res_modules, size_t *res_n_modules); void til_module_render(til_module_context_t *context, til_stream_t *stream, unsigned ticks, til_fb_fragment_t **fragment_ptr); -int til_module_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, const char *parent_path, til_setup_t *setup, til_module_context_t **res_context); +int til_module_create_context(const til_module_t *module, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup, til_module_context_t **res_context); til_module_context_t * til_module_destroy_context(til_module_context_t *context, til_stream_t *stream); int til_module_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup); int til_module_randomize_setup(const til_module_t *module, unsigned seed, til_setup_t **res_setup, char **res_arg); diff --git a/src/til_module_context.c b/src/til_module_context.c index bf87ce2..98a32cd 100644 --- a/src/til_module_context.c +++ b/src/til_module_context.c @@ -27,33 +27,29 @@ * as the callers are generally using it in place of calloc(), and assign it to a * container struct of some other type but having an embedded til_module_context_t. * - * path must not be NULL, and the context always takes ownership of the path; it's freed @ context_free(). + * setup must not be NULL, even for modules without a setup method, as the setup *always* provides the path + * for the context. The context takes a reference on the provided setup, which will be dropped when the + * context is freed. */ -void * til_module_context_new(const til_module_t *module, size_t size, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup) +void * til_module_context_new(const til_module_t *module, size_t size, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup) { til_module_context_t *module_context; assert(module); assert(size >= sizeof(til_module_context_t)); assert(n_cpus > 0); - assert(path); /* modules must be able to key things like taps off their context's path */ + assert(setup); /* modules must be able to key things like taps off their context's path @ setup->path */ module_context = calloc(1, size); - if (!module_context) { - free(path); - + if (!module_context) return NULL; - } module_context->module = module; module_context->stream = stream; module_context->seed = seed; module_context->ticks = ticks; module_context->n_cpus = n_cpus; - module_context->path = path; - module_context->path_hash = til_jenkins((uint8_t *)path, strlen(path)); - if (setup) - module_context->setup = til_setup_ref(setup); + module_context->setup = til_setup_ref(setup); return module_context; } @@ -66,14 +62,12 @@ void * til_module_context_new(const til_module_t *module, size_t size, til_strea */ void * til_module_context_free(til_module_context_t *module_context) { - char *path; til_stream_t *stream; til_setup_t *setup; if (!module_context) return NULL; - path = module_context->path; /* free last just in case the module destructor makes use of it */ stream = module_context->stream; setup = module_context->setup; @@ -82,8 +76,7 @@ void * til_module_context_free(til_module_context_t *module_context) else free(module_context); - free(path); - (void) til_setup_free(setup); + (void) til_setup_free(setup); /* free last just in case the module destructor makes use of it */ /* cleanup any pipes this context might have had in the stream, if the * module's destroy_context() also does this it's harmlessly idempotent diff --git a/src/til_module_context.h b/src/til_module_context.h index 7a5fca5..cbbfb8e 100644 --- a/src/til_module_context.h +++ b/src/til_module_context.h @@ -1,8 +1,6 @@ #ifndef _TIL_MODULE_CONTEXT_H #define _TIL_MODULE_CONTEXT_H -#include <stdint.h> - typedef struct til_module_context_t til_module_context_t; typedef struct til_module_t til_module_t; typedef struct til_setup_t til_setup_t; @@ -14,12 +12,12 @@ struct til_module_context_t { unsigned seed; unsigned ticks; unsigned n_cpus; - char *path; /* for locating this instance of the module, NOT a file path */ - uint32_t path_hash; - til_setup_t *setup; /* optional baked setup this context was made from (reffed by context when present) */ + 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. + */ }; -void * til_module_context_new(const til_module_t *module, size_t size, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, char *path, til_setup_t *setup); +void * til_module_context_new(const til_module_t *module, size_t size, til_stream_t *stream, unsigned seed, unsigned ticks, unsigned n_cpus, til_setup_t *setup); void * til_module_context_free(til_module_context_t *module_context); #endif diff --git a/src/til_stream.h b/src/til_stream.h index 3f0a618..da1abdf 100644 --- a/src/til_stream.h +++ b/src/til_stream.h @@ -21,6 +21,7 @@ #include <stdint.h> #include "til_module_context.h" +#include "til_setup.h" typedef struct til_stream_t til_stream_t; typedef struct til_stream_pipe_t til_stream_pipe_t; @@ -52,7 +53,7 @@ int til_stream_tap(til_stream_t *stream, const void *owner, const void *owner_fo /* convenience helper for use within modules */ static inline int til_stream_tap_context(til_stream_t *stream, const til_module_context_t *module_context, const void *owner_foo, const til_tap_t *tap) { - return til_stream_tap(stream, module_context, owner_foo, module_context->path, module_context->path_hash, tap); + return til_stream_tap(stream, module_context, owner_foo, module_context->setup->path, module_context->setup->path_hash, tap); } void til_stream_untap_owner(til_stream_t *stream, const void *owner); |