mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 07:43:01 +01:00
Queue downloads so that they are invoked on UI thread.
This commit is contained in:
committed by
Michael Steenbeek
parent
473ce29cb3
commit
c479ada2ca
@@ -34,6 +34,7 @@ private:
|
||||
std::vector<rct_object_entry> _downloadedEntries;
|
||||
size_t _currentDownloadIndex{};
|
||||
std::mutex _downloadedEntriesMutex;
|
||||
bool _nextDownloadQueued{};
|
||||
|
||||
// TODO static due to INTENT_EXTRA_CALLBACK not allowing a std::function
|
||||
inline static bool _downloadingObjects;
|
||||
@@ -44,7 +45,7 @@ public:
|
||||
_entries = entries;
|
||||
_currentDownloadIndex = 0;
|
||||
_downloadingObjects = true;
|
||||
NextDownload();
|
||||
QueueNextDownload();
|
||||
}
|
||||
|
||||
bool IsDownloading() const
|
||||
@@ -58,6 +59,15 @@ public:
|
||||
return _downloadedEntries;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (_nextDownloadQueued)
|
||||
{
|
||||
_nextDownloadQueued = false;
|
||||
NextDownload();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void UpdateProgress(const std::string& name, size_t count, size_t total)
|
||||
{
|
||||
@@ -75,6 +85,11 @@ private:
|
||||
context_open_intent(&intent);
|
||||
}
|
||||
|
||||
void QueueNextDownload()
|
||||
{
|
||||
_nextDownloadQueued = true;
|
||||
}
|
||||
|
||||
void DownloadObject(const rct_object_entry& entry, const std::string name, const std::string_view url)
|
||||
{
|
||||
using namespace OpenRCT2::Network;
|
||||
@@ -103,13 +118,13 @@ private:
|
||||
{
|
||||
throw std::runtime_error("Non 200 status");
|
||||
}
|
||||
NextDownload();
|
||||
QueueNextDownload();
|
||||
});
|
||||
}
|
||||
catch (const std::exception&)
|
||||
{
|
||||
std::printf(" Failed to download %s\n", name.c_str());
|
||||
NextDownload();
|
||||
QueueNextDownload();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,12 +168,12 @@ private:
|
||||
else if (response.status == Http::Status::NotFound)
|
||||
{
|
||||
std::printf(" %s not found\n", name.c_str());
|
||||
NextDownload();
|
||||
QueueNextDownload();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::printf(" %s query failed (status %d)\n", name.c_str(), (int32_t)response.status);
|
||||
NextDownload();
|
||||
QueueNextDownload();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -393,6 +408,8 @@ static void window_object_load_error_update(rct_window* w)
|
||||
}
|
||||
|
||||
#ifndef DISABLE_HTTP
|
||||
_objDownloader.Update();
|
||||
|
||||
// Remove downloaded objects from our invalid entry list
|
||||
if (_objDownloader.IsDownloading())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user