Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RETRO_ENVIRONMENT_GET_CORE_DATA example usage #30

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
36 changes: 24 additions & 12 deletions tests/test/libretro-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@

#include "libretro.h"

static uint32_t *frame_buf;
typedef struct core_data_t {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think to really demonstrate this envcall, you'd need to move all currently-static state into it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be awesome. I'll see how much can be moved. Some of the callbacks are called before the core is initialized.

uint32_t *frame_buf;
} core_data_t;

static struct retro_log_callback logging;
static retro_log_printf_t log_cb;
static retro_video_refresh_t video_cb;
static retro_audio_sample_t audio_cb;
static retro_audio_sample_batch_t audio_batch_cb;
static retro_environment_t environ_cb;
static retro_input_poll_t input_poll_cb;
static retro_input_state_t input_state_cb;

static bool use_audio_cb;
static float last_aspect;
static float last_sample_rate;
Expand All @@ -29,27 +39,27 @@ static void fallback_log(enum retro_log_level level, const char *fmt, ...)

void retro_init(void)
{
frame_buf = calloc(320 * 240, sizeof(uint32_t));
core_data_t* core_data = calloc(1, sizeof(core_data_t));
core_data->frame_buf = calloc(320 * 240, sizeof(uint32_t));
environ_cb(RETRO_ENVIRONMENT_SET_CORE_DATA, (void*)core_data);
}

void retro_deinit(void)
{
free(frame_buf);
frame_buf = NULL;
core_data_t* core_data = NULL;
environ_cb(RETRO_ENVIRONMENT_GET_CORE_DATA, &core_data);

if (core_data != NULL) {
free(core_data->frame_buf);
free(core_data);
}
}

unsigned retro_api_version(void)
{
return RETRO_API_VERSION;
}

static retro_video_refresh_t video_cb;
static retro_audio_sample_t audio_cb;
static retro_audio_sample_batch_t audio_batch_cb;
static retro_environment_t environ_cb;
static retro_input_poll_t input_poll_cb;
static retro_input_state_t input_state_cb;

void retro_set_controller_port_device(unsigned port, unsigned device)
{
#define max_descriptions 10
Expand Down Expand Up @@ -418,7 +428,9 @@ static void render_checkered(void)
}
else
{
buf = frame_buf;
core_data_t* core_data = NULL;
environ_cb(RETRO_ENVIRONMENT_GET_CORE_DATA, &core_data);
buf = core_data->frame_buf;
stride = 320;
}

Expand Down
Loading
Loading