From 02dc90d7bd1b591b075baccff5da82efba2809f1 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 23 Sep 2016 03:19:33 +0200 Subject: [PATCH] Move code from runloop.c to dirs.c --- command.c | 4 +- dirs.c | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ dirs.h | 12 +++++ runloop.c | 130 ++------------------------------------------------ runloop.h | 4 -- 5 files changed, 157 insertions(+), 133 deletions(-) diff --git a/command.c b/command.c index f5f826b54e..db54e95aac 100644 --- a/command.c +++ b/command.c @@ -2411,12 +2411,12 @@ bool command_event(enum event_command cmd, void *data) #endif break; case CMD_EVENT_SHADER_DIR_DEINIT: - runloop_ctl(RUNLOOP_CTL_SHADER_DIR_DEINIT, NULL); + dir_free_shader(); break; case CMD_EVENT_SHADER_DIR_INIT: command_event(CMD_EVENT_SHADER_DIR_DEINIT, NULL); - if (!runloop_ctl(RUNLOOP_CTL_SHADER_DIR_INIT, NULL)) + if (!dir_init_shader()) return false; break; case CMD_EVENT_BSV_MOVIE_DEINIT: diff --git a/dirs.c b/dirs.c index 374b24960b..6c10cff0ad 100644 --- a/dirs.c +++ b/dirs.c @@ -16,19 +16,159 @@ #include #include #include +#include #include #include #include #include #include "dirs.h" +#include "configuration.h" +#include "command.h" #include "defaults.h" +#include "list_special.h" +#include "file_path_special.h" +#include "msg_hash.h" +#include "runloop.h" +#include "verbosity.h" + +struct rarch_dir_list +{ + struct string_list *list; + size_t ptr; +}; + +static struct rarch_dir_list dir_shader_list; static char dir_osk_overlay[PATH_MAX_LENGTH] = {0}; static char dir_system[PATH_MAX_LENGTH] = {0}; static char dir_savefile[PATH_MAX_LENGTH] = {0}; static char dir_savestate[PATH_MAX_LENGTH] = {0}; +static bool shader_dir_init(struct rarch_dir_list *dir_list) +{ + unsigned i; + settings_t *settings = config_get_ptr(); + + if (!*settings->directory.video_shader) + return false; + + dir_list->list = dir_list_new_special( + settings->directory.video_shader, DIR_LIST_SHADERS, NULL); + + if (!dir_list->list || dir_list->list->size == 0) + { + command_event(CMD_EVENT_SHADER_DIR_DEINIT, NULL); + return false; + } + + dir_list->ptr = 0; + dir_list_sort(dir_list->list, false); + + for (i = 0; i < dir_list->list->size; i++) + RARCH_LOG("%s \"%s\"\n", + msg_hash_to_str(MSG_FOUND_SHADER), + dir_list->list->elems[i].data); + return true; +} + +/* init functions */ + +bool dir_init_shader(void) +{ + return shader_dir_init(&dir_shader_list); +} + +/* free functions */ + +bool dir_free_shader(void) +{ + struct rarch_dir_list *dir_list = + (struct rarch_dir_list*)&dir_shader_list; + + if (!dir_list) + return false; + + dir_list_free(dir_list->list); + dir_list->list = NULL; + dir_list->ptr = 0; + + return true; +} + +/* check functions */ + +/** + * dir_check_shader: + * @pressed_next : was next shader key pressed? + * @pressed_previous : was previous shader key pressed? + * + * Checks if any one of the shader keys has been pressed for this frame: + * a) Next shader index. + * b) Previous shader index. + * + * Will also immediately apply the shader. + **/ +void dir_check_shader(bool pressed_next, bool pressed_prev) +{ + + char msg[128] = {0}; + const char *shader = NULL; + enum rarch_shader_type type = RARCH_SHADER_NONE; + struct rarch_dir_list *dir_list = (struct rarch_dir_list*)&dir_shader_list; + + if (!dir_list || !dir_list->list) + return; + + if (pressed_next) + { + dir_list->ptr = (dir_list->ptr + 1) % + dir_list->list->size; + } + else if (pressed_prev) + { + if (dir_list->ptr == 0) + dir_list->ptr = dir_list->list->size - 1; + else + dir_list->ptr--; + } + else + return; + + shader = dir_list->list->elems[dir_list->ptr].data; + + switch (msg_hash_to_file_type(msg_hash_calculate( + path_get_extension(shader)))) + { + case FILE_TYPE_SHADER_GLSL: + case FILE_TYPE_SHADER_PRESET_GLSLP: + type = RARCH_SHADER_GLSL; + break; + case FILE_TYPE_SHADER_SLANG: + case FILE_TYPE_SHADER_PRESET_SLANGP: + type = RARCH_SHADER_SLANG; + break; + case FILE_TYPE_SHADER_CG: + case FILE_TYPE_SHADER_PRESET_CGP: + type = RARCH_SHADER_CG; + break; + default: + return; + } + + snprintf(msg, sizeof(msg), "%s #%u: \"%s\".", + msg_hash_to_str(MSG_SHADER), + (unsigned)dir_list->ptr, shader); + runloop_msg_queue_push(msg, 2, 120, true); + + RARCH_LOG("%s \"%s\".\n", + msg_hash_to_str(MSG_APPLYING_SHADER), + shader); + + if (!video_driver_set_shader(type, shader)) + RARCH_WARN("%s\n", msg_hash_to_str(MSG_FAILED_TO_APPLY_SHADER)); +} + /* empty functions */ bool dir_is_system_empty(void) diff --git a/dirs.h b/dirs.h index d97a156533..9a4c282b2c 100644 --- a/dirs.h +++ b/dirs.h @@ -21,6 +21,18 @@ RETRO_BEGIN_DECLS +/* init functions */ + +bool dir_init_shader(void); + +/* free functions */ + +bool dir_free_shader(void); + +/* check functions */ + +void dir_check_shader(bool pressed_next, bool pressed_prev); + /* empty functions */ bool dir_is_savefile_empty(void); diff --git a/runloop.c b/runloop.c index c9e43f8568..ce19ef080a 100644 --- a/runloop.c +++ b/runloop.c @@ -100,18 +100,11 @@ cmd->state[1], cmd->state[2])) #endif -struct rarch_dir_list -{ - struct string_list *list; - size_t ptr; -}; - typedef struct event_cmd_state { retro_input_t state[3]; } event_cmd_state_t; -static struct rarch_dir_list runloop_shader_dir; static rarch_system_info_t runloop_system; static struct retro_frame_time_callback runloop_frame_time; static char runloop_fullpath[PATH_MAX_LENGTH] = {0}; @@ -388,115 +381,6 @@ static void runloop_check_stateslots(settings_t *settings, RARCH_LOG("%s\n", msg); } -static void shader_dir_free(struct rarch_dir_list *dir_list) -{ - if (!dir_list) - return; - - dir_list_free(dir_list->list); - dir_list->list = NULL; - dir_list->ptr = 0; -} - -static bool shader_dir_init(struct rarch_dir_list *dir_list) -{ - unsigned i; - settings_t *settings = config_get_ptr(); - - if (!*settings->directory.video_shader) - return false; - - dir_list->list = dir_list_new_special( - settings->directory.video_shader, DIR_LIST_SHADERS, NULL); - - if (!dir_list->list || dir_list->list->size == 0) - { - command_event(CMD_EVENT_SHADER_DIR_DEINIT, NULL); - return false; - } - - dir_list->ptr = 0; - dir_list_sort(dir_list->list, false); - - for (i = 0; i < dir_list->list->size; i++) - RARCH_LOG("%s \"%s\"\n", - msg_hash_to_str(MSG_FOUND_SHADER), - dir_list->list->elems[i].data); - return true; -} - -/** - * runloop_check_shader_dir: - * @pressed_next : was next shader key pressed? - * @pressed_previous : was previous shader key pressed? - * - * Checks if any one of the shader keys has been pressed for this frame: - * a) Next shader index. - * b) Previous shader index. - * - * Will also immediately apply the shader. - **/ -static void runloop_check_shader_dir( - struct rarch_dir_list *dir_list, - bool pressed_next, bool pressed_prev) -{ - - char msg[128] = {0}; - const char *shader = NULL; - enum rarch_shader_type type = RARCH_SHADER_NONE; - - if (!dir_list || !dir_list->list) - return; - - if (pressed_next) - { - dir_list->ptr = (dir_list->ptr + 1) % - dir_list->list->size; - } - else if (pressed_prev) - { - if (dir_list->ptr == 0) - dir_list->ptr = dir_list->list->size - 1; - else - dir_list->ptr--; - } - else - return; - - shader = dir_list->list->elems[dir_list->ptr].data; - - switch (msg_hash_to_file_type(msg_hash_calculate( - path_get_extension(shader)))) - { - case FILE_TYPE_SHADER_GLSL: - case FILE_TYPE_SHADER_PRESET_GLSLP: - type = RARCH_SHADER_GLSL; - break; - case FILE_TYPE_SHADER_SLANG: - case FILE_TYPE_SHADER_PRESET_SLANGP: - type = RARCH_SHADER_SLANG; - break; - case FILE_TYPE_SHADER_CG: - case FILE_TYPE_SHADER_PRESET_CGP: - type = RARCH_SHADER_CG; - break; - default: - return; - } - - snprintf(msg, sizeof(msg), "%s #%u: \"%s\".", - msg_hash_to_str(MSG_SHADER), - (unsigned)dir_list->ptr, shader); - runloop_msg_queue_push(msg, 2, 120, true); - - RARCH_LOG("%s \"%s\".\n", - msg_hash_to_str(MSG_APPLYING_SHADER), - shader); - - if (!video_driver_set_shader(type, shader)) - RARCH_WARN("%s\n", msg_hash_to_str(MSG_FAILED_TO_APPLY_SHADER)); -} - /** * rarch_game_specific_options: * @@ -570,8 +454,7 @@ static bool runloop_check_idle_state(event_cmd_state_t *cmd) return true; } -static bool runloop_check_state(event_cmd_state_t *cmd, - struct rarch_dir_list *shader_dir) +static bool runloop_check_state(event_cmd_state_t *cmd) { bool tmp = false; settings_t *settings = config_get_ptr(); @@ -638,11 +521,9 @@ static bool runloop_check_state(event_cmd_state_t *cmd, if (runloop_cmd_triggered(cmd, RARCH_SHADER_NEXT) || runloop_cmd_triggered(cmd, RARCH_SHADER_PREV)) - { - runloop_check_shader_dir(shader_dir, + dir_check_shader( runloop_cmd_triggered(cmd, RARCH_SHADER_NEXT), runloop_cmd_triggered(cmd, RARCH_SHADER_PREV)); - } if (runloop_cmd_triggered(cmd, RARCH_DISK_EJECT_TOGGLE)) command_event(CMD_EVENT_DISK_EJECT_TOGGLE, NULL); @@ -674,11 +555,6 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data) switch (state) { - case RUNLOOP_CTL_SHADER_DIR_DEINIT: - shader_dir_free(&runloop_shader_dir); - break; - case RUNLOOP_CTL_SHADER_DIR_INIT: - return shader_dir_init(&runloop_shader_dir); case RUNLOOP_CTL_SYSTEM_INFO_INIT: core_get_system_info(&runloop_system.info); @@ -1479,7 +1355,7 @@ int runloop_iterate(unsigned *sleep_ms) } #endif - if (!runloop_check_state(&cmd, &runloop_shader_dir)) + if (!runloop_check_state(&cmd)) { /* RetroArch has been paused. */ core_poll(); diff --git a/runloop.h b/runloop.h index 602809e2e6..fe22da5609 100644 --- a/runloop.h +++ b/runloop.h @@ -126,10 +126,6 @@ enum runloop_ctl_state RUNLOOP_CTL_CORE_OPTIONS_DEINIT, RUNLOOP_CTL_CORE_OPTIONS_FREE, - /* Shader dir */ - RUNLOOP_CTL_SHADER_DIR_DEINIT, - RUNLOOP_CTL_SHADER_DIR_INIT, - /* System info */ RUNLOOP_CTL_SYSTEM_INFO_GET, RUNLOOP_CTL_SYSTEM_INFO_INIT,