1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

Fix all cached media being loaded at once on the main thread

This commit is contained in:
Gregor Parzefall 2024-04-02 09:39:44 +02:00 committed by sfan5
parent a9a0f1e129
commit b2982a6f14
3 changed files with 19 additions and 0 deletions

View file

@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
#include "clientmedia.h"
#include "gettext.h"
#include "httpfetch.h"
#include "client.h"
#include "filecache.h"
@ -184,6 +185,11 @@ void ClientMediaDownloader::step(Client *client)
void ClientMediaDownloader::initialStep(Client *client)
{
std::wstring loading_text = wstrgettext("Media...");
// Tradeoff between responsiveness during media loading and media loading speed
const u64 chunk_time_ms = 33;
u64 last_time = porting::getTimeMs();
// Check media cache
m_uncached_count = m_files.size();
for (auto &file_it : m_files) {
@ -195,6 +201,13 @@ void ClientMediaDownloader::initialStep(Client *client)
filestatus->received = true;
m_uncached_count--;
}
u64 cur_time = porting::getTimeMs();
u64 dtime = porting::getDeltaMs(last_time, cur_time);
if (dtime >= chunk_time_ms) {
client->drawLoadScreen(loading_text, dtime / 1000.0f, 30);
last_time = cur_time;
}
}
assert(m_uncached_received_count == 0);