summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2022-04-24 19:24:47 -0700
committerVito Caputo <vcaputo@pengaru.com>2022-04-24 19:24:47 -0700
commit9f9f9eaa096e6be8c1613014868e919d6991b188 (patch)
treeba943101653dd2729cad4ae19c9e6f5f583f5977 /src
parent1435249cd1cac95d31403a9592018eaad9c7cb00 (diff)
*: s/void */til_setup_t */
This brings something resembling an actual type to the private objects returrned in *res_setup. Internally libtil/rototiller wants this to be a til_setup_t, and it's up to the private users of what's returned in *res_setup to embed this appropriately and either use container_of() or casting when simply embedded at the start to go between til_setup_t and their private containing struct. Everywhere *res_setup was previously allocated using calloc() is now using til_setup_new() with a free_func, which til_setup_new() will initialize appropriately. There's still some remaining work to do with the supplied free_func in some modules, where free() isn't quite appropriate. Setup freeing isn't actually being performed yet, but this sets the foundation for that to happen in a subsequent commit that cleans up the setup leaks. Many modules use a static default setup for when no setup has been provided. In those cases, the free_func would be NULL, which til_setup_new() refuses to do. When setup freeing actually starts happening, it'll simply skip freeing when til_setup_t.free_func is NULL.
Diffstat (limited to 'src')
-rw-r--r--src/drm_fb.c2
-rw-r--r--src/main.c6
-rw-r--r--src/modules/checkers/checkers.c11
-rw-r--r--src/modules/compose/compose.c21
-rw-r--r--src/modules/drizzle/drizzle.c11
-rw-r--r--src/modules/flui2d/flui2d.c17
-rw-r--r--src/modules/julia/julia.c2
-rw-r--r--src/modules/meta2d/meta2d.c2
-rw-r--r--src/modules/montage/montage.c6
-rw-r--r--src/modules/pixbounce/pixbounce.c2
-rw-r--r--src/modules/plasma/plasma.c2
-rw-r--r--src/modules/plato/plato.c2
-rw-r--r--src/modules/ray/ray.c2
-rw-r--r--src/modules/roto/roto.c2
-rw-r--r--src/modules/rtv/rtv.c22
-rw-r--r--src/modules/snow/snow.c2
-rw-r--r--src/modules/sparkler/sparkler.c11
-rw-r--r--src/modules/spiro/spiro.c2
-rw-r--r--src/modules/stars/stars.c11
-rw-r--r--src/modules/submit/submit.c11
-rw-r--r--src/modules/swab/swab.c2
-rw-r--r--src/modules/swarm/swarm.c11
-rw-r--r--src/sdl_fb.c2
-rw-r--r--src/setup.c3
-rw-r--r--src/setup.h3
-rw-r--r--src/til.c6
-rw-r--r--src/til.h11
-rw-r--r--src/til_fb.h3
28 files changed, 103 insertions, 85 deletions
diff --git a/src/drm_fb.c b/src/drm_fb.c
index 67d8e68..328c92c 100644
--- a/src/drm_fb.c
+++ b/src/drm_fb.c
@@ -283,7 +283,7 @@ static int mode_desc_generator(void *setup_context, const til_setting_desc_t **r
/* setup is called repeatedly as settings is constructed, until 0 is returned. */
/* a negative value is returned on error */
/* positive value indicates another setting is needed, described in next_setting */
-static int drm_fb_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup)
+static int drm_fb_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup)
{
drm_fb_setup_t context = {};
til_setting_desc_generator_t generators[] = {
diff --git a/src/main.c b/src/main.c
index 15bde39..9174ec3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -51,9 +51,9 @@ static rototiller_t rototiller;
typedef struct setup_t {
til_settings_t *module;
- void *module_setup;
+ til_setup_t *module_setup;
til_settings_t *video;
- void *video_setup;
+ til_setup_t *video_setup;
} setup_t;
/* FIXME: this is unnecessarily copy-pasta, i think modules should just be made
@@ -62,7 +62,7 @@ typedef struct setup_t {
*/
/* select video backend if not yet selected, then setup the selected backend. */
-static int setup_video(til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup)
+static int setup_video(til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup)
{
til_setting_t *setting;
const char *video;
diff --git a/src/modules/checkers/checkers.c b/src/modules/checkers/checkers.c
index a88f17c..2b626e7 100644
--- a/src/modules/checkers/checkers.c
+++ b/src/modules/checkers/checkers.c
@@ -41,6 +41,7 @@ typedef enum checkers_dynamics_t {
} checkers_dynamics_t;
typedef struct checkers_setup_t {
+ til_setup_t til_setup;
unsigned size;
checkers_pattern_t pattern;
checkers_dynamics_t dynamics;
@@ -60,12 +61,12 @@ static checkers_setup_t checkers_default_setup = {
};
-static void * checkers_create_context(unsigned ticks, unsigned num_cpus, void *setup)
+static void * checkers_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup)
{
checkers_context_t *ctxt;
if (!setup)
- setup = &checkers_default_setup;
+ setup = &checkers_default_setup.til_setup;
ctxt = calloc(1, sizeof(checkers_context_t));
if (!ctxt)
@@ -150,7 +151,7 @@ static void checkers_render_fragment(void *context, unsigned ticks, unsigned cpu
}
-static int checkers_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup)
+static int checkers_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup)
{
const char *size;
const char *pattern;
@@ -252,7 +253,7 @@ static int checkers_setup(const til_settings_t *settings, til_setting_t **res_se
if (res_setup) {
checkers_setup_t *setup;
- setup = calloc(1, sizeof(*setup));
+ setup = til_setup_new(sizeof(*setup), (void(*)(til_setup_t *))free);
if (!setup)
return -ENOMEM;
@@ -283,7 +284,7 @@ static int checkers_setup(const til_settings_t *settings, til_setting_t **res_se
if (setup->dynamics != CHECKERS_DYNAMICS_ODD && setup->dynamics != CHECKERS_DYNAMICS_EVEN)
sscanf(dynamics_rate, "%f", &setup->rate);
- *res_setup = setup;
+ *res_setup = &setup->til_setup;
}
return 0;
diff --git a/src/modules/compose/compose.c b/src/modules/compose/compose.c
index 180df44..0fa1204 100644
--- a/src/modules/compose/compose.c
+++ b/src/modules/compose/compose.c
@@ -37,14 +37,15 @@ typedef struct compose_context_t {
} compose_context_t;
typedef struct compose_setup_t {
+ til_setup_t til_setup;
size_t n_layers;
char *layers[];
} compose_setup_t;
-static void * compose_create_context(unsigned ticks, unsigned num_cpus, void *setup);
+static void * compose_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup);
static void compose_destroy_context(void *context);
static void compose_prepare_frame(void *context, unsigned ticks, unsigned n_cpus, til_fb_fragment_t *fragment, til_fragmenter_t *res_fragmenter);
-static int compose_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup);
+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);
static compose_setup_t compose_default_setup = {
.layers = { "drizzle", "stars", "spiro", "plato", NULL },
@@ -61,13 +62,13 @@ til_module_t compose_module = {
};
-static void * compose_create_context(unsigned ticks, unsigned num_cpus, void *setup)
+static void * compose_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup)
{
compose_context_t *ctxt;
size_t n;
if (!setup)
- setup = &compose_default_setup;
+ setup = &compose_default_setup.til_setup;
for (n = 0; ((compose_setup_t *)setup)->layers[n]; n++);
@@ -79,7 +80,7 @@ static void * compose_create_context(unsigned ticks, unsigned num_cpus, void *se
for (int i = 0; i < n; i++) {
const til_module_t *layer_module;
- void *layer_setup = NULL;
+ til_setup_t *layer_setup = NULL;
layer_module = til_lookup_module(((compose_setup_t *)setup)->layers[i]);
(void) til_module_randomize_setup(layer_module, &layer_setup, NULL);
@@ -117,7 +118,7 @@ static void compose_prepare_frame(void *context, unsigned ticks, unsigned n_cpus
}
-static int compose_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup)
+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)
{
const char *layers;
int r;
@@ -137,7 +138,7 @@ static int compose_setup(const til_settings_t *settings, til_setting_t **res_set
/* turn layers colon-separated list into a null-terminated array of strings */
if (res_setup) {
- compose_setup_t *setup = NULL;
+ compose_setup_t *setup;
const til_module_t **modules;
size_t n_modules;
char *toklayers, *layer;
@@ -153,6 +154,10 @@ static int compose_setup(const til_settings_t *settings, til_setting_t **res_set
if (!layer)
return -EINVAL;
+ setup = til_setup_new(sizeof(*setup), (void(*)(til_setup_t *))free);
+ if (!setup)
+ return -ENOMEM;
+
do {
compose_setup_t *new;
size_t i;
@@ -184,7 +189,7 @@ static int compose_setup(const til_settings_t *settings, til_setting_t **res_set
setup = new;
} while (layer = strtok(NULL, ":"));
- *res_setup = setup;
+ *res_setup = &setup->til_setup;
}
return 0;
diff --git a/src/modules/drizzle/drizzle.c b/src/modules/drizzle/drizzle.c
index d3d3c3e..2fa3b75 100644
--- a/src/modules/drizzle/drizzle.c
+++ b/src/modules/drizzle/drizzle.c
@@ -36,6 +36,7 @@ typedef struct v2f_t {
} v2f_t;
typedef struct drizzle_setup_t {
+ til_setup_t til_setup;
float viscosity;
} drizzle_setup_t;
@@ -72,12 +73,12 @@ static inline uint32_t color_to_uint32(v3f_t color) {
}
-static void * drizzle_create_context(unsigned ticks, unsigned num_cpus, void *setup)
+static void * drizzle_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup)
{
drizzle_context_t *ctxt;
if (!setup)
- setup = &drizzle_default_setup;
+ setup = &drizzle_default_setup.til_setup;
ctxt = calloc(1, sizeof(drizzle_context_t));
if (!ctxt)
@@ -165,7 +166,7 @@ static void drizzle_render_fragment(void *context, unsigned ticks, unsigned cpu,
}
-static int drizzle_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup)
+static int drizzle_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup)
{
const char *viscosity;
const char *values[] = {
@@ -195,13 +196,13 @@ static int drizzle_setup(const til_settings_t *settings, til_setting_t **res_set
if (res_setup) {
drizzle_setup_t *setup;
- setup = calloc(1, sizeof(*setup));
+ setup = til_setup_new(sizeof(*setup), (void(*)(til_setup_t *))free);
if (!setup)
return -ENOMEM;
sscanf(viscosity, "%f", &setup->viscosity);
- *res_setup = setup;
+ *res_setup = &setup->til_setup;
}
return 0;
diff --git a/src/modules/flui2d/flui2d.c b/src/modules/flui2d/flui2d.c
index d5b3b72..1c2715d 100644
--- a/src/modules/flui2d/flui2d.c
+++ b/src/modules/flui2d/flui2d.c
@@ -181,9 +181,10 @@ typedef struct flui2d_context_t {
} flui2d_context_t;
typedef struct flui2d_setup_t {
- float viscosity;
- float diffusion;
- float decay;
+ til_setup_t til_setup;
+ float viscosity;
+ float diffusion;
+ float decay;
} flui2d_setup_t;
static flui2d_setup_t flui2d_default_setup = {
@@ -193,12 +194,12 @@ static flui2d_setup_t flui2d_default_setup = {
};
-static void * flui2d_create_context(unsigned ticks, unsigned num_cpus, void *setup)
+static void * flui2d_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup)
{
flui2d_context_t *ctxt;
if (!setup)
- setup = &flui2d_default_setup;
+ setup = &flui2d_default_setup.til_setup;
ctxt = calloc(1, sizeof(flui2d_context_t));
if (!ctxt)
@@ -294,7 +295,7 @@ static void flui2d_render_fragment(void *context, unsigned ticks, unsigned cpu,
/* Settings hooks for configurable variables */
-static int flui2d_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup)
+static int flui2d_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup)
{
const char *viscosity;
const char *diffusion;
@@ -368,7 +369,7 @@ static int flui2d_setup(const til_settings_t *settings, til_setting_t **res_sett
if (res_setup) {
flui2d_setup_t *setup;
- setup = calloc(1, sizeof(*setup));
+ setup = til_setup_new(sizeof(*setup), (void(*)(til_setup_t *))free);
if (!setup)
return -ENOMEM;
@@ -383,7 +384,7 @@ static int flui2d_setup(const til_settings_t *settings, til_setting_t **res_sett
return -EINVAL;
}
- *res_setup = setup;
+ *res_setup = &setup->til_setup;
}
return 0;
diff --git a/src/modules/julia/julia.c b/src/modules/julia/julia.c
index dfe6726..fb3bdae 100644
--- a/src/modules/julia/julia.c
+++ b/src/modules/julia/julia.c
@@ -66,7 +66,7 @@ static uint32_t colors[] = {
};
-static void * julia_create_context(unsigned ticks, unsigned num_cpus, void *setup)
+static void * julia_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup)
{
return calloc(1, sizeof(julia_context_t));
}
diff --git a/src/modules/meta2d/meta2d.c b/src/modules/meta2d/meta2d.c
index 4e8024b..8edff42 100644
--- a/src/modules/meta2d/meta2d.c
+++ b/src/modules/meta2d/meta2d.c
@@ -66,7 +66,7 @@ static inline uint32_t color_to_uint32(v3f_t color) {
}
-static void * meta2d_create_context(unsigned ticks, unsigned num_cpus, void *setup)
+static void * meta2d_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup)
{
meta2d_context_t *ctxt;
diff --git a/src/modules/montage/montage.c b/src/modules/montage/montage.c
index 15c1354..268d7db 100644
--- a/src/modules/montage/montage.c
+++ b/src/modules/montage/montage.c
@@ -16,7 +16,7 @@ typedef struct montage_context_t {
} montage_context_t;
static void setup_next_module(montage_context_t *ctxt);
-static void * montage_create_context(unsigned ticks, unsigned num_cpus, void *setup);
+static void * montage_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup);
static void montage_destroy_context(void *context);
static void montage_prepare_frame(void *context, unsigned ticks, unsigned n_cpus, til_fb_fragment_t *fragment, til_fragmenter_t *res_fragmenter);
static void montage_render_fragment(void *context, unsigned ticks, unsigned cpu, til_fb_fragment_t *fragment);
@@ -32,7 +32,7 @@ til_module_t montage_module = {
};
-static void * montage_create_context(unsigned ticks, unsigned num_cpus, void *setup)
+static void * montage_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup)
{
const til_module_t **modules, *rtv_module, *compose_module;
size_t n_modules;
@@ -88,7 +88,7 @@ static void * montage_create_context(unsigned ticks, unsigned num_cpus, void *se
for (size_t i = 0; i < ctxt->n_modules; i++) {
const til_module_t *module = ctxt->modules[i];
- void *setup = NULL;
+ til_setup_t *setup = NULL;
(void) til_module_randomize_setup(module, &setup, NULL);
diff --git a/src/modules/pixbounce/pixbounce.c b/src/modules/pixbounce/pixbounce.c
index ff2d990..5f54644 100644
--- a/src/modules/pixbounce/pixbounce.c
+++ b/src/modules/pixbounce/pixbounce.c
@@ -109,7 +109,7 @@ static int pick_pix(int num_pics, int last_pic)
return pix_num;
}
-static void * pixbounce_create_context(unsigned ticks, unsigned num_cpus, void *setup)
+static void * pixbounce_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup)
{
pixbounce_context_t *ctxt;
diff --git a/src/modules/plasma/plasma.c b/src/modules/plasma/plasma.c
index c6380ef..81540c5 100644
--- a/src/modules/plasma/plasma.c
+++ b/src/modules/plasma/plasma.c
@@ -52,7 +52,7 @@ static void init_plasma(int32_t *costab, int32_t *sintab)
}
-static void * plasma_create_context(unsigned ticks, unsigned num_cpus, void *setup)
+static void * plasma_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup)
{
static int initialized;
diff --git a/src/modules/plato/plato.c b/src/modules/plato/plato.c
index 5942d93..bc38f2d 100644
--- a/src/modules/plato/plato.c
+++ b/src/modules/plato/plato.c
@@ -609,7 +609,7 @@ static void draw_polyhedron(const polyhedron_t *polyhedron, m4f_t *transform, ti
}
-static void * plato_create_context(unsigned ticks, unsigned num_cpus, void *setup)
+static void * plato_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup)
{
plato_context_t *ctxt;
diff --git a/src/modules/ray/ray.c b/src/modules/ray/ray.c
index 79e14ce..49d3371 100644
--- a/src/modules/ray/ray.c
+++ b/src/modules/ray/ray.c
@@ -130,7 +130,7 @@ typedef struct ray_context_t {
} ray_context_t;
-static void * ray_create_context(unsigned ticks, unsigned num_cpus, void *setup)
+static void * ray_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup)
{
return calloc(1, sizeof(ray_context_t));
}
diff --git a/src/modules/roto/roto.c b/src/modules/roto/roto.c
index ac66987..5409970 100644
--- a/src/modules/roto/roto.c
+++ b/src/modules/roto/roto.c
@@ -32,7 +32,7 @@ static int32_t costab[FIXED_TRIG_LUT_SIZE], sintab[FIXED_TRIG_LUT_SIZE];
static uint8_t texture[256][256];
static color_t palette[2];
-static void * roto_create_context(unsigned ticks, unsigned num_cpus, void *setup)
+static void * roto_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup)
{
return calloc(1, sizeof(roto_context_t));
}
diff --git a/src/modules/rtv/rtv.c b/src/modules/rtv/rtv.c
index 742b2bc..06dfd90 100644
--- a/src/modules/rtv/rtv.c
+++ b/src/modules/rtv/rtv.c
@@ -25,7 +25,7 @@
typedef struct rtv_channel_t {
const til_module_t *module;
void *module_ctxt;
- void *module_setup;
+ til_setup_t *module_setup;
time_t last_on_time, cumulative_time;
char *settings;
txt_t *caption;
@@ -51,6 +51,7 @@ typedef struct rtv_context_t {
} rtv_context_t;
typedef struct rtv_setup_t {
+ til_setup_t til_setup;
unsigned duration;
unsigned context_duration;
unsigned snow_duration;
@@ -60,11 +61,11 @@ typedef struct rtv_setup_t {
} rtv_setup_t;
static void setup_next_channel(rtv_context_t *ctxt, unsigned ticks);
-static void * rtv_create_context(unsigned ticks, unsigned num_cpus, void *setup);
+static void * rtv_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup);
static void rtv_destroy_context(void *context);
static void rtv_prepare_frame(void *context, unsigned ticks, unsigned n_cpus, til_fb_fragment_t *fragment, til_fragmenter_t *res_fragmenter);
static void rtv_finish_frame(void *context, unsigned ticks, til_fb_fragment_t *fragment);
-static int rtv_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup);
+static int rtv_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup);
static rtv_setup_t rtv_default_setup = {
.duration = RTV_DURATION_SECS,
@@ -203,7 +204,7 @@ static int rtv_should_skip_module(const rtv_setup_t *setup, const til_module_t *
}
-static void * rtv_create_context(unsigned ticks, unsigned num_cpus, void *setup)
+static void * rtv_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup)
{
rtv_context_t *ctxt;
const til_module_t **modules;
@@ -211,13 +212,13 @@ static void * rtv_create_context(unsigned ticks, unsigned num_cpus, void *setup)
static til_module_t none_module = {};
if (!setup)
- setup = &rtv_default_setup;
+ setup = &rtv_default_setup.til_setup;
til_get_modules(&modules, &n_modules);
/* how many modules are in the setup? */
for (size_t i = 0; i < n_modules; i++) {
- if (!rtv_should_skip_module(setup, modules[i]))
+ if (!rtv_should_skip_module((rtv_setup_t *)setup, modules[i]))
n_channels++;
}
@@ -238,7 +239,7 @@ static void * rtv_create_context(unsigned ticks, unsigned num_cpus, void *setup)
}
for (size_t i = 0; i < n_modules; i++) {
- if (!rtv_should_skip_module(setup, modules[i]))
+ if (!rtv_should_skip_module((rtv_setup_t *)setup, modules[i]))
ctxt->channels[ctxt->n_channels++].module = modules[i];
}
@@ -298,7 +299,7 @@ static void rtv_finish_frame(void *context, unsigned ticks, til_fb_fragment_t *f
}
-static int rtv_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup)
+static int rtv_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup)
{
const char *channels;
const char *duration;
@@ -393,7 +394,8 @@ static int rtv_setup(const til_settings_t *settings, til_setting_t **res_setting
if (res_setup) {
rtv_setup_t *setup;
- setup = calloc(1, sizeof(*setup) + sizeof(setup->channels[0]));
+ /* FIXME: rtv_setup_t.snow_module needs freeing, so we need a bespoke free_func */
+ setup = til_setup_new(sizeof(*setup) + sizeof(setup->channels[0]), (void(*)(til_setup_t *))free);
if (!setup)
return -ENOMEM;
@@ -446,7 +448,7 @@ static int rtv_setup(const til_settings_t *settings, til_setting_t **res_setting
sscanf(caption_duration, "%u", &setup->caption_duration);
sscanf(snow_duration, "%u", &setup->snow_duration);
- *res_setup = setup;
+ *res_setup = &setup->til_setup;
}
return 0;
diff --git a/src/modules/snow/snow.c b/src/modules/snow/snow.c
index f61f2e9..cd364a0 100644
--- a/src/modules/snow/snow.c
+++ b/src/modules/snow/snow.c
@@ -20,7 +20,7 @@ typedef struct snow_context_t {
} snow_context_t;
-static void * snow_create_context(unsigned ticks, unsigned n_cpus, void *setup)
+static void * snow_create_context(unsigned ticks, unsigned n_cpus, til_setup_t *setup)
{
snow_context_t *ctxt;
diff --git a/src/modules/sparkler/sparkler.c b/src/modules/sparkler/sparkler.c
index ec706b9..62abfe5 100644
--- a/src/modules/sparkler/sparkler.c
+++ b/src/modules/sparkler/sparkler.c
@@ -17,6 +17,7 @@
#define INIT_PARTS 100
typedef struct sparkler_setup_t {
+ til_setup_t til_setup;
unsigned show_bsp_leafs:1;
unsigned show_bsp_matches:1;
unsigned show_bsp_matches_affected_only:1;
@@ -33,12 +34,12 @@ extern particle_ops_t simple_ops;
static sparkler_setup_t sparkler_default_setup;
-static void * sparkler_create_context(unsigned ticks, unsigned num_cpus, void *setup)
+static void * sparkler_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup)
{
sparkler_context_t *ctxt;
if (!setup)
- setup = &sparkler_default_setup;
+ setup = &sparkler_default_setup.til_setup;
ctxt = calloc(1, sizeof(sparkler_context_t));
if (!ctxt)
@@ -108,7 +109,7 @@ static void sparkler_render_fragment(void *context, unsigned ticks, unsigned cpu
/* Settings hooks for configurable variables */
-static int sparkler_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup)
+static int sparkler_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup)
{
const char *show_bsp_leafs;
const char *show_bsp_leafs_min_depth;
@@ -192,7 +193,7 @@ static int sparkler_setup(const til_settings_t *settings, til_setting_t **res_se
if (res_setup) {
sparkler_setup_t *setup;
- setup = calloc(1, sizeof(*setup));
+ setup = til_setup_new(sizeof(*setup), (void(*)(til_setup_t *))free);
if (!setup)
return -ENOMEM;
@@ -209,7 +210,7 @@ static int sparkler_setup(const til_settings_t *settings, til_setting_t **res_se
setup->show_bsp_matches_affected_only = 1;
}
- *res_setup = setup;
+ *res_setup = &setup->til_setup;
}
return 0;
diff --git a/src/modules/spiro/spiro.c b/src/modules/spiro/spiro.c
index 546dc60..bf93b27 100644
--- a/src/modules/spiro/spiro.c
+++ b/src/modules/spiro/spiro.c
@@ -29,7 +29,7 @@ typedef struct spiro_context_t {
} spiro_context_t;
-static void * spiro_create_context(unsigned ticks, unsigned num_cpus, void *setup)
+static void * spiro_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup)
{
spiro_context_t *ctxt;
float z;
diff --git a/src/modules/stars/stars.c b/src/modules/stars/stars.c
index d7093fe..150602a 100644
--- a/src/modules/stars/stars.c
+++ b/src/modules/stars/stars.c
@@ -35,6 +35,7 @@ typedef struct stars_context_t {
} stars_context_t;
typedef struct stars_setup_t {
+ til_setup_t til_setup;
float rot_adj;
} stars_setup_t;
@@ -48,14 +49,14 @@ float get_random_unit_coord() {
}
-static void * stars_create_context(unsigned ticks, unsigned num_cpus, void *setup)
+static void * stars_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup)
{
stars_context_t *ctxt;
float z;
struct points* p_ptr = NULL;
if (!setup)
- setup = &stars_default_setup;
+ setup = &stars_default_setup.til_setup;
ctxt = malloc(sizeof(stars_context_t));
if (!ctxt)
@@ -211,7 +212,7 @@ static void stars_render_fragment(void *context, unsigned ticks, unsigned cpu, t
ctxt->offset_y = tmp_y;
}
-int stars_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup)
+int stars_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup)
{
const char *rot_adj;
const char *rot_adj_values[] = {
@@ -243,13 +244,13 @@ int stars_setup(const til_settings_t *settings, til_setting_t **res_setting, con
if (res_setup) {
stars_setup_t *setup;
- setup = calloc(1, sizeof(*setup));
+ setup = til_setup_new(sizeof(*setup), (void(*)(til_setup_t *))free);
if (!setup)
return -ENOMEM;
sscanf(rot_adj, "%f", &setup->rot_adj);
- *res_setup = setup;
+ *res_setup = &setup->til_setup;
}
return 0;
diff --git a/src/modules/submit/submit.c b/src/modules/submit/submit.c
index e1f6008..f8e2ff0 100644
--- a/src/modules/submit/submit.c
+++ b/src/modules/submit/submit.c
@@ -58,6 +58,7 @@ typedef struct submit_context_t {
} submit_context_t;
typedef struct submit_setup_t {
+ til_setup_t til_setup;
unsigned bilerp:1;
} submit_setup_t;
@@ -264,12 +265,12 @@ static void setup_grid(submit_context_t *ctxt)
}
-static void * submit_create_context(unsigned ticks, unsigned num_cpus, void *setup)
+static void * submit_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup)
{
submit_context_t *ctxt;
if (!setup)
- setup = &submit_default_setup;
+ setup = &submit_default_setup.til_setup;
ctxt = calloc(1, sizeof(submit_context_t));
if (!ctxt)
@@ -329,7 +330,7 @@ static void submit_render_fragment(void *context, unsigned ticks, unsigned cpu,
}
-static int submit_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup)
+static int submit_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup)
{
const char *values[] = {
"off",
@@ -357,14 +358,14 @@ static int submit_setup(const til_settings_t *settings, til_setting_t **res_sett
if (res_setup) {
submit_setup_t *setup;
- setup = calloc(1, sizeof(*setup));
+ setup = til_setup_new(sizeof(*setup), (void(*)(til_setup_t *))free);
if (!setup)
return -ENOMEM;
if (!strcasecmp(bilerp, "on"))
setup->bilerp = 1;
- *res_setup = setup;
+ *res_setup = &setup->til_setup;
}
return 0;
diff --git a/src/modules/swab/swab.c b/src/modules/swab/swab.c
index b64ca2b..a635e4d 100644
--- a/src/modules/swab/swab.c
+++ b/src/modules/swab/swab.c
@@ -65,7 +65,7 @@ static inline uint32_t color_to_uint32(color_t color) {
}
-static void * swab_create_context(unsigned ticks, unsigned num_cpus, void *setup)
+static void * swab_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup)
{
swab_context_t *ctxt;
diff --git a/src/modules/swarm/swarm.c b/src/modules/swarm/swarm.c
index e708082..0d70568 100644
--- a/src/modules/swarm/swarm.c
+++ b/src/modules/swarm/swarm.c
@@ -48,6 +48,7 @@ typedef enum swarm_draw_style_t {
} swarm_draw_style_t;
typedef struct swarm_setup_t {
+ til_setup_t til_setup;
swarm_draw_style_t draw_style;
} swarm_setup_t;
@@ -178,12 +179,12 @@ static inline uint32_t color_to_uint32(v3f_t color) {
}
-static void * swarm_create_context(unsigned ticks, unsigned num_cpus, void *setup)
+static void * swarm_create_context(unsigned ticks, unsigned num_cpus, til_setup_t *setup)
{
swarm_context_t *ctxt;
if (!setup)
- setup = &swarm_default_setup;
+ setup = &swarm_default_setup.til_setup;
ctxt = calloc(1, sizeof(swarm_context_t) + sizeof(*(ctxt->boids)) * SWARM_SIZE);
if (!ctxt)
@@ -421,7 +422,7 @@ static void swarm_render_fragment(void *context, unsigned ticks, unsigned cpu, t
}
-static int swarm_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup)
+static int swarm_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup)
{
const char *styles[] = {
"points",
@@ -448,7 +449,7 @@ static int swarm_setup(const til_settings_t *settings, til_setting_t **res_setti
if (res_setup) {
swarm_setup_t *setup;
- setup = calloc(1, sizeof(*setup));
+ setup = til_setup_new(sizeof(*setup), (void(*)(til_setup_t *))free);
if (!setup)
return -ENOMEM;
@@ -457,7 +458,7 @@ static int swarm_setup(const til_settings_t *settings, til_setting_t **res_setti
setup->draw_style = i;
}
- *res_setup = setup;
+ *res_setup = &setup->til_setup;
}
return 0;
diff --git a/src/sdl_fb.c b/src/sdl_fb.c
index 72bc7b6..2605d6c 100644
--- a/src/sdl_fb.c
+++ b/src/sdl_fb.c
@@ -26,7 +26,7 @@ struct sdl_fb_page_t {
};
-static int sdl_fb_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup)
+static int sdl_fb_setup(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup)
{
const char *fullscreen_values[] = {
"off",
diff --git a/src/setup.c b/src/setup.c
index 8f2708d..0791da8 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -2,6 +2,7 @@
#include <stdio.h>
#include "til_settings.h"
+#include "til_setup.h"
#include "til_util.h"
/* add key=value, but if key is NULL, use value as key. */
@@ -21,7 +22,7 @@ static int add_value(til_settings_t *settings, const char *key, const char *valu
/* returns negative on error, otherwise number of additions made to settings */
-int setup_interactively(til_settings_t *settings, int (*setup_func)(til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup), int defaults, void **res_setup)
+int setup_interactively(til_settings_t *settings, int (*setup_func)(til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup), int defaults, til_setup_t **res_setup)
{
unsigned additions = 0;
char buf[256] = "\n";
diff --git a/src/setup.h b/src/setup.h
index a32f57c..3ca501d 100644
--- a/src/setup.h
+++ b/src/setup.h
@@ -2,7 +2,8 @@
#define _SETUP_H
#include "til_settings.h"
+#include "til_setup.h"
-int setup_interactively(til_settings_t *settings, int (*setup_func)(til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup), int defaults, void **res_setup);
+int setup_interactively(til_settings_t *settings, int (*setup_func)(til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup), int defaults, til_setup_t **res_setup);
#endif
diff --git a/src/til.c b/src/til.c
index f47e8ac..d7281ee 100644
--- a/src/til.c
+++ b/src/til.c
@@ -157,7 +157,7 @@ void til_module_render(const til_module_t *module, void *context, unsigned ticks
}
-int til_module_create_context(const til_module_t *module, unsigned ticks, void *setup, void **res_context)
+int til_module_create_context(const til_module_t *module, unsigned ticks, til_setup_t *setup, void **res_context)
{
void *context;
@@ -191,7 +191,7 @@ void * til_module_destroy_context(const til_module_t *module, void *context)
/* select module if not yet selected, then setup the module. */
-int til_module_setup(til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup)
+int til_module_setup(til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup)
{
til_setting_t *setting;
const til_module_t *module;
@@ -239,7 +239,7 @@ int til_module_setup(til_settings_t *settings, til_setting_t **res_setting, cons
/* originally taken from rtv, this randomizes a module's setup @res_setup, args @res_arg
* returns 0 on no setup, 1 on setup successful with results stored @res_*, -errno on error.
*/
-int til_module_randomize_setup(const til_module_t *module, void **res_setup, char **res_arg)
+int til_module_randomize_setup(const til_module_t *module, til_setup_t **res_setup, char **res_arg)
{
til_settings_t *settings;
til_setting_t *setting;
diff --git a/src/til.h b/src/til.h
index 572f408..42cbcf2 100644
--- a/src/til.h
+++ b/src/til.h
@@ -2,6 +2,7 @@
#define _TIL_H
#include "til_fb.h"
+#include "til_setup.h"
/* til_fragmenter produces fragments from an input fragment, num being the desired fragment for the current call.
* return value of 1 means a fragment has been produced, 0 means num is beyond the end of fragments. */
@@ -12,12 +13,12 @@ typedef struct til_setting_desc_t til_setting_desc_t;
typedef struct til_knob_t til_knob_t;
typedef struct til_module_t {
- void * (*create_context)(unsigned ticks, unsigned n_cpus, void *setup);
+ void * (*create_context)(unsigned ticks, unsigned n_cpus, til_setup_t *setup);
void (*destroy_context)(void *context);
void (*prepare_frame)(void *context, unsigned ticks, unsigned n_cpus, til_fb_fragment_t *fragment, til_fragmenter_t *res_fragmenter);
void (*render_fragment)(void *context, unsigned ticks, unsigned cpu, til_fb_fragment_t *fragment);
void (*finish_frame)(void *context, unsigned ticks, til_fb_fragment_t *fragment);
- int (*setup)(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup);
+ int (*setup)(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup);
size_t (*knobs)(void *context, til_knob_t **res_knobs);
char *name;
char *description;
@@ -30,9 +31,9 @@ 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(const til_module_t *module, void *context, unsigned ticks, til_fb_fragment_t *fragment);
-int til_module_create_context(const til_module_t *module, unsigned ticks, void *setup, void **res_context);
+int til_module_create_context(const til_module_t *module, unsigned ticks, til_setup_t *setup, void **res_context);
void * til_module_destroy_context(const til_module_t *module, void *context);
-int til_module_setup(til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup);
-int til_module_randomize_setup(const til_module_t *module, void **res_setup, char **res_arg);
+int til_module_setup(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, til_setup_t **res_setup, char **res_arg);
#endif
diff --git a/src/til_fb.h b/src/til_fb.h
index cbca0a7..5504457 100644
--- a/src/til_fb.h
+++ b/src/til_fb.h
@@ -5,6 +5,7 @@
#include <string.h>
#include "til_settings.h"
+#include "til_setup.h"
/* All renderers should target fb_fragment_t, which may or may not represent
* a full-screen mmap. Helpers are provided for subdividing fragments for
@@ -35,7 +36,7 @@ typedef struct til_fb_t til_fb_t;
/* Supply this struct to fb_new() with the appropriate context */
typedef struct til_fb_ops_t {
- int (*setup)(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, void **res_setup);
+ int (*setup)(const til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup);
int (*init)(const til_settings_t *settings, void **res_context);
void (*shutdown)(til_fb_t *fb, void *context);
int (*acquire)(til_fb_t *fb, void *context, void *page);
© All Rights Reserved