Skip to content

Commit

Permalink
Fix all cached media being loaded at once on the main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
grorp authored and sfan5 committed Apr 5, 2024
1 parent a9a0f1e commit b2982a6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/client/client.cpp
Expand Up @@ -1795,6 +1795,11 @@ float Client::mediaReceiveProgress()
return 1.0; // downloader only exists when not yet done
}

void Client::drawLoadScreen(const std::wstring &text, float dtime, int percent) {
m_rendering_engine->run();
m_rendering_engine->draw_load_screen(text, guienv, m_tsrc, dtime, percent);
}

struct TextureUpdateArgs {
gui::IGUIEnvironment *guienv;
u64 last_time_ms;
Expand Down
1 change: 1 addition & 0 deletions src/client/client.h
Expand Up @@ -356,6 +356,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef

float mediaReceiveProgress();

void drawLoadScreen(const std::wstring &text, float dtime, int percent);
void afterContentReceived();
void showUpdateProgressTexture(void *args, u32 progress, u32 max_progress);

Expand Down
13 changes: 13 additions & 0 deletions src/client/clientmedia.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit b2982a6

Please sign in to comment.