From 2139abe8b7cbb885e2117f822d7ceedb570898eb Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 20 May 2017 15:50:38 +0200 Subject: [PATCH 01/10] Cut down on code duplication --- command.c | 7 ++----- command.h | 2 ++ dirs.c | 39 ++------------------------------------- 3 files changed, 6 insertions(+), 42 deletions(-) diff --git a/command.c b/command.c index 696131c077..b35e60408d 100644 --- a/command.c +++ b/command.c @@ -157,8 +157,7 @@ struct cmd_action_map const char *arg_desc; }; -#ifdef HAVE_COMMAND -static bool command_set_shader(const char *arg) +bool command_set_shader(const char *arg) { char msg[256]; enum rarch_shader_type type = RARCH_SHADER_NONE; @@ -190,7 +189,7 @@ static bool command_set_shader(const char *arg) return video_driver_set_shader(type, arg); } - +#ifdef HAVE_COMMAND #ifdef HAVE_CHEEVOS static bool command_read_ram(const char *arg) { @@ -631,8 +630,6 @@ static void command_stdin_poll(command_t *handle) bool command_poll(command_t *handle) { - memset(handle->state, 0, sizeof(handle->state)); - #if defined(HAVE_NETWORKING) && defined(HAVE_NETWORK_CMD) #ifdef HAVE_COMMAND command_network_poll(handle); diff --git a/command.h b/command.h index d5365c4c73..e5001c549e 100644 --- a/command.h +++ b/command.h @@ -221,6 +221,8 @@ enum event_command CMD_EVENT_RESTORE_DEFAULT_SHADER_PRESET }; +bool command_set_shader(const char *arg); + #ifdef HAVE_COMMAND #if defined(HAVE_NETWORKING) && defined(HAVE_NETWORK_CMD) bool command_network_send(const char *cmd_); diff --git a/dirs.c b/dirs.c index d41cc5bc6a..3ad005a87a 100644 --- a/dirs.c +++ b/dirs.c @@ -23,6 +23,7 @@ #include #include "dirs.h" +#include "command.h" #include "configuration.h" #include "command.h" #include "defaults.h" @@ -108,9 +109,6 @@ bool dir_free_shader(void) **/ void dir_check_shader(bool pressed_next, bool pressed_prev) { - char msg[128]; - 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) @@ -131,40 +129,7 @@ void dir_check_shader(bool pressed_next, bool pressed_prev) 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; - } - - msg[0] = '\0'; - - 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)); + command_set_shader(dir_list->list->elems[dir_list->ptr].data); } /* empty functions */ From ff8a7f22fc5a1e9eb3e977b04c475fcc1fc34a2d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 20 May 2017 15:52:07 +0200 Subject: [PATCH 02/10] Header include cleanup --- dirs.c | 1 - 1 file changed, 1 deletion(-) diff --git a/dirs.c b/dirs.c index 3ad005a87a..6e0b22c680 100644 --- a/dirs.c +++ b/dirs.c @@ -27,7 +27,6 @@ #include "configuration.h" #include "command.h" #include "defaults.h" -#include "gfx/video_driver.h" #include "list_special.h" #include "file_path_special.h" #include "msg_hash.h" From eec0613c10d3afbd0f6cb48aeaf48f9c40e9a042 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 20 May 2017 16:24:32 +0200 Subject: [PATCH 03/10] Add header include --- libretro-common/streams/stdin_stream.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libretro-common/streams/stdin_stream.c b/libretro-common/streams/stdin_stream.c index 36f5bc5b00..83c5bf469b 100644 --- a/libretro-common/streams/stdin_stream.c +++ b/libretro-common/streams/stdin_stream.c @@ -32,6 +32,8 @@ #include #endif +#include + #if defined(_WIN32) && defined(_XBOX) size_t read_stdin(char *buf, size_t size) { From 0742ebec21c29b9dbb2cc64ec078e89bfc9a87f0 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 20 May 2017 16:32:57 +0200 Subject: [PATCH 04/10] Get rid of local_enable variable --- command.c | 5 +---- command.h | 2 +- input/input_driver.c | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/command.c b/command.c index b35e60408d..59df0f734b 100644 --- a/command.c +++ b/command.c @@ -90,7 +90,6 @@ struct command { - bool local_enable; #ifdef HAVE_STDIN_CMD bool stdin_enable; char stdin_buf[STDIN_BUF_SIZE]; @@ -540,14 +539,12 @@ static bool command_stdin_init(command_t *handle) } #endif -command_t *command_new(bool local_enable) +command_t *command_new(void) { command_t *handle = (command_t*)calloc(1, sizeof(*handle)); if (!handle) return NULL; - handle->local_enable = local_enable; - return handle; } diff --git a/command.h b/command.h index e5001c549e..24ed1e3dc3 100644 --- a/command.h +++ b/command.h @@ -235,7 +235,7 @@ bool command_network_new( bool network_enable, uint16_t port); -command_t *command_new(bool local_enable); +command_t *command_new(void); bool command_poll(command_t *handle); diff --git a/input/input_driver.c b/input/input_driver.c index 7378d92627..8fcd5a6949 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -1183,7 +1183,7 @@ bool input_driver_init_command(void) "Cannot use this command interface.\n"); } - input_driver_command = command_new(false); + input_driver_command = command_new(); if (command_network_new( input_driver_command, From 1ac44d8ecae3e1c17ec083a2be7edca22bcbf1d4 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 20 May 2017 17:45:02 +0200 Subject: [PATCH 05/10] Fix hidden directories/files no longer showing up --- libretro-common/lists/dir_list.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libretro-common/lists/dir_list.c b/libretro-common/lists/dir_list.c index 9e9fcd9310..a290ca74af 100644 --- a/libretro-common/lists/dir_list.c +++ b/libretro-common/lists/dir_list.c @@ -124,7 +124,7 @@ static int parse_dir_entry(const char *name, char *file_path, if (!include_dirs && is_dir) return 1; - if (string_is_equal_fast(name, ".", 1) || string_is_equal_fast(name, "..", 2)) + if (!strcmp(name, ".") || !strcmp(name, "..")) return 1; if (!is_dir && ext_list && From b7b7c67ca36e98375c9f41bc239a28af97d06e51 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 20 May 2017 17:47:56 +0200 Subject: [PATCH 06/10] Windows buildfix --- gfx/drivers/d3d.cpp | 8 +------- gfx/video_driver.c | 6 ++++++ gfx/video_driver.h | 2 ++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/gfx/drivers/d3d.cpp b/gfx/drivers/d3d.cpp index e2a39d1bb8..72a3dbf37e 100644 --- a/gfx/drivers/d3d.cpp +++ b/gfx/drivers/d3d.cpp @@ -886,14 +886,8 @@ static bool d3d_alive(void *data) if (resize) { - gfx_ctx_mode_t mode; - d3d->should_resize = true; - - mode.width = temp_width; - mode.height = temp_height; - - current_video_context.set_resize(video_context_data, mode.width, mode.height); + video_driver_set_resize(temp_width, temp_height); d3d_restore(d3d); } diff --git a/gfx/video_driver.c b/gfx/video_driver.c index aa2cddb153..2360911347 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -411,6 +411,12 @@ static bool set_resize_null(void *a, unsigned b, unsigned c) return false; } +void video_driver_set_resize(unsigned width, unsigned height) +{ + if (current_video_context.set_resize) + current_video_context.set_resize(video_context_data, width, height); +} + /** * video_driver_find_handle: * @idx : index of driver to get handle to. diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 2109b44cb0..fe9ccb1c13 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -1066,6 +1066,8 @@ void video_driver_set_threaded(bool val); void video_driver_get_status(uint64_t *frame_count, bool * is_alive, bool *is_focused); +void video_driver_set_resize(unsigned width, unsigned height); + extern video_driver_t video_gl; extern video_driver_t video_vulkan; extern video_driver_t video_psp1; From b009b87530263b98f636125e70e2635d0bb0c24c Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 20 May 2017 17:54:06 +0200 Subject: [PATCH 07/10] Make this check a bit faster --- libretro-common/lists/dir_list.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libretro-common/lists/dir_list.c b/libretro-common/lists/dir_list.c index a290ca74af..a2e4e2b998 100644 --- a/libretro-common/lists/dir_list.c +++ b/libretro-common/lists/dir_list.c @@ -124,7 +124,8 @@ static int parse_dir_entry(const char *name, char *file_path, if (!include_dirs && is_dir) return 1; - if (!strcmp(name, ".") || !strcmp(name, "..")) + if ((name[0] == '.' && name[1] == '\0') || + (name[0] == '.' && name[1] == '.' && name[2] == '\0')) return 1; if (!is_dir && ext_list && From b4f0ebca4d00dfb7df6fc85cb9a17d96fa8aad62 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 20 May 2017 17:55:26 +0200 Subject: [PATCH 08/10] Cleanups --- libretro-common/include/lists/dir_list.h | 17 ----- libretro-common/lists/dir_list.c | 83 ++++++++++++------------ 2 files changed, 42 insertions(+), 58 deletions(-) diff --git a/libretro-common/include/lists/dir_list.h b/libretro-common/include/lists/dir_list.h index 027078238f..3b4a9c573d 100644 --- a/libretro-common/include/lists/dir_list.h +++ b/libretro-common/include/lists/dir_list.h @@ -65,23 +65,6 @@ void dir_list_sort(struct string_list *list, bool dir_first); **/ void dir_list_free(struct string_list *list); -/** - * dir_list_read: - * @dir : directory path. - * @list : the string list to add files to - * @ext_list : the string list of extensions to include - * @include_dirs : include directories as part of the finished directory listing? - * @include_hidden : include hidden files and directories as part of the finished directory listing? - * @include_compressed : Only include files which match ext. Do not try to match compressed files, etc. - * @recursive : list directory contents recursively - * - * Add files within a directory to an existing string list - * - * Returns: -1 on error, 0 on success. - **/ -int dir_list_read(const char *dir, struct string_list *list, struct string_list *ext_list, - bool include_dirs, bool include_hidden, bool include_compressed, bool recursive); - RETRO_END_DECLS #endif diff --git a/libretro-common/lists/dir_list.c b/libretro-common/lists/dir_list.c index a2e4e2b998..a138b2a1a9 100644 --- a/libretro-common/lists/dir_list.c +++ b/libretro-common/lists/dir_list.c @@ -154,46 +154,6 @@ static int parse_dir_entry(const char *name, char *file_path, return 0; } -/** - * dir_list_new: - * @dir : directory path. - * @ext : allowed extensions of file directory entries to include. - * @include_dirs : include directories as part of the finished directory listing? - * @include_hidden : include hidden files and directories as part of the finished directory listing? - * @include_compressed : Only include files which match ext. Do not try to match compressed files, etc. - * @recursive : list directory contents recursively - * - * Create a directory listing. - * - * Returns: pointer to a directory listing of type 'struct string_list *' on success, - * NULL in case of error. Has to be freed manually. - **/ -struct string_list *dir_list_new(const char *dir, - const char *ext, bool include_dirs, - bool include_hidden, bool include_compressed, - bool recursive) -{ - struct string_list *ext_list = NULL; - struct string_list *list = NULL; - - if (!(list = string_list_new())) - return NULL; - - if (ext) - ext_list = string_split(ext, "|"); - - if(dir_list_read(dir, list, ext_list, include_dirs, - include_hidden, include_compressed, recursive) == -1) - { - string_list_free(list); - string_list_free(ext_list); - return NULL; - } - - string_list_free(ext_list); - return list; -} - /** * dir_list_read: * @dir : directory path. @@ -208,7 +168,7 @@ struct string_list *dir_list_new(const char *dir, * * Returns: -1 on error, 0 on success. **/ -int dir_list_read(const char *dir, +static int dir_list_read(const char *dir, struct string_list *list, struct string_list *ext_list, bool include_dirs, bool include_hidden, bool include_compressed, bool recursive) @@ -276,3 +236,44 @@ int dir_list_read(const char *dir, return 0; } + +/** + * dir_list_new: + * @dir : directory path. + * @ext : allowed extensions of file directory entries to include. + * @include_dirs : include directories as part of the finished directory listing? + * @include_hidden : include hidden files and directories as part of the finished directory listing? + * @include_compressed : Only include files which match ext. Do not try to match compressed files, etc. + * @recursive : list directory contents recursively + * + * Create a directory listing. + * + * Returns: pointer to a directory listing of type 'struct string_list *' on success, + * NULL in case of error. Has to be freed manually. + **/ +struct string_list *dir_list_new(const char *dir, + const char *ext, bool include_dirs, + bool include_hidden, bool include_compressed, + bool recursive) +{ + struct string_list *ext_list = NULL; + struct string_list *list = NULL; + + if (!(list = string_list_new())) + return NULL; + + if (ext) + ext_list = string_split(ext, "|"); + + if(dir_list_read(dir, list, ext_list, include_dirs, + include_hidden, include_compressed, recursive) == -1) + { + string_list_free(list); + string_list_free(ext_list); + return NULL; + } + + string_list_free(ext_list); + return list; +} + From e4055e0d1baa792362e9ab595ab29d0c5f55b6b5 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 20 May 2017 19:05:09 +0200 Subject: [PATCH 09/10] Add headers --- libretro-common/streams/stdin_stream.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libretro-common/streams/stdin_stream.c b/libretro-common/streams/stdin_stream.c index 83c5bf469b..f0e6bf4d22 100644 --- a/libretro-common/streams/stdin_stream.c +++ b/libretro-common/streams/stdin_stream.c @@ -20,6 +20,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include +#include +#include #include #include From 188d213c8d83bffdf1358feab86c16144f10f4ce Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 20 May 2017 19:24:21 +0200 Subject: [PATCH 10/10] Cleanups --- retroarch.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/retroarch.c b/retroarch.c index b24925a2f6..b5d101e755 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1093,20 +1093,15 @@ bool retroarch_validate_game_options(char *s, size_t len, bool mkdir) { char core_path[PATH_MAX_LENGTH]; char config_directory[PATH_MAX_LENGTH]; - const char *core_name = NULL; - const char *game_name = NULL; rarch_system_info_t *system = runloop_get_system_info(); - - config_directory[0] = core_path[0] = '\0'; - - if (system) - core_name = system->info.library_name; - - game_name = path_basename(path_get(RARCH_PATH_BASENAME)); + const char *core_name = system ? system->info.library_name : NULL; + const char *game_name = path_basename(path_get(RARCH_PATH_BASENAME)); if (string_is_empty(core_name) || string_is_empty(game_name)) return false; + config_directory[0] = core_path[0] = '\0'; + fill_pathname_application_special(config_directory, sizeof(config_directory), APPLICATION_SPECIAL_DIRECTORY_CONFIG);