move achievement activation to background thread

This commit is contained in:
Jamiras 2021-11-16 10:03:05 -07:00
parent 4faf2f82f1
commit 2adf52a493
3 changed files with 34 additions and 23 deletions

View File

@ -1313,27 +1313,8 @@ static void rcheevos_fetch_badges(void)
rcheevos_client_fetch_badges(rcheevos_fetch_badges_callback, NULL);
}
static void rcheevos_start_session(void)
static void rcheevos_start_session_async(retro_task_t* task)
{
if (rcheevos_load_aborted())
{
CHEEVOS_LOG(RCHEEVOS_TAG "Load aborted before starting session\n");
return;
}
if ( rcheevos_locals.game.achievement_count == 0
&& rcheevos_locals.game.leaderboard_count == 0)
{
if (!rcheevos_locals.runtime.richpresence)
{
/* nothing for the runtime to process,
* disable hardcore and bail */
rcheevos_show_game_placard();
rcheevos_pause_hardcore();
return;
}
}
rcheevos_begin_load_state(RCHEEVOS_LOAD_STATE_STARTING_SESSION);
/* activate the achievements and leaderboards
@ -1378,10 +1359,41 @@ static void rcheevos_start_session(void)
rcheevos_show_game_placard();
task_set_finished(task, true);
if (rcheevos_end_load_state() == 0)
rcheevos_fetch_badges();
}
static void rcheevos_start_session(void)
{
retro_task_t* task;
if (rcheevos_load_aborted())
{
CHEEVOS_LOG(RCHEEVOS_TAG "Load aborted before starting session\n");
return;
}
if (rcheevos_locals.game.achievement_count == 0
&& rcheevos_locals.game.leaderboard_count == 0)
{
if (!rcheevos_locals.runtime.richpresence)
{
/* nothing for the runtime to process,
* disable hardcore and bail */
rcheevos_show_game_placard();
rcheevos_pause_hardcore();
return;
}
}
/* this is called on the primary thread. use a task to do the initialization on a background thread */
task = task_init();
task->handler = rcheevos_start_session_async;
task_queue_push(task);
}
static void rcheevos_initialize_runtime_callback(void* userdata)
{
rcheevos_start_session();

View File

@ -442,9 +442,7 @@ static void rcheevos_async_http_task_callback(
* response is properly formatted or will encounter a parse failure
* before reading past the end of the data */
if (request->handler)
{
request->handler(request, data, buffer, sizeof(buffer));
}
}
if (!buffer[0])

View File

@ -297,7 +297,8 @@ static void gfx_widget_achievement_popup_next(void* userdata)
if (state->queue_read_index >= 0)
{
gfx_widget_achievement_popup_free_current(state);
if (state->queue[state->queue_read_index].title)
gfx_widget_achievement_popup_free_current(state);
/* start the next popup (if present) */
if (state->queue[state->queue_read_index].title)