mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-01-18 06:25:37 +00:00
Achievements: Drain outstanding requests when switching games
Stops data being lost when loading state due to data not being downloaded yet.
This commit is contained in:
parent
d9722516c3
commit
aee8163317
|
@ -70,6 +70,12 @@ void HTTPDownloader::CreatePostRequest(std::string url, std::string post_data, R
|
||||||
LockedAddRequest(req);
|
LockedAddRequest(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HTTPDownloader::HasAnyRequests()
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(m_pending_http_request_lock);
|
||||||
|
return !m_pending_http_requests.empty();
|
||||||
|
}
|
||||||
|
|
||||||
void HTTPDownloader::LockedPollRequests(std::unique_lock<std::mutex>& lock)
|
void HTTPDownloader::LockedPollRequests(std::unique_lock<std::mutex>& lock)
|
||||||
{
|
{
|
||||||
if (m_pending_http_requests.empty())
|
if (m_pending_http_requests.empty())
|
||||||
|
|
|
@ -64,6 +64,8 @@ public:
|
||||||
|
|
||||||
void CreateRequest(std::string url, Request::Callback callback);
|
void CreateRequest(std::string url, Request::Callback callback);
|
||||||
void CreatePostRequest(std::string url, std::string post_data, Request::Callback callback);
|
void CreatePostRequest(std::string url, std::string post_data, Request::Callback callback);
|
||||||
|
|
||||||
|
bool HasAnyRequests();
|
||||||
void PollRequests();
|
void PollRequests();
|
||||||
void WaitForAllRequests();
|
void WaitForAllRequests();
|
||||||
|
|
||||||
|
|
|
@ -707,6 +707,14 @@ bool Achievements::DoState(StateWrapper& sw)
|
||||||
|
|
||||||
if (sw.IsReading())
|
if (sw.IsReading())
|
||||||
{
|
{
|
||||||
|
// if we're active, make sure we've downloaded and activated all the achievements
|
||||||
|
// before deserializing, otherwise that state's going to get lost.
|
||||||
|
if (s_http_downloader->HasAnyRequests())
|
||||||
|
{
|
||||||
|
Host::DisplayLoadingScreen("Downloading achievements data...");
|
||||||
|
s_http_downloader->WaitForAllRequests();
|
||||||
|
}
|
||||||
|
|
||||||
u32 data_size = 0;
|
u32 data_size = 0;
|
||||||
sw.Do(&data_size);
|
sw.Do(&data_size);
|
||||||
if (data_size == 0)
|
if (data_size == 0)
|
||||||
|
@ -1321,6 +1329,7 @@ void Achievements::GameChanged(const std::string& path, CDImage* image)
|
||||||
if (!temp_image)
|
if (!temp_image)
|
||||||
{
|
{
|
||||||
Log_ErrorPrintf("Failed to open temporary CD image '%s'", path.c_str());
|
Log_ErrorPrintf("Failed to open temporary CD image '%s'", path.c_str());
|
||||||
|
s_http_downloader->WaitForAllRequests();
|
||||||
std::unique_lock lock(s_achievements_mutex);
|
std::unique_lock lock(s_achievements_mutex);
|
||||||
DisableChallengeMode();
|
DisableChallengeMode();
|
||||||
ClearGameInfo();
|
ClearGameInfo();
|
||||||
|
@ -1341,7 +1350,11 @@ void Achievements::GameChanged(const std::string& path, CDImage* image)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (s_http_downloader->HasAnyRequests())
|
||||||
|
{
|
||||||
|
Host::DisplayLoadingScreen("Downloading achievements data...");
|
||||||
s_http_downloader->WaitForAllRequests();
|
s_http_downloader->WaitForAllRequests();
|
||||||
|
}
|
||||||
|
|
||||||
if (image && image->HasSubImages() && image->GetCurrentSubImage() != 0)
|
if (image && image->HasSubImages() && image->GetCurrentSubImage() != 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue