summaryrefslogtreecommitdiff
path: root/src/sdl_fb.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-08-05 00:07:16 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-08-05 00:17:33 -0700
commit3cc953518d1c2b84f08f5693d3566db4462623a8 (patch)
tree48f04a0f90bd465d822ec31900a631d88959e5f2 /src/sdl_fb.c
parentd7b92d1b6dd1b152c7263763de7e8f6b174583d4 (diff)
til_setup,*: add til_setup_t.creator pointer
Particularly with nested modules it's annoying to have to stow the module separate from the setup during the setup process. If the baked setup included the module pointer in the non-module-specific-setup part of the setup, then nested settings could finalize using the generic module setup wrapper and just rely on this til_setup_t.creator pointer to contain the appropriate module. Which should enable tossing out a bunch of copy-n-pasta surrounding nested modules setup. Note this has to be a void* since til_setup_t is a generic thing used equally by both the fb code and the module code. Hence why this is called "creator" and not "module", as well as the void* as opposed to til_module_t*. Also if rototiller ever grows a sound backend, the setup machinery will be reused there as well, and it'll be yet another creator handle that isn't an til_fb_ops_t or a til_module_t. It's assumed that the callers producing these setups won't be trying to pass them to the wrong places i.e. a module setup getting passed to an fb backend and vice versa. I'm mildly annoyed about having to move the various til_module_t blocks to above the module's foo_setup(), but it seemed like the least annoying option. This may be revisited.
Diffstat (limited to 'src/sdl_fb.c')
-rw-r--r--src/sdl_fb.c176
1 files changed, 90 insertions, 86 deletions
diff --git a/src/sdl_fb.c b/src/sdl_fb.c
index 6221a83..16609f8 100644
--- a/src/sdl_fb.c
+++ b/src/sdl_fb.c
@@ -36,92 +36,6 @@ typedef struct sdl_fb_t {
} sdl_fb_t;
-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",
- "on",
- NULL
- };
- const char *fullscreen;
- const char *size;
- int r;
-
- r = til_settings_get_and_describe_value(settings,
- &(til_setting_spec_t){
- .name = "SDL fullscreen mode",
- .key = "fullscreen",
- .regex = NULL,
- .preferred = fullscreen_values[0],
- .values = fullscreen_values,
- .annotations = NULL
- },
- &fullscreen,
- res_setting,
- res_desc);
- if (r)
- return r;
-
- if (!strcasecmp(fullscreen, "off")) {
- r = til_settings_get_and_describe_value(settings,
- &(til_setting_spec_t){
- .name = "SDL window size",
- .key = "size",
- .regex = "[1-9][0-9]*[xX][1-9][0-9]*",
- .preferred = "640x480",
- .values = NULL,
- .annotations = NULL
- },
- &size,
- res_setting,
- res_desc);
- if (r)
- return r;
- } else if ((size = til_settings_get_value_by_key(settings, "size", res_setting)) && !(*res_setting)->desc) {
- /* if fullscreen=on AND size=WxH is specified, we'll do a more legacy style SDL fullscreen
- * where it tries to change the video mode. But if size is unspecified, it'll be a desktop
- * style fullscreen where it just uses a fullscreen window in the existing video mode, and
- * we won't forcibly require a size= be specified.
- */
- /* FIXME TODO: this is all copy-n-pasta grossness that wouldn't need to exist if
- * til_settings_get_and_describe_value() just supported optional settings we only
- * describe when they're already present. It just needs something like an optional flag,
- * to be added in a future commit which will remove this hack.
- */
- r = til_setting_desc_new( settings,
- &(til_setting_spec_t){
- .name = "SDL window size",
- .key = "size",
- .regex = "[1-9][0-9]*[xX][1-9][0-9]*",
- .preferred = "640x480",
- .values = NULL,
- .annotations = NULL
- }, res_desc);
- if (r < 0)
- return r;
-
- return 1;
- }
-
- if (res_setup) {
- sdl_fb_setup_t *setup;
-
- setup = til_setup_new(settings, sizeof(*setup), NULL);
- if (!setup)
- return -ENOMEM;
-
- if (!strcasecmp(fullscreen, "on"))
- setup->fullscreen = 1;
-
- if (size)
- sscanf(size, "%u%*[xX]%u", &setup->width, &setup->height);
-
- *res_setup = &setup->til_setup;
- }
-
- return 0;
-}
-
static int sdl_err_to_errno(int err)
{
switch (err) {
@@ -343,6 +257,9 @@ static int sdl_fb_page_flip(til_fb_t *fb, void *context, void *page)
}
+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);
+
+
til_fb_ops_t sdl_fb_ops = {
.setup = sdl_fb_setup,
.init = sdl_fb_init,
@@ -353,3 +270,90 @@ til_fb_ops_t sdl_fb_ops = {
.page_free = sdl_fb_page_free,
.page_flip = sdl_fb_page_flip
};
+
+
+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",
+ "on",
+ NULL
+ };
+ const char *fullscreen;
+ const char *size;
+ int r;
+
+ r = til_settings_get_and_describe_value(settings,
+ &(til_setting_spec_t){
+ .name = "SDL fullscreen mode",
+ .key = "fullscreen",
+ .regex = NULL,
+ .preferred = fullscreen_values[0],
+ .values = fullscreen_values,
+ .annotations = NULL
+ },
+ &fullscreen,
+ res_setting,
+ res_desc);
+ if (r)
+ return r;
+
+ if (!strcasecmp(fullscreen, "off")) {
+ r = til_settings_get_and_describe_value(settings,
+ &(til_setting_spec_t){
+ .name = "SDL window size",
+ .key = "size",
+ .regex = "[1-9][0-9]*[xX][1-9][0-9]*",
+ .preferred = "640x480",
+ .values = NULL,
+ .annotations = NULL
+ },
+ &size,
+ res_setting,
+ res_desc);
+ if (r)
+ return r;
+ } else if ((size = til_settings_get_value_by_key(settings, "size", res_setting)) && !(*res_setting)->desc) {
+ /* if fullscreen=on AND size=WxH is specified, we'll do a more legacy style SDL fullscreen
+ * where it tries to change the video mode. But if size is unspecified, it'll be a desktop
+ * style fullscreen where it just uses a fullscreen window in the existing video mode, and
+ * we won't forcibly require a size= be specified.
+ */
+ /* FIXME TODO: this is all copy-n-pasta grossness that wouldn't need to exist if
+ * til_settings_get_and_describe_value() just supported optional settings we only
+ * describe when they're already present. It just needs something like an optional flag,
+ * to be added in a future commit which will remove this hack.
+ */
+ r = til_setting_desc_new( settings,
+ &(til_setting_spec_t){
+ .name = "SDL window size",
+ .key = "size",
+ .regex = "[1-9][0-9]*[xX][1-9][0-9]*",
+ .preferred = "640x480",
+ .values = NULL,
+ .annotations = NULL
+ }, res_desc);
+ if (r < 0)
+ return r;
+
+ return 1;
+ }
+
+ if (res_setup) {
+ sdl_fb_setup_t *setup;
+
+ setup = til_setup_new(settings, sizeof(*setup), NULL, &sdl_fb_ops);
+ if (!setup)
+ return -ENOMEM;
+
+ if (!strcasecmp(fullscreen, "on"))
+ setup->fullscreen = 1;
+
+ if (size)
+ sscanf(size, "%u%*[xX]%u", &setup->width, &setup->height);
+
+ *res_setup = &setup->til_setup;
+ }
+
+ return 0;
+}
© All Rights Reserved