Create menu_shader_manager_apply_changes and move code to menu_shader.c
This commit is contained in:
parent
3bfa247770
commit
822bbe4e92
|
@ -320,7 +320,7 @@ int menu_shader_manager_setting_toggle(
|
|||
{
|
||||
if (!driver.menu)
|
||||
{
|
||||
RARCH_ERR("Cannot toggle shader setting, menu handle is not initialized.\n");
|
||||
RARCH_ERR("Menu handle is not initialized.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -536,6 +536,31 @@ int handle_shader_pass_setting(struct gfx_shader *shader, unsigned action)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void menu_shader_manager_apply_changes(void)
|
||||
{
|
||||
unsigned shader_type = RARCH_SHADER_NONE;
|
||||
shader_type = menu_shader_manager_get_type(driver.menu->shader);
|
||||
|
||||
if (driver.menu->shader->passes && shader_type != RARCH_SHADER_NONE)
|
||||
menu_shader_manager_save_preset(NULL, true);
|
||||
else
|
||||
{
|
||||
#if defined(HAVE_CG) || defined(HAVE_HLSL) || defined(HAVE_GLSL)
|
||||
shader_type = gfx_shader_parse_type("", DEFAULT_SHADER_TYPE);
|
||||
#endif
|
||||
|
||||
if (shader_type == RARCH_SHADER_NONE)
|
||||
{
|
||||
#if defined(HAVE_GLSL)
|
||||
shader_type = RARCH_SHADER_GLSL;
|
||||
#elif defined(HAVE_CG) || defined(HAVE_HLSL)
|
||||
shader_type = RARCH_SHADER_CG;
|
||||
#endif
|
||||
}
|
||||
menu_shader_manager_set_preset(NULL, shader_type, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void menu_shader_manager_init(void *data) {}
|
||||
|
@ -565,4 +590,6 @@ int handle_shader_pass_setting(struct gfx_shader *shader)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void menu_shader_manager_apply_changes(void) { }
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,17 +24,25 @@
|
|||
#include "../../gfx/shader_parse.h"
|
||||
|
||||
void menu_shader_manager_init(void *data);
|
||||
|
||||
void menu_shader_manager_set_preset(struct gfx_shader *shader,
|
||||
unsigned type, const char *cgp_path);
|
||||
|
||||
int menu_shader_manager_setting_toggle(
|
||||
unsigned id, const char *label, unsigned action);
|
||||
|
||||
void menu_shader_manager_save_preset(
|
||||
const char *basename, bool apply);
|
||||
|
||||
unsigned menu_shader_manager_get_type(
|
||||
const struct gfx_shader *shader);
|
||||
|
||||
void menu_shader_manager_get_str(struct gfx_shader *shader,
|
||||
char *type_str, size_t type_str_size, const char *menu_label,
|
||||
const char *label, unsigned type);
|
||||
|
||||
int handle_shader_pass_setting(struct gfx_shader *shader, unsigned action);
|
||||
|
||||
void menu_shader_manager_apply_changes(void);
|
||||
|
||||
#endif
|
||||
|
|
197
retroarch.c
197
retroarch.c
|
@ -2852,6 +2852,92 @@ void rarch_main_set_state(unsigned cmd)
|
|||
}
|
||||
}
|
||||
|
||||
/* Save a new config to a file. Filename is based
|
||||
* on heuristics to avoid typing. */
|
||||
|
||||
static void save_core_config(void)
|
||||
{
|
||||
char config_dir[PATH_MAX], config_name[PATH_MAX],
|
||||
config_path[PATH_MAX], msg[PATH_MAX];
|
||||
bool found_path = false;
|
||||
|
||||
*config_dir = '\0';
|
||||
|
||||
if (*g_settings.menu_config_directory)
|
||||
strlcpy(config_dir, g_settings.menu_config_directory,
|
||||
sizeof(config_dir));
|
||||
else if (*g_extern.config_path) /* Fallback */
|
||||
fill_pathname_basedir(config_dir, g_extern.config_path,
|
||||
sizeof(config_dir));
|
||||
else
|
||||
{
|
||||
const char *msg = "Config directory not set. Cannot save new config.";
|
||||
msg_queue_clear(g_extern.msg_queue);
|
||||
msg_queue_push(g_extern.msg_queue, msg, 1, 180);
|
||||
RARCH_ERR("%s\n", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Infer file name based on libretro core. */
|
||||
if (*g_settings.libretro && path_file_exists(g_settings.libretro))
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
/* In case of collision, find an alternative name. */
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
char tmp[64];
|
||||
fill_pathname_base(config_name, g_settings.libretro,
|
||||
sizeof(config_name));
|
||||
path_remove_extension(config_name);
|
||||
fill_pathname_join(config_path, config_dir, config_name,
|
||||
sizeof(config_path));
|
||||
|
||||
*tmp = '\0';
|
||||
|
||||
if (i)
|
||||
snprintf(tmp, sizeof(tmp), "-%u.cfg", i);
|
||||
else
|
||||
strlcpy(tmp, ".cfg", sizeof(tmp));
|
||||
|
||||
strlcat(config_path, tmp, sizeof(config_path));
|
||||
|
||||
if (!path_file_exists(config_path))
|
||||
{
|
||||
found_path = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Fallback to system time... */
|
||||
if (!found_path)
|
||||
{
|
||||
RARCH_WARN("Cannot infer new config path. Use current time.\n");
|
||||
fill_dated_filename(config_name, "cfg", sizeof(config_name));
|
||||
fill_pathname_join(config_path, config_dir, config_name,
|
||||
sizeof(config_path));
|
||||
}
|
||||
|
||||
if (config_save_file(config_path))
|
||||
{
|
||||
strlcpy(g_extern.config_path, config_path,
|
||||
sizeof(g_extern.config_path));
|
||||
snprintf(msg, sizeof(msg), "Saved new config to \"%s\".",
|
||||
config_path);
|
||||
RARCH_LOG("%s\n", msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(msg, sizeof(msg), "Failed saving config to \"%s\".",
|
||||
config_path);
|
||||
RARCH_ERR("%s\n", msg);
|
||||
}
|
||||
|
||||
msg_queue_clear(g_extern.msg_queue);
|
||||
msg_queue_push(g_extern.msg_queue, msg, 1, 180);
|
||||
}
|
||||
|
||||
void rarch_main_command(unsigned cmd)
|
||||
{
|
||||
bool boolean = false;
|
||||
|
@ -3082,117 +3168,10 @@ void rarch_main_command(unsigned cmd)
|
|||
rarch_main_set_state(RARCH_ACTION_STATE_EXITSPAWN);
|
||||
break;
|
||||
case RARCH_CMD_MENU_SAVE_CONFIG:
|
||||
{
|
||||
/* Save a new config to a file. Filename is based
|
||||
* on heuristics to avoid typing. */
|
||||
|
||||
char config_dir[PATH_MAX], config_name[PATH_MAX],
|
||||
config_path[PATH_MAX], msg[PATH_MAX];
|
||||
bool found_path = false;
|
||||
|
||||
*config_dir = '\0';
|
||||
|
||||
if (*g_settings.menu_config_directory)
|
||||
strlcpy(config_dir, g_settings.menu_config_directory,
|
||||
sizeof(config_dir));
|
||||
else if (*g_extern.config_path) /* Fallback */
|
||||
fill_pathname_basedir(config_dir, g_extern.config_path,
|
||||
sizeof(config_dir));
|
||||
else
|
||||
{
|
||||
const char *msg = "Config directory not set. Cannot save new config.";
|
||||
msg_queue_clear(g_extern.msg_queue);
|
||||
msg_queue_push(g_extern.msg_queue, msg, 1, 180);
|
||||
RARCH_ERR("%s\n", msg);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Infer file name based on libretro core. */
|
||||
if (*g_settings.libretro && path_file_exists(g_settings.libretro))
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
/* In case of collision, find an alternative name. */
|
||||
for (i = 0; i < 16; i++)
|
||||
{
|
||||
char tmp[64];
|
||||
fill_pathname_base(config_name, g_settings.libretro,
|
||||
sizeof(config_name));
|
||||
path_remove_extension(config_name);
|
||||
fill_pathname_join(config_path, config_dir, config_name,
|
||||
sizeof(config_path));
|
||||
|
||||
*tmp = '\0';
|
||||
|
||||
if (i)
|
||||
snprintf(tmp, sizeof(tmp), "-%u.cfg", i);
|
||||
else
|
||||
strlcpy(tmp, ".cfg", sizeof(tmp));
|
||||
|
||||
strlcat(config_path, tmp, sizeof(config_path));
|
||||
|
||||
if (!path_file_exists(config_path))
|
||||
{
|
||||
found_path = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Fallback to system time... */
|
||||
if (!found_path)
|
||||
{
|
||||
RARCH_WARN("Cannot infer new config path. Use current time.\n");
|
||||
fill_dated_filename(config_name, "cfg", sizeof(config_name));
|
||||
fill_pathname_join(config_path, config_dir, config_name,
|
||||
sizeof(config_path));
|
||||
}
|
||||
|
||||
if (config_save_file(config_path))
|
||||
{
|
||||
strlcpy(g_extern.config_path, config_path,
|
||||
sizeof(g_extern.config_path));
|
||||
snprintf(msg, sizeof(msg), "Saved new config to \"%s\".",
|
||||
config_path);
|
||||
RARCH_LOG("%s\n", msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(msg, sizeof(msg), "Failed saving config to \"%s\".",
|
||||
config_path);
|
||||
RARCH_ERR("%s\n", msg);
|
||||
}
|
||||
|
||||
msg_queue_clear(g_extern.msg_queue);
|
||||
msg_queue_push(g_extern.msg_queue, msg, 1, 180);
|
||||
}
|
||||
save_core_config();
|
||||
break;
|
||||
case RARCH_CMD_SHADERS_APPLY_CHANGES:
|
||||
#ifdef HAVE_MENU
|
||||
{
|
||||
unsigned shader_type = RARCH_SHADER_NONE;
|
||||
shader_type = menu_shader_manager_get_type(driver.menu->shader);
|
||||
|
||||
if (driver.menu->shader->passes && shader_type != RARCH_SHADER_NONE)
|
||||
menu_shader_manager_save_preset(NULL, true);
|
||||
else
|
||||
{
|
||||
#if defined(HAVE_CG) || defined(HAVE_HLSL) || defined(HAVE_GLSL)
|
||||
shader_type = gfx_shader_parse_type("", DEFAULT_SHADER_TYPE);
|
||||
#endif
|
||||
|
||||
if (shader_type == RARCH_SHADER_NONE)
|
||||
{
|
||||
#if defined(HAVE_GLSL)
|
||||
shader_type = RARCH_SHADER_GLSL;
|
||||
#elif defined(HAVE_CG) || defined(HAVE_HLSL)
|
||||
shader_type = RARCH_SHADER_CG;
|
||||
#endif
|
||||
}
|
||||
menu_shader_manager_set_preset(NULL, shader_type, NULL);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
menu_shader_manager_apply_changes();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue