mirror of
https://github.com/minetest/minetest.git
synced 2024-08-19 21:14:15 +02:00
Fix all cached media being loaded at once on the main thread
This commit is contained in:
parent
a9a0f1e129
commit
b2982a6f14
@ -1795,6 +1795,11 @@ float Client::mediaReceiveProgress()
|
|||||||
return 1.0; // downloader only exists when not yet done
|
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 {
|
struct TextureUpdateArgs {
|
||||||
gui::IGUIEnvironment *guienv;
|
gui::IGUIEnvironment *guienv;
|
||||||
u64 last_time_ms;
|
u64 last_time_ms;
|
||||||
|
@ -356,6 +356,7 @@ public:
|
|||||||
|
|
||||||
float mediaReceiveProgress();
|
float mediaReceiveProgress();
|
||||||
|
|
||||||
|
void drawLoadScreen(const std::wstring &text, float dtime, int percent);
|
||||||
void afterContentReceived();
|
void afterContentReceived();
|
||||||
void showUpdateProgressTexture(void *args, u32 progress, u32 max_progress);
|
void showUpdateProgressTexture(void *args, u32 progress, u32 max_progress);
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "clientmedia.h"
|
#include "clientmedia.h"
|
||||||
|
#include "gettext.h"
|
||||||
#include "httpfetch.h"
|
#include "httpfetch.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "filecache.h"
|
#include "filecache.h"
|
||||||
@ -184,6 +185,11 @@ void ClientMediaDownloader::step(Client *client)
|
|||||||
|
|
||||||
void ClientMediaDownloader::initialStep(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
|
// Check media cache
|
||||||
m_uncached_count = m_files.size();
|
m_uncached_count = m_files.size();
|
||||||
for (auto &file_it : m_files) {
|
for (auto &file_it : m_files) {
|
||||||
@ -195,6 +201,13 @@ void ClientMediaDownloader::initialStep(Client *client)
|
|||||||
filestatus->received = true;
|
filestatus->received = true;
|
||||||
m_uncached_count--;
|
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);
|
assert(m_uncached_received_count == 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user