From eb42919e456e650c3d970f69510a698d40cd8b17 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sun, 10 Mar 2019 20:20:48 +0200 Subject: [PATCH] Shader config entries. --- cfgfile.cpp | 148 ++++++++++++++++++++++++++++++++++++------ include/options.h | 1 + main.cpp | 2 +- od-win32/win32gui.cpp | 2 + 4 files changed, 132 insertions(+), 21 deletions(-) diff --git a/cfgfile.cpp b/cfgfile.cpp index 0f603f5b..d17cf152 100644 --- a/cfgfile.cpp +++ b/cfgfile.cpp @@ -7293,6 +7293,44 @@ end: return err; } +static int execcmdline(struct uae_prefs *prefs, int argv, TCHAR **argc, TCHAR *out, int outsize, bool confonly) +{ + int ret = 0; + bool changed = false; + for (int i = 0; i < argv; i++) { + if (i + 2 <= argv) { + if (!confonly) { + if (!_tcsicmp(argc[i], _T("shellexec"))) { + uae_ShellExecute(argc[i + 1]); + } else if (!_tcsicmp(argc[i], _T("dbg"))) { + debug_parser(argc[i + 1], out, outsize); + } else if (!inputdevice_uaelib(argc[i], argc[i + 1])) { + if (!cfgfile_parse_uaelib_option(prefs, argc[i], argc[i + 1], 0)) { + if (!cfgfile_parse_option(prefs, argc[i], argc[i + 1], 0)) { + ret = 5; + break; + } + } + changed = true; + } + } else { + if (!cfgfile_parse_option(prefs, argc[i], argc[i + 1], 0)) { + ret = 5; + break; + } + changed = true; + } + i++; + } + } + if (changed) { + inputdevice_fix_prefs(prefs, false); + set_config_changed(); + set_special(SPCFLAG_MODE_CHANGE); + } + return 0; +} + uae_u32 cfgfile_modify (uae_u32 index, const TCHAR *parms, uae_u32 size, TCHAR *out, uae_u32 outsize) { TCHAR *p; @@ -7350,26 +7388,7 @@ uae_u32 cfgfile_modify (uae_u32 index, const TCHAR *parms, uae_u32 size, TCHAR * goto end; } - for (i = 0; i < argv; i++) { - if (i + 2 <= argv) { - if (!_tcsicmp (argc[i], _T("shellexec"))) { - uae_ShellExecute(argc[i + 1]); - } else if (!_tcsicmp (argc[i], _T("dbg"))) { - debug_parser (argc[i + 1], out, outsize); - } else if (!inputdevice_uaelib (argc[i], argc[i + 1])) { - if (!cfgfile_parse_uaelib_option (&changed_prefs, argc[i], argc[i + 1], 0)) { - if (!cfgfile_parse_option (&changed_prefs, argc[i], argc[i + 1], 0)) { - err = 5; - break; - } - } - } - inputdevice_fix_prefs(&changed_prefs, false); - set_config_changed (); - set_special(SPCFLAG_MODE_CHANGE); - i++; - } - } + err = execcmdline(&changed_prefs, argv, argc, out, outsize, false); end: for (i = 0; i < argv; i++) xfree (argc[i]); @@ -8993,6 +9012,95 @@ int built_in_cpuboard_prefs(struct uae_prefs *p) return 1; } +#ifdef _WIN32 +#define SHADERPARM "string winuae_config : WINUAE_CONFIG =" + +// Parse early because actual shader parsing happens after screen mode +// is already open and if shader config modifies screen parameters, +// it would cause annoying flickering. +void cfgfile_get_shader_config(struct uae_prefs *prefs, int rtg) +{ + TCHAR pluginpath[MAX_DPATH]; + if (!get_plugin_path(pluginpath, sizeof pluginpath / sizeof(TCHAR), _T("filtershaders\\direct3d"))) + return; + for (int i = 0; i < 2 * MAX_FILTERSHADERS + 1; i++) { + TCHAR tmp[MAX_DPATH]; + if (!prefs->gf[rtg].gfx_filtershader[i][0]) + continue; + _tcscpy(tmp, pluginpath); + _tcscat(tmp, prefs->gf[rtg].gfx_filtershader[i]); + struct zfile *z = zfile_fopen(tmp, _T("r")); + if (!z) + continue; + bool started = false; + bool quoted = false; + bool done = false; + TCHAR *cmd = NULL; + int len = 0; + int totallen = 0; + int linecnt = 15; + while (!done) { + char linep[MAX_DPATH], *line; + if (!zfile_fgetsa(linep, MAX_DPATH, z)) + break; + if (!started) { + linecnt--; + if (linecnt < 0) + break; + } + line = linep + strspn(linep, "\t \r\n"); + trimwsa(line); + char *p = line; + if (p[0] == '/' && p[1] == '/') + continue; + if (p[0] == ';') + continue; + if (!started) { + if (!strnicmp(line, SHADERPARM, strlen(SHADERPARM))) { + started = true; + p += strlen(SHADERPARM); + totallen = 1000; + cmd = xcalloc(TCHAR, totallen); + } + } else { + while (!done && *p) { + if (*p == '\"') { + quoted = !quoted; + } else if (!quoted && *p == ';') { + done = true; + } else if (quoted) { + if (len + 2 >= totallen) { + totallen += 1000; + cmd = xrealloc(TCHAR, cmd, totallen); + } + cmd[len++] = *p; + } + p++; + } + } + } + if (cmd) { + TCHAR *argc[UAELIB_MAX_PARSE]; + cmd[len] = 0; + write_log(_T("Shader '%s' config '%s'\n"), tmp, cmd); + int argv = cmdlineparser(cmd, argc, UAELIB_MAX_PARSE); + if (argv > 0) { + execcmdline(prefs, argv, argc, NULL, 0, true); + } + for (int i = 0; i < argv; i++) { + xfree(argc[i]); + } + } + xfree(cmd); + zfile_fclose(z); + } +} +#else +void cfgfile_get_shader_config(struct uae_prefs *p, int rtg) +{ +} +#endif + void set_config_changed (void) { config_changed = 1; diff --git a/include/options.h b/include/options.h index de3f51c7..035c39f9 100644 --- a/include/options.h +++ b/include/options.h @@ -971,6 +971,7 @@ extern void cfgfile_compatibility_rtg(struct uae_prefs *p); extern bool cfgfile_detect_art(struct uae_prefs *p, TCHAR *path); extern const TCHAR *cfgfile_getconfigdata(int *len); extern bool cfgfile_createconfigstore(struct uae_prefs *p); +extern void cfgfile_get_shader_config(struct uae_prefs *p, int rtg); extern void check_prefs_changed_custom (void); extern void check_prefs_changed_cpu (void); diff --git a/main.cpp b/main.cpp index 9d4ad58c..291dc247 100644 --- a/main.cpp +++ b/main.cpp @@ -1155,7 +1155,7 @@ static int real_main2 (int argc, TCHAR **argv) canbang = 0; #endif #endif - + cfgfile_get_shader_config(&currprefs, 0); fixup_prefs (&currprefs, true); #ifdef RETROPLATFORM rp_fixup_options (&currprefs); diff --git a/od-win32/win32gui.cpp b/od-win32/win32gui.cpp index 895fe4ab..d442d24b 100644 --- a/od-win32/win32gui.cpp +++ b/od-win32/win32gui.cpp @@ -2320,6 +2320,7 @@ int target_cfgfile_load (struct uae_prefs *p, const TCHAR *filename, int type, i } } } + cfgfile_get_shader_config(p, 0); v = 1; return v; } @@ -19494,6 +19495,7 @@ static void filter_handle (HWND hDlg) if (item > 0) { if (item > UAE_FILTER_LAST) { _stprintf (workprefs.gf[filter_nativertg].gfx_filtershader[filterstackpos], _T("%s.fx"), tmp + 5); + cfgfile_get_shader_config(&workprefs, full_property_sheet ? 0 : filter_nativertg); } else { item--; workprefs.gf[filter_nativertg].gfx_filter = uaefilters[item].type; -- 2.47.3