Skip to content

Commit

Permalink
Merge branch 'libretro:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanaobrien authored Dec 5, 2023
2 parents 7c2a36b + 456f9b0 commit b0cdeba
Show file tree
Hide file tree
Showing 58 changed files with 2,247 additions and 635 deletions.
67 changes: 62 additions & 5 deletions cheevos/cheevos.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ static rcheevos_locals_t rcheevos_locals =
{{0}},/* memory */
#ifdef HAVE_THREADS
CMD_EVENT_NONE, /* queued_command */
false, /* game_placard_requested */
#endif
#ifndef HAVE_RC_CLIENT
"", /* displayname */
Expand Down Expand Up @@ -134,6 +135,9 @@ rcheevos_locals_t* get_rcheevos_locals(void)
Supporting functions.
*****************************************************************************/

#define CMD_CHEEVOS_NON_COMMAND -1
static void rcheevos_show_game_placard(void);

#ifndef CHEEVOS_VERBOSE
void rcheevos_log(const char* fmt, ...)
{
Expand Down Expand Up @@ -602,6 +606,39 @@ static void rcheevos_server_error(const char* api_name, const char* message)
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_ERROR);
}

static void rcheevos_server_disconnected()
{
CHEEVOS_LOG(RCHEEVOS_TAG "Unable to communicate with RetroAchievements server\n");

/* always show message - even with widget. it helps the user understand what the widget is for */
{
const char* message = msg_hash_to_str(MENU_ENUM_LABEL_CHEEVOS_SERVER_DISCONNECTED);
runloop_msg_queue_push(message, 0, 3 * 60, false, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_WARNING);
}

#if defined(HAVE_GFX_WIDGETS)
if (gfx_widgets_ready())
gfx_widget_set_cheevos_disconnect(true);
#endif
}

static void rcheevos_server_reconnected()
{
CHEEVOS_LOG(RCHEEVOS_TAG "All pending requests synced to RetroAchievements server\n");

{
const char* message = msg_hash_to_str(MENU_ENUM_LABEL_CHEEVOS_SERVER_RECONNECTED);
runloop_msg_queue_push(message, 0, 3 * 60, false, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_SUCCESS);
}

#if defined(HAVE_GFX_WIDGETS)
if (gfx_widgets_ready())
gfx_widget_set_cheevos_disconnect(false);
#endif
}

static void rcheevos_client_event_handler(const rc_client_event_t* event, rc_client_t* client)
{
switch (event->type)
Expand Down Expand Up @@ -657,10 +694,10 @@ static void rcheevos_client_event_handler(const rc_client_event_t* event, rc_cli
rcheevos_server_error(event->server_error->api, event->server_error->error_message);
break;
case RC_CLIENT_EVENT_DISCONNECTED:
CHEEVOS_LOG(RCHEEVOS_TAG "Unable to communicate with RetroAchievements server");
rcheevos_server_disconnected();
break;
case RC_CLIENT_EVENT_RECONNECTED:
CHEEVOS_LOG(RCHEEVOS_TAG "All pending requests synced to RetroAchievements server");
rcheevos_server_reconnected();
break;
default:
#ifndef NDEBUG
Expand Down Expand Up @@ -1202,9 +1239,12 @@ bool rcheevos_unload(void)
/* Clean up after completed tasks */
task_queue_check();
}
#endif
#endif

#ifdef HAVE_THREADS
rcheevos_locals.queued_command = CMD_EVENT_NONE;
#endif
rcheevos_locals.game_placard_requested = false;
#endif

if (rcheevos_locals.memory.count > 0)
Expand Down Expand Up @@ -1866,8 +1906,16 @@ void rcheevos_test(void)
#ifdef HAVE_THREADS
if (rcheevos_locals.queued_command != CMD_EVENT_NONE)
{
command_event(rcheevos_locals.queued_command, NULL);
if (rcheevos_locals.queued_command != CMD_CHEEVOS_NON_COMMAND)
command_event(rcheevos_locals.queued_command, NULL);

rcheevos_locals.queued_command = CMD_EVENT_NONE;

if (rcheevos_locals.game_placard_requested)
{
rcheevos_locals.game_placard_requested = false;
rcheevos_show_game_placard();
}
}
#endif

Expand Down Expand Up @@ -2414,7 +2462,16 @@ static void rcheevos_client_load_game_callback(int result,
rc_client_set_read_memory_function(client, rcheevos_client_read_memory);
}

rcheevos_show_game_placard();
#ifdef HAVE_THREADS
if (!task_is_on_main_thread())
{
/* have to "schedule" this. game image should not be loaded on background thread */
rcheevos_locals.queued_command = CMD_CHEEVOS_NON_COMMAND;
rcheevos_locals.game_placard_requested = true;
}
else
rcheevos_show_game_placard();
#endif

rcheevos_finalize_game_load(client);

Expand Down
1 change: 1 addition & 0 deletions cheevos/cheevos_locals.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ typedef struct rcheevos_locals_t

#ifdef HAVE_THREADS
enum event_command queued_command; /* action queued by background thread to be run on main thread */
bool game_placard_requested; /* request to display game placard */
#endif

#ifndef HAVE_RC_CLIENT
Expand Down
16 changes: 15 additions & 1 deletion cheevos/cheevos_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "../deps/rcheevos/include/rc_runtime_types.h"
#include "../deps/rcheevos/include/rc_api_runtime.h"
#include "../deps/rcheevos/src/rc_client_internal.h"

#include "../menu/menu_driver.h"
#include "../menu/menu_entries.h"
Expand Down Expand Up @@ -295,6 +296,15 @@ void rcheevos_menu_populate(void* data)
rcheevos_menu_reset_badges();
rcheevos_locals->menuitem_count = 0;

if (rcheevos_locals->client->state.disconnect)
{
menu_entries_append(info->list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_ACHIEVEMENT_SERVER_UNREACHABLE),
msg_hash_to_str(MENU_ENUM_SUBLABEL_ACHIEVEMENT_SERVER_UNREACHABLE),
MENU_ENUM_LABEL_ACHIEVEMENT_SERVER_UNREACHABLE,
MENU_INFO_ACHIEVEMENTS_SERVER_UNREACHABLE, 0, 0, NULL);
}

if (game && game->id != 0)
{
/* first menu item is the Pause/Resume Hardcore option (unless hardcore is completely disabled) */
Expand Down Expand Up @@ -466,7 +476,11 @@ uintptr_t rcheevos_get_badge_texture(const char* badge, bool locked, bool downlo
return 0;

/* OpenGL driver crashes if gfx_display_reset_textures_list is called on a background thread */
retro_assert(task_is_on_main_thread());
if (!task_is_on_main_thread())
{
CHEEVOS_ERR(RCHEEVOS_TAG "attempt to load badge %s from background thread", badge);
retro_assert(task_is_on_main_thread());
}

snprintf(badge_file, sizeof(badge_file), "%s%s%s", badge,
locked ? "_lock" : "", FILE_PATH_PNG_EXTENSION);
Expand Down
1 change: 1 addition & 0 deletions gfx/gfx_widgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ void gfx_widgets_clear_leaderboard_displays(void);
void gfx_widgets_set_challenge_display(unsigned id, const char* badge);
void gfx_widgets_clear_challenge_displays(void);
void gfx_widget_set_achievement_progress(const char* badge, const char* progress);
void gfx_widget_set_cheevos_disconnect(bool visible);
#endif

/* TODO/FIXME/WARNING: Not thread safe! */
Expand Down
2 changes: 0 additions & 2 deletions gfx/video_crt_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@
#include "../paths.h"
#include "gfx_display.h"

#if !defined(HAVE_VIDEOCORE)
#include "../deps/switchres/switchres_wrapper.h"
static sr_mode srm;
#endif

#ifdef HAVE_CONFIG_H
#include "../config.h"
Expand Down
47 changes: 46 additions & 1 deletion gfx/widgets/gfx_widget_leaderboard_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ struct progress_tracker_info

#define CHEEVO_LBOARD_FIRST_FIXED_CHAR 0x2D /* -./0123456789: */
#define CHEEVO_LBOARD_LAST_FIXED_CHAR 0x3A

/* TODO: rename; this file handles all achievement tracker information, not just leaderboards */
struct gfx_widget_leaderboard_display_state
{
#ifdef HAVE_THREADS
Expand All @@ -64,6 +66,7 @@ struct gfx_widget_leaderboard_display_state
unsigned challenge_count;
uint16_t char_width[CHEEVO_LBOARD_LAST_FIXED_CHAR - CHEEVO_LBOARD_FIRST_FIXED_CHAR + 1];
uint16_t fixed_char_width;
bool disconnected;
};

typedef struct gfx_widget_leaderboard_display_state gfx_widget_leaderboard_display_state_t;
Expand Down Expand Up @@ -109,7 +112,10 @@ static void gfx_widget_leaderboard_display_frame(void* data, void* userdata)
gfx_widget_leaderboard_display_state_t *state = &p_w_leaderboard_display_st;

/* if there's nothing to display, just bail */
if (state->tracker_count == 0 && state->challenge_count == 0 && state->progress_tracker.show_until == 0)
if (state->tracker_count == 0 &&
state->challenge_count == 0 &&
state->progress_tracker.show_until == 0 &&
!state->disconnected)
return;

#ifdef HAVE_THREADS
Expand Down Expand Up @@ -335,6 +341,38 @@ static void gfx_widget_leaderboard_display_frame(void* data, void* userdata)
TEXT_COLOR_INFO, TEXT_ALIGN_LEFT, true);
}
}

if (state->disconnected)
{
const char* disconnected_text = "! RA !";
const unsigned disconnect_widget_width = font_driver_get_message_width(
state->dispwidget_ptr->gfx_widget_fonts.msg_queue.font,
disconnected_text, 0, 1) + CHEEVO_LBOARD_DISPLAY_PADDING * 2;
const unsigned disconnect_widget_height =
p_dispwidget->gfx_widget_fonts.msg_queue.line_height + (CHEEVO_LBOARD_DISPLAY_PADDING - 1) * 2;
x = video_width - disconnect_widget_width - spacing;
y -= disconnect_widget_height + spacing;

/* Backdrop */
gfx_display_draw_quad(
p_disp,
video_info->userdata,
video_width, video_height,
(int)x, (int)y, disconnect_widget_width, disconnect_widget_height,
video_width, video_height,
p_dispwidget->backdrop_orig,
NULL);

/* Text */
char_x = (float)(x + CHEEVO_LBOARD_DISPLAY_PADDING);
char_y = (float)(y + disconnect_widget_height - (CHEEVO_LBOARD_DISPLAY_PADDING - 1)
- p_dispwidget->gfx_widget_fonts.msg_queue.line_descender);

gfx_widgets_draw_text(&p_dispwidget->gfx_widget_fonts.msg_queue,
disconnected_text, char_x, char_y,
video_width, video_height,
TEXT_COLOR_INFO, TEXT_ALIGN_LEFT, true);
}
}

#ifdef HAVE_THREADS
Expand Down Expand Up @@ -542,6 +580,13 @@ void gfx_widget_set_achievement_progress(const char* badge, const char* progress
video_driver_texture_unload(&old_badge_id);
}

void gfx_widget_set_cheevos_disconnect(bool value)
{
gfx_widget_leaderboard_display_state_t* state = &p_w_leaderboard_display_st;
state->disconnected = value;
}


const gfx_widget_t gfx_widget_leaderboard_display = {
&gfx_widget_leaderboard_display_init,
&gfx_widget_leaderboard_display_free,
Expand Down
1 change: 1 addition & 0 deletions intl/msg_hash_ar.h
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,7 @@ MSG_HASH(
MENU_ENUM_SUBLABEL_JOYPAD_DRIVER,
"مشغل Joypad للاستخدام."
)

MSG_HASH(
MENU_ENUM_LABEL_VALUE_VIDEO_DRIVER,
"نظام تشغيل الفيديو"
Expand Down
1 change: 1 addition & 0 deletions intl/msg_hash_ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,7 @@ MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_DRIVER,
"Entrada"
)

MSG_HASH(
MENU_ENUM_LABEL_VALUE_VIDEO_DRIVER,
"Videu"
Expand Down
1 change: 1 addition & 0 deletions intl/msg_hash_be.h
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,7 @@ MSG_HASH(
MENU_ENUM_SUBLABEL_JOYPAD_DRIVER,
"Ужыты драйвер кантролера."
)

MSG_HASH(
MENU_ENUM_LABEL_VALUE_VIDEO_DRIVER,
"Відэа"
Expand Down
1 change: 1 addition & 0 deletions intl/msg_hash_ca.h
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ MSG_HASH(
MENU_ENUM_SUBLABEL_JOYPAD_DRIVER,
"Tipus de comandament de joc que es farà servir."
)

MSG_HASH(
MENU_ENUM_LABEL_VALUE_VIDEO_DRIVER,
"Vídeo"
Expand Down
5 changes: 1 addition & 4 deletions intl/msg_hash_chs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1496,10 +1496,6 @@ MSG_HASH(
MENU_ENUM_SUBLABEL_INPUT_DRIVER,
"使用的输入驱动。某些视频驱动强制使用不同的输入驱动。"
)
MSG_HASH(
MENU_ENUM_LABEL_HELP_INPUT_DRIVER_UDEV,
"Udev 输入设备使用最近的 evdev 手柄 API 来驱动游戏手柄,也支持即插即用和力反馈。\n设备读取 evdev 记录支持当前键盘及按键回滚、鼠标和触摸板。\n大多数发行版默认情况下,/dev/input的节点是root专用的 (模式600) 。您可以设置一个 udev 规则,使非 root 用户可以访问它们。"
)
MSG_HASH(
MENU_ENUM_LABEL_HELP_INPUT_DRIVER_LINUXRAW,
"Linuxraw 输入驱动程序需要一个活动的 TTY。 键盘事件直接从 TTY 读取,从而使其更简单,但不像udev那样灵活。 Mice 等根本不支持。此驱动程序使用旧的游戏杆API(/dev/input/js*)。"
Expand All @@ -1516,6 +1512,7 @@ MSG_HASH(
MENU_ENUM_SUBLABEL_JOYPAD_DRIVER,
"要使用的手柄驱动。"
)

MSG_HASH(
MENU_ENUM_LABEL_VALUE_VIDEO_DRIVER,
"视频"
Expand Down
5 changes: 1 addition & 4 deletions intl/msg_hash_cht.h
Original file line number Diff line number Diff line change
Expand Up @@ -1440,10 +1440,6 @@ MSG_HASH(
MENU_ENUM_SUBLABEL_INPUT_DRIVER,
"設定鍵盤、滑鼠和光線槍等輸入裝置使用的驅動程式, 此選項會依據顯示驅動程式強制變更。"
)
MSG_HASH(
MENU_ENUM_LABEL_HELP_INPUT_DRIVER_UDEV,
"udev輸入驅動程式。\n此驅動程式使用evdev API, 支援熱插拔和力反饋。\n讀取事件驅動程式(evdev)支援鍵盤, 還支援鍵盤回呼、滑鼠和觸控板。\n大多數發行版預設情況下, /dev/input裝置節點僅限root權限使用, 可以設定一個裝置管理員(udev)規則, 用於非root權限時使用。"
)
MSG_HASH(
MENU_ENUM_LABEL_HELP_INPUT_DRIVER_LINUXRAW,
"linuxraw輸入驅動程式。\n需要開啟終端機(TTY)直接從終端機讀取鍵盤事件, 不支援滑鼠輸入不如裝置管理員(udev)操作方便。\n此驅動程式使用joystick API (/dev/input/js*)。"
Expand All @@ -1460,6 +1456,7 @@ MSG_HASH(
MENU_ENUM_SUBLABEL_JOYPAD_DRIVER,
"設定遊戲控制器使用的驅動程式。"
)

MSG_HASH(
MENU_ENUM_LABEL_VALUE_VIDEO_DRIVER,
"顯示"
Expand Down
Loading

0 comments on commit b0cdeba

Please sign in to comment.