mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-24 00:20:01 +00:00
Merge pull request #12473 from jdgleaver/content-data-api
Add API extension for setting 'need_fullpath' based on content file extension and to request persistent frontend content data buffers
This commit is contained in:
commit
d8a5505204
@ -124,6 +124,10 @@ bool content_set_subsystem_by_name(const char* subsystem_name);
|
||||
/* Get the current subsystem "friendly name" */
|
||||
void content_get_subsystem_friendly_name(const char* subsystem_name, char* subsystem_friendly_name, size_t len);
|
||||
|
||||
/* Sets overrides which modify frontend handling of
|
||||
* specific content file types */
|
||||
bool content_file_override_set(const struct retro_system_content_info_override *overrides);
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
||||
#endif
|
||||
|
@ -1388,6 +1388,111 @@ enum retro_mod
|
||||
* fastforwarding state will occur in this case).
|
||||
*/
|
||||
|
||||
#define RETRO_ENVIRONMENT_SET_CONTENT_INFO_OVERRIDE 65
|
||||
/* const struct retro_system_content_info_override * --
|
||||
* Allows an implementation to override 'global' content
|
||||
* info parameters reported by retro_get_system_info().
|
||||
* Overrides also affect subsystem content info parameters
|
||||
* set via RETRO_ENVIRONMENT_SET_SUBSYSTEM_INFO.
|
||||
* This function must be called inside retro_set_environment().
|
||||
* If callback returns false, content info overrides
|
||||
* are unsupported by the frontend, and will be ignored.
|
||||
* If callback returns true, extended game info may be
|
||||
* retrieved by calling RETRO_ENVIRONMENT_GET_GAME_INFO_EXT
|
||||
* in retro_load_game() or retro_load_game_special().
|
||||
*
|
||||
* 'data' points to an array of retro_system_content_info_override
|
||||
* structs terminated by a { NULL, false, false } element.
|
||||
* If 'data' is NULL, no changes will be made to the frontend;
|
||||
* a core may therefore pass NULL in order to test whether
|
||||
* the RETRO_ENVIRONMENT_SET_CONTENT_INFO_OVERRIDE and
|
||||
* RETRO_ENVIRONMENT_GET_GAME_INFO_EXT callbacks are supported
|
||||
* by the frontend.
|
||||
*
|
||||
* For struct member descriptions, see the definition of
|
||||
* struct retro_system_content_info_override.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* - struct retro_system_info:
|
||||
* {
|
||||
* "My Core", // library_name
|
||||
* "v1.0", // library_version
|
||||
* "m3u|md|cue|iso|chd|sms|gg|sg", // valid_extensions
|
||||
* true, // need_fullpath
|
||||
* false // block_extract
|
||||
* }
|
||||
*
|
||||
* - Array of struct retro_system_content_info_override:
|
||||
* {
|
||||
* {
|
||||
* "md|sms|gg", // extensions
|
||||
* false, // need_fullpath
|
||||
* true // persistent_data
|
||||
* },
|
||||
* {
|
||||
* "sg", // extensions
|
||||
* false, // need_fullpath
|
||||
* false // persistent_data
|
||||
* },
|
||||
* { NULL, false, false }
|
||||
* }
|
||||
*
|
||||
* Result:
|
||||
* - Files of type m3u, cue, iso, chd will not be
|
||||
* loaded by the frontend. Frontend will pass a
|
||||
* valid path to the core, and core will handle
|
||||
* loading internally
|
||||
* - Files of type md, sms, gg will be loaded by
|
||||
* the frontend. A valid memory buffer will be
|
||||
* passed to the core. This memory buffer will
|
||||
* remain valid until retro_deinit() returns
|
||||
* - Files of type sg will be loaded by the frontend.
|
||||
* A valid memory buffer will be passed to the core.
|
||||
* This memory buffer will remain valid until
|
||||
* retro_load_game() (or retro_load_game_special())
|
||||
* returns
|
||||
*
|
||||
* NOTE: If an extension is listed multiple times in
|
||||
* an array of retro_system_content_info_override
|
||||
* structs, only the first instance will be registered
|
||||
*/
|
||||
|
||||
#define RETRO_ENVIRONMENT_GET_GAME_INFO_EXT 66
|
||||
/* const struct retro_game_info_ext ** --
|
||||
* Allows an implementation to fetch extended game
|
||||
* information, providing additional content path
|
||||
* and memory buffer status details.
|
||||
* This function may only be called inside
|
||||
* retro_load_game() or retro_load_game_special().
|
||||
* If callback returns false, extended game information
|
||||
* is unsupported by the frontend. In this case, only
|
||||
* regular retro_game_info will be available.
|
||||
* RETRO_ENVIRONMENT_GET_GAME_INFO_EXT is guaranteed
|
||||
* to return true if RETRO_ENVIRONMENT_SET_CONTENT_INFO_OVERRIDE
|
||||
* returns true.
|
||||
*
|
||||
* 'data' points to an array of retro_game_info_ext structs.
|
||||
*
|
||||
* For struct member descriptions, see the definition of
|
||||
* struct retro_game_info_ext.
|
||||
*
|
||||
* - If function is called inside retro_load_game(),
|
||||
* the retro_game_info_ext array is guaranteed to
|
||||
* have a size of 1 - i.e. the returned pointer may
|
||||
* be used to access directly the members of the
|
||||
* first retro_game_info_ext struct, for example:
|
||||
*
|
||||
* struct retro_game_info_ext *game_info_ext;
|
||||
* if (environ_cb(RETRO_ENVIRONMENT_GET_GAME_INFO_EXT, &game_info_ext))
|
||||
* printf("Content Directory: %s\n", game_info_ext->dir);
|
||||
*
|
||||
* - If the function is called inside retro_load_game_special(),
|
||||
* the retro_game_info_ext array is guaranteed to have a
|
||||
* size equal to the num_info argument passed to
|
||||
* retro_load_game_special()
|
||||
*/
|
||||
|
||||
/* VFS functionality */
|
||||
|
||||
/* File paths:
|
||||
@ -2791,6 +2896,213 @@ struct retro_system_info
|
||||
bool block_extract;
|
||||
};
|
||||
|
||||
/* Defines overrides which modify frontend handling of
|
||||
* specific content file types.
|
||||
* An array of retro_system_content_info_override is
|
||||
* passed to RETRO_ENVIRONMENT_SET_CONTENT_INFO_OVERRIDE
|
||||
* NOTE: In the following descriptions, references to
|
||||
* retro_load_game() may be replaced with
|
||||
* retro_load_game_special() */
|
||||
struct retro_system_content_info_override
|
||||
{
|
||||
/* A list of file extensions for which the override
|
||||
* should apply, delimited by a 'pipe' character
|
||||
* (e.g. "md|sms|gg")
|
||||
* Permitted file extensions are limited to those
|
||||
* included in retro_system_info::valid_extensions
|
||||
* and/or retro_subsystem_rom_info::valid_extensions */
|
||||
const char *extensions;
|
||||
|
||||
/* Overrides the need_fullpath value set in
|
||||
* retro_system_info and/or retro_subsystem_rom_info.
|
||||
* To reiterate:
|
||||
*
|
||||
* If need_fullpath is true and retro_load_game() is called:
|
||||
* - retro_game_info::path is guaranteed to contain a valid
|
||||
* path to an existent file
|
||||
* - retro_game_info::data and retro_game_info::size are invalid
|
||||
*
|
||||
* If need_fullpath is false and retro_load_game() is called:
|
||||
* - retro_game_info::path may be NULL
|
||||
* - retro_game_info::data and retro_game_info::size are guaranteed
|
||||
* to be valid
|
||||
*
|
||||
* In addition:
|
||||
*
|
||||
* If need_fullpath is true and retro_load_game() is called:
|
||||
* - retro_game_info_ext::full_path is guaranteed to contain a valid
|
||||
* path to an existent file
|
||||
* - retro_game_info_ext::archive_path may be NULL
|
||||
* - retro_game_info_ext::archive_file may be NULL
|
||||
* - retro_game_info_ext::dir is guaranteed to contain a valid path
|
||||
* to the directory in which the content file exists
|
||||
* - retro_game_info_ext::name is guaranteed to contain the
|
||||
* basename of the content file, without extension
|
||||
* - retro_game_info_ext::ext is guaranteed to contain the
|
||||
* extension of the content file in lower case format
|
||||
* - retro_game_info_ext::data and retro_game_info_ext::size
|
||||
* are invalid
|
||||
*
|
||||
* If need_fullpath is false and retro_load_game() is called:
|
||||
* - If retro_game_info_ext::file_in_archive is false:
|
||||
* - retro_game_info_ext::full_path is guaranteed to contain
|
||||
* a valid path to an existent file
|
||||
* - retro_game_info_ext::archive_path may be NULL
|
||||
* - retro_game_info_ext::archive_file may be NULL
|
||||
* - retro_game_info_ext::dir is guaranteed to contain a
|
||||
* valid path to the directory in which the content file exists
|
||||
* - retro_game_info_ext::name is guaranteed to contain the
|
||||
* basename of the content file, without extension
|
||||
* - retro_game_info_ext::ext is guaranteed to contain the
|
||||
* extension of the content file in lower case format
|
||||
* - If retro_game_info_ext::file_in_archive is true:
|
||||
* - retro_game_info_ext::full_path may be NULL
|
||||
* - retro_game_info_ext::archive_path is guaranteed to
|
||||
* contain a valid path to an existent compressed file
|
||||
* inside which the content file is located
|
||||
* - retro_game_info_ext::archive_file is guaranteed to
|
||||
* contain a valid path to an existent content file
|
||||
* inside the compressed file referred to by
|
||||
* retro_game_info_ext::archive_path
|
||||
* e.g. for a compressed file '/path/to/foo.zip'
|
||||
* containing 'bar.sfc'
|
||||
* > retro_game_info_ext::archive_path will be '/path/to/foo.zip'
|
||||
* > retro_game_info_ext::archive_file will be 'bar.sfc'
|
||||
* - retro_game_info_ext::dir is guaranteed to contain a
|
||||
* valid path to the directory in which the compressed file
|
||||
* (containing the content file) exists
|
||||
* - retro_game_info_ext::name is guaranteed to contain
|
||||
* EITHER
|
||||
* 1) the basename of the compressed file (containing
|
||||
* the content file), without extension
|
||||
* OR
|
||||
* 2) the basename of the content file inside the
|
||||
* compressed file, without extension
|
||||
* In either case, a core should consider 'name' to
|
||||
* be the canonical name/ID of the the content file
|
||||
* - retro_game_info_ext::ext is guaranteed to contain the
|
||||
* extension of the content file inside the compressed file,
|
||||
* in lower case format
|
||||
* - retro_game_info_ext::data and retro_game_info_ext::size are
|
||||
* guaranteed to be valid */
|
||||
bool need_fullpath;
|
||||
|
||||
/* If need_fullpath is false, specifies whether the content
|
||||
* data buffer available in retro_load_game() is 'persistent'
|
||||
*
|
||||
* If persistent_data is false and retro_load_game() is called:
|
||||
* - retro_game_info::data and retro_game_info::size
|
||||
* are valid only until retro_load_game() returns
|
||||
* - retro_game_info_ext::data and retro_game_info_ext::size
|
||||
* are valid only until retro_load_game() returns
|
||||
*
|
||||
* If persistent_data is true and retro_load_game() is called:
|
||||
* - retro_game_info::data and retro_game_info::size
|
||||
* are valid until retro_deinit() returns
|
||||
* - retro_game_info_ext::data and retro_game_info_ext::size
|
||||
* are valid until retro_deinit() returns */
|
||||
bool persistent_data;
|
||||
};
|
||||
|
||||
/* Similar to retro_game_info, but provides extended
|
||||
* information about the source content file and
|
||||
* game memory buffer status.
|
||||
* And array of retro_game_info_ext is returned by
|
||||
* RETRO_ENVIRONMENT_GET_GAME_INFO_EXT
|
||||
* NOTE: In the following descriptions, references to
|
||||
* retro_load_game() may be replaced with
|
||||
* retro_load_game_special() */
|
||||
struct retro_game_info_ext
|
||||
{
|
||||
/* - If file_in_archive is false, contains a valid
|
||||
* path to an existent content file (UTF-8 encoded)
|
||||
* - If file_in_archive is true, may be NULL */
|
||||
const char *full_path;
|
||||
|
||||
/* - If file_in_archive is false, may be NULL
|
||||
* - If file_in_archive is true, contains a valid path
|
||||
* to an existent compressed file inside which the
|
||||
* content file is located (UTF-8 encoded) */
|
||||
const char *archive_path;
|
||||
|
||||
/* - If file_in_archive is false, may be NULL
|
||||
* - If file_in_archive is true, contain a valid path
|
||||
* to an existent content file inside the compressed
|
||||
* file referred to by archive_path (UTF-8 encoded)
|
||||
* e.g. for a compressed file '/path/to/foo.zip'
|
||||
* containing 'bar.sfc'
|
||||
* > archive_path will be '/path/to/foo.zip'
|
||||
* > archive_file will be 'bar.sfc' */
|
||||
const char *archive_file;
|
||||
|
||||
/* - If file_in_archive is false, contains a valid path
|
||||
* to the directory in which the content file exists
|
||||
* (UTF-8 encoded)
|
||||
* - If file_in_archive is true, contains a valid path
|
||||
* to the directory in which the compressed file
|
||||
* (containing the content file) exists (UTF-8 encoded) */
|
||||
const char *dir;
|
||||
|
||||
/* Contains the canonical name/ID of the content file
|
||||
* (UTF-8 encoded). Intended for use when identifying
|
||||
* 'complementary' content named after the loaded file -
|
||||
* i.e. companion data of a different format (a CD image
|
||||
* required by a ROM), texture packs, internally handled
|
||||
* save files, etc.
|
||||
* - If file_in_archive is false, contains the basename
|
||||
* of the content file, without extension
|
||||
* - If file_in_archive is true, then string is
|
||||
* implementation specific. A frontend may choose to
|
||||
* set a name value of:
|
||||
* EITHER
|
||||
* 1) the basename of the compressed file (containing
|
||||
* the content file), without extension
|
||||
* OR
|
||||
* 2) the basename of the content file inside the
|
||||
* compressed file, without extension
|
||||
* RetroArch sets the 'name' value according to (1).
|
||||
* A frontend that supports routine loading of
|
||||
* content from archives containing multiple unrelated
|
||||
* content files may set the 'name' value according
|
||||
* to (2). */
|
||||
const char *name;
|
||||
|
||||
/* - If file_in_archive is false, contains the extension
|
||||
* of the content file in lower case format
|
||||
* - If file_in_archive is true, contains the extension
|
||||
* of the content file inside the compressed file,
|
||||
* in lower case format */
|
||||
const char *ext;
|
||||
|
||||
/* String of implementation specific meta-data. */
|
||||
const char *meta;
|
||||
|
||||
/* Memory buffer of loaded game content. Will be NULL:
|
||||
* IF
|
||||
* - retro_system_info::need_fullpath is true and
|
||||
* retro_system_content_info_override::need_fullpath
|
||||
* is unset
|
||||
* OR
|
||||
* - retro_system_content_info_override::need_fullpath
|
||||
* is true */
|
||||
const void *data;
|
||||
|
||||
/* Size of game content memory buffer, in bytes */
|
||||
size_t size;
|
||||
|
||||
/* True if loaded content file is inside a compressed
|
||||
* archive */
|
||||
bool file_in_archive;
|
||||
|
||||
/* - If data is NULL, value is unset/ignored
|
||||
* - If data is non-NULL:
|
||||
* - If persistent_data is false, data and size are
|
||||
* valid only until retro_load_game() returns
|
||||
* - If persistent_data is true, data and size are
|
||||
* are valid until retro_deinit() returns */
|
||||
bool persistent_data;
|
||||
};
|
||||
|
||||
struct retro_game_geometry
|
||||
{
|
||||
unsigned base_width; /* Nominal video width of game. */
|
||||
|
93
retroarch.c
93
retroarch.c
@ -18526,6 +18526,48 @@ static bool rarch_environment_cb(unsigned cmd, void *data)
|
||||
}
|
||||
break;
|
||||
|
||||
case RETRO_ENVIRONMENT_SET_CONTENT_INFO_OVERRIDE:
|
||||
{
|
||||
const struct retro_system_content_info_override *overrides =
|
||||
(const struct retro_system_content_info_override *)data;
|
||||
|
||||
RARCH_LOG("[Environ]: RETRO_ENVIRONMENT_SET_CONTENT_INFO_OVERRIDE.\n");
|
||||
|
||||
/* Passing NULL always results in 'success' - this
|
||||
* allows cores to test for frontend support of
|
||||
* the RETRO_ENVIRONMENT_SET_CONTENT_INFO_OVERRIDE and
|
||||
* RETRO_ENVIRONMENT_GET_GAME_INFO_EXT callbacks */
|
||||
if (!overrides)
|
||||
return true;
|
||||
|
||||
return content_file_override_set(overrides);
|
||||
}
|
||||
break;
|
||||
|
||||
case RETRO_ENVIRONMENT_GET_GAME_INFO_EXT:
|
||||
{
|
||||
content_state_t *p_content =
|
||||
content_state_get_ptr();
|
||||
const struct retro_game_info_ext **game_info_ext =
|
||||
(const struct retro_game_info_ext **)data;
|
||||
|
||||
RARCH_LOG("[Environ]: RETRO_ENVIRONMENT_GET_GAME_INFO_EXT.\n");
|
||||
|
||||
if (!game_info_ext)
|
||||
return false;
|
||||
|
||||
if (p_content &&
|
||||
p_content->content_list &&
|
||||
p_content->content_list->game_info_ext)
|
||||
*game_info_ext = p_content->content_list->game_info_ext;
|
||||
else
|
||||
{
|
||||
RARCH_ERR("[Environ]: Failed to retrieve extended game info\n");
|
||||
*game_info_ext = NULL;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
RARCH_LOG("[Environ]: UNSUPPORTED (#%u).\n", cmd);
|
||||
@ -18938,7 +18980,6 @@ static void free_retro_ctx_load_content_info(struct
|
||||
if (!dest)
|
||||
return;
|
||||
|
||||
core_free_retro_game_info(dest->info);
|
||||
string_list_free((struct string_list*)dest->content);
|
||||
if (dest->info)
|
||||
free(dest->info);
|
||||
@ -18956,33 +18997,20 @@ static struct retro_game_info* clone_retro_game_info(const
|
||||
if (!dest)
|
||||
return NULL;
|
||||
|
||||
dest->path = NULL;
|
||||
dest->data = NULL;
|
||||
dest->size = 0;
|
||||
dest->meta = NULL;
|
||||
|
||||
if (src->size && src->data)
|
||||
{
|
||||
void *data = malloc(src->size);
|
||||
|
||||
if (data)
|
||||
{
|
||||
memcpy(data, src->data, src->size);
|
||||
dest->data = data;
|
||||
}
|
||||
}
|
||||
|
||||
if (!string_is_empty(src->path))
|
||||
dest->path = strdup(src->path);
|
||||
if (!string_is_empty(src->meta))
|
||||
dest->meta = strdup(src->meta);
|
||||
|
||||
dest->size = src->size;
|
||||
/* content_file_init() guarantees that all
|
||||
* elements of the source retro_game_info
|
||||
* struct will persist for the lifetime of
|
||||
* the core. This means we do not have to
|
||||
* copy any data; pointer assignment is
|
||||
* sufficient */
|
||||
dest->path = src->path;
|
||||
dest->data = src->data;
|
||||
dest->size = src->size;
|
||||
dest->meta = src->meta;
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
static struct retro_ctx_load_content_info
|
||||
*clone_retro_ctx_load_content_info(
|
||||
const struct retro_ctx_load_content_info *src)
|
||||
@ -39391,23 +39419,6 @@ bool core_has_set_input_descriptor(void)
|
||||
return p_rarch->current_core.has_set_input_descriptors;
|
||||
}
|
||||
|
||||
#if defined(HAVE_RUNAHEAD)
|
||||
static void core_free_retro_game_info(struct retro_game_info *dest)
|
||||
{
|
||||
if (!dest)
|
||||
return;
|
||||
if (dest->path)
|
||||
free((void*)dest->path);
|
||||
if (dest->data)
|
||||
free((void*)dest->data);
|
||||
if (dest->meta)
|
||||
free((void*)dest->meta);
|
||||
dest->path = NULL;
|
||||
dest->data = NULL;
|
||||
dest->meta = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
unsigned int retroarch_get_rotation(void)
|
||||
{
|
||||
struct rarch_state *p_rarch = &rarch_st;
|
||||
|
35
retroarch.h
35
retroarch.h
@ -295,10 +295,43 @@ typedef struct global
|
||||
bool cli_load_menu_on_error;
|
||||
} global_t;
|
||||
|
||||
typedef struct content_file_override
|
||||
{
|
||||
char *ext;
|
||||
bool need_fullpath;
|
||||
bool persistent_data;
|
||||
} content_file_override_t;
|
||||
|
||||
typedef struct content_file_info
|
||||
{
|
||||
char *full_path;
|
||||
char *archive_path;
|
||||
char *archive_file;
|
||||
char *dir;
|
||||
char *name;
|
||||
char *ext;
|
||||
char *meta; /* Unused at present */
|
||||
void *data;
|
||||
size_t data_size;
|
||||
bool file_in_archive;
|
||||
bool persistent_data;
|
||||
} content_file_info_t;
|
||||
|
||||
typedef struct content_file_list
|
||||
{
|
||||
content_file_info_t *entries;
|
||||
struct string_list *temporary_files;
|
||||
struct retro_game_info *game_info;
|
||||
struct retro_game_info_ext *game_info_ext;
|
||||
size_t size;
|
||||
} content_file_list_t;
|
||||
|
||||
typedef struct content_state
|
||||
{
|
||||
char *pending_subsystem_roms[RARCH_MAX_SUBSYSTEM_ROMS];
|
||||
struct string_list *temporary_content;
|
||||
|
||||
content_file_override_t *content_override_list;
|
||||
content_file_list_t *content_list;
|
||||
|
||||
int pending_subsystem_rom_num;
|
||||
int pending_subsystem_id;
|
||||
|
@ -136,9 +136,6 @@ static void drivers_init(struct rarch_state *p_rarch,
|
||||
int flags,
|
||||
bool verbosity_enabled);
|
||||
|
||||
#if defined(HAVE_RUNAHEAD)
|
||||
static void core_free_retro_game_info(struct retro_game_info *dest);
|
||||
#endif
|
||||
static bool core_load(struct rarch_state *p_rarch,
|
||||
unsigned poll_type_behavior);
|
||||
static bool core_unload_game(struct rarch_state *p_rarch);
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user