mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-24 00:03:11 +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;
|
std::vector<rct_object_entry> _downloadedEntries;
|
||||||
size_t _currentDownloadIndex{};
|
size_t _currentDownloadIndex{};
|
||||||
std::mutex _downloadedEntriesMutex;
|
std::mutex _downloadedEntriesMutex;
|
||||||
|
bool _nextDownloadQueued{};
|
||||||
|
|
||||||
// TODO static due to INTENT_EXTRA_CALLBACK not allowing a std::function
|
// TODO static due to INTENT_EXTRA_CALLBACK not allowing a std::function
|
||||||
inline static bool _downloadingObjects;
|
inline static bool _downloadingObjects;
|
||||||
@@ -44,7 +45,7 @@ public:
|
|||||||
_entries = entries;
|
_entries = entries;
|
||||||
_currentDownloadIndex = 0;
|
_currentDownloadIndex = 0;
|
||||||
_downloadingObjects = true;
|
_downloadingObjects = true;
|
||||||
NextDownload();
|
QueueNextDownload();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsDownloading() const
|
bool IsDownloading() const
|
||||||
@@ -58,6 +59,15 @@ public:
|
|||||||
return _downloadedEntries;
|
return _downloadedEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
if (_nextDownloadQueued)
|
||||||
|
{
|
||||||
|
_nextDownloadQueued = false;
|
||||||
|
NextDownload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void UpdateProgress(const std::string& name, size_t count, size_t total)
|
void UpdateProgress(const std::string& name, size_t count, size_t total)
|
||||||
{
|
{
|
||||||
@@ -75,6 +85,11 @@ private:
|
|||||||
context_open_intent(&intent);
|
context_open_intent(&intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QueueNextDownload()
|
||||||
|
{
|
||||||
|
_nextDownloadQueued = true;
|
||||||
|
}
|
||||||
|
|
||||||
void DownloadObject(const rct_object_entry& entry, const std::string name, const std::string_view url)
|
void DownloadObject(const rct_object_entry& entry, const std::string name, const std::string_view url)
|
||||||
{
|
{
|
||||||
using namespace OpenRCT2::Network;
|
using namespace OpenRCT2::Network;
|
||||||
@@ -103,13 +118,13 @@ private:
|
|||||||
{
|
{
|
||||||
throw std::runtime_error("Non 200 status");
|
throw std::runtime_error("Non 200 status");
|
||||||
}
|
}
|
||||||
NextDownload();
|
QueueNextDownload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (const std::exception&)
|
catch (const std::exception&)
|
||||||
{
|
{
|
||||||
std::printf(" Failed to download %s\n", name.c_str());
|
std::printf(" Failed to download %s\n", name.c_str());
|
||||||
NextDownload();
|
QueueNextDownload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,12 +168,12 @@ private:
|
|||||||
else if (response.status == Http::Status::NotFound)
|
else if (response.status == Http::Status::NotFound)
|
||||||
{
|
{
|
||||||
std::printf(" %s not found\n", name.c_str());
|
std::printf(" %s not found\n", name.c_str());
|
||||||
NextDownload();
|
QueueNextDownload();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::printf(" %s query failed (status %d)\n", name.c_str(), (int32_t)response.status);
|
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
|
#ifndef DISABLE_HTTP
|
||||||
|
_objDownloader.Update();
|
||||||
|
|
||||||
// Remove downloaded objects from our invalid entry list
|
// Remove downloaded objects from our invalid entry list
|
||||||
if (_objDownloader.IsDownloading())
|
if (_objDownloader.IsDownloading())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user