summaryrefslogtreecommitdiff
path: root/src/modules/submit/submit.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2022-04-01 17:47:19 -0700
committerVito Caputo <vcaputo@pengaru.com>2022-04-01 17:59:03 -0700
commit6b8790a22c38e0d5419eb5a4dac5e30f684ae473 (patch)
tree444ac5369c34a705cd302862928ccad237d68bfe /src/modules/submit/submit.c
parent78c275b094b63e01a5f7bc71af80fe787911bbf4 (diff)
modules/*: instantiate and use setups
Now modules allocate and return an opaque setup pointer in res_setup when they implement a setup method. Defaults are utilized when ${module}_create_context() receives a NULL setup. The default setup used in this case should match the defaults/preferred values emitted by the module's setup method. But performing setup should always be optional, so a NULL setup provided to create_context() is to be expected. No cleanup of these setup instances is currently performed, so it's a small memory leak for now. Since these are opaque and may contain nested references to other allocations, simply using free() somewhere in the frontend is insufficient. There will probably need to be something like a til_module_t.setup_free() method added in the future which modules may assign libc's free() to when appropriate, or their own more elaborate version. Lifecycle for the settings is very simple; the setup method returns an instance, the caller is expected to free it when no longer needed (once free is implemented). The create_context consumer of a given setup must make its own copy of the settings if necessary, and may not keep a reference - it must assume the setup will be freed immediately after create_context() returns. This enables the ability to reuse a setup instance across multiple create_context() calls if desired, one can imagine something like running the same module with the same settings multiple times across multiple displays for instance. If the module has significant entropy the output will differ despite being configured identically... With this commit one may change settings for any of the modules *while* the modules are actively rendering a given context, and the settings should *not* be visible. They should only affect the context they're supplied to.
Diffstat (limited to 'src/modules/submit/submit.c')
-rw-r--r--src/modules/submit/submit.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/modules/submit/submit.c b/src/modules/submit/submit.c
index a2dea77..e1f6008 100644
--- a/src/modules/submit/submit.c
+++ b/src/modules/submit/submit.c
@@ -53,12 +53,15 @@ typedef struct submit_context_t {
grid_player_t *players[NUM_PLAYERS];
uint32_t seq;
uint32_t game_winner;
+ unsigned bilerp:1;
uint8_t cells[GRID_SIZE * GRID_SIZE];
} submit_context_t;
+typedef struct submit_setup_t {
+ unsigned bilerp:1;
+} submit_setup_t;
-static int bilerp_setting;
-
+static submit_setup_t submit_default_setup;
/* convert a color into a packed, 32-bit rgb pixel value (taken from libs/ray/ray_color.h) */
static inline uint32_t color_to_uint32(color_t color) {
@@ -265,10 +268,14 @@ static void * submit_create_context(unsigned ticks, unsigned num_cpus, void *set
{
submit_context_t *ctxt;
+ if (!setup)
+ setup = &submit_default_setup;
+
ctxt = calloc(1, sizeof(submit_context_t));
if (!ctxt)
return NULL;
+ ctxt->bilerp = ((submit_setup_t *)setup)->bilerp;
setup_grid(ctxt);
return ctxt;
@@ -315,7 +322,7 @@ static void submit_render_fragment(void *context, unsigned ticks, unsigned cpu,
{
submit_context_t *ctxt = context;
- if (!bilerp_setting)
+ if (!ctxt->bilerp)
draw_grid(ctxt, fragment);
else
draw_grid_bilerp(ctxt, fragment);
@@ -347,10 +354,18 @@ static int submit_setup(const til_settings_t *settings, til_setting_t **res_sett
if (r)
return r;
- if (!strcasecmp(bilerp, "on"))
- bilerp_setting = 1;
- else
- bilerp_setting = 0;
+ if (res_setup) {
+ submit_setup_t *setup;
+
+ setup = calloc(1, sizeof(*setup));
+ if (!setup)
+ return -ENOMEM;
+
+ if (!strcasecmp(bilerp, "on"))
+ setup->bilerp = 1;
+
+ *res_setup = setup;
+ }
return 0;
}
© All Rights Reserved