From 5c269d38a1c08a384923c113a63a3ac9c2f253d5 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 8 May 2016 05:17:31 +0200 Subject: [PATCH] (content.c) Remove content_ctl --- command_event.c | 10 ++-- content.c | 103 +++++++++++++++++++++------------------ content.h | 37 ++++++-------- dynamic.c | 4 +- frontend/frontend.c | 4 +- menu/menu_driver.c | 2 +- movie.c | 4 +- netplay/netplay_common.c | 8 +-- retroarch.c | 6 +-- 9 files changed, 89 insertions(+), 89 deletions(-) diff --git a/command_event.c b/command_event.c index 9dedb199db..279211a773 100644 --- a/command_event.c +++ b/command_event.c @@ -555,13 +555,13 @@ static bool event_init_content(void) if (rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL)) return true; - if (!content_ctl(CONTENT_CTL_DOES_NOT_NEED_CONTENT, NULL)) + if (!content_does_not_need_content()) rarch_ctl(RARCH_CTL_FILL_PATHNAMES, NULL); - if (!content_ctl(CONTENT_CTL_INIT, NULL)) + if (!content_init()) return false; - if (content_ctl(CONTENT_CTL_DOES_NOT_NEED_CONTENT, NULL)) + if (content_does_not_need_content()) return true; event_set_savestate_auto_index(); @@ -632,7 +632,7 @@ static bool event_save_auto_state(void) return false; if (rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL)) return false; - if (content_ctl(CONTENT_CTL_DOES_NOT_NEED_CONTENT, NULL)) + if (content_does_not_need_content()) return false; #ifdef HAVE_CHEEVOS @@ -1588,7 +1588,7 @@ bool event_cmd_ctl(enum event_command cmd, void *data) input_driver_ctl(RARCH_INPUT_CTL_REMOTE_INIT, NULL); break; case EVENT_CMD_TEMPORARY_CONTENT_DEINIT: - content_ctl(CONTENT_CTL_DEINIT, NULL); + content_deinit(); break; case EVENT_CMD_SUBSYSTEM_FULLPATHS_DEINIT: { diff --git a/content.c b/content.c index 2f509fbf2e..968d941bf7 100644 --- a/content.c +++ b/content.c @@ -92,7 +92,7 @@ struct sram_block static const struct file_archive_file_backend *stream_backend = NULL; static struct string_list *temporary_content = NULL; -static bool content_is_inited = false; +static bool _content_is_inited = false; static bool core_does_not_need_content = false; static uint32_t content_crc = 0; @@ -954,7 +954,7 @@ static bool read_content_file(unsigned i, const char *path, void **buf, patch_content(&ret_buf, length); #ifdef HAVE_ZLIB - content_ctl(CONTENT_CTL_GET_CRC, &content_crc_ptr); + content_get_crc(&content_crc_ptr); stream_info.a = 0; stream_info.b = ret_buf; @@ -1597,9 +1597,9 @@ static bool init_content_file_set_attribs( attr.i = system->info.block_extract; attr.i |= system->info.need_fullpath << 1; - attr.i |= (!content_ctl(CONTENT_CTL_DOES_NOT_NEED_CONTENT, NULL)) << 2; + attr.i |= (!content_does_not_need_content()) << 2; - if (content_ctl(CONTENT_CTL_DOES_NOT_NEED_CONTENT, NULL) + if (content_does_not_need_content() && settings->set_supports_no_game_enable) string_list_append(content, "", attr); else @@ -1700,51 +1700,58 @@ static bool content_file_free(struct string_list *temporary_content) return true; } -bool content_ctl(enum content_ctl_state state, void *data) +bool content_does_not_need_content(void) { - switch(state) - { - case CONTENT_CTL_DOES_NOT_NEED_CONTENT: - return core_does_not_need_content; - case CONTENT_CTL_SET_DOES_NOT_NEED_CONTENT: - core_does_not_need_content = true; - break; - case CONTENT_CTL_UNSET_DOES_NOT_NEED_CONTENT: - core_does_not_need_content = false; - break; - case CONTENT_CTL_GET_CRC: - { - uint32_t **content_crc_ptr = (uint32_t**)data; - if (!content_crc_ptr) - return false; - *content_crc_ptr = &content_crc; - } - break; - case CONTENT_CTL_IS_INITED: - return content_is_inited; - case CONTENT_CTL_DEINIT: - content_file_free(temporary_content); - temporary_content = NULL; - content_crc = 0; - content_is_inited = false; - core_does_not_need_content = false; - break; - case CONTENT_CTL_INIT: - content_is_inited = false; - temporary_content = string_list_new(); - if (!temporary_content) - return false; - if (content_file_init(temporary_content)) - { - content_is_inited = true; - return true; - } - content_ctl(CONTENT_CTL_DEINIT, NULL); - return false; - case CONTENT_CTL_NONE: - default: - break; - } + return core_does_not_need_content; +} +void content_set_does_not_need_content(void) +{ + core_does_not_need_content = true; +} + +void content_unset_does_not_need_content(void) +{ + core_does_not_need_content = false; +} + +bool content_get_crc(uint32_t **content_crc_ptr) +{ + if (!content_crc_ptr) + return false; + *content_crc_ptr = &content_crc; return true; } + +bool content_is_inited(void) +{ + return _content_is_inited; +} + +void content_deinit(void) +{ + content_file_free(temporary_content); + temporary_content = NULL; + content_crc = 0; + _content_is_inited = false; + core_does_not_need_content = false; +} + +/* Initializes and loads a content file for the currently + * selected libretro core. */ +bool content_init(void) +{ + temporary_content = string_list_new(); + if (!temporary_content) + goto error; + + if (!content_file_init(temporary_content)) + goto error; + + _content_is_inited = true; + return true; + +error: + content_deinit(); + return false; +} diff --git a/content.h b/content.h index e2d5948b40..e02ee8f692 100644 --- a/content.h +++ b/content.h @@ -30,27 +30,6 @@ extern "C" { #endif -enum content_ctl_state -{ - CONTENT_CTL_NONE = 0, - - CONTENT_CTL_IS_INITED, - - CONTENT_CTL_DOES_NOT_NEED_CONTENT, - - CONTENT_CTL_SET_DOES_NOT_NEED_CONTENT, - - CONTENT_CTL_UNSET_DOES_NOT_NEED_CONTENT, - - /* Initializes and loads a content file for the currently - * selected libretro core. */ - CONTENT_CTL_INIT, - - CONTENT_CTL_DEINIT, - - CONTENT_CTL_GET_CRC, -}; - typedef struct ram_type { const char *path; @@ -93,7 +72,21 @@ bool content_save_state(const char *path); * as-is. */ bool content_load(content_ctx_info_t *info); -bool content_ctl(enum content_ctl_state state, void *data); +bool content_does_not_need_content(void); + +void content_set_does_not_need_content(void); + +void content_unset_does_not_need_content(void); + +bool content_get_crc(uint32_t **content_crc_ptr); + +bool content_is_inited(void); + +void content_deinit(void); + +/* Initializes and loads a content file for the currently + * selected libretro core. */ +bool content_init(void); #ifdef __cplusplus } diff --git a/dynamic.c b/dynamic.c index db1f0adff2..2c580a9b69 100644 --- a/dynamic.c +++ b/dynamic.c @@ -1005,9 +1005,9 @@ bool rarch_environment_cb(unsigned cmd, void *data) RARCH_LOG("Environ SET_SUPPORT_NO_GAME: %s.\n", state ? "yes" : "no"); if (state) - content_ctl(CONTENT_CTL_SET_DOES_NOT_NEED_CONTENT, NULL); + content_set_does_not_need_content(); else - content_ctl(CONTENT_CTL_UNSET_DOES_NOT_NEED_CONTENT, NULL); + content_unset_does_not_need_content(); break; } diff --git a/frontend/frontend.c b/frontend/frontend.c index cb68e911b6..e8037df0fb 100644 --- a/frontend/frontend.c +++ b/frontend/frontend.c @@ -133,7 +133,7 @@ int rarch_main(int argc, char *argv[], void *data) runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); runloop_ctl(RUNLOOP_CTL_GET_CONTENT_PATH, &fullpath); - if (content_ctl(CONTENT_CTL_IS_INITED, NULL) || content_ctl(CONTENT_CTL_DOES_NOT_NEED_CONTENT, NULL)) + if (content_is_inited() || content_does_not_need_content()) { char tmp[PATH_MAX_LENGTH]; struct retro_system_info *info = system ? &system->info : NULL; @@ -149,7 +149,7 @@ int rarch_main(int argc, char *argv[], void *data) if (rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL) || !info) content_push_to_history_playlist( - content_ctl(CONTENT_CTL_DOES_NOT_NEED_CONTENT, NULL) || *tmp, + content_does_not_need_content() || *tmp, *tmp ? tmp : NULL, info); } diff --git a/menu/menu_driver.c b/menu/menu_driver.c index f25469389a..1f0517c450 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -529,7 +529,7 @@ bool menu_driver_ctl(enum rarch_menu_ctl_state state, void *data) menu_driver_data_own = true; break; case RARCH_MENU_CTL_UNSET_OWN_DRIVER: - if (!content_ctl(CONTENT_CTL_IS_INITED, NULL)) + if (!content_is_inited()) return false; menu_driver_data_own = false; break; diff --git a/movie.c b/movie.c index 086e8bbcdb..3b22f13873 100644 --- a/movie.c +++ b/movie.c @@ -97,7 +97,7 @@ static bool init_playback(bsv_movie_t *handle, const char *path) return false; } - content_ctl(CONTENT_CTL_GET_CRC, &content_crc_ptr); + content_get_crc(&content_crc_ptr); if (swap_if_big32(header[CRC_INDEX]) != *content_crc_ptr) RARCH_WARN("CRC32 checksum mismatch between content file and saved content checksum in replay file header; replay highly likely to desync on playback.\n"); @@ -151,7 +151,7 @@ static bool init_record(bsv_movie_t *handle, const char *path) return false; } - content_ctl(CONTENT_CTL_GET_CRC, &content_crc_ptr); + content_get_crc(&content_crc_ptr); /* This value is supposed to show up as * BSV1 in a HEX editor, big-endian. */ diff --git a/netplay/netplay_common.c b/netplay/netplay_common.c index dbdcb9e8fb..f6bc3deb0b 100644 --- a/netplay/netplay_common.c +++ b/netplay/netplay_common.c @@ -78,7 +78,7 @@ uint32_t *np_bsv_header_generate(size_t *size, uint32_t magic) if (!header) goto error; - content_ctl(CONTENT_CTL_GET_CRC, &content_crc_ptr); + content_get_crc(&content_crc_ptr); bsv_header[MAGIC_INDEX] = swap_if_little32(BSV_MAGIC); bsv_header[SERIALIZER_INDEX] = swap_if_big32(magic); @@ -123,7 +123,7 @@ bool np_bsv_parse_header(const uint32_t *header, uint32_t magic) in_crc = swap_if_big32(header[CRC_INDEX]); - content_ctl(CONTENT_CTL_GET_CRC, &content_crc_ptr); + content_get_crc(&content_crc_ptr); if (in_crc != *content_crc_ptr) { @@ -205,7 +205,7 @@ bool np_send_info(netplay_t *netplay) mem_info.id = RETRO_MEMORY_SAVE_RAM; core_get_memory(&mem_info); - content_ctl(CONTENT_CTL_GET_CRC, &content_crc_ptr); + content_get_crc(&content_crc_ptr); header[0] = htonl(*content_crc_ptr); header[1] = htonl(np_impl_magic()); @@ -257,7 +257,7 @@ bool np_get_info(netplay_t *netplay) return false; } - content_ctl(CONTENT_CTL_GET_CRC, &content_crc_ptr); + content_get_crc(&content_crc_ptr); if (*content_crc_ptr != ntohl(header[0])) { diff --git a/retroarch.c b/retroarch.c index 5f2f64908c..fb22ec1ef7 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1050,7 +1050,7 @@ static void parse_input(int argc, char *argv[]) set_special_paths(argv + optind, argc - optind); } else - content_ctl(CONTENT_CTL_SET_DOES_NOT_NEED_CONTENT, NULL); + content_set_does_not_need_content(); /* Copy SRM/state dirs used, so they can be reused on reentrancy. */ if (global->has_set.save_path && @@ -1451,14 +1451,14 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data) case RARCH_CTL_SET_PATHS_REDIRECT: if(settings->sort_savestates_enable || settings->sort_savefiles_enable) { - if (content_ctl(CONTENT_CTL_DOES_NOT_NEED_CONTENT, NULL)) + if (content_does_not_need_content()) return false; set_paths_redirect(global->name.base); } break; case RARCH_CTL_SET_SRAM_ENABLE: global->sram.use = rarch_ctl(RARCH_CTL_IS_PLAIN_CORE, NULL) - && !content_ctl(CONTENT_CTL_DOES_NOT_NEED_CONTENT, NULL); + && !content_does_not_need_content(); break; case RARCH_CTL_SET_ERROR_ON_INIT: rarch_error_on_init = true;