From bbf0346efde3eea645ec672a7a1f5ddc69846969 Mon Sep 17 00:00:00 2001 From: Silent Date: Sat, 29 Jul 2023 18:56:38 +0200 Subject: [PATCH] Achievements: Fix Leaderboard submission UI when multiple leaderboards update at once --- src/frontend-common/achievements.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/frontend-common/achievements.cpp b/src/frontend-common/achievements.cpp index 940f039afe..5f61aed0b8 100644 --- a/src/frontend-common/achievements.cpp +++ b/src/frontend-common/achievements.cpp @@ -104,7 +104,7 @@ static void SendPingCallback(s32 status_code, std::string content_type, Common:: static void UnlockAchievementCallback(s32 status_code, std::string content_type, Common::HTTPDownloader::Request::Data data); static void SubmitLeaderboardCallback(s32 status_code, std::string content_type, - Common::HTTPDownloader::Request::Data data); + Common::HTTPDownloader::Request::Data data, u32 lboard_id); static bool s_active = false; static bool s_logged_in = false; @@ -137,7 +137,6 @@ static std::string s_rich_presence_string; static Common::Timer s_last_ping_time; static u32 s_last_queried_lboard = 0; -static u32 s_submitting_lboard_id = 0; static std::optional> s_lboard_entries; template @@ -356,7 +355,6 @@ void Achievements::ClearGameInfo(bool clear_achievements, bool clear_leaderboard } s_last_queried_lboard = 0; - s_submitting_lboard_id = 0; s_lboard_entries.reset(); } @@ -1741,7 +1739,7 @@ void Achievements::UnlockAchievementCallback(s32 status_code, std::string conten } void Achievements::SubmitLeaderboardCallback(s32 status_code, std::string content_type, - Common::HTTPDownloader::Request::Data data) + Common::HTTPDownloader::Request::Data data, u32 lboard_id) { if (!System::IsValid()) return; @@ -1755,11 +1753,7 @@ void Achievements::SubmitLeaderboardCallback(s32 status_code, std::string conten // Force the next leaderboard query to repopulate everything, just in case the user wants to see their new score s_last_queried_lboard = 0; - // RA API doesn't send us the leaderboard ID back.. hopefully we don't submit two at once :/ - if (s_submitting_lboard_id == 0) - return; - - const Leaderboard* lb = GetLeaderboardByID(std::exchange(s_submitting_lboard_id, 0u)); + const Leaderboard* lb = GetLeaderboardByID(lboard_id); if (!lb || !FullscreenUI::IsInitialized() || !g_settings.achievements_notifications) return; @@ -1870,17 +1864,16 @@ void Achievements::SubmitLeaderboard(u32 leaderboard_id, int value) return; } - std::unique_lock lock(s_achievements_mutex); - - s_submitting_lboard_id = leaderboard_id; - RAPIRequest request; request.username = s_username.c_str(); request.api_token = s_api_token.c_str(); request.game_hash = s_game_hash.c_str(); request.leaderboard_id = leaderboard_id; request.score = value; - request.Send(SubmitLeaderboardCallback); + request.Send( + [leaderboard_id](s32 status_code, const std::string& content_type, Common::HTTPDownloader::Request::Data data) { + SubmitLeaderboardCallback(status_code, content_type, std::move(data), leaderboard_id); + }); } void Achievements::AchievementPrimed(u32 achievement_id)