Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions dynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ struct retro_core_t

unsigned poll_type;
uint8_t flags;

/**
* Arbitrary core data.
*
* @see RETRO_ENVIRONMENT_GET_CORE_DATA
*/
void *core_data;
};


Expand Down
26 changes: 26 additions & 0 deletions libretro-common/include/libretro.h
Original file line number Diff line number Diff line change
Expand Up @@ -2574,6 +2574,32 @@ enum retro_mod
*/
#define RETRO_ENVIRONMENT_GET_FILE_BROWSER_START_DIRECTORY 80

/**
* Sets a pointer to arbitrary data for the actively running core.
Comment thread
RobLoach marked this conversation as resolved.
*
* Intended for use as a substitute for global state, which is a common
* source of bugs. Can be set in either \c retro_init() or \c retro_load_game().
*
* @param[in] data <tt>void *</tt>. Pointer to the data to set.
* @return \c true if the environment call is available.
*
* @see RETRO_ENVIRONMENT_GET_CORE_DATA
*/
#define RETRO_ENVIRONMENT_SET_CORE_DATA (81 | RETRO_ENVIRONMENT_EXPERIMENTAL)

/**
* Gets a pointer to arbitrary data for the actively running core.
*
* This is persistent for the lifetime of the core until \c retro_deinit() is called.
*
* @param[out] data <tt>void **</tt>. Pointer to the data that was set.
* May be \c NULL if the data was not set yet.
* @return \c true if the environment call is available.
*
* @see RETRO_ENVIRONMENT_SET_CORE_DATA
*/
#define RETRO_ENVIRONMENT_GET_CORE_DATA (82 | RETRO_ENVIRONMENT_EXPERIMENTAL)

/**@}*/

/**
Expand Down
12 changes: 12 additions & 0 deletions runloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -3556,6 +3556,18 @@ bool runloop_environment_cb(unsigned cmd, void *data)
}
}
break;

case RETRO_ENVIRONMENT_SET_CORE_DATA:
runloop_st->current_core.core_data = data;
break;

case RETRO_ENVIRONMENT_GET_CORE_DATA:
if (data != NULL) {
void **core_data = (void **)data;
*core_data = runloop_st->current_core.core_data;
}
break;

default:
RARCH_LOG("[Environ]: UNSUPPORTED (#%u).\n", cmd);
return false;
Expand Down