(menu_shader.c) Refactor away some strcmp usage

This commit is contained in:
twinaphex 2015-06-14 16:35:32 +02:00
parent d70d838ab1
commit 068f3cf8bc
2 changed files with 50 additions and 37 deletions

View File

@ -191,6 +191,10 @@ extern "C" {
#define MENU_VALUE_DIR 0x0af95f55U
#define MENU_VALUE_NO_CORE 0x7d5472cbU
#define MENU_VALUE_DETECT 0xab8da89eU
#define MENU_VALUE_GLSLP 0x0f840c87U
#define MENU_VALUE_CGP 0x0b8865bfU
#define MENU_VALUE_GLSL 0x7c976537U
#define MENU_VALUE_CG 0x0059776fU
#define MENU_LABEL_CONTENT_ACTIONS 0xa0d76970U
#define MENU_LABEL_DETECT_CORE_LIST 0xaa07c341U

View File

@ -18,8 +18,10 @@
#include <compat/strl.h>
#include <file/file_path.h>
#include <rhash.h>
#include "menu.h"
#include "menu_hash.h"
#include "menu_shader.h"
#include "menu_setting.h"
#include "../configuration.h"
@ -32,6 +34,7 @@
void menu_shader_manager_init(menu_handle_t *menu)
{
#ifdef HAVE_SHADER_MANAGER
uint32_t ext_hash;
char preset_path[PATH_MAX_LENGTH];
const char *ext = NULL;
struct video_shader *shader = NULL;
@ -71,48 +74,54 @@ void menu_shader_manager_init(menu_handle_t *menu)
}
ext = path_get_extension(settings->video.shader_path);
if (strcmp(ext, "glslp") == 0 || strcmp(ext, "cgp") == 0)
ext_hash = djb2_calculate(ext);
switch (ext_hash)
{
conf = config_file_new(settings->video.shader_path);
if (conf)
{
if (video_shader_read_conf_cgp(conf, shader))
case MENU_VALUE_GLSLP:
case MENU_VALUE_CGP:
conf = config_file_new(settings->video.shader_path);
if (conf)
{
video_shader_resolve_relative(shader, settings->video.shader_path);
video_shader_resolve_parameters(conf, shader);
if (video_shader_read_conf_cgp(conf, shader))
{
video_shader_resolve_relative(shader, settings->video.shader_path);
video_shader_resolve_parameters(conf, shader);
}
config_file_free(conf);
}
config_file_free(conf);
}
}
else if (strcmp(ext, "glsl") == 0 || strcmp(ext, "cg") == 0)
{
strlcpy(shader->pass[0].source.path, settings->video.shader_path,
sizeof(shader->pass[0].source.path));
shader->passes = 1;
}
else
{
const char *shader_dir = *settings->video.shader_dir ?
settings->video.shader_dir : settings->system_directory;
fill_pathname_join(preset_path, shader_dir, "menu.glslp", sizeof(preset_path));
conf = config_file_new(preset_path);
if (!conf)
{
fill_pathname_join(preset_path, shader_dir, "menu.cgp", sizeof(preset_path));
conf = config_file_new(preset_path);
}
if (conf)
{
if (video_shader_read_conf_cgp(conf, shader))
break;
case MENU_VALUE_GLSL:
case MENU_VALUE_CG:
strlcpy(shader->pass[0].source.path, settings->video.shader_path,
sizeof(shader->pass[0].source.path));
shader->passes = 1;
break;
default:
{
video_shader_resolve_relative(shader, preset_path);
video_shader_resolve_parameters(conf, shader);
const char *shader_dir = *settings->video.shader_dir ?
settings->video.shader_dir : settings->system_directory;
fill_pathname_join(preset_path, shader_dir, "menu.glslp", sizeof(preset_path));
conf = config_file_new(preset_path);
if (!conf)
{
fill_pathname_join(preset_path, shader_dir, "menu.cgp", sizeof(preset_path));
conf = config_file_new(preset_path);
}
if (conf)
{
if (video_shader_read_conf_cgp(conf, shader))
{
video_shader_resolve_relative(shader, preset_path);
video_shader_resolve_parameters(conf, shader);
}
config_file_free(conf);
}
}
config_file_free(conf);
}
break;
}
#endif
}