Leaderboards: Implement missing teardown

This commit is contained in:
Silent 2021-06-19 12:27:47 +02:00
parent bc34a75e03
commit c97aafb79d
No known key found for this signature in database
GPG Key ID: AE53149BB0C45AF1
1 changed files with 40 additions and 17 deletions

View File

@ -181,26 +181,45 @@ static Achievement* GetAchievementByID(u32 id)
return nullptr; return nullptr;
} }
static void ClearGameInfo() static void ClearGameInfo(bool clear_achievements = true, bool clear_leaderboards = true)
{ {
const bool had_game = (g_game_id != 0); const bool had_game = (g_game_id != 0);
s_has_rich_presence = false; if (clear_achievements)
while (!s_achievements.empty())
{ {
Achievement& ach = s_achievements.back(); while (!s_achievements.empty())
DeactivateAchievement(&ach); {
s_achievements.pop_back(); Achievement& ach = s_achievements.back();
DeactivateAchievement(&ach);
s_achievements.pop_back();
}
}
if (clear_leaderboards)
{
while (!s_leaderboards.empty())
{
Leaderboard& lb = s_leaderboards.back();
rc_runtime_deactivate_lboard(&s_rcheevos_runtime, lb.id);
s_leaderboards.pop_back();
}
s_last_queried_lboard = 0;
s_lboard_entries.reset();
} }
std::string().swap(s_game_title); if (s_achievements.empty() && s_leaderboards.empty())
std::string().swap(s_game_developer); {
std::string().swap(s_game_publisher); // Ready to tear down cheevos completely
std::string().swap(s_game_release_date); s_has_rich_presence = false;
std::string().swap(s_game_icon);
s_rich_presence_string.clear(); std::string().swap(s_game_title);
g_game_id = 0; std::string().swap(s_game_developer);
std::string().swap(s_game_publisher);
std::string().swap(s_game_release_date);
std::string().swap(s_game_icon);
s_rich_presence_string.clear();
g_game_id = 0;
}
if (had_game) if (had_game)
GetHostInterface()->OnAchievementsRefreshed(); GetHostInterface()->OnAchievementsRefreshed();
@ -577,7 +596,7 @@ static void GetUserUnlocksCallback(s32 status_code, const FrontendCommon::HTTPDo
rapidjson::Document doc; rapidjson::Document doc;
if (!ParseResponseJSON("Get User Unlocks", status_code, data, doc)) if (!ParseResponseJSON("Get User Unlocks", status_code, data, doc))
{ {
ClearGameInfo(); ClearGameInfo(true, false);
return; return;
} }
@ -586,7 +605,7 @@ static void GetUserUnlocksCallback(s32 status_code, const FrontendCommon::HTTPDo
if (game_id != g_game_id) if (game_id != g_game_id)
{ {
FormattedError("GameID from user unlocks doesn't match (got %u expected %u)", game_id, g_game_id); FormattedError("GameID from user unlocks doesn't match (got %u expected %u)", game_id, g_game_id);
ClearGameInfo(); ClearGameInfo(true, false);
return; return;
} }
@ -779,6 +798,7 @@ static void GetPatchesCallback(s32 status_code, const FrontendCommon::HTTPDownlo
Log_InfoPrintf("Game Developer: %s", s_game_developer.c_str()); Log_InfoPrintf("Game Developer: %s", s_game_developer.c_str());
Log_InfoPrintf("Game Publisher: %s", s_game_publisher.c_str()); Log_InfoPrintf("Game Publisher: %s", s_game_publisher.c_str());
Log_InfoPrintf("Achievements: %zu", s_achievements.size()); Log_InfoPrintf("Achievements: %zu", s_achievements.size());
Log_InfoPrintf("Leaderboards: %zu", s_leaderboards.size());
if (!s_achievements.empty() || s_has_rich_presence) if (!s_achievements.empty() || s_has_rich_presence)
{ {
@ -796,8 +816,11 @@ static void GetPatchesCallback(s32 status_code, const FrontendCommon::HTTPDownlo
else else
{ {
DisplayAchievementSummary(); DisplayAchievementSummary();
}
if (s_achievements.empty() && s_leaderboards.empty() && !s_has_rich_presence)
{
ClearGameInfo(); ClearGameInfo();
return;
} }
} }